bool bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh) { unsigned int state = 0; short bpp = bitmap_get_bpp( img ); int stride = bitmap_get_rowstride( img ); int err; if( img->resized != NULL ) { if( img->resized->width != nw || img->resized->height != nh ) { bitmap_destroy( img->resized ); img->resized = NULL; } else { /* the bitmap is already resized */ return(true); } } /* allocate the mem for resized bitmap */ if (img->opaque == true) { state |= BITMAP_OPAQUE; } img->resized = bitmap_create_ex( nw, nh, bpp, nw*bpp, state, NULL ); if( img->resized == NULL ) { printf("W: %d, H: %d, bpp: %d\n", nw, nh, bpp); assert(img->resized); return(false); } /* allocate an converter, only for resizing */ err = Hermes_ConverterRequest( hermes_h, fmt, fmt ); if( err == 0 ) { return(false); } err = Hermes_ConverterCopy( hermes_h, img->pixdata, 0, /* x src coord of top left in pixel coords */ 0, /* y src coord of top left in pixel coords */ bitmap_get_width( img ), bitmap_get_height( img ), stride, /* stride as bytes */ img->resized->pixdata, 0, /* x dst coord of top left in pixel coords */ 0, /* y dst coord of top left in pixel coords */ nw, nh, bitmap_get_rowstride(img->resized) /* stride as bytes */ ); if( err == 0 ) { bitmap_destroy( img->resized ); img->resized = NULL; return(false); } return(true); }
static GstPadLinkReturn gst_hermes_colorspace_link (GstPad * pad, const GstCaps * caps) { GstHermesColorspace *space; GstPad *otherpad; GstStructure *structure; GstPadLinkReturn link_ret; int width, height; double fps; int i; space = GST_HERMES_COLORSPACE (gst_pad_get_parent (pad)); otherpad = (pad == space->sinkpad) ? space->srcpad : space->sinkpad; link_ret = gst_pad_try_set_caps (otherpad, caps); if (link_ret == GST_PAD_LINK_OK) { space->passthru = TRUE; return link_ret; } structure = gst_caps_get_structure (caps, 0); for (i = 0; i < G_N_ELEMENTS (gst_hermes_colorspace_formats); i++) { GstCaps *icaps; GstCaps *fcaps; fcaps = gst_caps_copy (gst_static_caps_get (&gst_hermes_colorspace_formats [i].caps)); icaps = gst_caps_intersect (caps, fcaps); if (!gst_caps_is_empty (icaps)) { break; } gst_caps_free (icaps); } if (i == G_N_ELEMENTS (gst_hermes_colorspace_formats)) { g_assert_not_reached (); return GST_PAD_LINK_REFUSED; } gst_structure_get_int (structure, "width", &width); gst_structure_get_int (structure, "height", &height); gst_structure_get_double (structure, "framerate", &fps); GST_INFO ("size: %dx%d", space->width, space->height); if (gst_pad_is_negotiated (otherpad)) { GstCaps *othercaps; othercaps = gst_caps_copy (gst_pad_get_negotiated_caps (otherpad)); gst_caps_set_simple (othercaps, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", G_TYPE_DOUBLE, fps, NULL); link_ret = gst_pad_try_set_caps (otherpad, othercaps); if (link_ret != GST_PAD_LINK_OK) { return link_ret; } } if (pad == space->srcpad) { space->src_format_index = i; gst_hermes_colorspace_structure_to_hermes_format (&space->src_format, structure); } else { space->sink_format_index = i; gst_hermes_colorspace_structure_to_hermes_format (&space->sink_format, structure); } space->sink_stride = width * (space->sink_format.bits / 8); space->src_stride = width * (space->src_format.bits / 8); space->sink_size = space->sink_stride * height; space->src_size = space->src_stride * height; space->width = width; space->height = height; space->fps = fps; if (gst_pad_is_negotiated (otherpad)) { if (!Hermes_ConverterRequest (space->h_handle, &space->sink_format, &space->src_format)) { g_warning ("Hermes: could not get converter\n"); return GST_PAD_LINK_REFUSED; } g_print ("inited\n"); } return GST_PAD_LINK_OK; }
static gboolean colorspace_setup_converter (GstHermesColorspace * space, GstCaps * from_caps, GstCaps * to_caps) { guint32 from_space, to_space; GstStructure *from_struct; GstStructure *to_struct; g_return_val_if_fail (to_caps != NULL, FALSE); g_return_val_if_fail (from_caps != NULL, FALSE); from_struct = gst_caps_get_structure (from_caps, 0); to_struct = gst_caps_get_structure (to_caps, 0); from_space = GST_MAKE_FOURCC ('R', 'G', 'B', ' '); gst_structure_get_fourcc (from_struct, "format", &from_space); to_space = GST_MAKE_FOURCC ('R', 'G', 'B', ' '); gst_structure_get_fourcc (to_struct, "format", &to_space); GST_INFO ("set up converter for " GST_FOURCC_FORMAT " (%08x) to " GST_FOURCC_FORMAT " (%08x)", GST_FOURCC_ARGS (from_space), from_space, GST_FOURCC_ARGS (to_space), to_space); switch (from_space) { case GST_MAKE_FOURCC ('R', 'G', 'B', ' '): { gint from_bpp; gst_structure_get_int (from_struct, "bpp", &from_bpp); switch (to_space) { case GST_MAKE_FOURCC ('R', 'G', 'B', ' '): #ifdef HAVE_HERMES { gint to_bpp; gst_structure_get_int (to_struct, "bpp", &to_bpp); gst_structure_get_int (from_struct, "red_mask", &space->source.r); gst_structure_get_int (from_struct, "green_mask", &space->source.g); gst_structure_get_int (from_struct, "blue_mask", &space->source.b); space->source.a = 0; space->srcbpp = space->source.bits = from_bpp; space->source.indexed = 0; space->source.has_colorkey = 0; GST_INFO ("source red mask %08x", space->source.r); GST_INFO ("source green mask %08x", space->source.g); GST_INFO ("source blue mask %08x", space->source.b); GST_INFO ("source bpp %08x", space->srcbpp); gst_structure_get_int (to_struct, "red_mask", &space->dest.r); gst_structure_get_int (to_struct, "green_mask", &space->dest.g); gst_structure_get_int (to_struct, "blue_mask", &space->dest.b); space->dest.a = 0; space->destbpp = space->dest.bits = to_bpp; space->dest.indexed = 0; space->dest.has_colorkey = 0; GST_INFO ("dest red mask %08x", space->dest.r); GST_INFO ("dest green mask %08x", space->dest.g); GST_INFO ("dest blue mask %08x", space->dest.b); GST_INFO ("dest bpp %08x", space->destbpp); if (!Hermes_ConverterRequest (space->h_handle, &space->source, &space->dest)) { g_warning ("Hermes: could not get converter\n"); return FALSE; } GST_INFO ("converter set up"); space->type = GST_HERMES_COLORSPACE_HERMES; return TRUE; } #else g_warning ("colorspace: compiled without hermes!"); return FALSE; #endif case GST_MAKE_FOURCC ('Y', 'V', '1', '2'): if (from_bpp == 32) { space->type = GST_HERMES_COLORSPACE_RGB32_YV12; space->destbpp = 12; return TRUE; } case GST_MAKE_FOURCC ('I', '4', '2', '0'): if (from_bpp == 32) { space->type = GST_HERMES_COLORSPACE_RGB32_I420; space->destbpp = 12; return TRUE; } case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'): GST_INFO ("colorspace: RGB to YUV with bpp %d not implemented!!", from_bpp); return FALSE; } break; } case GST_MAKE_FOURCC ('I', '4', '2', '0'): switch (to_space) { case GST_MAKE_FOURCC ('R', 'G', 'B', ' '): GST_INFO ("colorspace: YUV to RGB"); gst_structure_get_int (to_struct, "bpp", &space->destbpp); space->converter = gst_hermes_colorspace_yuv2rgb_get_converter (from_caps, to_caps); space->type = GST_HERMES_COLORSPACE_YUV_RGB; return TRUE; case GST_MAKE_FOURCC ('I', '4', '2', '0'): space->type = GST_HERMES_COLORSPACE_NONE; space->destbpp = 12; return TRUE; case GST_MAKE_FOURCC ('Y', 'V', '1', '2'): space->type = GST_HERMES_COLORSPACE_420_SWAP; space->destbpp = 12; return TRUE; } break; case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'): switch (to_space) { case GST_MAKE_FOURCC ('I', '4', '2', '0'): space->type = GST_HERMES_COLORSPACE_YUY2_I420; space->destbpp = 12; return TRUE; case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'): space->type = GST_HERMES_COLORSPACE_NONE; space->destbpp = 16; return TRUE; case GST_MAKE_FOURCC ('R', 'G', 'B', ' '): GST_INFO ("colorspace: YUY2 to RGB not implemented!!"); return FALSE; } break; case GST_MAKE_FOURCC ('Y', 'V', '1', '2'): switch (to_space) { case GST_MAKE_FOURCC ('R', 'G', 'B', ' '): GST_INFO ("colorspace: YV12 to RGB"); gst_structure_get_int (to_struct, "bpp", &space->destbpp); space->converter = gst_hermes_colorspace_yuv2rgb_get_converter (from_caps, to_caps); space->type = GST_HERMES_COLORSPACE_YUV_RGB; return TRUE; case GST_MAKE_FOURCC ('I', '4', '2', '0'): space->type = GST_HERMES_COLORSPACE_420_SWAP; space->destbpp = 12; return TRUE; case GST_MAKE_FOURCC ('Y', 'V', '1', '2'): space->type = GST_HERMES_COLORSPACE_NONE; space->destbpp = 12; return TRUE; } break; } return FALSE; }