[SCM] libav/experimental: Fix cropping, depending on enc pix fmt

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 15:46:56 UTC 2013


The following commit has been merged in the experimental branch:
commit f2651e7a6c7a9f492158a36af635eb4fb8ebac36
Author: Baptiste Coudurier <baptiste.coudurier at gmail.com>
Date:   Fri Mar 10 13:55:48 2006 +0000

    Fix cropping, depending on enc pix fmt
    
    Originally committed as revision 5134 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/ffmpeg.c b/ffmpeg.c
index 22a6b9d..3011501 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -847,20 +847,10 @@ static void do_video_out(AVFormatContext *s,
             }
         }
     } else if (ost->video_crop) {
-        picture_crop_temp.data[0] = formatted_picture->data[0] +
-                (ost->topBand * formatted_picture->linesize[0]) + ost->leftBand;
-
-        picture_crop_temp.data[1] = formatted_picture->data[1] +
-                ((ost->topBand >> 1) * formatted_picture->linesize[1]) +
-                (ost->leftBand >> 1);
-
-        picture_crop_temp.data[2] = formatted_picture->data[2] +
-                ((ost->topBand >> 1) * formatted_picture->linesize[2]) +
-                (ost->leftBand >> 1);
-
-        picture_crop_temp.linesize[0] = formatted_picture->linesize[0];
-        picture_crop_temp.linesize[1] = formatted_picture->linesize[1];
-        picture_crop_temp.linesize[2] = formatted_picture->linesize[2];
+        if (img_crop((AVPicture *)&picture_crop_temp, (AVPicture *)formatted_picture, enc->pix_fmt, ost->topBand, ost->leftBand) < 0) {
+            av_log(NULL, AV_LOG_ERROR, "error cropping picture\n");
+            goto the_end;
+        }
         final_picture = &picture_crop_temp;
     } else if (ost->video_pad) {
         final_picture = &ost->pict_tmp;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index a9f3164..6c33373 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2555,6 +2555,9 @@ int is_adx(const unsigned char *buf,size_t bufsize);
 void img_copy(AVPicture *dst, const AVPicture *src,
               int pix_fmt, int width, int height);
 
+int img_crop(AVPicture *dst, const AVPicture *src,
+             int pix_fmt, int top_band, int left_band);
+
 /* av_log API */
 
 #include <stdarg.h>
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 850f9b0..e03706d 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -1951,6 +1951,31 @@ static inline int is_yuv_planar(PixFmtInfo *ps)
         ps->pixel_type == FF_PIXEL_PLANAR;
 }
 
+/**
+ * Crop image top and left side
+ */
+int img_crop(AVPicture *dst, const AVPicture *src,
+              int pix_fmt, int top_band, int left_band)
+{
+    int y_shift;
+    int x_shift;
+
+    if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
+        return -1;
+
+    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_band >> x_shift);
+    dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
+
+    dst->linesize[0] = src->linesize[0];
+    dst->linesize[1] = src->linesize[1];
+    dst->linesize[2] = src->linesize[2];
+    return 0;
+}
+
 /* XXX: always use linesize. Return -1 if not supported */
 int img_convert(AVPicture *dst, int dst_pix_fmt,
                 const AVPicture *src, int src_pix_fmt,

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list