Skip to content

Commit e5640e6

Browse files
committed
libpostproc/tests: Factor ff_chksum() out
Signed-off-by: Michael Niedermayer <[email protected]>
1 parent 9bf54cd commit e5640e6

File tree

6 files changed

+77
-48
lines changed

6 files changed

+77
-48
lines changed

libpostproc/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ HEADERS = postprocess.h \
99
OBJS = postprocess.o \
1010
version.o \
1111

12+
TESTOBJS = tests/test_utils.o \
13+
1214
# Windows resource file
1315
SHLIBOBJS-$(HAVE_GNU_WINDRES) += postprocres.o
1416

1517
TESTPROGS = blocktest \
1618
stripetest \
1719
temptest \
20+
21+
$(SUBDIR)tests/blocktest$(EXESUF): $(SUBDIR)tests/test_utils.o
22+
$(SUBDIR)tests/stripetest$(EXESUF): $(SUBDIR)tests/test_utils.o
23+
$(SUBDIR)tests/temptest$(EXESUF): $(SUBDIR)tests/test_utils.o

libpostproc/tests/blocktest.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "libavutil/frame.h"
2222
#include "libavutil/adler32.h"
2323
#include "libpostproc/postprocess.h"
24+
#include "test_utils.h"
2425

2526
typedef const uint8_t *cuint8;
2627

@@ -39,21 +40,6 @@ static void blocks(AVFrame *frame, int blocksize, int mul)
3940
}
4041
}
4142

42-
static int64_t chksum(AVFrame *f)
43-
{
44-
AVAdler a = 123;
45-
46-
for(int y=0; y<f->height; y++) {
47-
a = av_adler32_update(a, &f->data[0][y*f->linesize[0]], f->width);
48-
}
49-
for(int y=0; y<(f->height+1)/2; y++) {
50-
a = av_adler32_update(a, &f->data[1][y*f->linesize[1]], (f->width+1)/2);
51-
a = av_adler32_update(a, &f->data[2][y*f->linesize[2]], (f->width+1)/2);
52-
}
53-
54-
return a;
55-
}
56-
5743
static int64_t test(int width, int height, const char * filter_string, int blocksize, int flags, int pict_type, int quality) {
5844
AVFrame *in = av_frame_alloc();
5945
AVFrame *out = av_frame_alloc();
@@ -90,7 +76,7 @@ static int64_t test(int width, int height, const char * filter_string, int block
9076
width, height, qp, QP_STRIDE,
9177
mode, context, pict_type);
9278

93-
ret = chksum(out);
79+
ret = ff_chksum(out);
9480
end:
9581
av_frame_free(&in);
9682
av_frame_free(&out);

libpostproc/tests/stripetest.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "libavutil/frame.h"
2222
#include "libavutil/adler32.h"
2323
#include "libpostproc/postprocess.h"
24+
#include "test_utils.h"
2425

2526
typedef const uint8_t *cuint8;
2627

@@ -48,21 +49,6 @@ static void strips(AVFrame *frame, int mul)
4849
}
4950
}
5051

51-
static int64_t chksum(AVFrame *f)
52-
{
53-
AVAdler a = 123;
54-
55-
for(int y=0; y<f->height; y++) {
56-
a = av_adler32_update(a, &f->data[0][y*f->linesize[0]], f->width);
57-
}
58-
for(int y=0; y<(f->height+1)/2; y++) {
59-
a = av_adler32_update(a, &f->data[1][y*f->linesize[1]], (f->width+1)/2);
60-
a = av_adler32_update(a, &f->data[2][y*f->linesize[2]], (f->width+1)/2);
61-
}
62-
63-
return a;
64-
}
65-
6652
static int64_t test(int width, int height, const char *testname, int mul, int flags, int pict_type, int quality) {
6753
AVFrame *in = av_frame_alloc();
6854
AVFrame *out = av_frame_alloc();
@@ -94,7 +80,7 @@ static int64_t test(int width, int height, const char *testname, int mul, int fl
9480
width, height, NULL, 0,
9581
mode, context, pict_type);
9682

97-
ret = chksum(out);
83+
ret = ff_chksum(out);
9884
end:
9985
av_frame_free(&in);
10086
av_frame_free(&out);

libpostproc/tests/temptest.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "libavutil/frame.h"
2222
#include "libavutil/adler32.h"
2323
#include "libpostproc/postprocess.h"
24+
#include "test_utils.h"
2425

2526
typedef const uint8_t *cuint8;
2627

@@ -41,21 +42,6 @@ static void stuff(AVFrame *frame, unsigned *state, int mul)
4142
}
4243
}
4344

44-
static int64_t chksum(AVFrame *f)
45-
{
46-
AVAdler a = 123;
47-
48-
for(int y=0; y<f->height; y++) {
49-
a = av_adler32_update(a, &f->data[0][y*f->linesize[0]], f->width);
50-
}
51-
for(int y=0; y<(f->height+1)/2; y++) {
52-
a = av_adler32_update(a, &f->data[1][y*f->linesize[1]], (f->width+1)/2);
53-
a = av_adler32_update(a, &f->data[2][y*f->linesize[2]], (f->width+1)/2);
54-
}
55-
56-
return a;
57-
}
58-
5945
static int64_t test(int width, int height, const char *testname, int mul, int flags, int pict_type, int quality) {
6046
AVFrame *in = av_frame_alloc();
6147
AVFrame *out = av_frame_alloc();
@@ -89,7 +75,7 @@ static int64_t test(int width, int height, const char *testname, int mul, int fl
8975
width, height, NULL, 0,
9076
mode, context, pict_type);
9177

92-
ret += chksum(out);
78+
ret += ff_chksum(out);
9379
ret *= 1664525U;
9480
}
9581
end:

libpostproc/tests/test_utils.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025 Michael Niedermayer
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 "libavutil/frame.h"
22+
#include "libavutil/adler32.h"
23+
#include "test_utils.h"
24+
25+
int64_t ff_chksum(AVFrame *f)
26+
{
27+
AVAdler a = 123;
28+
29+
for(int y=0; y<f->height; y++) {
30+
a = av_adler32_update(a, &f->data[0][y*f->linesize[0]], f->width);
31+
}
32+
for(int y=0; y<(f->height+1)/2; y++) {
33+
a = av_adler32_update(a, &f->data[1][y*f->linesize[1]], (f->width+1)/2);
34+
a = av_adler32_update(a, &f->data[2][y*f->linesize[2]], (f->width+1)/2);
35+
}
36+
37+
return a;
38+
}

libpostproc/tests/test_utils.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2025 Michael Niedermayer
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+
22+
#ifndef POSTPROC_TESTS_TEST_UTILS_H
23+
#define POSTPROC_TESTS_TEST_UTILS_H
24+
25+
int64_t ff_chksum(AVFrame *f);
26+
27+
#endif /* POSTPROC_TESTS_TEST_UTILS_H */

0 commit comments

Comments
 (0)