summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorStefano Sabatini <stefano.sabatini-lala@poste.it>2010-07-30 11:33:31 +0000
committerStefano Sabatini <stefano.sabatini-lala@poste.it>2010-07-30 11:33:31 +0000
commitb59d12b1b920c0bbdaca5ec59e4d56ffa1535d1d (patch)
tree73561794516cab735f6858eaf3972555d5abf599 /libavfilter
parent92dd4959df59b92e9b2ac20ddebb0522b906d294 (diff)
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
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/vf_crop.c50
1 files changed, 11 insertions, 39 deletions
diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
index 6bfee038f4..e71a77bce6 100644
--- a/libavfilter/vf_crop.c
+++ b/libavfilter/vf_crop.c
@@ -32,7 +32,7 @@ typedef struct {
int w; ///< width 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
} CropContext;
@@ -82,42 +82,14 @@ static int config_input(AVFilterLink *link)
{
AVFilterContext *ctx = link->dst;
CropContext *crop = ctx->priv;
+ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[link->format];
+ int i;
- switch (link->format) {
- case PIX_FMT_RGB48BE:
- case PIX_FMT_RGB48LE:
- crop->bpp = 48;
- break;
- 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;
+ memset(crop->max_step, 0, sizeof(crop->max_step));
+ for (i = 0; i < 4; i++) {
+ const AVComponentDescriptor *comp = &(pix_desc->comp[i]);
+ if ((comp->step_minus1+1) > crop->max_step[comp->plane])
+ crop->max_step[comp->plane] = comp->step_minus1+1;
}
crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
@@ -167,13 +139,13 @@ static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
ref2->h = crop->h;
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)) {
for (i = 1; i < 3; i ++) {
if (ref2->data[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)
/* alpha plane */
if (ref2->data[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);