Commit b59d12b1 authored by Stefano Sabatini's avatar Stefano Sabatini

Compute the max pixel step for each plane, and use it in place of

hardcoding that value in a switch.

More compact and correct.

Originally committed as revision 24594 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 92dd4959
...@@ -32,7 +32,7 @@ typedef struct { ...@@ -32,7 +32,7 @@ typedef struct {
int w; ///< width of the cropped area int w; ///< width of the cropped area
int h; ///< height of the cropped area int h; ///< height of the cropped area
int bpp; ///< bits per pixel int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes
int hsub, vsub; ///< chroma subsampling int hsub, vsub; ///< chroma subsampling
} CropContext; } CropContext;
...@@ -82,42 +82,14 @@ static int config_input(AVFilterLink *link) ...@@ -82,42 +82,14 @@ static int config_input(AVFilterLink *link)
{ {
AVFilterContext *ctx = link->dst; AVFilterContext *ctx = link->dst;
CropContext *crop = ctx->priv; CropContext *crop = ctx->priv;
const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[link->format];
int i;
switch (link->format) { memset(crop->max_step, 0, sizeof(crop->max_step));
case PIX_FMT_RGB48BE: for (i = 0; i < 4; i++) {
case PIX_FMT_RGB48LE: const AVComponentDescriptor *comp = &(pix_desc->comp[i]);
crop->bpp = 48; if ((comp->step_minus1+1) > crop->max_step[comp->plane])
break; crop->max_step[comp->plane] = comp->step_minus1+1;
case PIX_FMT_ARGB:
case PIX_FMT_RGBA:
case PIX_FMT_ABGR:
case PIX_FMT_BGRA:
crop->bpp = 32;
break;
case PIX_FMT_RGB24:
case PIX_FMT_BGR24:
crop->bpp = 24;
break;
case PIX_FMT_RGB565BE:
case PIX_FMT_RGB565LE:
case PIX_FMT_RGB555BE:
case PIX_FMT_RGB555LE:
case PIX_FMT_BGR565BE:
case PIX_FMT_BGR565LE:
case PIX_FMT_BGR555BE:
case PIX_FMT_BGR555LE:
case PIX_FMT_GRAY16BE:
case PIX_FMT_GRAY16LE:
case PIX_FMT_YUV420P16LE:
case PIX_FMT_YUV420P16BE:
case PIX_FMT_YUV422P16LE:
case PIX_FMT_YUV422P16BE:
case PIX_FMT_YUV444P16LE:
case PIX_FMT_YUV444P16BE:
crop->bpp = 16;
break;
default:
crop->bpp = 8;
} }
crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w; crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
...@@ -167,13 +139,13 @@ static void start_frame(AVFilterLink *link, AVFilterPicRef *picref) ...@@ -167,13 +139,13 @@ static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
ref2->h = crop->h; ref2->h = crop->h;
ref2->data[0] += crop->y * ref2->linesize[0]; ref2->data[0] += crop->y * ref2->linesize[0];
ref2->data[0] += (crop->x * crop->bpp) >> 3; 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)) {
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];
ref2->data[i] += ((crop->x * crop->bpp) >> 3) >> crop->hsub; ref2->data[i] += (crop->x * crop->max_step[i]) >> crop->hsub;
} }
} }
} }
...@@ -181,7 +153,7 @@ static void start_frame(AVFilterLink *link, AVFilterPicRef *picref) ...@@ -181,7 +153,7 @@ static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
/* alpha plane */ /* alpha plane */
if (ref2->data[3]) { if (ref2->data[3]) {
ref2->data[3] += crop->y * ref2->linesize[3]; ref2->data[3] += crop->y * ref2->linesize[3];
ref2->data[3] += (crop->x * crop->bpp) >> 3; ref2->data[3] += (crop->x * crop->max_step[3]);
} }
avfilter_start_frame(link->dst->outputs[0], ref2); avfilter_start_frame(link->dst->outputs[0], ref2);
......
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