[FFmpeg-devel] packed rgb cropping patch

Teemu Keinonen tkeinonen
Wed Jan 2 19:43:05 CET 2008


Hi all,

I made small change to libavcodec/imgconvert.c to support cropping of packed
RGB images. I need a pointer to how to make a patch or such is this is accepted.
Does this seem correct? It worked when clipping some flashsv videos.

int av_picture_crop(AVPicture *dst, const AVPicture *src,
              int pix_fmt, int top_band, int left_band)
{
    if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
        return -1;

        if (!is_yuv_planar(&pix_fmt_info[pix_fmt]))
        {
                if (pix_fmt_info[pix_fmt].depth != 8)
                {
                        av_log(NULL, AV_LOG_ERROR, "Only 8bits/channel
packed formats supported.\n");
                        return -1;
                }
                dst->data[0] =
src->data[0]+src->linesize[0]*top_band+(left_band*pix_fmt_info[pix_\
fmt].nb_channels);
                dst->linesize[0] = src->linesize[0];
        }
        else
        {
                int y_shift;
                int x_shift;

                y_shift = pix_fmt_info[pix_fmt].y_chroma_shift;
                x_shift = pix_fmt_info[pix_fmt].x_chroma_shift;

                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_b\
and >> x_shift);
                dst->data[2] = src->data[2] + ((top_band >> y_shift) *
src->linesize[2]) + (left_b\
and >> x_shift);

                dst->linesize[0] = src->linesize[0];
                dst->linesize[1] = src->linesize[1];
                dst->linesize[2] = src->linesize[2];
        }
    return 0;
}


- Teemu Keinonen




More information about the ffmpeg-devel mailing list