FFmpeg
Loading...
Searching...
No Matches
png.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Zhao Zhili <quinkblack@foxmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <string.h>
22
24#include "libavcodec/pngdsp.h"
25
26#include "checkasm.h"
27
28#define BUF_SIZE 4096
29
30#define randomize_buf(buf, size) \
31 do { \
32 for (int i = 0; i < size; i++) \
33 buf[i] = (uint8_t)rnd(); \
34 } while (0)
35
37{
38 LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE]);
39 LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE]);
40 LOCAL_ALIGNED_16(uint8_t, src, [2], [BUF_SIZE]);
41
42 declare_func(void, uint8_t * dst, const uint8_t *src1,
43 const uint8_t *src2, int w);
44
46 memcpy(dst1, dst0, BUF_SIZE);
49
50 const int size[] = {15, 2043, 4096};
51 for (int i = 0; i < FF_ARRAY_ELEMS(size); i++) {
52 if (check_func(c->add_bytes_l2, "add_bytes_l2_%d", size[i])) {
53 call_ref(dst0, src[0], src[1], size[i]);
54 call_new(dst1, src[0], src[1], size[i]);
55 checkasm_check(uint8_t, dst0, BUF_SIZE, dst1, BUF_SIZE, BUF_SIZE, 1, "dst");
56 if (size[i] == BUF_SIZE)
57 bench_new(dst1, src[0], src[1], BUF_SIZE);
58 }
59 }
60}
61
63{
64 LOCAL_ALIGNED_16(uint8_t, dst0_buf, [BUF_SIZE]);
65 LOCAL_ALIGNED_16(uint8_t, dst1_buf, [BUF_SIZE]);
66 LOCAL_ALIGNED_16(uint8_t, src, [BUF_SIZE]);
67 LOCAL_ALIGNED_16(uint8_t, top_buf, [BUF_SIZE]);
68
69 randomize_buf(dst0_buf, BUF_SIZE);
71 randomize_buf(top_buf, BUF_SIZE);
72
73 declare_func(void, uint8_t * dst, const uint8_t *src,
74 const uint8_t *top, int w, int bpp);
75
76 const int bpps[] = {3, 4, 6, 8};
77 for (int i = 0; i < FF_ARRAY_ELEMS(bpps); i++) {
78 int bpp = bpps[i];
79 if (check_func(c->add_paeth_prediction, "add_paeth_prediction_%d", bpp)) {
80 // add_paeth_prediction reads start from (dst - bpp) and (top - bpp).
81 uint8_t *dst0 = &dst0_buf[bpp];
82 uint8_t *dst1 = &dst1_buf[bpp];
83 uint8_t *top = &top_buf[bpp];
84 int w = (BUF_SIZE - bpp) / bpp * bpp;
85
86 // dst buffer is both read and written, so dst0 and dst1 must remain the same before test
87 memcpy(dst1_buf, dst0_buf, BUF_SIZE);
88
89 call_ref(dst0, src, top, w, bpp);
90 call_new(dst1, src, top, w, bpp);
91
92 /* This match the use case in ff_png_filter_row, that x86 asm version of
93 * add_paeth_prediction doesn't write last two bytes for bpp = 3 and 6.
94 * The C function takes care to rewrite the last 3 bytes.
95 */
96 if (bpp & 3) {
97 for (int j = w - 3; j < w; j++)
98 dst1[j] = dst0[j];
99 }
100 // check dst_buf to ensure there is no overwrite
101 checkasm_check(uint8_t, dst0_buf, 0, dst1_buf, 0, BUF_SIZE, 1, "dst");
102 bench_new(dst1, src, top, w, bpp);
103 }
104 }
105}
106
108{
110
112
114 report("add_bytes_l2");
116 report("add_paeth_prediction");
117}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define declare_func
Definition test.h:489
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
const pixel * src2
uint8_t w
Definition llvidencdsp.c:39
#define LOCAL_ALIGNED_16(t, v,...)
av_cold void ff_pngdsp_init(PNGDSPContext *dsp)
Definition pngdsp.c:85
#define BUF_SIZE
Definition setpts.c:159
#define FF_ARRAY_ELEMS(a)
#define src1
Definition h264pred.c:141
static void check_add_bytes_l2(const PNGDSPContext *c)
Definition png.c:36
#define randomize_buf(buf, size)
Definition png.c:30
static void check_add_paeth_prediction(const PNGDSPContext *c)
Definition png.c:62
void checkasm_check_png(void)
Definition png.c:107
#define src
Definition vp8dsp.c:248
int size
static double c[64]