colorspace.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 <stdlib.h>
  23. #include <inttypes.h>
  24. #include "libavutil/mem.h"
  25. #include "libswscale/swscale.h"
  26. #include "libswscale/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 = av_malloc(SIZE);
  35. uint8_t *dstBuffer = 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. ff_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, rgb12to15),
  50. FUNC(2, 2, rgb15to16),
  51. FUNC(2, 3, rgb15to24),
  52. FUNC(2, 4, rgb15to32),
  53. FUNC(2, 3, rgb16to24),
  54. FUNC(2, 4, rgb16to32),
  55. FUNC(3, 2, rgb24to15),
  56. FUNC(3, 2, rgb24to16),
  57. FUNC(3, 4, rgb24to32),
  58. FUNC(4, 2, rgb32to15),
  59. FUNC(4, 2, rgb32to16),
  60. FUNC(4, 3, rgb32to24),
  61. FUNC(2, 2, rgb16to15),
  62. FUNC(2, 2, rgb12tobgr12),
  63. FUNC(2, 2, rgb15tobgr15),
  64. FUNC(2, 2, rgb15tobgr16),
  65. FUNC(2, 3, rgb15tobgr24),
  66. FUNC(2, 4, rgb15tobgr32),
  67. FUNC(2, 2, rgb16tobgr15),
  68. FUNC(2, 2, rgb16tobgr16),
  69. FUNC(2, 3, rgb16tobgr24),
  70. FUNC(2, 4, rgb16tobgr32),
  71. FUNC(3, 2, rgb24tobgr15),
  72. FUNC(3, 2, rgb24tobgr16),
  73. FUNC(3, 3, rgb24tobgr24),
  74. FUNC(3, 4, rgb24tobgr32),
  75. FUNC(4, 2, rgb32tobgr15),
  76. FUNC(4, 2, rgb32tobgr16),
  77. FUNC(4, 3, rgb32tobgr24),
  78. FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
  79. FUNC(6, 6, rgb48tobgr48_nobswap),
  80. FUNC(6, 6, rgb48tobgr48_bswap),
  81. FUNC(8, 6, rgb64to48_nobswap),
  82. FUNC(8, 6, rgb64to48_bswap),
  83. FUNC(8, 6, rgb64tobgr48_nobswap),
  84. FUNC(8, 6, rgb64tobgr48_bswap),
  85. FUNC(0, 0, NULL)
  86. };
  87. int width;
  88. int failed = 0;
  89. int srcBpp = 0;
  90. int dstBpp = 0;
  91. if (!func_info[funcNum].func)
  92. break;
  93. av_log(NULL, AV_LOG_INFO, ".");
  94. memset(srcBuffer, srcByte, SIZE);
  95. for (width = 63; width > 0; width--) {
  96. int dstOffset;
  97. for (dstOffset = 128; dstOffset < 196; dstOffset += 4) {
  98. int srcOffset;
  99. memset(dstBuffer, dstByte, SIZE);
  100. for (srcOffset = 128; srcOffset < 196; srcOffset += 4) {
  101. uint8_t *src = srcBuffer + srcOffset;
  102. uint8_t *dst = dstBuffer + dstOffset;
  103. const char *name = NULL;
  104. // don't fill the screen with shit ...
  105. if (failed)
  106. break;
  107. srcBpp = func_info[funcNum].src_bpp;
  108. dstBpp = func_info[funcNum].dst_bpp;
  109. name = func_info[funcNum].name;
  110. func_info[funcNum].func(src, dst, width * srcBpp);
  111. if (!srcBpp)
  112. break;
  113. for (i = 0; i < SIZE; i++) {
  114. if (srcBuffer[i] != srcByte) {
  115. av_log(NULL, AV_LOG_INFO,
  116. "src damaged at %d w:%d src:%d dst:%d %s\n",
  117. i, width, srcOffset, dstOffset, name);
  118. failed = 1;
  119. break;
  120. }
  121. }
  122. for (i = 0; i < dstOffset; i++) {
  123. if (dstBuffer[i] != dstByte) {
  124. av_log(NULL, AV_LOG_INFO,
  125. "dst damaged at %d w:%d src:%d dst:%d %s\n",
  126. i, width, srcOffset, dstOffset, name);
  127. failed = 1;
  128. break;
  129. }
  130. }
  131. for (i = dstOffset + width * dstBpp; i < SIZE; i++) {
  132. if (dstBuffer[i] != dstByte) {
  133. av_log(NULL, AV_LOG_INFO,
  134. "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. }
  141. }
  142. }
  143. if (failed)
  144. failedNum++;
  145. else if (srcBpp)
  146. passedNum++;
  147. }
  148. av_log(NULL, AV_LOG_INFO,
  149. "\n%d converters passed, %d converters randomly overwrote memory\n",
  150. passedNum, failedNum);
  151. return failedNum;
  152. }