]> granicus.if.org Git - handbrake/commitdiff
lapsharp: mirror image data into stride region
authorJohn Stebbins <jstebbins.hb@gmail.com>
Sat, 19 Jan 2019 18:41:59 +0000 (10:41 -0800)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 20 Jan 2019 17:20:47 +0000 (09:20 -0800)
Adds a function to mirror image data into stride region. Mirroring the
data results in a less visible artefact down the right edge of the
image. Blanking resulted in a dark edge artefact.

Keeps function that blanks stride region and improves it's speed,
although it's not currently used.

libhb/fifo.c
libhb/internal.h
libhb/lapsharp.c

index b631e46dbb1ce6e66d8edcc0ff3483169e7b7562..be9c44313fc20a84348741c824a4a32b9b91cca7 100644 (file)
@@ -599,27 +599,72 @@ hb_buffer_t * hb_frame_buffer_init( int pix_fmt, int width, int height )
 
 void hb_frame_buffer_blank_stride(hb_buffer_t * buf)
 {
-    int pp, xx, yy, stride;
+    uint8_t * data;
+    int       pp, yy, width, height, stride, height_stride;
 
     for (pp = 0; pp < 4; pp++)
     {
-        if (buf->plane[pp].data != NULL)
+        data          = buf->plane[pp].data;
+        width         = buf->plane[pp].width;
+        height        = buf->plane[pp].height;
+        stride        = buf->plane[pp].stride;
+        height_stride = buf->plane[pp].height_stride;
+
+        if (data != NULL)
         {
-            stride = buf->plane[pp].stride;
-            for (yy = 0; yy < buf->plane[pp].height; yy++)
+            // Blank right margin
+            for (yy = 0; yy < height; yy++)
             {
-                for (xx = buf->plane[pp].width; xx < stride; xx++)
-                {
-                    *(buf->plane[pp].data + (yy * stride) + xx) = 0x80;
-                }
+                memset(data + yy * stride + width, 0x80, stride - width);
+            }
+            // Blank bottom margin
+            for (yy = height; yy < height_stride; yy++)
+            {
+                memset(data + yy * stride, 0x80, stride);
             }
-            for (yy = buf->plane[pp].height;
-                 yy < buf->plane[pp].height_stride; yy++)
+        }
+    }
+}
+
+void hb_frame_buffer_mirror_stride(hb_buffer_t * buf)
+{
+    uint8_t * data;
+    int       pp, ii, yy, width, height, stride, height_stride;
+    int       pos, margin, margin_front, margin_back;
+
+    for (pp = 0; pp < 4; pp++)
+    {
+        data          = buf->plane[pp].data;
+        width         = buf->plane[pp].width;
+        height        = buf->plane[pp].height;
+        stride        = buf->plane[pp].stride;
+        height_stride = buf->plane[pp].height_stride;
+        if (data != NULL)
+        {
+            margin       = stride - width;
+            margin_front = margin / 2;
+            margin_back  = margin - margin_front;
+            for (yy = 0; yy < height; yy++)
             {
-                for (xx = 0; xx < stride; xx++)
+                // Mirror final row pixels into front of stride region
+                pos = yy * stride + width;
+                for (ii = 0; ii < margin_back; ii++)
                 {
-                    *(buf->plane[pp].data + (yy * stride) + xx) = 0x80;
+                    *(data + pos + ii) = *(data + pos - ii - 1);
                 }
+                // Mirror start of next row into end of stride region
+                pos = (yy + 1) * stride - 1;
+                for (ii = 0; ii < margin_front; ii++)
+                {
+                    *(data + pos - ii) = *(data + pos + ii + 1);
+                }
+            }
+            // Mirror bottom rows into height_stride
+            pos = height * stride;
+            for (ii = 0; ii < height_stride - height; ii++)
+            {
+                memcpy(data + pos + ii * stride,
+                       data + pos - ((ii + 1) * stride), stride);
             }
         }
     }
index 1ad82d7f35874af9eb18838dda0b2f8fa5714ff6..dde9083978223e430256d658d126c8a238e6e6b6 100644 (file)
@@ -162,6 +162,7 @@ hb_buffer_t * hb_buffer_init( int size );
 hb_buffer_t * hb_buffer_eof_init( void );
 hb_buffer_t * hb_frame_buffer_init( int pix_fmt, int w, int h);
 void          hb_frame_buffer_blank_stride(hb_buffer_t * buf);
+void          hb_frame_buffer_mirror_stride(hb_buffer_t * buf);
 void          hb_buffer_init_planes( hb_buffer_t * b );
 void          hb_buffer_realloc( hb_buffer_t *, int size );
 void          hb_video_buffer_realloc( hb_buffer_t * b, int w, int h );
index 29d3122f5c79f83c991e9c1ce276014c845f4899..d7146c0317884d38705fece2e6d1920f4f769b06 100644 (file)
@@ -283,7 +283,7 @@ static int hb_lapsharp_work(hb_filter_object_t *filter,
         return HB_FILTER_DONE;
     }
 
-    hb_frame_buffer_blank_stride(in);
+    hb_frame_buffer_mirror_stride(in);
     out = hb_frame_buffer_init(in->f.fmt, in->f.width, in->f.height);
 
     int c;