You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.6KB

  1. /*
  2. *
  3. * This file is part of FFmpeg.
  4. *
  5. * FFmpeg is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * FFmpeg is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #include <string.h>
  20. #include "libavutil/common.h"
  21. #include "libavutil/intreadwrite.h"
  22. #include "libavutil/mem.h"
  23. #include "libswscale/swscale.h"
  24. #include "libswscale/swscale_internal.h"
  25. #include "checkasm.h"
  26. #define randomize_buffers(buf, size) \
  27. do { \
  28. int j; \
  29. for (j = 0; j < size; j+=4) \
  30. AV_WN32(buf + j, rnd()); \
  31. } while (0)
  32. #define SRC_PIXELS 128
  33. static void check_hscale(void)
  34. {
  35. #define MAX_FILTER_WIDTH 40
  36. #define FILTER_SIZES 5
  37. static const int filter_sizes[FILTER_SIZES] = { 4, 8, 16, 32, 40 };
  38. #define HSCALE_PAIRS 2
  39. static const int hscale_pairs[HSCALE_PAIRS][2] = {
  40. { 8, 14 },
  41. { 8, 18 },
  42. };
  43. int i, j, fsi, hpi, width;
  44. struct SwsContext *ctx;
  45. // padded
  46. LOCAL_ALIGNED_32(uint8_t, src, [FFALIGN(SRC_PIXELS + MAX_FILTER_WIDTH - 1, 4)]);
  47. LOCAL_ALIGNED_32(uint32_t, dst0, [SRC_PIXELS]);
  48. LOCAL_ALIGNED_32(uint32_t, dst1, [SRC_PIXELS]);
  49. // padded
  50. LOCAL_ALIGNED_32(int16_t, filter, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]);
  51. LOCAL_ALIGNED_32(int32_t, filterPos, [SRC_PIXELS]);
  52. // The dst parameter here is either int16_t or int32_t but we use void* to
  53. // just cover both cases.
  54. declare_func_emms(AV_CPU_FLAG_MMX, void, void *c, void *dst, int dstW,
  55. const uint8_t *src, const int16_t *filter,
  56. const int32_t *filterPos, int filterSize);
  57. ctx = sws_alloc_context();
  58. if (sws_init_context(ctx, NULL, NULL) < 0)
  59. fail();
  60. randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1);
  61. for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) {
  62. for (fsi = 0; fsi < FILTER_SIZES; fsi++) {
  63. width = filter_sizes[fsi];
  64. ctx->srcBpc = hscale_pairs[hpi][0];
  65. ctx->dstBpc = hscale_pairs[hpi][1];
  66. ctx->hLumFilterSize = ctx->hChrFilterSize = width;
  67. for (i = 0; i < SRC_PIXELS; i++) {
  68. filterPos[i] = i;
  69. // These filter cofficients are chosen to try break two corner
  70. // cases, namely:
  71. //
  72. // - Negative filter coefficients. The filters output signed
  73. // values, and it should be possible to end up with negative
  74. // output values.
  75. //
  76. // - Positive clipping. The hscale filter function has clipping
  77. // at (1<<15) - 1
  78. //
  79. // The coefficients sum to the 1.0 point for the hscale
  80. // functions (1 << 14).
  81. for (j = 0; j < width; j++) {
  82. filter[i * width + j] = -((1 << 14) / (width - 1));
  83. }
  84. filter[i * width + (rnd() % width)] = ((1 << 15) - 1);
  85. }
  86. for (i = 0; i < MAX_FILTER_WIDTH; i++) {
  87. // These values should be unused in SIMD implementations but
  88. // may still be read, random coefficients here should help show
  89. // issues where they are used in error.
  90. filter[SRC_PIXELS * width + i] = rnd();
  91. }
  92. ff_getSwsFunc(ctx);
  93. if (check_func(ctx->hcScale, "hscale_%d_to_%d_width%d", ctx->srcBpc, ctx->dstBpc + 1, width)) {
  94. memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0]));
  95. memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0]));
  96. call_ref(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width);
  97. call_new(NULL, dst1, SRC_PIXELS, src, filter, filterPos, width);
  98. if (memcmp(dst0, dst1, SRC_PIXELS * sizeof(dst0[0])))
  99. fail();
  100. bench_new(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width);
  101. }
  102. }
  103. }
  104. sws_freeContext(ctx);
  105. }
  106. void checkasm_check_sw_scale(void)
  107. {
  108. check_hscale();
  109. report("hscale");
  110. }