diff --git a/ext/cog/cogframe.c b/ext/cog/cogframe.c index 974fa7b041..50a21891d0 100644 --- a/ext/cog/cogframe.c +++ b/ext/cog/cogframe.c @@ -864,7 +864,7 @@ cog_frame_convert (CogFrame * dest, CogFrame * src) } if ((dest_format & 3) != (frame->format & 3)) { - frame = cog_virt_frame_new_subsample (frame, dest_format); + frame = cog_virt_frame_new_subsample (frame, dest_format, 2); GST_DEBUG ("subsample %p", frame); } diff --git a/ext/cog/cogvirtframe.c b/ext/cog/cogvirtframe.c index 718c91ba84..edaa5934d3 100644 --- a/ext/cog/cogvirtframe.c +++ b/ext/cog/cogvirtframe.c @@ -1532,18 +1532,24 @@ convert_422_444 (CogFrame * frame, void *_dest, int component, int i) { uint8_t *dest = _dest; uint8_t *src; + int n_taps = frame->param1; src = cog_virt_frame_get_line (frame->virt_frame1, component, i); if (component == 0) { orc_memcpy (dest, src, frame->width); } else { - cogorc_upsample_horiz_cosite_1tap (dest, src, - frame->components[component].width / 2 - 1); -#if 0 - cogorc_upsample_horiz_cosite (dest, src, src + 1, - frame->components[component].width / 2 - 1); -#endif + switch (n_taps) { + default: + case 1: + cogorc_upsample_horiz_cosite_1tap (dest, src, + frame->components[component].width / 2 - 1); + break; + case 2: + cogorc_upsample_horiz_cosite (dest, src, src + 1, + frame->components[component].width / 2 - 1); + break; + } dest[frame->components[component].width - 2] = src[frame->components[component].width / 2 - 1]; dest[frame->components[component].width - 1] = @@ -1556,33 +1562,38 @@ convert_420_422 (CogFrame * frame, void *_dest, int component, int i) { uint8_t *dest = _dest; uint8_t *src; + int n_taps = frame->param1; if (component == 0) { src = cog_virt_frame_get_line (frame->virt_frame1, component, i); orc_memcpy (dest, src, frame->components[component].width); } else { -#if 0 - if ((i & 1) && i < frame->components[component].height - 1) { - uint8_t *src2; + switch (n_taps) { + case 1: + default: + src = cog_virt_frame_get_line (frame->virt_frame1, component, i >> 1); + orc_memcpy (dest, src, frame->components[component].width); + break; + case 2: + if ((i & 1) && i < frame->components[component].height - 1) { + uint8_t *src2; - src = cog_virt_frame_get_line (frame->virt_frame1, component, i >> 1); - src2 = cog_virt_frame_get_line (frame->virt_frame1, - component, (i >> 1) + 1); - cogorc_upsample_vert_avgub (dest, src, src2, - frame->components[component].width); - } else { - src = cog_virt_frame_get_line (frame->virt_frame1, component, i >> 1); - orc_memcpy (dest, src, frame->components[component].width); + src = cog_virt_frame_get_line (frame->virt_frame1, component, i >> 1); + src2 = cog_virt_frame_get_line (frame->virt_frame1, + component, (i >> 1) + 1); + cogorc_upsample_vert_avgub (dest, src, src2, + frame->components[component].width); + } else { + src = cog_virt_frame_get_line (frame->virt_frame1, component, i >> 1); + orc_memcpy (dest, src, frame->components[component].width); + } + break; } -#else - src = cog_virt_frame_get_line (frame->virt_frame1, component, i >> 1); - orc_memcpy (dest, src, frame->components[component].width); -#endif } } CogFrame * -cog_virt_frame_new_subsample (CogFrame * vf, CogFrameFormat format) +cog_virt_frame_new_subsample (CogFrame * vf, CogFrameFormat format, int n_taps) { CogFrame *virt_frame; CogFrameRenderFunc render_line; @@ -1599,6 +1610,7 @@ cog_virt_frame_new_subsample (CogFrame * vf, CogFrameFormat format) vf->width, vf->height); virt_frame->virt_frame1 = vf; virt_frame->render_line = convert_444_422; + virt_frame->param1 = n_taps; vf = virt_frame; render_line = convert_422_420; @@ -1614,6 +1626,7 @@ cog_virt_frame_new_subsample (CogFrame * vf, CogFrameFormat format) vf->width, vf->height); virt_frame->virt_frame1 = vf; virt_frame->render_line = convert_420_422; + virt_frame->param1 = n_taps; vf = virt_frame; render_line = convert_422_444; @@ -1626,6 +1639,7 @@ cog_virt_frame_new_subsample (CogFrame * vf, CogFrameFormat format) } virt_frame = cog_frame_new_virtual (NULL, format, vf->width, vf->height); virt_frame->virt_frame1 = vf; + virt_frame->param1 = n_taps; virt_frame->render_line = render_line; return virt_frame; diff --git a/ext/cog/cogvirtframe.h b/ext/cog/cogvirtframe.h index 3895b4ea35..dfe405a5b4 100644 --- a/ext/cog/cogvirtframe.h +++ b/ext/cog/cogvirtframe.h @@ -29,7 +29,7 @@ CogFrame *cog_virt_frame_new_pack_v210 (CogFrame *vf); CogFrame *cog_virt_frame_new_pack_RGB (CogFrame *vf); CogFrame *cog_virt_frame_new_color_matrix_YCbCr_to_RGB (CogFrame *vf, CogColorMatrix color_matrix, int coefficient_bits); CogFrame * cog_virt_frame_new_color_matrix_RGB_to_YCbCr (CogFrame * vf, CogColorMatrix color_matrix, int coefficient_bits); -CogFrame *cog_virt_frame_new_subsample (CogFrame *vf, CogFrameFormat format); +CogFrame *cog_virt_frame_new_subsample (CogFrame *vf, CogFrameFormat format, int n_taps); CogFrame * cog_virt_frame_new_convert_u8 (CogFrame *vf); CogFrame * cog_virt_frame_new_convert_s16 (CogFrame *vf); diff --git a/ext/cog/gstcogcolorspace.c b/ext/cog/gstcogcolorspace.c index c076f5e0f2..b2b7c1514e 100644 --- a/ext/cog/gstcogcolorspace.c +++ b/ext/cog/gstcogcolorspace.c @@ -448,7 +448,8 @@ gst_cogcolorspace_transform (GstBaseTransform * base_transform, compress->color_matrix, 8); } - frame = cog_virt_frame_new_subsample (frame, new_subsample); + frame = cog_virt_frame_new_subsample (frame, new_subsample, + (compress->quality >= 3) ? 2 : 1); if (gst_video_format_is_rgb (out_format) && gst_video_format_is_yuv (in_format)) { diff --git a/ext/cog/gstcolorconvert.c b/ext/cog/gstcolorconvert.c index 5401b67a2e..f04583a059 100644 --- a/ext/cog/gstcolorconvert.c +++ b/ext/cog/gstcolorconvert.c @@ -238,18 +238,18 @@ gst_colorconvert_transform_ip (GstBaseTransform * base_transform, li->format, li->width, li->height); vf = cog_virt_frame_new_unpack (cog_frame_ref (frame)); - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_444); + vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_444, 2); vf = cog_virt_frame_new_color_transform (vf); if (frame->format == COG_FRAME_FORMAT_YUYV) { - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422); + vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422, 2); vf = cog_virt_frame_new_pack_YUY2 (vf); } else if (frame->format == COG_FRAME_FORMAT_UYVY) { - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422); + vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422, 2); vf = cog_virt_frame_new_pack_UYVY (vf); } else if (frame->format == COG_FRAME_FORMAT_AYUV) { vf = cog_virt_frame_new_pack_AYUV (vf); } else if (frame->format == COG_FRAME_FORMAT_U8_420) { - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_420); + vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_420, 2); } else { g_assert_not_reached (); } diff --git a/ext/cog/gstlogoinsert.c b/ext/cog/gstlogoinsert.c index 4aea9fa2e6..8f4a340367 100644 --- a/ext/cog/gstlogoinsert.c +++ b/ext/cog/gstlogoinsert.c @@ -261,13 +261,13 @@ gst_logoinsert_transform_ip (GstBaseTransform * base_transform, GstBuffer * buf) CogFrame *f; f = cog_virt_frame_extract_alpha (cog_frame_ref (li->ayuv_frame)); - f = cog_virt_frame_new_subsample (f, frame->format); + f = cog_virt_frame_new_subsample (f, frame->format, 2); li->alpha_frame = cog_frame_realize (f); f = cog_virt_frame_new_unpack (cog_frame_ref (li->ayuv_frame)); f = cog_virt_frame_new_color_matrix_RGB_to_YCbCr (f, COG_COLOR_MATRIX_SDTV, 8); - f = cog_virt_frame_new_subsample (f, frame->format); + f = cog_virt_frame_new_subsample (f, frame->format, 2); li->overlay_frame = cog_frame_realize (f); }