colorspace-test.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdio.h>
  21. #include <string.h> /* for memset() */
  22. #include <unistd.h>
  23. #include <stdlib.h>
  24. #include <inttypes.h>
  25. #include "swscale.h"
  26. #include "rgb2rgb.h"
  27. #define SIZE 1000
  28. #define srcByte 0x55
  29. #define dstByte 0xBB
  30. #define FUNC(s,d,n) {s,d,#n,n}
  31. int main(int argc, char **argv)
  32. {
  33. int i, funcNum;
  34. uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
  35. uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
  36. int failedNum=0;
  37. int passedNum=0;
  38. if (!srcBuffer || !dstBuffer)
  39. return -1;
  40. av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
  41. sws_rgb2rgb_init();
  42. for(funcNum=0; ; funcNum++) {
  43. struct func_info_s {
  44. int src_bpp;
  45. int dst_bpp;
  46. const char *name;
  47. void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
  48. } func_info[] = {
  49. FUNC(2, 2, rgb15to16),
  50. FUNC(2, 3, rgb15to24),
  51. FUNC(2, 4, rgb15to32),
  52. FUNC(2, 3, rgb16to24),
  53. FUNC(2, 4, rgb16to32),
  54. FUNC(3, 2, rgb24to15),
  55. FUNC(3, 2, rgb24to16),
  56. FUNC(3, 4, rgb24to32),
  57. FUNC(4, 2, rgb32to15),
  58. FUNC(4, 2, rgb32to16),
  59. FUNC(4, 3, rgb32to24),
  60. FUNC(2, 2, rgb16to15),
  61. FUNC(2, 2, rgb15tobgr15),
  62. FUNC(2, 2, rgb15tobgr16),
  63. FUNC(2, 3, rgb15tobgr24),
  64. FUNC(2, 4, rgb15tobgr32),
  65. FUNC(2, 2, rgb16tobgr15),
  66. FUNC(2, 2, rgb16tobgr16),
  67. FUNC(2, 3, rgb16tobgr24),
  68. FUNC(2, 4, rgb16tobgr32),
  69. FUNC(3, 2, rgb24tobgr15),
  70. FUNC(3, 2, rgb24tobgr16),
  71. FUNC(3, 3, rgb24tobgr24),
  72. FUNC(3, 4, rgb24tobgr32),
  73. FUNC(4, 2, rgb32tobgr15),
  74. FUNC(4, 2, rgb32tobgr16),
  75. FUNC(4, 3, rgb32tobgr24),
  76. FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
  77. FUNC(0, 0, NULL)
  78. };
  79. int width;
  80. int failed=0;
  81. int srcBpp=0;
  82. int dstBpp=0;
  83. if (!func_info[funcNum].func) break;
  84. av_log(NULL, AV_LOG_INFO,".");
  85. memset(srcBuffer, srcByte, SIZE);
  86. for(width=63; width>0; width--) {
  87. int dstOffset;
  88. for(dstOffset=128; dstOffset<196; dstOffset+=4) {
  89. int srcOffset;
  90. memset(dstBuffer, dstByte, SIZE);
  91. for(srcOffset=128; srcOffset<196; srcOffset+=4) {
  92. uint8_t *src= srcBuffer+srcOffset;
  93. uint8_t *dst= dstBuffer+dstOffset;
  94. const char *name=NULL;
  95. if(failed) break; //don't fill the screen with shit ...
  96. srcBpp = func_info[funcNum].src_bpp;
  97. dstBpp = func_info[funcNum].dst_bpp;
  98. name = func_info[funcNum].name;
  99. func_info[funcNum].func(src, dst, width*srcBpp);
  100. if(!srcBpp) break;
  101. for(i=0; i<SIZE; i++) {
  102. if(srcBuffer[i]!=srcByte) {
  103. av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
  104. i, width, srcOffset, dstOffset, name);
  105. failed=1;
  106. break;
  107. }
  108. }
  109. for(i=0; i<dstOffset; i++) {
  110. if(dstBuffer[i]!=dstByte) {
  111. av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
  112. i, width, srcOffset, dstOffset, name);
  113. failed=1;
  114. break;
  115. }
  116. }
  117. for(i=dstOffset + width*dstBpp; i<SIZE; i++) {
  118. if(dstBuffer[i]!=dstByte) {
  119. av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
  120. i, width, srcOffset, dstOffset, name);
  121. failed=1;
  122. break;
  123. }
  124. }
  125. }
  126. }
  127. }
  128. if(failed) failedNum++;
  129. else if(srcBpp) passedNum++;
  130. }
  131. av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
  132. return failedNum;
  133. }