3 * This file is part of FFmpeg.
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.
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.
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.
22 #include "libavutil/common.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem.h"
26 #include "libswscale/swscale.h"
27 #include "libswscale/swscale_internal.h"
31 #define randomize_buffers(buf, size) \
34 for (j = 0; j < size; j+=4) \
35 AV_WN32(buf + j, rnd()); \
38 #define SRC_PIXELS 128
40 static void check_hscale(void)
42 #define MAX_FILTER_WIDTH 40
43 #define FILTER_SIZES 5
44 static const int filter_sizes[FILTER_SIZES] = { 4, 8, 16, 32, 40 };
46 #define HSCALE_PAIRS 2
47 static const int hscale_pairs[HSCALE_PAIRS][2] = {
52 int i, j, fsi, hpi, width;
53 struct SwsContext *ctx;
56 LOCAL_ALIGNED_32(uint8_t, src, [FFALIGN(SRC_PIXELS + MAX_FILTER_WIDTH - 1, 4)]);
57 LOCAL_ALIGNED_32(uint32_t, dst0, [SRC_PIXELS]);
58 LOCAL_ALIGNED_32(uint32_t, dst1, [SRC_PIXELS]);
61 LOCAL_ALIGNED_32(int16_t, filter, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]);
62 LOCAL_ALIGNED_32(int32_t, filterPos, [SRC_PIXELS]);
64 // The dst parameter here is either int16_t or int32_t but we use void* to
65 // just cover both cases.
66 declare_func_emms(AV_CPU_FLAG_MMX, void, void *c, void *dst, int dstW,
67 const uint8_t *src, const int16_t *filter,
68 const int32_t *filterPos, int filterSize);
70 ctx = sws_alloc_context();
71 if (sws_init_context(ctx, NULL, NULL) < 0)
74 randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1);
76 for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) {
77 for (fsi = 0; fsi < FILTER_SIZES; fsi++) {
78 width = filter_sizes[fsi];
80 ctx->srcBpc = hscale_pairs[hpi][0];
81 ctx->dstBpc = hscale_pairs[hpi][1];
82 ctx->hLumFilterSize = ctx->hChrFilterSize = width;
84 for (i = 0; i < SRC_PIXELS; i++) {
87 // These filter cofficients are chosen to try break two corner
90 // - Negative filter coefficients. The filters output signed
91 // values, and it should be possible to end up with negative
94 // - Positive clipping. The hscale filter function has clipping
97 // The coefficients sum to the 1.0 point for the hscale
98 // functions (1 << 14).
100 for (j = 0; j < width; j++) {
101 filter[i * width + j] = -((1 << 14) / (width - 1));
103 filter[i * width + (rnd() % width)] = ((1 << 15) - 1);
106 for (i = 0; i < MAX_FILTER_WIDTH; i++) {
107 // These values should be unused in SIMD implementations but
108 // may still be read, random coefficients here should help show
109 // issues where they are used in error.
111 filter[SRC_PIXELS * width + i] = rnd();
115 if (check_func(ctx->hcScale, "hscale_%d_to_%d_width%d", ctx->srcBpc, ctx->dstBpc + 1, width)) {
116 memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0]));
117 memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0]));
119 call_ref(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width);
120 call_new(NULL, dst1, SRC_PIXELS, src, filter, filterPos, width);
121 if (memcmp(dst0, dst1, SRC_PIXELS * sizeof(dst0[0])))
123 bench_new(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width);
127 sws_freeContext(ctx);
130 void checkasm_check_sw_scale(void)