Fixes Ticket #4910
Showing the changes to libavfilter/tests (1 of 7 files). Show all
Unified · Split
| @@ -0,0 +1,92 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (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 GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "libavfilter/vf_nlmeans.c" | ||
| 20 | |||
| 21 | static void display_integral(const uint32_t *ii, int w, int h, int lz_32) | ||
| 22 | { | ||
| 23 | int x, y; | ||
| 24 | |||
| 25 | for (y = 0; y < h; y++) { | ||
| 26 | for (x = 0; x < w; x++) | ||
| 27 | printf(" %7x", ii[y*lz_32 + x]); | ||
| 28 | printf("\n"); | ||
| 29 | } | ||
| 30 | printf("---------------\n"); | ||
| 31 | } | ||
| 32 | |||
| 33 | int main(void) | ||
| 34 | { | ||
| 35 | int ret = 0, xoff, yoff; | ||
| 36 | |||
| 37 | // arbitrary test source of size 6x4 and linesize=8 | ||
| 38 | const int w = 6, h = 5, lz = 8; | ||
| 39 | static const uint8_t src[] = { | ||
| 40 | 0xb0, 0x71, 0xfb, 0xd8, 0x01, 0xd9, /***/ 0x01, 0x02, | ||
| 41 | 0x51, 0x8e, 0x41, 0x0f, 0x84, 0x58, /***/ 0x03, 0x04, | ||
| 42 | 0xc7, 0x8d, 0x07, 0x70, 0x5c, 0x47, /***/ 0x05, 0x06, | ||
| 43 | 0x09, 0x4e, 0xfc, 0x74, 0x8f, 0x9a, /***/ 0x07, 0x08, | ||
| 44 | 0x60, 0x8e, 0x20, 0xaa, 0x95, 0x7d, /***/ 0x09, 0x0a, | ||
| 45 | }; | ||
| 46 | |||
| 47 | const int e = 3; | ||
| 48 | const int ii_w = w+e*2, ii_h = h+e*2; | ||
| 49 | |||
| 50 | // align to 4 the linesize, "+1" is for the space of the left 0-column | ||
| 51 | const int ii_lz_32 = ((ii_w + 1) + 3) & ~3; | ||
| 52 | |||
| 53 | // "+1" is for the space of the top 0-line | ||
| 54 | uint32_t *ii = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii)); | ||
| 55 | uint32_t *ii2 = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii2)); | ||
| 56 | |||
| 57 | uint32_t *ii_start = ii + ii_lz_32 + 1; // skip top 0-line and left 0-column | ||
| 58 | uint32_t *ii_start2 = ii2 + ii_lz_32 + 1; // skip top 0-line and left 0-column | ||
| 59 | |||
| 60 | if (!ii || !ii2) | ||
| 61 | return -1; | ||
| 62 | |||
| 63 | for (yoff = -e; yoff <= e; yoff++) { | ||
| 64 | for (xoff = -e; xoff <= e; xoff++) { | ||
| 65 | int x, y; | ||
| 66 | |||
| 67 | printf("xoff=%d yoff=%d\n", xoff, yoff); | ||
| 68 | |||
| 69 | compute_ssd_integral_image(ii_start, ii_lz_32, | ||
| 70 | src, lz, xoff, yoff, e, w, h); | ||
| 71 | display_integral(ii_start, ii_w, ii_h, ii_lz_32); | ||
| 72 | |||
| 73 | compute_unsafe_ssd_integral_image(ii_start2, ii_lz_32, | ||
| 74 | 0, 0, | ||
| 75 | src, lz, | ||
| 76 | xoff, yoff, e, w, h, | ||
| 77 | ii_w, ii_h); | ||
| 78 | display_integral(ii_start2, ii_w, ii_h, ii_lz_32); | ||
| 79 | |||
| 80 | if (memcmp(ii, ii2, (ii_h+1) * ii_lz_32 * sizeof(*ii))) { | ||
| 81 | printf("Integral mismatch\n"); | ||
| 82 | ret = 1; | ||
| 83 | goto end; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | end: | ||
| 89 | av_freep(&ii); | ||
| 90 | av_freep(&ii2); | ||
| 91 | return ret; | ||
| 92 | } | ||