[FFmpeg-devel] [PATCH] lavfi/drawutils: attempt to fix subsampling.

Clément Bœsch ubitux at gmail.com
Tue May 28 15:09:12 CEST 2013


---

Fix green lines with
  ./ffmpeg -i matrixbench_mpeg2.mpg -an -vsync 0 -vf 'select=isnan(prev_selected_t)+gte(t-prev_selected_t\,4),scale=90:45,tile=10x9' -y out.jpg

Reported by a user on FFmpeg-user ml

The last two chunks are the only necessary to fix the issue. I'm not
comfortable enough with drawutils to say if those changes are enough.

BTW, I'm quite sceptical about the ff_draw_round_to_sub() function.
---
 libavfilter/drawutils.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c
index 272d9df..f8aa8cc 100644
--- a/libavfilter/drawutils.c
+++ b/libavfilter/drawutils.c
@@ -93,7 +93,7 @@ int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t
             int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
 
             pixel_step[plane] = 1;
-            line_size = (w >> hsub1) * pixel_step[plane];
+            line_size = FF_CEIL_RSHIFT(w, hsub1) * pixel_step[plane];
             line[plane] = av_malloc(line_size);
             memset(line[plane], dst_color[plane], line_size);
         }
@@ -114,9 +114,9 @@ void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4],
         int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
 
         p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
-        for (i = 0; i < (h >> vsub1); i++) {
+        for (i = 0; i < FF_CEIL_RSHIFT(h, vsub1); i++) {
             memcpy(p + (x >> hsub1) * pixelstep[plane],
-                   src[plane], (w >> hsub1) * pixelstep[plane]);
+                   src[plane], FF_CEIL_RSHIFT(w, hsub1) * pixelstep[plane]);
             p += dst_linesize[plane];
         }
     }
@@ -134,9 +134,9 @@ void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4],
         int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
 
         p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
-        for (i = 0; i < (h >> vsub1); i++) {
+        for (i = 0; i < FF_CEIL_RSHIFT(h, vsub1); i++) {
             memcpy(p + (x >> hsub1) * pixelstep[plane],
-                   src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), (w >> hsub1) * pixelstep[plane]);
+                   src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), FF_CEIL_RSHIFT(w, hsub1) * pixelstep[plane]);
             p += dst_linesize[plane];
         }
     }
@@ -233,8 +233,8 @@ void ff_copy_rectangle2(FFDrawContext *draw,
     for (plane = 0; plane < draw->nb_planes; plane++) {
         p = pointer_at(draw, src, src_linesize, plane, src_x, src_y);
         q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
-        wp = (w >> draw->hsub[plane]) * draw->pixelstep[plane];
-        hp = (h >> draw->vsub[plane]);
+        wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]) * draw->pixelstep[plane];
+        hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]);
         for (y = 0; y < hp; y++) {
             memcpy(q, p, wp);
             p += src_linesize[plane];
@@ -252,8 +252,8 @@ void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color,
 
     for (plane = 0; plane < draw->nb_planes; plane++) {
         p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
-        wp = (w >> draw->hsub[plane]);
-        hp = (h >> draw->vsub[plane]);
+        wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]);
+        hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]);
         if (!hp)
             return;
         p = p0;
-- 
1.8.2.3



More information about the ffmpeg-devel mailing list