27 #undef HAVE_AV_CONFIG_H
28 #include "libavutil/imgutils.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/avutil.h"
31 #include "libavutil/crc.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/lfg.h"
39 ((x) == AV_PIX_FMT_GRAY8 || \
40 (x) == AV_PIX_FMT_Y400A || \
41 (x) == AV_PIX_FMT_GRAY16BE || \
42 (x) == AV_PIX_FMT_GRAY16LE)
43 #define hasChroma(x) \
45 (x) == AV_PIX_FMT_MONOBLACK || \
46 (x) == AV_PIX_FMT_MONOWHITE))
48 ((x) == AV_PIX_FMT_BGR32 || \
49 (x) == AV_PIX_FMT_BGR32_1 || \
50 (x) == AV_PIX_FMT_RGB32 || \
51 (x) == AV_PIX_FMT_RGB32_1 || \
52 (x) == AV_PIX_FMT_YUVA420P)
55 int stride2,
int w,
int h)
60 for (y = 0; y < h; y++) {
61 for (x = 0; x < w; x++) {
62 int d = src1[x + y * stride1] - src2[x + y * stride2];
81 int srcW,
int srcH,
int dstW,
int dstH,
int flags,
88 static int cur_srcW, cur_srcH;
90 static int srcStride[4];
93 int dstStride[4] = {0};
95 uint64_t ssdY, ssdU = 0, ssdV = 0, ssdA = 0;
96 struct SwsContext *dstContext = NULL, *outContext = NULL;
100 if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH) {
104 for (p = 0; p < 4; p++)
108 for (p = 0; p < 4; p++) {
109 srcStride[p] =
FFALIGN(srcStride[p], 16);
111 src[p] =
av_mallocz(srcStride[p] * srcH + 16);
112 if (srcStride[p] && !src[p]) {
121 fprintf(stderr,
"Failed to get %s ---> %s\n",
127 sws_scale(srcContext, (
const uint8_t *
const*)ref, refStride, 0, h, src, srcStride);
136 for (i = 0; i < 4; i++) {
143 dstStride[i] =
FFALIGN(dstStride[i], 16);
145 dst[i] =
av_mallocz(dstStride[i] * dstH + 16);
146 if (dstStride[i] && !dst[i]) {
154 dstContext =
sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat,
155 flags, NULL, NULL, NULL);
157 fprintf(stderr,
"Failed to get %s ---> %s\n",
163 printf(
" %s %dx%d -> %s %3dx%3d flags=%2d",
164 desc_src->
name, srcW, srcH,
165 desc_dst->
name, dstW, dstH,
169 sws_scale(dstContext, (
const uint8_t *
const*)src, srcStride, 0, srcH, dst, dstStride);
171 for (i = 0; i < 4 && dstStride[i]; i++)
173 dstStride[i] * dstH);
175 if (r && crc == r->
crc) {
181 for (i = 0; i < 4; i++) {
182 refStride[i] =
FFALIGN(refStride[i], 16);
185 if (refStride[i] && !out[i]) {
195 fprintf(stderr,
"Failed to get %s ---> %s\n",
197 desc_yuva420p->
name);
201 sws_scale(outContext, (
const uint8_t *
const*)dst, dstStride, 0, dstH, out, refStride);
203 ssdY =
getSSD(ref[0], out[0], refStride[0], refStride[0], w, h);
206 ssdU =
getSSD(ref[1], out[1], refStride[1], refStride[1],
207 (w + 1) >> 1, (h + 1) >> 1);
208 ssdV =
getSSD(ref[2], out[2], refStride[2], refStride[2],
209 (w + 1) >> 1, (h + 1) >> 1);
212 ssdA =
getSSD(ref[3], out[3], refStride[3], refStride[3], w, h);
221 for (i = 0; i < 4; i++)
226 printf(
" CRC=%08x SSD=%5"PRId64
",%5"PRId64
",%5"PRId64
",%5"PRId64
"\n",
227 crc, ssdY, ssdU, ssdV, ssdA);
232 for (i = 0; i < 4; i++)
247 const int dstW[] = { srcW - srcW / 3,
srcW, srcW + srcW / 3, 0 };
248 const int dstH[] = { srcH - srcH / 3,
srcH, srcH + srcH / 3, 0 };
271 printf(
"%s -> %s\n", desc_src->
name, desc_dst->
name);
274 for (k = 0; flags[k] && !
res; k++)
275 for (i = 0; dstW[i] && !
res; i++)
276 for (j = 0; dstH[j] && !
res; j++)
277 res =
doTest(ref, refStride, w, h,
278 srcFormat, dstFormat,
279 srcW, srcH, dstW[i], dstH[j], flags[k],
295 while (fgets(buf,
sizeof(buf), fp)) {
307 " %12s %dx%d -> %12s %dx%d flags=%d CRC=%x"
308 " SSD=%"SCNd64
", %"SCNd64
", %"SCNd64
", %"SCNd64
"\n",
309 srcStr, &srcW, &srcH, dstStr, &dstW, &dstH,
312 srcStr[0] = dstStr[0] = 0;
313 ret = sscanf(buf,
"%12s -> %12s\n", srcStr, dstStr);
320 srcW > 8192
U || srcH > 8192
U || dstW > 8192
U || dstH > 8192
U) {
321 fprintf(stderr,
"malformed input file\n");
332 doTest(ref, refStride, w, h,
333 srcFormat, dstFormat,
334 srcW, srcH, dstW, dstH, flags,
344 int main(
int argc,
char **argv)
349 const uint8_t *
const rgb_src[4] = { rgb_data, NULL, NULL, NULL };
350 int rgb_stride[4] = { 4 *
W, 0, 0, 0 };
361 if (!rgb_data || !data)
364 for (i = 1; i < argc; i += 2) {
365 if (argv[i][0] !=
'-' || i + 1 == argc)
367 if (!strcmp(argv[i],
"-ref")) {
368 fp = fopen(argv[i + 1],
"r");
370 fprintf(stderr,
"could not open '%s'\n", argv[i + 1]);
373 }
else if (!strcmp(argv[i],
"-src")) {
376 fprintf(stderr,
"invalid pixel format %s\n", argv[i + 1]);
379 }
else if (!strcmp(argv[i],
"-dst")) {
382 fprintf(stderr,
"invalid pixel format %s\n", argv[i + 1]);
387 fprintf(stderr,
"bad option or argument missing (%s)\n", argv[i]);
397 for (y = 0; y <
H; y++)
398 for (x = 0; x <
W * 4; x++)
400 sws_scale(sws, rgb_src, rgb_stride, 0, H, src, stride);
405 res =
fileTest(src, stride, W, H, fp, srcFormat, dstFormat);
408 selfTest(src, stride, W, H, srcFormat, dstFormat);
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
static int fileTest(uint8_t *ref[4], int refStride[4], int w, int h, FILE *fp, enum AVPixelFormat srcFormat_in, enum AVPixelFormat dstFormat_in)
#define SWS_FAST_BILINEAR
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int srcH
Height of source luma/alpha planes.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static av_cold int end(AVCodecContext *avctx)
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst...
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
enum AVPixelFormat dstFormat
Destination pixel format.
int dstH
Height of destination luma/alpha planes.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
AVPixelFormat
Pixel format.
int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported input format, 0 otherwise.
static uint64_t getSSD(const uint8_t *src1, const uint8_t *src2, int stride1, int stride2, int w, int h)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length) av_pure
Calculate the CRC of a block.
int dstW
Width of destination luma/alpha planes.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
void av_lfg_init(AVLFG *c, unsigned int seed)
int sws_isSupportedOutput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported output format, 0 otherwise.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
enum AVPixelFormat srcFormat
Source pixel format.
static int doTest(uint8_t *ref[4], int refStride[4], int w, int h, enum AVPixelFormat srcFormat, enum AVPixelFormat dstFormat, int srcW, int srcH, int dstW, int dstH, int flags, struct Results *r)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static void selfTest(uint8_t *ref[4], int refStride[4], int w, int h, enum AVPixelFormat srcFormat_in, enum AVPixelFormat dstFormat_in)
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
int main(int argc, char **argv)
int srcW
Width of source luma/alpha planes.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...