pixdesc: mark pseudopaletted formats with a special flag.

This makes it possible to dintinguish them from PAL8.

Fixes an invalid write in avpicture_layout().
pull/3/merge
Anton Khirnov 13 years ago
parent 8e37038a34
commit 38d5533228
  1. 3
      doc/APIchanges
  2. 8
      libavcodec/imgconvert.c
  3. 3
      libavcodec/rawdec.c
  4. 3
      libavfilter/vf_crop.c
  5. 3
      libavfilter/vf_pixdesctest.c
  6. 3
      libavfilter/vf_scale.c
  7. 2
      libavutil/avutil.h
  8. 9
      libavutil/imgutils.c
  9. 8
      libavutil/pixdesc.c
  10. 6
      libavutil/pixdesc.h
  11. 4
      libswscale/swscale_internal.h

@ -13,6 +13,9 @@ libavutil: 2011-04-18
API changes, most recent first: API changes, most recent first:
2012-02-xx - xxxxxxx - lavu 51.22.1 - pixdesc.h
Add PIX_FMT_PSEUDOPAL flag.
2012-02-01 - xxxxxxx - lavc 54.01.0 2012-02-01 - xxxxxxx - lavc 54.01.0
Add avcodec_encode_video2() and deprecate avcodec_encode_video(). Add avcodec_encode_video2() and deprecate avcodec_encode_video().

@ -471,15 +471,9 @@ int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height)
AVPicture dummy_pict; AVPicture dummy_pict;
if(av_image_check_size(width, height, 0, NULL)) if(av_image_check_size(width, height, 0, NULL))
return -1; return -1;
switch (pix_fmt) { if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PSEUDOPAL)
case PIX_FMT_RGB8:
case PIX_FMT_BGR8:
case PIX_FMT_RGB4_BYTE:
case PIX_FMT_BGR4_BYTE:
case PIX_FMT_GRAY8:
// do not include palette for these pseudo-paletted formats // do not include palette for these pseudo-paletted formats
return width * height; return width * height;
}
return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height); return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
} }

@ -158,8 +158,7 @@ static int raw_decode(AVCodecContext *avctx,
avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
if((avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length) || if((avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length) ||
(avctx->pix_fmt!=PIX_FMT_PAL8 && (av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PSEUDOPAL)) {
(av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PAL))){
frame->data[1]= context->palette; frame->data[1]= context->palette;
} }
if (avctx->pix_fmt == PIX_FMT_PAL8) { if (avctx->pix_fmt == PIX_FMT_PAL8) {

@ -272,7 +272,8 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
ref2->data[0] += crop->y * ref2->linesize[0]; ref2->data[0] += crop->y * ref2->linesize[0];
ref2->data[0] += crop->x * crop->max_step[0]; ref2->data[0] += crop->x * crop->max_step[0];
if (!(av_pix_fmt_descriptors[link->format].flags & PIX_FMT_PAL)) { if (!(av_pix_fmt_descriptors[link->format].flags & PIX_FMT_PAL ||
av_pix_fmt_descriptors[link->format].flags & PIX_FMT_PSEUDOPAL)) {
for (i = 1; i < 3; i ++) { for (i = 1; i < 3; i ++) {
if (ref2->data[i]) { if (ref2->data[i]) {
ref2->data[i] += (crop->y >> crop->vsub) * ref2->linesize[i]; ref2->data[i] += (crop->y >> crop->vsub) * ref2->linesize[i];

@ -72,7 +72,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
} }
/* copy palette */ /* copy palette */
if (priv->pix_desc->flags & PIX_FMT_PAL) if (priv->pix_desc->flags & PIX_FMT_PAL ||
priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
memcpy(outpicref->data[1], outpicref->data[1], 256*4); memcpy(outpicref->data[1], outpicref->data[1], 256*4);
avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0)); avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));

@ -208,7 +208,8 @@ static int config_props(AVFilterLink *outlink)
outlink->w, outlink->h, av_pix_fmt_descriptors[outlink->format].name, outlink->w, outlink->h, av_pix_fmt_descriptors[outlink->format].name,
scale->flags); scale->flags);
scale->input_is_pal = av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL; scale->input_is_pal = av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL ||
av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PSEUDOPAL;
if (scale->sws) if (scale->sws)
sws_freeContext(scale->sws); sws_freeContext(scale->sws);

@ -155,7 +155,7 @@
#define LIBAVUTIL_VERSION_MAJOR 51 #define LIBAVUTIL_VERSION_MAJOR 51
#define LIBAVUTIL_VERSION_MINOR 22 #define LIBAVUTIL_VERSION_MINOR 22
#define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_MICRO 1
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \ LIBAVUTIL_VERSION_MINOR, \

@ -108,7 +108,8 @@ int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int heigh
return AVERROR(EINVAL); return AVERROR(EINVAL);
size[0] = linesizes[0] * height; size[0] = linesizes[0] * height;
if (desc->flags & PIX_FMT_PAL) { if (desc->flags & PIX_FMT_PAL ||
desc->flags & PIX_FMT_PSEUDOPAL) {
size[0] = (size[0] + 3) & ~3; size[0] = (size[0] + 3) & ~3;
data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */ data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */
return size[0] + 256 * 4; return size[0] + 256 * 4;
@ -196,7 +197,8 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
av_free(buf); av_free(buf);
return ret; return ret;
} }
if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PAL) if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PAL ||
av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PSEUDOPAL)
ff_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt); ff_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt);
return ret; return ret;
@ -243,7 +245,8 @@ void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
if (desc->flags & PIX_FMT_HWACCEL) if (desc->flags & PIX_FMT_HWACCEL)
return; return;
if (desc->flags & PIX_FMT_PAL) { if (desc->flags & PIX_FMT_PAL ||
desc->flags & PIX_FMT_PSEUDOPAL) {
av_image_copy_plane(dst_data[0], dst_linesizes[0], av_image_copy_plane(dst_data[0], dst_linesizes[0],
src_data[0], src_linesizes[0], src_data[0], src_linesizes[0],
width, height); width, height);

@ -327,7 +327,7 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
{ 0, 0, 1, 3, 2 }, /* G */ { 0, 0, 1, 3, 2 }, /* G */
{ 0, 0, 1, 0, 2 }, /* R */ { 0, 0, 1, 0, 2 }, /* R */
}, },
.flags = PIX_FMT_PAL | PIX_FMT_RGB, .flags = PIX_FMT_RGB | PIX_FMT_PSEUDOPAL,
}, },
[PIX_FMT_BGR4] = { [PIX_FMT_BGR4] = {
.name = "bgr4", .name = "bgr4",
@ -351,7 +351,7 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
{ 0, 0, 1, 1, 1 }, /* G */ { 0, 0, 1, 1, 1 }, /* G */
{ 0, 0, 1, 0, 0 }, /* R */ { 0, 0, 1, 0, 0 }, /* R */
}, },
.flags = PIX_FMT_PAL | PIX_FMT_RGB, .flags = PIX_FMT_RGB | PIX_FMT_PSEUDOPAL,
}, },
[PIX_FMT_RGB8] = { [PIX_FMT_RGB8] = {
.name = "rgb8", .name = "rgb8",
@ -363,7 +363,7 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
{ 0, 0, 1, 3, 2 }, /* G */ { 0, 0, 1, 3, 2 }, /* G */
{ 0, 0, 1, 0, 2 }, /* B */ { 0, 0, 1, 0, 2 }, /* B */
}, },
.flags = PIX_FMT_PAL | PIX_FMT_RGB, .flags = PIX_FMT_RGB | PIX_FMT_PSEUDOPAL,
}, },
[PIX_FMT_RGB4] = { [PIX_FMT_RGB4] = {
.name = "rgb4", .name = "rgb4",
@ -387,7 +387,7 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
{ 0, 0, 1, 1, 1 }, /* G */ { 0, 0, 1, 1, 1 }, /* G */
{ 0, 0, 1, 0, 0 }, /* B */ { 0, 0, 1, 0, 0 }, /* B */
}, },
.flags = PIX_FMT_PAL | PIX_FMT_RGB, .flags = PIX_FMT_RGB | PIX_FMT_PSEUDOPAL,
}, },
[PIX_FMT_NV12] = { [PIX_FMT_NV12] = {
.name = "nv12", .name = "nv12",

@ -89,6 +89,12 @@ typedef struct AVPixFmtDescriptor{
#define PIX_FMT_HWACCEL 8 ///< Pixel format is an HW accelerated format. #define PIX_FMT_HWACCEL 8 ///< Pixel format is an HW accelerated format.
#define PIX_FMT_PLANAR 16 ///< At least one pixel component is not in the first data plane #define PIX_FMT_PLANAR 16 ///< At least one pixel component is not in the first data plane
#define PIX_FMT_RGB 32 ///< The pixel format contains RGB-like data (as opposed to YUV/grayscale) #define PIX_FMT_RGB 32 ///< The pixel format contains RGB-like data (as opposed to YUV/grayscale)
/**
* The pixel format is "pseudo-paletted". This means that Libav treats it as
* paletted internally, but the palette is generated by the decoder and is not
* stored in the file.
*/
#define PIX_FMT_PSEUDOPAL 64
/** /**
* The array of all the pixel format descriptors. * The array of all the pixel format descriptors.

@ -627,7 +627,9 @@ const char *sws_format_name(enum PixelFormat format);
(av_pix_fmt_descriptors[x].nb_components >= 2 && \ (av_pix_fmt_descriptors[x].nb_components >= 2 && \
(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) (av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
#define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A) #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || \
(av_pix_fmt_descriptors[x].flags & PIX_FMT_PSEUDOPAL) || \
(x) == PIX_FMT_Y400A)
extern const uint64_t ff_dither4[2]; extern const uint64_t ff_dither4[2];
extern const uint64_t ff_dither8[2]; extern const uint64_t ff_dither8[2];

Loading…
Cancel
Save