colorspace-test.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. static int cpu_caps;
  32. static char *args_parse(int argc, char *argv[])
  33. {
  34. int o;
  35. while ((o = getopt(argc, argv, "m23")) != -1) {
  36. switch (o) {
  37. case 'm':
  38. cpu_caps |= SWS_CPU_CAPS_MMX;
  39. break;
  40. case '2':
  41. cpu_caps |= SWS_CPU_CAPS_MMX2;
  42. break;
  43. case '3':
  44. cpu_caps |= SWS_CPU_CAPS_3DNOW;
  45. break;
  46. default:
  47. av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o);
  48. }
  49. }
  50. return argv[optind];
  51. }
  52. int main(int argc, char **argv)
  53. {
  54. int i, funcNum;
  55. uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
  56. uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
  57. int failedNum=0;
  58. int passedNum=0;
  59. if (!srcBuffer || !dstBuffer)
  60. return -1;
  61. av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
  62. args_parse(argc, argv);
  63. av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps);
  64. sws_rgb2rgb_init(cpu_caps);
  65. for(funcNum=0; ; funcNum++) {
  66. struct func_info_s {
  67. int src_bpp;
  68. int dst_bpp;
  69. const char *name;
  70. void (*func)(const uint8_t *src, uint8_t *dst, long src_size);
  71. } func_info[] = {
  72. FUNC(2, 2, rgb15to16),
  73. FUNC(2, 3, rgb15to24),
  74. FUNC(2, 4, rgb15to32),
  75. FUNC(2, 3, rgb16to24),
  76. FUNC(2, 4, rgb16to32),
  77. FUNC(3, 2, rgb24to15),
  78. FUNC(3, 2, rgb24to16),
  79. FUNC(3, 4, rgb24to32),
  80. FUNC(4, 2, rgb32to15),
  81. FUNC(4, 2, rgb32to16),
  82. FUNC(4, 3, rgb32to24),
  83. FUNC(2, 2, rgb16to15),
  84. FUNC(2, 2, rgb15tobgr15),
  85. FUNC(2, 2, rgb15tobgr16),
  86. FUNC(2, 3, rgb15tobgr24),
  87. FUNC(2, 4, rgb15tobgr32),
  88. FUNC(2, 2, rgb16tobgr15),
  89. FUNC(2, 2, rgb16tobgr16),
  90. FUNC(2, 3, rgb16tobgr24),
  91. FUNC(2, 4, rgb16tobgr32),
  92. FUNC(3, 2, rgb24tobgr15),
  93. FUNC(3, 2, rgb24tobgr16),
  94. FUNC(3, 3, rgb24tobgr24),
  95. FUNC(3, 4, rgb24tobgr32),
  96. FUNC(4, 2, rgb32tobgr15),
  97. FUNC(4, 2, rgb32tobgr16),
  98. FUNC(4, 3, rgb32tobgr24),
  99. FUNC(4, 4, rgb32tobgr32),
  100. FUNC(0, 0, NULL)
  101. };
  102. int width;
  103. int failed=0;
  104. int srcBpp=0;
  105. int dstBpp=0;
  106. if (!func_info[funcNum].func) break;
  107. av_log(NULL, AV_LOG_INFO,".");
  108. memset(srcBuffer, srcByte, SIZE);
  109. for(width=63; width>0; width--) {
  110. int dstOffset;
  111. for(dstOffset=128; dstOffset<196; dstOffset+=4) {
  112. int srcOffset;
  113. memset(dstBuffer, dstByte, SIZE);
  114. for(srcOffset=128; srcOffset<196; srcOffset+=4) {
  115. uint8_t *src= srcBuffer+srcOffset;
  116. uint8_t *dst= dstBuffer+dstOffset;
  117. const char *name=NULL;
  118. if(failed) break; //don't fill the screen with shit ...
  119. srcBpp = func_info[funcNum].src_bpp;
  120. dstBpp = func_info[funcNum].dst_bpp;
  121. name = func_info[funcNum].name;
  122. func_info[funcNum].func(src, dst, width*srcBpp);
  123. if(!srcBpp) break;
  124. for(i=0; i<SIZE; i++) {
  125. if(srcBuffer[i]!=srcByte) {
  126. av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
  127. i, width, srcOffset, dstOffset, name);
  128. failed=1;
  129. break;
  130. }
  131. }
  132. for(i=0; i<dstOffset; i++) {
  133. if(dstBuffer[i]!=dstByte) {
  134. av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
  135. i, width, srcOffset, dstOffset, name);
  136. failed=1;
  137. break;
  138. }
  139. }
  140. for(i=dstOffset + width*dstBpp; i<SIZE; i++) {
  141. if(dstBuffer[i]!=dstByte) {
  142. av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
  143. i, width, srcOffset, dstOffset, name);
  144. failed=1;
  145. break;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. if(failed) failedNum++;
  152. else if(srcBpp) passedNum++;
  153. }
  154. av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
  155. return failedNum;
  156. }