Revision b59d12b1 libavfilter/vf_crop.c

View differences:

libavfilter/vf_crop.c
32 32
    int  w;             ///< width of the cropped area
33 33
    int  h;             ///< height of the cropped area
34 34

  
35
    int bpp;            ///< bits per pixel
35
    int max_step[4];    ///< max pixel step for each plane, expressed as a number of bytes
36 36
    int hsub, vsub;     ///< chroma subsampling
37 37
} CropContext;
38 38

  
......
82 82
{
83 83
    AVFilterContext *ctx = link->dst;
84 84
    CropContext *crop = ctx->priv;
85
    const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[link->format];
86
    int i;
85 87

  
86
    switch (link->format) {
87
    case PIX_FMT_RGB48BE:
88
    case PIX_FMT_RGB48LE:
89
        crop->bpp = 48;
90
        break;
91
    case PIX_FMT_ARGB:
92
    case PIX_FMT_RGBA:
93
    case PIX_FMT_ABGR:
94
    case PIX_FMT_BGRA:
95
        crop->bpp = 32;
96
        break;
97
    case PIX_FMT_RGB24:
98
    case PIX_FMT_BGR24:
99
        crop->bpp = 24;
100
        break;
101
    case PIX_FMT_RGB565BE:
102
    case PIX_FMT_RGB565LE:
103
    case PIX_FMT_RGB555BE:
104
    case PIX_FMT_RGB555LE:
105
    case PIX_FMT_BGR565BE:
106
    case PIX_FMT_BGR565LE:
107
    case PIX_FMT_BGR555BE:
108
    case PIX_FMT_BGR555LE:
109
    case PIX_FMT_GRAY16BE:
110
    case PIX_FMT_GRAY16LE:
111
    case PIX_FMT_YUV420P16LE:
112
    case PIX_FMT_YUV420P16BE:
113
    case PIX_FMT_YUV422P16LE:
114
    case PIX_FMT_YUV422P16BE:
115
    case PIX_FMT_YUV444P16LE:
116
    case PIX_FMT_YUV444P16BE:
117
        crop->bpp = 16;
118
        break;
119
    default:
120
        crop->bpp = 8;
88
    memset(crop->max_step, 0, sizeof(crop->max_step));
89
    for (i = 0; i < 4; i++) {
90
        const AVComponentDescriptor *comp = &(pix_desc->comp[i]);
91
        if ((comp->step_minus1+1) > crop->max_step[comp->plane])
92
            crop->max_step[comp->plane] = comp->step_minus1+1;
121 93
    }
122 94

  
123 95
    crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
......
167 139
    ref2->h        = crop->h;
168 140

  
169 141
    ref2->data[0] += crop->y * ref2->linesize[0];
170
    ref2->data[0] += (crop->x * crop->bpp) >> 3;
142
    ref2->data[0] += (crop->x * crop->max_step[0]);
171 143

  
172 144
    if (!(av_pix_fmt_descriptors[link->format].flags & PIX_FMT_PAL)) {
173 145
        for (i = 1; i < 3; i ++) {
174 146
            if (ref2->data[i]) {
175 147
                ref2->data[i] += (crop->y >> crop->vsub) * ref2->linesize[i];
176
                ref2->data[i] += ((crop->x * crop->bpp) >> 3) >> crop->hsub;
148
                ref2->data[i] += (crop->x * crop->max_step[i]) >> crop->hsub;
177 149
            }
178 150
        }
179 151
    }
......
181 153
    /* alpha plane */
182 154
    if (ref2->data[3]) {
183 155
        ref2->data[3] += crop->y * ref2->linesize[3];
184
        ref2->data[3] += (crop->x * crop->bpp) >> 3;
156
        ref2->data[3] += (crop->x * crop->max_step[3]);
185 157
    }
186 158

  
187 159
    avfilter_start_frame(link->dst->outputs[0], ref2);

Also available in: Unified diff