1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-08 13:22:53 +02:00

lavc: do not use av_pix_fmt_descriptors directly.

This commit is contained in:
Anton Khirnov 2012-10-06 13:29:37 +02:00
parent 9953ff3cd8
commit 50ba57e0ce
9 changed files with 61 additions and 46 deletions

View File

@ -410,13 +410,15 @@ static const PixFmtInfo pix_fmt_info[AV_PIX_FMT_NB] = {
void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift) void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
{ {
*h_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
*v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h; *h_shift = desc->log2_chroma_w;
*v_shift = desc->log2_chroma_h;
} }
int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt) int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
{ {
return av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
return desc->flags & PIX_FMT_HWACCEL;
} }
int avpicture_fill(AVPicture *picture, uint8_t *ptr, int avpicture_fill(AVPicture *picture, uint8_t *ptr,
@ -437,7 +439,7 @@ int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width
unsigned char *dest, int dest_size) unsigned char *dest, int dest_size)
{ {
int i, j, nb_planes = 0, linesizes[4]; int i, j, nb_planes = 0, linesizes[4];
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int size = avpicture_get_size(pix_fmt, width, height); int size = avpicture_get_size(pix_fmt, width, height);
if (size > dest_size || size < 0) if (size > dest_size || size < 0)
@ -469,9 +471,11 @@ int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height) int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
{ {
AVPicture dummy_pict; AVPicture dummy_pict;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
if(av_image_check_size(width, height, 0, NULL)) if(av_image_check_size(width, height, 0, NULL))
return -1; return -1;
if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PSEUDOPAL) if (desc->flags & PIX_FMT_PSEUDOPAL)
// 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);
@ -481,8 +485,8 @@ int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat
int has_alpha) int has_alpha)
{ {
const PixFmtInfo *pf, *ps; const PixFmtInfo *pf, *ps;
const AVPixFmtDescriptor *src_desc = &av_pix_fmt_descriptors[src_pix_fmt]; const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
const AVPixFmtDescriptor *dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt]; const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
int loss; int loss;
ps = &pix_fmt_info[src_pix_fmt]; ps = &pix_fmt_info[src_pix_fmt];
@ -540,7 +544,7 @@ static int avg_bits_per_pixel(enum AVPixelFormat pix_fmt)
{ {
int bits; int bits;
const PixFmtInfo *pf; const PixFmtInfo *pf;
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
pf = &pix_fmt_info[pix_fmt]; pf = &pix_fmt_info[pix_fmt];
switch(pf->pixel_type) { switch(pf->pixel_type) {
@ -797,14 +801,15 @@ static inline int is_yuv_planar(const PixFmtInfo *ps)
int av_picture_crop(AVPicture *dst, const AVPicture *src, int av_picture_crop(AVPicture *dst, const AVPicture *src,
enum AVPixelFormat pix_fmt, int top_band, int left_band) enum AVPixelFormat pix_fmt, int top_band, int left_band)
{ {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int y_shift; int y_shift;
int x_shift; int x_shift;
if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt])) if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
return -1; return -1;
y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h; y_shift = desc->log2_chroma_h;
x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w; x_shift = desc->log2_chroma_w;
dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band; dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift); dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
@ -820,6 +825,7 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
enum AVPixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright, enum AVPixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright,
int *color) int *color)
{ {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
uint8_t *optr; uint8_t *optr;
int y_shift; int y_shift;
int x_shift; int x_shift;
@ -830,8 +836,8 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
!is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1; !is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
x_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_w : 0; x_shift = i ? desc->log2_chroma_w : 0;
y_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_h : 0; y_shift = i ? desc->log2_chroma_h : 0;
if (padtop || padleft) { if (padtop || padleft) {
memset(dst->data[i], color[i], memset(dst->data[i], color[i],

View File

@ -75,32 +75,32 @@ typedef struct {
static int libopenjpeg_matches_pix_fmt(const opj_image_t *img, static int libopenjpeg_matches_pix_fmt(const opj_image_t *img,
enum AVPixelFormat pix_fmt) enum AVPixelFormat pix_fmt)
{ {
AVPixFmtDescriptor des = av_pix_fmt_descriptors[pix_fmt]; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int match = 1; int match = 1;
if (des.nb_components != img->numcomps) { if (desc->nb_components != img->numcomps) {
return 0; return 0;
} }
switch (des.nb_components) { switch (desc->nb_components) {
case 4: case 4:
match = match && match = match &&
des.comp[3].depth_minus1 + 1 >= img->comps[3].prec && desc->comp[3].depth_minus1 + 1 >= img->comps[3].prec &&
1 == img->comps[3].dx && 1 == img->comps[3].dx &&
1 == img->comps[3].dy; 1 == img->comps[3].dy;
case 3: case 3:
match = match && match = match &&
des.comp[2].depth_minus1 + 1 >= img->comps[2].prec && desc->comp[2].depth_minus1 + 1 >= img->comps[2].prec &&
1 << des.log2_chroma_w == img->comps[2].dx && 1 << desc->log2_chroma_w == img->comps[2].dx &&
1 << des.log2_chroma_h == img->comps[2].dy; 1 << desc->log2_chroma_h == img->comps[2].dy;
case 2: case 2:
match = match && match = match &&
des.comp[1].depth_minus1 + 1 >= img->comps[1].prec && desc->comp[1].depth_minus1 + 1 >= img->comps[1].prec &&
1 << des.log2_chroma_w == img->comps[1].dx && 1 << desc->log2_chroma_w == img->comps[1].dx &&
1 << des.log2_chroma_h == img->comps[1].dy; 1 << desc->log2_chroma_h == img->comps[1].dy;
case 1: case 1:
match = match && match = match &&
des.comp[0].depth_minus1 + 1 >= img->comps[0].prec && desc->comp[0].depth_minus1 + 1 >= img->comps[0].prec &&
1 == img->comps[0].dx && 1 == img->comps[0].dx &&
1 == img->comps[0].dy; 1 == img->comps[0].dy;
default: default:
@ -146,14 +146,15 @@ static enum AVPixelFormat libopenjpeg_guess_pix_fmt(const opj_image_t *image)
static inline int libopenjpeg_ispacked(enum AVPixelFormat pix_fmt) static inline int libopenjpeg_ispacked(enum AVPixelFormat pix_fmt)
{ {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int i, component_plane; int i, component_plane;
if (pix_fmt == AV_PIX_FMT_GRAY16) if (pix_fmt == AV_PIX_FMT_GRAY16)
return 0; return 0;
component_plane = av_pix_fmt_descriptors[pix_fmt].comp[0].plane; component_plane = desc->comp[0].plane;
for (i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) { for (i = 1; i < desc->nb_components; i++) {
if (component_plane != av_pix_fmt_descriptors[pix_fmt].comp[i].plane) if (component_plane != desc->comp[i].plane)
return 0; return 0;
} }
return 1; return 1;
@ -259,6 +260,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size; int buf_size = avpkt->size;
LibOpenJPEGContext *ctx = avctx->priv_data; LibOpenJPEGContext *ctx = avctx->priv_data;
AVFrame *picture = &ctx->image, *output = data; AVFrame *picture = &ctx->image, *output = data;
const AVPixFmtDescriptor *desc;
opj_dinfo_t *dec; opj_dinfo_t *dec;
opj_cio_t *stream; opj_cio_t *stream;
opj_image_t *image; opj_image_t *image;
@ -373,8 +375,8 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
goto done; goto done;
} }
pixel_size = desc = av_pix_fmt_desc_get(avctx->pix_fmt);
av_pix_fmt_descriptors[avctx->pix_fmt].comp[0].step_minus1 + 1; pixel_size = desc->comp[0].step_minus1 + 1;
ispacked = libopenjpeg_ispacked(avctx->pix_fmt); ispacked = libopenjpeg_ispacked(avctx->pix_fmt);
switch (pixel_size) { switch (pixel_size) {

View File

@ -69,22 +69,23 @@ static void info_callback(const char *msg, void *data)
static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx, static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
opj_cparameters_t *parameters) opj_cparameters_t *parameters)
{ {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
opj_image_cmptparm_t *cmptparm; opj_image_cmptparm_t *cmptparm;
OPJ_COLOR_SPACE color_space; OPJ_COLOR_SPACE color_space;
opj_image_t *img; opj_image_t *img;
int i; int i;
int sub_dx[4]; int sub_dx[4];
int sub_dy[4]; int sub_dy[4];
int numcomps = av_pix_fmt_descriptors[avctx->pix_fmt].nb_components; int numcomps = desc->nb_components;
sub_dx[0] = sub_dx[0] =
sub_dx[3] = 1; sub_dx[3] = 1;
sub_dy[0] = sub_dy[0] =
sub_dy[3] = 1; sub_dy[3] = 1;
sub_dx[1] = sub_dx[1] =
sub_dx[2] = 1 << av_pix_fmt_descriptors[avctx->pix_fmt].log2_chroma_w; sub_dx[2] = 1 << desc->log2_chroma_w;
sub_dy[1] = sub_dy[1] =
sub_dy[2] = 1 << av_pix_fmt_descriptors[avctx->pix_fmt].log2_chroma_h; sub_dy[2] = 1 << desc->log2_chroma_h;
switch (avctx->pix_fmt) { switch (avctx->pix_fmt) {
case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_GRAY8:
@ -129,10 +130,8 @@ static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
} }
for (i = 0; i < numcomps; i++) { for (i = 0; i < numcomps; i++) {
cmptparm[i].prec = cmptparm[i].prec = desc->comp[i].depth_minus1 + 1;
av_pix_fmt_descriptors[avctx->pix_fmt].comp[i].depth_minus1 + 1; cmptparm[i].bpp = desc->comp[i].depth_minus1 + 1;
cmptparm[i].bpp =
av_pix_fmt_descriptors[avctx->pix_fmt].comp[i].depth_minus1 + 1;
cmptparm[i].sgnd = 0; cmptparm[i].sgnd = 0;
cmptparm[i].dx = sub_dx[i]; cmptparm[i].dx = sub_dx[i];
cmptparm[i].dy = sub_dy[i]; cmptparm[i].dy = sub_dy[i];

View File

@ -1527,8 +1527,9 @@ void ff_MPV_frame_end(MpegEncContext *s)
s->current_picture.f.reference && s->current_picture.f.reference &&
!s->intra_only && !s->intra_only &&
!(s->flags & CODEC_FLAG_EMU_EDGE)) { !(s->flags & CODEC_FLAG_EMU_EDGE)) {
int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h; int hshift = desc->log2_chroma_w;
int vshift = desc->log2_chroma_h;
s->dsp.draw_edges(s->current_picture.f.data[0], s->linesize, s->dsp.draw_edges(s->current_picture.f.data[0], s->linesize,
s->h_edge_pos, s->v_edge_pos, s->h_edge_pos, s->v_edge_pos,
EDGE_WIDTH, EDGE_WIDTH, EDGE_WIDTH, EDGE_WIDTH,
@ -2342,9 +2343,10 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
&& s->current_picture.f.reference && s->current_picture.f.reference
&& !s->intra_only && !s->intra_only
&& !(s->flags&CODEC_FLAG_EMU_EDGE)) { && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
int sides = 0, edge_h; int sides = 0, edge_h;
int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w; int hshift = desc->log2_chroma_w;
int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h; int vshift = desc->log2_chroma_h;
if (y==0) sides |= EDGE_TOP; if (y==0) sides |= EDGE_TOP;
if (y + h >= s->v_edge_pos) sides |= EDGE_BOTTOM; if (y + h >= s->v_edge_pos) sides |= EDGE_BOTTOM;

View File

@ -119,6 +119,7 @@ static int raw_decode(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data; const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
RawVideoContext *context = avctx->priv_data; RawVideoContext *context = avctx->priv_data;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
int res; int res;
AVFrame *frame = data; AVFrame *frame = data;
@ -161,7 +162,7 @@ static int raw_decode(AVCodecContext *avctx,
avctx->width, avctx->height)) < 0) avctx->width, avctx->height)) < 0)
return res; return res;
if((avctx->pix_fmt==AV_PIX_FMT_PAL8 && buf_size < context->length) || if((avctx->pix_fmt==AV_PIX_FMT_PAL8 && buf_size < context->length) ||
(av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PSEUDOPAL)) { (desc->flags & PIX_FMT_PSEUDOPAL)) {
frame->data[1]= context->palette; frame->data[1]= context->palette;
} }
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {

View File

@ -33,10 +33,12 @@
static av_cold int raw_init_encoder(AVCodecContext *avctx) static av_cold int raw_init_encoder(AVCodecContext *avctx)
{ {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
avctx->coded_frame = avctx->priv_data; avctx->coded_frame = avctx->priv_data;
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1; avctx->coded_frame->key_frame = 1;
avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]); avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
if(!avctx->codec_tag) if(!avctx->codec_tag)
avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
return 0; return 0;

View File

@ -240,7 +240,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
case AV_PIX_FMT_RGB24: case AV_PIX_FMT_RGB24:
case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_GRAY8:
case AV_PIX_FMT_PAL8: case AV_PIX_FMT_PAL8:
pfd = &av_pix_fmt_descriptors[avctx->pix_fmt]; pfd = av_pix_fmt_desc_get(avctx->pix_fmt);
s->bpp = av_get_bits_per_pixel(pfd); s->bpp = av_get_bits_per_pixel(pfd);
if (pfd->flags & PIX_FMT_PAL) { if (pfd->flags & PIX_FMT_PAL) {
s->photometric_interpretation = 3; s->photometric_interpretation = 3;

View File

@ -247,7 +247,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height) void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
{ {
int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
int chroma_shift = desc->log2_chroma_w;
int linesize_align[AV_NUM_DATA_POINTERS]; int linesize_align[AV_NUM_DATA_POINTERS];
int align; int align;
@ -422,7 +423,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
int unaligned; int unaligned;
AVPicture picture; AVPicture picture;
int stride_align[AV_NUM_DATA_POINTERS]; int stride_align[AV_NUM_DATA_POINTERS];
const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1 + 1; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
const int pixel_size = desc->comp[0].step_minus1 + 1;
avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);

View File

@ -43,14 +43,15 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *p, int *got_packet) const AVFrame *p, int *got_packet)
{ {
enum AVPixelFormat pix_fmt = avctx->pix_fmt; enum AVPixelFormat pix_fmt = avctx->pix_fmt;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0; uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
uint32_t rgb[3] = { 0 }, bitorder = 0; uint32_t rgb[3] = { 0 }, bitorder = 0;
uint32_t header_size; uint32_t header_size;
int i, out_size, ret; int i, out_size, ret;
uint8_t *ptr, *buf; uint8_t *ptr, *buf;
pixdepth = av_get_bits_per_pixel(&av_pix_fmt_descriptors[pix_fmt]); pixdepth = av_get_bits_per_pixel(desc);
if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BE) if (desc->flags & PIX_FMT_BE)
be = 1; be = 1;
switch (pix_fmt) { switch (pix_fmt) {
case AV_PIX_FMT_ARGB: case AV_PIX_FMT_ARGB: