static GstFlowReturn gst_colorconvert_transform_ip (GstBaseTransform * base_transform, GstBuffer * buf) { GstColorconvert *li; CogFrame *frame; CogFrame *vf; g_return_val_if_fail (GST_IS_COLORCONVERT (base_transform), GST_FLOW_ERROR); li = GST_COLORCONVERT (base_transform); frame = gst_cog_buffer_wrap (gst_buffer_ref (buf), 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, COG_CHROMA_SITE_MPEG2, 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, COG_CHROMA_SITE_MPEG2, 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, COG_CHROMA_SITE_MPEG2, 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, COG_CHROMA_SITE_MPEG2, 2); } else { g_assert_not_reached (); } cog_virt_frame_render (vf, frame); cog_frame_unref (frame); cog_frame_unref (vf); return GST_FLOW_OK; }
static GstFlowReturn gst_logoinsert_transform_ip (GstBaseTransform * base_transform, GstBuffer * buf) { GstLogoinsert *li; CogFrame *frame; g_return_val_if_fail (GST_IS_LOGOINSERT (base_transform), GST_FLOW_ERROR); li = GST_LOGOINSERT (base_transform); if (li->argb_frame == NULL) return GST_FLOW_OK; frame = gst_cog_buffer_wrap (gst_buffer_ref (buf), li->format, li->width, li->height); if (li->overlay_frame == NULL) { CogFrame *f; f = cog_virt_frame_extract_alpha (cog_frame_ref (li->argb_frame)); f = cog_virt_frame_new_subsample (f, frame->format, COG_CHROMA_SITE_MPEG2, 2); li->alpha_frame = cog_frame_realize (f); f = cog_virt_frame_new_unpack (cog_frame_ref (li->argb_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, COG_CHROMA_SITE_MPEG2, 2); li->overlay_frame = cog_frame_realize (f); } if (1) { int i, j; int k; guint8 *dest; guint8 *src; guint8 *alpha; int offset_x, offset_y; for (k = 0; k < 3; k++) { offset_x = frame->components[k].width - li->alpha_frame->components[k].width; offset_y = frame->components[k].height - li->alpha_frame->components[k].height; for (j = 0; j < li->overlay_frame->components[k].height; j++) { dest = COG_FRAME_DATA_GET_LINE (frame->components + k, j + offset_y); src = COG_FRAME_DATA_GET_LINE (li->overlay_frame->components + k, j); alpha = COG_FRAME_DATA_GET_LINE (li->alpha_frame->components + k, j); #define oil_divide_255(x) ((((x)+128) + (((x)+128)>>8))>>8) for (i = 0; i < li->overlay_frame->components[k].width; i++) { dest[i + offset_x] = oil_divide_255 (src[i] * alpha[i] + dest[i + offset_x] * (255 - alpha[i])); } } } } cog_frame_unref (frame); return GST_FLOW_OK; }