sw_range_convert.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <string.h>
  19. #include "libavutil/common.h"
  20. #include "libavutil/intreadwrite.h"
  21. #include "libavutil/mem.h"
  22. #include "libavutil/mem_internal.h"
  23. #include "libswscale/swscale.h"
  24. #include "libswscale/swscale_internal.h"
  25. #include "checkasm.h"
  26. static void check_lumConvertRange(int from)
  27. {
  28. const char *func_str = from ? "lumRangeFromJpeg" : "lumRangeToJpeg";
  29. #define LARGEST_INPUT_SIZE 512
  30. #define INPUT_SIZES 6
  31. static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
  32. struct SwsContext *ctx;
  33. LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE]);
  34. LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE]);
  35. declare_func(void, int16_t *dst, int width);
  36. ctx = sws_alloc_context();
  37. if (sws_init_context(ctx, NULL, NULL) < 0)
  38. fail();
  39. ctx->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P;
  40. ctx->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
  41. ctx->srcRange = from;
  42. ctx->dstRange = !from;
  43. for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) {
  44. int width = input_sizes[dstWi];
  45. for (int i = 0; i < width; i++) {
  46. uint8_t r = rnd();
  47. dst0[i] = (int16_t) r << 7;
  48. dst1[i] = (int16_t) r << 7;
  49. }
  50. ff_sws_init_scale(ctx);
  51. if (check_func(ctx->lumConvertRange, "%s_%d", func_str, width)) {
  52. call_ref(dst0, width);
  53. call_new(dst1, width);
  54. if (memcmp(dst0, dst1, width * sizeof(int16_t)))
  55. fail();
  56. bench_new(dst1, width);
  57. }
  58. }
  59. sws_freeContext(ctx);
  60. }
  61. #undef LARGEST_INPUT_SIZE
  62. #undef INPUT_SIZES
  63. static void check_chrConvertRange(int from)
  64. {
  65. const char *func_str = from ? "chrRangeFromJpeg" : "chrRangeToJpeg";
  66. #define LARGEST_INPUT_SIZE 512
  67. #define INPUT_SIZES 6
  68. static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
  69. struct SwsContext *ctx;
  70. LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE]);
  71. LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE]);
  72. LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE]);
  73. LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE]);
  74. declare_func(void, int16_t *dstU, int16_t *dstV, int width);
  75. ctx = sws_alloc_context();
  76. if (sws_init_context(ctx, NULL, NULL) < 0)
  77. fail();
  78. ctx->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P;
  79. ctx->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
  80. ctx->srcRange = from;
  81. ctx->dstRange = !from;
  82. for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) {
  83. int width = input_sizes[dstWi];
  84. for (int i = 0; i < width; i++) {
  85. uint8_t r = rnd();
  86. dstU0[i] = (int16_t) r << 7;
  87. dstV0[i] = (int16_t) r << 7;
  88. dstU1[i] = (int16_t) r << 7;
  89. dstV1[i] = (int16_t) r << 7;
  90. }
  91. ff_sws_init_scale(ctx);
  92. if (check_func(ctx->chrConvertRange, "%s_%d", func_str, width)) {
  93. call_ref(dstU0, dstV0, width);
  94. call_new(dstU1, dstV1, width);
  95. if (memcmp(dstU0, dstU1, width * sizeof(int16_t)) ||
  96. memcmp(dstV0, dstV1, width * sizeof(int16_t)))
  97. fail();
  98. bench_new(dstU1, dstV1, width);
  99. }
  100. }
  101. sws_freeContext(ctx);
  102. }
  103. #undef LARGEST_INPUT_SIZE
  104. #undef INPUT_SIZES
  105. void checkasm_check_sw_range_convert(void)
  106. {
  107. check_lumConvertRange(1);
  108. report("lumRangeFromJpeg");
  109. check_chrConvertRange(1);
  110. report("chrRangeFromJpeg");
  111. check_lumConvertRange(0);
  112. report("lumRangeToJpeg");
  113. check_chrConvertRange(0);
  114. report("chrRangeToJpeg");
  115. }