sws: do not use av_pix_fmt_descriptors directly.

pull/6/head
Anton Khirnov 12 years ago
parent b7f1010c8f
commit 0a7068fa5d
  1. 3
      libswscale/output.c
  2. 27
      libswscale/swscale-test.c
  3. 6
      libswscale/swscale.c
  4. 130
      libswscale/swscale_internal.h
  5. 20
      libswscale/swscale_unscaled.c
  6. 26
      libswscale/utils.c

@ -1270,12 +1270,13 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
yuv2packedX_fn *yuv2packedX)
{
enum AVPixelFormat dstFormat = c->dstFormat;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
if (is16BPS(dstFormat)) {
*yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
*yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
} else if (is9_OR_10BPS(dstFormat)) {
if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 8) {
if (desc->comp[0].depth_minus1 == 8) {
*yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
*yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
} else {

@ -81,6 +81,9 @@ static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
int srcW, int srcH, int dstW, int dstH, int flags,
struct Results *r)
{
const AVPixFmtDescriptor *desc_yuva420p = av_pix_fmt_desc_get(AV_PIX_FMT_YUVA420P);
const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat);
const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat);
static enum AVPixelFormat cur_srcFormat;
static int cur_srcW, cur_srcH;
static uint8_t *src[4];
@ -115,8 +118,8 @@ static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
srcFormat, SWS_BILINEAR, NULL, NULL, NULL);
if (!srcContext) {
fprintf(stderr, "Failed to get %s ---> %s\n",
av_pix_fmt_descriptors[AV_PIX_FMT_YUVA420P].name,
av_pix_fmt_descriptors[srcFormat].name);
desc_yuva420p->name,
desc_src->name);
res = -1;
goto end;
}
@ -150,15 +153,14 @@ static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
flags, NULL, NULL, NULL);
if (!dstContext) {
fprintf(stderr, "Failed to get %s ---> %s\n",
av_pix_fmt_descriptors[srcFormat].name,
av_pix_fmt_descriptors[dstFormat].name);
desc_src->name, desc_dst->name);
res = -1;
goto end;
}
printf(" %s %dx%d -> %s %3dx%3d flags=%2d",
av_pix_fmt_descriptors[srcFormat].name, srcW, srcH,
av_pix_fmt_descriptors[dstFormat].name, dstW, dstH,
desc_src->name, srcW, srcH,
desc_dst->name, dstW, dstH,
flags);
fflush(stdout);
@ -188,8 +190,8 @@ static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
NULL, NULL, NULL);
if (!outContext) {
fprintf(stderr, "Failed to get %s ---> %s\n",
av_pix_fmt_descriptors[dstFormat].name,
av_pix_fmt_descriptors[AV_PIX_FMT_YUVA420P].name);
desc_dst->name,
desc_yuva420p->name);
res = -1;
goto end;
}
@ -242,6 +244,7 @@ static void selfTest(uint8_t *ref[4], int refStride[4], int w, int h,
const int dstW[] = { srcW - srcW / 3, srcW, srcW + srcW / 3, 0 };
const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 };
enum AVPixelFormat srcFormat, dstFormat;
const AVPixFmtDescriptor *desc_src, *desc_dst;
for (srcFormat = srcFormat_in != AV_PIX_FMT_NONE ? srcFormat_in : 0;
srcFormat < AV_PIX_FMT_NB; srcFormat++) {
@ -249,6 +252,8 @@ static void selfTest(uint8_t *ref[4], int refStride[4], int w, int h,
!sws_isSupportedOutput(srcFormat))
continue;
desc_src = av_pix_fmt_desc_get(srcFormat);
for (dstFormat = dstFormat_in != AV_PIX_FMT_NONE ? dstFormat_in : 0;
dstFormat < AV_PIX_FMT_NB; dstFormat++) {
int i, j, k;
@ -258,9 +263,9 @@ static void selfTest(uint8_t *ref[4], int refStride[4], int w, int h,
!sws_isSupportedOutput(dstFormat))
continue;
printf("%s -> %s\n",
av_pix_fmt_descriptors[srcFormat].name,
av_pix_fmt_descriptors[dstFormat].name);
desc_dst = av_pix_fmt_desc_get(dstFormat);
printf("%s -> %s\n", desc_src->name, desc_dst->name);
fflush(stdout);
for (k = 0; flags[k] && !res; k++)

@ -65,10 +65,11 @@ static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW,
const uint8_t *_src, const int16_t *filter,
const int32_t *filterPos, int filterSize)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
int i;
int32_t *dst = (int32_t *) _dst;
const uint16_t *src = (const uint16_t *) _src;
int bits = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
int bits = desc->comp[0].depth_minus1;
int sh = bits - 4;
for (i = 0; i < dstW; i++) {
@ -88,9 +89,10 @@ static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW,
const uint8_t *_src, const int16_t *filter,
const int32_t *filterPos, int filterSize)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
int i;
const uint16_t *src = (const uint16_t *) _src;
int sh = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
int sh = desc->comp[0].depth_minus1;
for (i = 0; i < dstW; i++) {
int j;

@ -27,6 +27,7 @@
#include <altivec.h>
#endif
#include "libavutil/avassert.h"
#include "libavutil/avutil.h"
#include "libavutil/common.h"
#include "libavutil/log.h"
@ -542,26 +543,47 @@ void ff_bfin_get_unscaled_swscale(SwsContext *c);
const char *sws_format_name(enum AVPixelFormat format);
#define is16BPS(x) \
(av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 15)
#define is9_OR_10BPS(x) \
(av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 8 || \
av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 9)
#define isBE(x) \
(av_pix_fmt_descriptors[x].flags & PIX_FMT_BE)
#define isYUV(x) \
(!(av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB) && \
av_pix_fmt_descriptors[x].nb_components >= 2)
#define isPlanarYUV(x) \
((av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR) && \
isYUV(x))
#define isRGB(x) \
(av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB)
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return desc->comp[0].depth_minus1 == 15;
}
static av_always_inline int is9_OR_10BPS(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return desc->comp[0].depth_minus1 == 8 || desc->comp[0].depth_minus1 == 9;
}
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return desc->flags & PIX_FMT_BE;
}
static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return !(desc->flags & PIX_FMT_RGB) && desc->nb_components >= 2;
}
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return ((desc->flags & PIX_FMT_PLANAR) && isYUV(pix_fmt));
}
static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return (desc->flags & PIX_FMT_RGB);
}
#if 0 // FIXME
#define isGray(x) \
@ -615,30 +637,50 @@ const char *sws_format_name(enum AVPixelFormat format);
(isRGBinInt(x) || \
isBGRinInt(x))
#define isALPHA(x) \
(av_pix_fmt_descriptors[x].nb_components == 2 || \
av_pix_fmt_descriptors[x].nb_components == 4)
#define isPacked(x) \
((av_pix_fmt_descriptors[x].nb_components >= 2 && \
!(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) || \
(x) == AV_PIX_FMT_PAL8)
#define isPlanar(x) \
(av_pix_fmt_descriptors[x].nb_components >= 2 && \
(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
#define isPackedRGB(x) \
((av_pix_fmt_descriptors[x].flags & \
(PIX_FMT_PLANAR | PIX_FMT_RGB)) == PIX_FMT_RGB)
#define isPlanarRGB(x) \
((av_pix_fmt_descriptors[x].flags & \
(PIX_FMT_PLANAR | PIX_FMT_RGB)) == (PIX_FMT_PLANAR | PIX_FMT_RGB))
#define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || \
(av_pix_fmt_descriptors[x].flags & PIX_FMT_PSEUDOPAL) || \
(x) == AV_PIX_FMT_Y400A)
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return desc->nb_components == 2 || desc->nb_components == 4;
}
static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return ((desc->nb_components >= 2 && !(desc->flags & PIX_FMT_PLANAR)) ||
pix_fmt == AV_PIX_FMT_PAL8);
}
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return (desc->nb_components >= 2 && (desc->flags & PIX_FMT_PLANAR));
}
static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return ((desc->flags & (PIX_FMT_PLANAR | PIX_FMT_RGB)) == PIX_FMT_RGB);
}
static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return ((desc->flags & (PIX_FMT_PLANAR | PIX_FMT_RGB)) ==
(PIX_FMT_PLANAR | PIX_FMT_RGB));
}
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_assert0(desc);
return ((desc->flags & PIX_FMT_PAL) || (desc->flags & PIX_FMT_PSEUDOPAL) ||
pix_fmt == AV_PIX_FMT_Y400A);
}
extern const uint64_t ff_dither4[2];
extern const uint64_t ff_dither8[2];

@ -462,13 +462,15 @@ static rgbConvFn findRgbConvFn(SwsContext *c)
const int srcId = c->srcFormatBpp;
const int dstId = c->dstFormatBpp;
rgbConvFn conv = NULL;
const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat);
const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat);
#define IS_NOT_NE(bpp, fmt) \
#define IS_NOT_NE(bpp, desc) \
(((bpp + 7) >> 3) == 2 && \
(!(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_BE) != !HAVE_BIGENDIAN))
(!(desc->flags & PIX_FMT_BE) != !HAVE_BIGENDIAN))
/* if this is non-native rgb444/555/565, don't handle it here. */
if (IS_NOT_NE(srcId, srcFormat) || IS_NOT_NE(dstId, dstFormat))
if (IS_NOT_NE(srcId, desc_src) || IS_NOT_NE(dstId, desc_dst))
return NULL;
#define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
@ -659,6 +661,8 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
int srcStride[], int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
int plane, i, j;
for (plane = 0; plane < 4; plane++) {
int length = (plane == 0 || plane == 3) ? c->srcW : -((-c->srcW ) >> c->chrDstHSubSample);
@ -678,8 +682,8 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
(plane == 3) ? 255 : 128);
} else {
if (is9_OR_10BPS(c->srcFormat)) {
const int src_depth = av_pix_fmt_descriptors[c->srcFormat].comp[plane].depth_minus1 + 1;
const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1 + 1;
const int src_depth = desc_src->comp[plane].depth_minus1 + 1;
const int dst_depth = desc_dst->comp[plane].depth_minus1 + 1;
const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
if (is16BPS(c->dstFormat)) {
@ -759,7 +763,7 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
}
}
} else if (is9_OR_10BPS(c->dstFormat)) {
const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1 + 1;
const int dst_depth = desc_dst->comp[plane].depth_minus1 + 1;
uint16_t *dstPtr2 = (uint16_t *) dstPtr;
if (is16BPS(c->srcFormat)) {
@ -839,7 +843,7 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
} else {
if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
length *= 2;
else if (!av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1)
else if (!desc_src->comp[0].depth_minus1)
length >>= 3; // monowhite/black
for (i = 0; i < height; i++) {
memcpy(dstPtr, srcPtr, length);
@ -991,7 +995,7 @@ static void reset_ptr(const uint8_t *src[], int format)
static int check_image_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt,
const int linesizes[4])
{
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int i;
for (i = 0; i < 4; i++) {

@ -168,8 +168,9 @@ extern const int32_t ff_yuv2rgb_coeffs[8][4];
const char *sws_format_name(enum AVPixelFormat format)
{
if ((unsigned)format < AV_PIX_FMT_NB && av_pix_fmt_descriptors[format].name)
return av_pix_fmt_descriptors[format].name;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
if (desc)
return desc->name;
else
return "Unknown format";
}
@ -745,14 +746,17 @@ static int initMMX2HScaler(int dstW, int xInc, uint8_t *filterCode,
static void getSubSampleFactors(int *h, int *v, enum AVPixelFormat format)
{
*h = av_pix_fmt_descriptors[format].log2_chroma_w;
*v = av_pix_fmt_descriptors[format].log2_chroma_h;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
*h = desc->log2_chroma_w;
*v = desc->log2_chroma_h;
}
int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
int srcRange, const int table[4], int dstRange,
int brightness, int contrast, int saturation)
{
const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
memcpy(c->srcColorspaceTable, inv_table, sizeof(int) * 4);
memcpy(c->dstColorspaceTable, table, sizeof(int) * 4);
@ -764,8 +768,8 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
if (isYUV(c->dstFormat) || isGray(c->dstFormat))
return -1;
c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[c->dstFormat]);
c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[c->srcFormat]);
c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness,
contrast, saturation);
@ -841,6 +845,8 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
int flags, cpu_flags;
enum AVPixelFormat srcFormat = c->srcFormat;
enum AVPixelFormat dstFormat = c->dstFormat;
const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat);
const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat);
cpu_flags = av_get_cpu_flags();
flags = c->flags;
@ -893,8 +899,8 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
c->lumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
c->lumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[dstFormat]);
c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[srcFormat]);
c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
c->vRounder = 4 * 0x0001000100010001ULL;
usesVFilter = (srcFilter->lumV && srcFilter->lumV->length > 1) ||
@ -963,10 +969,10 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
}
}
c->srcBpc = 1 + av_pix_fmt_descriptors[srcFormat].comp[0].depth_minus1;
c->srcBpc = 1 + desc_src->comp[0].depth_minus1;
if (c->srcBpc < 8)
c->srcBpc = 8;
c->dstBpc = 1 + av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1;
c->dstBpc = 1 + desc_dst->comp[0].depth_minus1;
if (c->dstBpc < 8)
c->dstBpc = 8;
if (c->dstBpc == 16)

Loading…
Cancel
Save