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.

136 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 "libavutil/mem_internal.h"
  24. #include "libswscale/swscale.h"
  25. #include "libswscale/swscale_internal.h"
  26. #include "checkasm.h"
  27. #define randomize_buffers(buf, size) \
  28. do { \
  29. int j; \
  30. for (j = 0; j < size; j+=4) \
  31. AV_WN32(buf + j, rnd()); \
  32. } while (0)
  33. #define SRC_PIXELS 128
  34. static void check_hscale(void)
  35. {
  36. #define MAX_FILTER_WIDTH 40
  37. #define FILTER_SIZES 5
  38. static const int filter_sizes[FILTER_SIZES] = { 4, 8, 16, 32, 40 };
  39. #define HSCALE_PAIRS 2
  40. static const int hscale_pairs[HSCALE_PAIRS][2] = {
  41. { 8, 14 },
  42. { 8, 18 },
  43. };
  44. int i, j, fsi, hpi, width;
  45. struct SwsContext *ctx;
  46. // padded
  47. LOCAL_ALIGNED_32(uint8_t, src, [FFALIGN(SRC_PIXELS + MAX_FILTER_WIDTH - 1, 4)]);
  48. LOCAL_ALIGNED_32(uint32_t, dst0, [SRC_PIXELS]);
  49. LOCAL_ALIGNED_32(uint32_t, dst1, [SRC_PIXELS]);
  50. // padded
  51. LOCAL_ALIGNED_32(int16_t, filter, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]);
  52. LOCAL_ALIGNED_32(int32_t, filterPos, [SRC_PIXELS]);
  53. // The dst parameter here is either int16_t or int32_t but we use void* to
  54. // just cover both cases.
  55. declare_func_emms(AV_CPU_FLAG_MMX, void, void *c, void *dst, int dstW,
  56. const uint8_t *src, const int16_t *filter,
  57. const int32_t *filterPos, int filterSize);
  58. ctx = sws_alloc_context();
  59. if (sws_init_context(ctx, NULL, NULL) < 0)
  60. fail();
  61. randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1);
  62. for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) {
  63. for (fsi = 0; fsi < FILTER_SIZES; fsi++) {
  64. width = filter_sizes[fsi];
  65. ctx->srcBpc = hscale_pairs[hpi][0];
  66. ctx->dstBpc = hscale_pairs[hpi][1];
  67. ctx->hLumFilterSize = ctx->hChrFilterSize = width;
  68. for (i = 0; i < SRC_PIXELS; i++) {
  69. filterPos[i] = i;
  70. // These filter cofficients are chosen to try break two corner
  71. // cases, namely:
  72. //
  73. // - Negative filter coefficients. The filters output signed
  74. // values, and it should be possible to end up with negative
  75. // output values.
  76. //
  77. // - Positive clipping. The hscale filter function has clipping
  78. // at (1<<15) - 1
  79. //
  80. // The coefficients sum to the 1.0 point for the hscale
  81. // functions (1 << 14).
  82. for (j = 0; j < width; j++) {
  83. filter[i * width + j] = -((1 << 14) / (width - 1));
  84. }
  85. filter[i * width + (rnd() % width)] = ((1 << 15) - 1);
  86. }
  87. for (i = 0; i < MAX_FILTER_WIDTH; i++) {
  88. // These values should be unused in SIMD implementations but
  89. // may still be read, random coefficients here should help show
  90. // issues where they are used in error.
  91. filter[SRC_PIXELS * width + i] = rnd();
  92. }
  93. ff_getSwsFunc(ctx);
  94. if (check_func(ctx->hcScale, "hscale_%d_to_%d_width%d", ctx->srcBpc, ctx->dstBpc + 1, width)) {
  95. memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0]));
  96. memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0]));
  97. call_ref(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width);
  98. call_new(NULL, dst1, SRC_PIXELS, src, filter, filterPos, width);
  99. if (memcmp(dst0, dst1, SRC_PIXELS * sizeof(dst0[0])))
  100. fail();
  101. bench_new(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width);
  102. }
  103. }
  104. }
  105. sws_freeContext(ctx);
  106. }
  107. void checkasm_check_sw_scale(void)
  108. {
  109. check_hscale();
  110. report("hscale");
  111. }