Commit 50ba57e0 authored by Anton Khirnov's avatar Anton Khirnov
Browse files

lavc: do not use av_pix_fmt_descriptors directly.

parent 9953ff3c
......@@ -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)
{
*h_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
*v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
*h_shift = desc->log2_chroma_w;
*v_shift = desc->log2_chroma_h;
}
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,
......@@ -437,7 +439,7 @@ int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width
unsigned char *dest, int dest_size)
{
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);
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)
{
AVPicture dummy_pict;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
if(av_image_check_size(width, height, 0, NULL))
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
return 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)
{
const PixFmtInfo *pf, *ps;
const AVPixFmtDescriptor *src_desc = &av_pix_fmt_descriptors[src_pix_fmt];
const AVPixFmtDescriptor *dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt];
const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
int loss;
ps = &pix_fmt_info[src_pix_fmt];
......@@ -540,7 +544,7 @@ static int avg_bits_per_pixel(enum AVPixelFormat pix_fmt)
{
int bits;
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];
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,
enum AVPixelFormat pix_fmt, int top_band, int left_band)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int y_shift;
int x_shift;
if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
return -1;
y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
y_shift = desc->log2_chroma_h;
x_shift = desc->log2_chroma_w;
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);
......@@ -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,
int *color)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
uint8_t *optr;
int y_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;
for (i = 0; i < 3; i++) {
x_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_w : 0;
y_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_h : 0;
x_shift = i ? desc->log2_chroma_w : 0;
y_shift = i ? desc->log2_chroma_h : 0;
if (padtop || padleft) {
memset(dst->data[i], color[i],
......
......@@ -75,32 +75,32 @@ typedef struct {
static int libopenjpeg_matches_pix_fmt(const opj_image_t *img,
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;
if (des.nb_components != img->numcomps) {
if (desc->nb_components != img->numcomps) {
return 0;
}
switch (des.nb_components) {
switch (desc->nb_components) {
case 4:
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].dy;
case 3:
match = match &&
des.comp[2].depth_minus1 + 1 >= img->comps[2].prec &&
1 << des.log2_chroma_w == img->comps[2].dx &&
1 << des.log2_chroma_h == img->comps[2].dy;
desc->comp[2].depth_minus1 + 1 >= img->comps[2].prec &&
1 << desc->log2_chroma_w == img->comps[2].dx &&
1 << desc->log2_chroma_h == img->comps[2].dy;
case 2:
match = match &&
des.comp[1].depth_minus1 + 1 >= img->comps[1].prec &&
1 << des.log2_chroma_w == img->comps[1].dx &&
1 << des.log2_chroma_h == img->comps[1].dy;
desc->comp[1].depth_minus1 + 1 >= img->comps[1].prec &&
1 << desc->log2_chroma_w == img->comps[1].dx &&
1 << desc->log2_chroma_h == img->comps[1].dy;
case 1:
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].dy;
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)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int i, component_plane;
if (pix_fmt == AV_PIX_FMT_GRAY16)
return 0;
component_plane = av_pix_fmt_descriptors[pix_fmt].comp[0].plane;
for (i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) {
if (component_plane != av_pix_fmt_descriptors[pix_fmt].comp[i].plane)
component_plane = desc->comp[0].plane;
for (i = 1; i < desc->nb_components; i++) {
if (component_plane != desc->comp[i].plane)
return 0;
}
return 1;
......@@ -259,6 +260,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size;
LibOpenJPEGContext *ctx = avctx->priv_data;
AVFrame *picture = &ctx->image, *output = data;
const AVPixFmtDescriptor *desc;
opj_dinfo_t *dec;
opj_cio_t *stream;
opj_image_t *image;
......@@ -373,8 +375,8 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
goto done;
}
pixel_size =
av_pix_fmt_descriptors[avctx->pix_fmt].comp[0].step_minus1 + 1;
desc = av_pix_fmt_desc_get(avctx->pix_fmt);
pixel_size = desc->comp[0].step_minus1 + 1;
ispacked = libopenjpeg_ispacked(avctx->pix_fmt);
switch (pixel_size) {
......
......@@ -69,22 +69,23 @@ static void info_callback(const char *msg, void *data)
static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
opj_cparameters_t *parameters)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
opj_image_cmptparm_t *cmptparm;
OPJ_COLOR_SPACE color_space;
opj_image_t *img;
int i;
int sub_dx[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[3] = 1;
sub_dy[0] =
sub_dy[3] = 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[2] = 1 << av_pix_fmt_descriptors[avctx->pix_fmt].log2_chroma_h;
sub_dy[2] = 1 << desc->log2_chroma_h;
switch (avctx->pix_fmt) {
case AV_PIX_FMT_GRAY8:
......@@ -129,10 +130,8 @@ static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
}
for (i = 0; i < numcomps; i++) {
cmptparm[i].prec =
av_pix_fmt_descriptors[avctx->pix_fmt].comp[i].depth_minus1 + 1;
cmptparm[i].bpp =
av_pix_fmt_descriptors[avctx->pix_fmt].comp[i].depth_minus1 + 1;
cmptparm[i].prec = desc->comp[i].depth_minus1 + 1;
cmptparm[i].bpp = desc->comp[i].depth_minus1 + 1;
cmptparm[i].sgnd = 0;
cmptparm[i].dx = sub_dx[i];
cmptparm[i].dy = sub_dy[i];
......
......@@ -1527,8 +1527,9 @@ void ff_MPV_frame_end(MpegEncContext *s)
s->current_picture.f.reference &&
!s->intra_only &&
!(s->flags & CODEC_FLAG_EMU_EDGE)) {
int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w;
int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
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->h_edge_pos, s->v_edge_pos,
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->intra_only
&& !(s->flags&CODEC_FLAG_EMU_EDGE)) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
int sides = 0, edge_h;
int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w;
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;
if (y==0) sides |= EDGE_TOP;
if (y + h >= s->v_edge_pos) sides |= EDGE_BOTTOM;
......
......@@ -119,6 +119,7 @@ static int raw_decode(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
RawVideoContext *context = avctx->priv_data;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
int res;
AVFrame *frame = data;
......@@ -161,7 +162,7 @@ static int raw_decode(AVCodecContext *avctx,
avctx->width, avctx->height)) < 0)
return res;
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;
}
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
......
......@@ -33,10 +33,12 @@
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->pict_type = AV_PICTURE_TYPE_I;
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)
avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
return 0;
......
......@@ -240,7 +240,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
case AV_PIX_FMT_RGB24:
case AV_PIX_FMT_GRAY8:
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);
if (pfd->flags & PIX_FMT_PAL) {
s->photometric_interpretation = 3;
......
......@@ -247,7 +247,8 @@ void avcodec_align_dimensions2(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 align;
......@@ -422,7 +423,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
int unaligned;
AVPicture picture;
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);
......
......@@ -43,14 +43,15 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *p, int *got_packet)
{
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 rgb[3] = { 0 }, bitorder = 0;
uint32_t header_size;
int i, out_size, ret;
uint8_t *ptr, *buf;
pixdepth = av_get_bits_per_pixel(&av_pix_fmt_descriptors[pix_fmt]);
if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BE)
pixdepth = av_get_bits_per_pixel(desc);
if (desc->flags & PIX_FMT_BE)
be = 1;
switch (pix_fmt) {
case AV_PIX_FMT_ARGB:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment