Exemple #1
0
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 void
gst_hermes_colorspace_chain (GstPad * pad, GstData * _data)
{
  GstBuffer *buf = GST_BUFFER (_data);
  GstHermesColorspace *space;
  GstBuffer *outbuf = NULL;

  g_return_if_fail (pad != NULL);
  g_return_if_fail (GST_IS_PAD (pad));
  g_return_if_fail (buf != NULL);

  space = GST_HERMES_COLORSPACE (gst_pad_get_parent (pad));

  g_return_if_fail (space != NULL);
  g_return_if_fail (GST_IS_COLORSPACE (space));

  if (space->passthru) {
    gst_pad_push (space->srcpad, _data);
    return;
  }

  if (GST_BUFFER_SIZE (buf) < space->sink_size) {
    g_critical ("input size is smaller than expected");
  }

  outbuf =
      gst_pad_alloc_buffer_and_set_caps (space->srcpad, GST_BUFFER_OFFSET_NONE,
      space->src_size);

  Hermes_ConverterCopy (space->h_handle,
      GST_BUFFER_DATA (buf), 0, 0, space->width, space->height,
      space->sink_stride, GST_BUFFER_DATA (outbuf), 0, 0,
      space->width, space->height, space->src_stride);

  GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
  GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);

  gst_buffer_unref (buf);
  gst_pad_push (space->srcpad, GST_DATA (outbuf));
}