From: John Stebbins Date: Sat, 19 Jan 2019 18:41:59 +0000 (-0800) Subject: lapsharp: mirror image data into stride region X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45e783372b35fe39f8ae7f488dfed7796793665e;p=handbrake lapsharp: mirror image data into stride region 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. --- diff --git a/libhb/fifo.c b/libhb/fifo.c index b631e46db..be9c44313 100644 --- a/libhb/fifo.c +++ b/libhb/fifo.c @@ -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); } } } diff --git a/libhb/internal.h b/libhb/internal.h index 1ad82d7f3..dde908397 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -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 ); diff --git a/libhb/lapsharp.c b/libhb/lapsharp.c index 29d3122f5..d7146c031 100644 --- a/libhb/lapsharp.c +++ b/libhb/lapsharp.c @@ -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;