Example #1
1
static void
draw_page (GtkPrintOperation *operation,
		   GtkPrintContext   *context,
		   gint               page_nr,
		   gpointer           user_data)
{
    ViewerCbInfo *info = (ViewerCbInfo *) user_data;

	cairo_t *cr;
	gdouble page_width, page_height;
  
	cr = gtk_print_context_get_cairo_context (context);
	page_width = gtk_print_context_get_width (context);
	page_height = gtk_print_context_get_height (context);

	{
		RsvgHandle *handle;
		RsvgDimensionData svg_dimensions;
		struct RsvgSizeCallbackData size_data;

		/* should not fail */
		handle = rsvg_handle_new_from_data(info->svg_bytes->data, info->svg_bytes->len, NULL);
		rsvg_handle_set_base_uri (handle, info->base_uri);
		rsvg_handle_set_dpi_x_y (handle, gtk_print_context_get_dpi_x(context), 
								 gtk_print_context_get_dpi_y(context));
		rsvg_handle_get_dimensions(handle, &svg_dimensions);

        if (svg_dimensions.width > page_width || svg_dimensions.height > page_height) {
            /* scale down the image to the page's size, while preserving the aspect ratio */

            if ((double) svg_dimensions.height * (double) page_width > (double) svg_dimensions.width * (double) page_height) {
                svg_dimensions.width = 0.5 + (double) svg_dimensions.width *(double) page_height / (double) svg_dimensions.height;
                svg_dimensions.height = page_height;
            } else {
                svg_dimensions.height = 0.5 + (double) svg_dimensions.height *(double) page_width / (double) svg_dimensions.width;
                svg_dimensions.width = page_width;
            }
        }

		size_data.type = RSVG_SIZE_WH;
		size_data.width = svg_dimensions.width;
		size_data.height = svg_dimensions.height;
		size_data.keep_aspect_ratio = FALSE;
		rsvg_handle_set_size_callback (handle, _rsvg_size_callback, &size_data, NULL);

		rsvg_handle_render_cairo(handle, cr);

		g_object_unref (handle);
	}
}
Example #2
0
void
SvgWindow::setSvg (CompString    &data,
		   decor_point_t p[2])
{
    RsvgHandle *svg = NULL;
    GError     *error = NULL;

    if (!gWindow)
	return;

    svg = rsvg_handle_new_from_data ((guint8 *) data.c_str (),
				     data.length (), &error);

    if (source)
    {
	rsvg_handle_free (source->svg);
	source->svg = svg;
    }
    else
    {
	source = new SvgSource;
	if (source)
	    source->svg = svg;
    }

    if (source && source->svg)
    {
	source->p1 = p[0];
	source->p2 = p[1];

	source->svg = svg;

	gWindow->glDrawSetEnabled (this, true);
	rsvg_handle_get_dimensions (svg, &source->dimension);

	updateSvgContext ();
    }
    else
    {
	if (svg)
	    rsvg_handle_free (svg);

	if (source)
	{
	    delete source;
	    source = NULL;
	}

	if (context)
	{
	    finiTexture (context->texture[0]);
	    delete context;
	    context = NULL;
	}

	gWindow->glDrawSetEnabled (this, false);
    }
}
Example #3
0
static VALUE
rb_rsvg_handle_new_from_data(VALUE self, VALUE data)
{
    GError *error = NULL;
    RsvgHandle *handle;

    handle = rsvg_handle_new_from_data((const guint8 *)RVAL2CSTR(data),
                                       RSTRING_LEN(data), &error);

    if (error)
        RAISE_GERROR(error);

    return GOBJ2RVAL(handle);
}
Example #4
0
static PyObject *_viewer_str(PyObject *self, PyObject *args) {
  char *str_source = NULL;
  int str_size;
  if (!PyArg_ParseTuple(args, "es#", "utf-16", &str_source, &str_size)) {
    PyErr_SetString(PyExc_TypeError, "source must be an SVG string or Unicode object.");
    return NULL;
  }

  if (done) {
    GError *error = NULL;
    if (!g_thread_create(thread, NULL, FALSE, &error)) {
      PyErr_Format(PyExc_RuntimeError, "Could not create GDK thread: %s", error->message);
      PyMem_Free(str_source);
      return NULL;
    }
  }

  if (rsvg != NULL) {
    g_object_unref(rsvg);
    rsvg = NULL;
  }

  GError* error = NULL;
  rsvg = rsvg_handle_new_from_data((guint8*)(str_source), (gsize)(str_size), &error);
  if (rsvg == NULL) {
    PyErr_Format(PyExc_RuntimeError, "Couldn't parse SVG: %s", error->message);
    PyMem_Free(str_source);
    return NULL;
  }

  /* wait for the window to appear, and don't wait forever */
  /* if 5 seconds are reached, don't explicitly throw an error, let */
  /* GDK do that if it needs to */
  g_thread_yield();
  time_t start = time(NULL);
  while (!ready) {
    time_t now = time(NULL);
    if (difftime(now, start) > 5) break;
  }

  gdk_threads_enter();
  gtk_widget_queue_draw(drawing_area);
  gdk_threads_leave();

  PyMem_Free(str_source);
  return Py_BuildValue("O", Py_None);
}
Example #5
0
static void
gst_rsvg_overlay_set_svg_data (GstRsvgOverlay * overlay, const gchar * data,
    gboolean consider_as_filename)
{
  GstBaseTransform *btrans = GST_BASE_TRANSFORM (overlay);
  gsize size;
  GError *error = NULL;

  if (overlay->handle) {
    g_object_unref (overlay->handle);
    overlay->handle = NULL;
    gst_base_transform_set_passthrough (btrans, TRUE);
  }

  /* data may be NULL */
  if (data) {
    size = strlen (data);
    if (size) {
      /* Read data either from string or from file */
      if (consider_as_filename)
        overlay->handle = rsvg_handle_new_from_file (data, &error);
      else
        overlay->handle =
            rsvg_handle_new_from_data ((guint8 *) data, size, &error);
      if (error || overlay->handle == NULL) {
        if (error) {
          GST_ERROR_OBJECT (overlay, "Cannot read SVG data: %s\n%s",
              error->message, data);
          g_error_free (error);
        } else {
          GST_ERROR_OBJECT (overlay, "Cannot read SVG data: %s", data);
        }
      } else {
        /* Get SVG dimension. */
        RsvgDimensionData svg_dimension;
        rsvg_handle_get_dimensions (overlay->handle, &svg_dimension);
        overlay->svg_width = svg_dimension.width;
        overlay->svg_height = svg_dimension.height;
        gst_base_transform_set_passthrough (btrans, FALSE);
        GST_INFO_OBJECT (overlay, "updated SVG, %d x %d", overlay->svg_width,
            overlay->svg_height);
      }
    }
  }
}
Example #6
0
/* Rasterise given SVG image into the PNG format. When dimensions (width and
 * height) are set to -1, than SVG view-box is used. If only height is set to
 * -1, then original aspect ratio is preserved and image is resized according
 * to the width parameter. Upon failure this function returns NULL. */
struct raster_png *raster_svg_to_png(const char *svg,
		unsigned int width, unsigned int height) {

	RsvgHandle *rsvg;
	RsvgDimensionData dimension;
	cairo_t *cr;
	cairo_surface_t *surface;
	cairo_matrix_t matrix;
	struct raster_png *png;

	if ((png = calloc(1, sizeof(*png))) == NULL)
		return NULL;

	if ((rsvg = rsvg_handle_new_from_data(svg, strlen(svg), NULL)) == NULL) {
		raster_png_free(png);
		return NULL;
	}

	/* initialize default dimensions based on the SVG view-box */
	rsvg_handle_get_dimensions(rsvg, &dimension);
	if (width == -1)
		width = dimension.width;
	if (height == -1)
		height = round((double)(width * dimension.height) / dimension.width);

	/* scale SVG image according to the given dimensions */
	cairo_matrix_init_scale(&matrix,
			(double)width / dimension.width, (double)height / dimension.height);

	surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
	cr = cairo_create(surface);
	cairo_set_matrix(cr, &matrix);

	/* draw our SVG data to the Cairo surface */
	if (rsvg_handle_render_cairo(rsvg, cr))
		cairo_surface_write_to_png_stream(surface, _png_write_callback, png);

	cairo_destroy(cr);
	cairo_surface_destroy(surface);
	g_object_unref(G_OBJECT(rsvg));

	return png;
}
Example #7
0
void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid,
             void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
{
  dt_iop_watermark_data_t *data = (dt_iop_watermark_data_t *)piece->data;
  float *in = (float *)ivoid;
  float *out = (float *)ovoid;
  const int ch = piece->colors;
  double angle = (M_PI / 180) * -data->rotate;

  /* Load svg if not loaded */
  gchar *svgdoc = _watermark_get_svgdoc(self, data, &piece->pipe->image);
  if(!svgdoc)
  {
    memcpy(ovoid, ivoid, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height);
    return;
  }

  /* create the rsvghandle from parsed svg data */
  GError *error = NULL;
  RsvgHandle *svg = rsvg_handle_new_from_data((const guint8 *)svgdoc, strlen(svgdoc), &error);
  g_free(svgdoc);
  if(!svg || error)
  {
    memcpy(ovoid, ivoid, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height);
    return;
  }

  /* setup stride for performance */
  int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, roi_out->width);

  /* create cairo memory surface */
  guint8 *image = (guint8 *)g_malloc0_n(roi_out->height, stride);
  cairo_surface_t *surface = cairo_image_surface_create_for_data(image, CAIRO_FORMAT_ARGB32, roi_out->width,
                                                                 roi_out->height, stride);
  if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS)
  {
    //   fprintf(stderr,"Cairo surface error: %s\n",cairo_status_to_string(cairo_surface_status(surface)));
    g_free(image);
    memcpy(ovoid, ivoid, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height);
    return;
  }

  /* create cairo context and setup transformation/scale */
  cairo_t *cr = cairo_create(surface);

  /* get the dimension of svg */
  RsvgDimensionData dimension;
  rsvg_handle_get_dimensions(svg, &dimension);

  //  width/height of current (possibly cropped) image
  const float iw = piece->buf_in.width;
  const float ih = piece->buf_in.height;
  const float uscale = data->scale / 100.0; // user scale, from GUI in percent

  // wbase, hbase are the base width and height, this is the multiplicator used for the offset computing
  // scale is the scale of the watermark itself and is used only to render it.

  float wbase, hbase, scale;

  if(data->sizeto == DT_SCALE_IMAGE)
  {
    // in image mode, the wbase and hbase are just the image width and height
    wbase = iw;
    hbase = ih;
    if(dimension.width > dimension.height)
      scale = (iw * roi_out->scale) / dimension.width;
    else
      scale = (ih * roi_out->scale) / dimension.height;
  }
  else
  {
    // in larger/smaller side mode, set wbase and hbase to the largest or smallest side of the image
    float larger;
    if(dimension.width > dimension.height)
      larger = (float)dimension.width;
    else
      larger = (float)dimension.height;

    if(iw > ih)
    {
      wbase = hbase = (data->sizeto == DT_SCALE_LARGER_BORDER) ? iw : ih;
      scale = (data->sizeto == DT_SCALE_LARGER_BORDER) ? (iw / larger) : (ih / larger);
    }
    else
    {
      wbase = hbase = (data->sizeto == DT_SCALE_SMALLER_BORDER) ? iw : ih;
      scale = (data->sizeto == DT_SCALE_SMALLER_BORDER) ? (iw / larger) : (ih / larger);
    }
    scale *= roi_out->scale;
  }

  scale *= uscale;

  // compute the width and height of the SVG object in image dimension. This is only used to properly
  // layout the watermark based on the alignment.

  float svg_width, svg_height;

  if(dimension.width > dimension.height)
  {
    if(data->sizeto == DT_SCALE_IMAGE || (iw > ih && data->sizeto == DT_SCALE_LARGER_BORDER)
       || (iw < ih && data->sizeto == DT_SCALE_SMALLER_BORDER))
    {
      svg_width = iw * uscale;
      svg_height = dimension.height * (svg_width / dimension.width);
    }
    else
    {
      svg_width = ih * uscale;
      svg_height = dimension.height * (svg_width / dimension.width);
    }
  }
  else
  {
    if(data->sizeto == DT_SCALE_IMAGE || (ih > iw && data->sizeto == DT_SCALE_LARGER_BORDER)
       || (ih < iw && data->sizeto == DT_SCALE_SMALLER_BORDER))
    {
      svg_height = ih * uscale;
      svg_width = dimension.width * (svg_height / dimension.height);
    }
    else
    {
      svg_height = iw * uscale;
      svg_width = dimension.width * (svg_height / dimension.height);
    }
  }

  // compute bounding box of rotated watermark
  float bb_width, bb_height;
  bb_width = fabs(svg_width * cos(angle)) + fabs(svg_height * sin(angle));
  bb_height = fabs(svg_width * sin(angle)) + fabs(svg_height * cos(angle));
  float bX = bb_width / 2.0 - svg_width / 2.0;
  float bY = bb_height / 2.0 - svg_height / 2.0;

  // compute translation for the given alignment in image dimension

  float ty = 0, tx = 0;
  if(data->alignment >= 0 && data->alignment < 3) // Align to verttop
    ty = bY;
  else if(data->alignment >= 3 && data->alignment < 6) // Align to vertcenter
    ty = (ih / 2.0) - (svg_height / 2.0);
  else if(data->alignment >= 6 && data->alignment < 9) // Align to vertbottom
    ty = ih - svg_height - bY;

  if(data->alignment == 0 || data->alignment == 3 || data->alignment == 6)
    tx = bX;
  else if(data->alignment == 1 || data->alignment == 4 || data->alignment == 7)
    tx = (iw / 2.0) - (svg_width / 2.0);
  else if(data->alignment == 2 || data->alignment == 5 || data->alignment == 8)
    tx = iw - svg_width - bX;

  // translate to position
  cairo_translate(cr, -roi_in->x, -roi_in->y);

  // add translation for the given value in GUI (xoffset,yoffset)
  tx += data->xoffset * wbase;
  ty += data->yoffset * hbase;

  cairo_translate(cr, tx * roi_out->scale, ty * roi_out->scale);

  // compute the center of the svg to rotate from the center
  float cX = svg_width / 2.0 * roi_out->scale;
  float cY = svg_height / 2.0 * roi_out->scale;

  cairo_translate(cr, cX, cY);
  cairo_rotate(cr, angle);
  cairo_translate(cr, -cX, -cY);

  // now set proper scale for the watermark itself
  cairo_scale(cr, scale, scale);

  /* render svg into surface*/
  dt_pthread_mutex_lock(&darktable.plugin_threadsafe);
  rsvg_handle_render_cairo(svg, cr);
  dt_pthread_mutex_unlock(&darktable.plugin_threadsafe);

  cairo_destroy(cr);

  /* ensure that all operations on surface finishing up */
  cairo_surface_flush(surface);

  /* render surface on output */
  guint8 *sd = image;
  float opacity = data->opacity / 100.0;
  /*
  #ifdef _OPENMP
    #pragma omp parallel for default(none) shared(in, out,sd,opacity) schedule(static)
  #endif
  */
  for(int j = 0; j < roi_out->height; j++)
    for(int i = 0; i < roi_out->width; i++)
    {
      float alpha = (sd[3] / 255.0) * opacity;
      /* svg uses a premultiplied alpha, so only use opacity for the blending */
      out[0] = ((1.0 - alpha) * in[0]) + (opacity * (sd[2] / 255.0));
      out[1] = ((1.0 - alpha) * in[1]) + (opacity * (sd[1] / 255.0));
      out[2] = ((1.0 - alpha) * in[2]) + (opacity * (sd[0] / 255.0));
      out[3] = in[3];

      out += ch;
      in += ch;
      sd += 4;
    }


  /* clean up */
  cairo_surface_destroy(surface);
  g_object_unref(svg);
  g_free(image);
}
Example #8
0
void process (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, void *ivoid, void *ovoid, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out)
{
  dt_iop_watermark_data_t *data = (dt_iop_watermark_data_t *)piece->data;
  float *in  = (float *)ivoid;
  float *out = (float *)ovoid;
  const int ch = piece->colors;

  /* Load svg if not loaded */
  gchar *svgdoc = _watermark_get_svgdoc (self, data, &piece->pipe->image);
  if (!svgdoc)
  {
    memcpy(ovoid, ivoid, sizeof(float)*ch*roi_out->width*roi_out->height);
    return;
  }

  /* create the rsvghandle from parsed svg data */
  GError *error = NULL;
  RsvgHandle *svg = rsvg_handle_new_from_data ((const guint8 *)svgdoc,strlen (svgdoc),&error);
  g_free (svgdoc);
  if (!svg || error)
  {
    memcpy(ovoid, ivoid, sizeof(float)*ch*roi_out->width*roi_out->height);
    return;
  }

  /* get the dimension of svg */
  RsvgDimensionData dimension;
  rsvg_handle_get_dimensions (svg,&dimension);

  /* calculate aligment of watermark */
  const float iw=piece->buf_in.width*roi_out->scale;
  const float ih=piece->buf_in.height*roi_out->scale;

  float scale=1.0;
  if ((dimension.width/dimension.height)>1.0)
    scale = iw/dimension.width;
  else
    scale = ih/dimension.height;

  scale *= (data->scale/100.0);

  /* setup stride for performance */
  int stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,roi_out->width);

  /* create cairo memory surface */
  guint8 *image= (guint8 *)g_malloc (stride*roi_out->height);
  memset (image,0,stride*roi_out->height);
  cairo_surface_t *surface = cairo_image_surface_create_for_data (image,CAIRO_FORMAT_ARGB32,roi_out->width,roi_out->height,stride);
  if (cairo_surface_status(surface)!=	CAIRO_STATUS_SUCCESS)
  {
//   fprintf(stderr,"Cairo surface error: %s\n",cairo_status_to_string(cairo_surface_status(surface)));
    g_free (image);
    memcpy(ovoid, ivoid, sizeof(float)*ch*roi_out->width*roi_out->height);
    return;
  }

  /* create cairo context and setup transformation/scale */
  cairo_t *cr = cairo_create (surface);

  float ty=0,tx=0;
  if( data->alignment >=0 && data->alignment <3) // Align to verttop
    ty=0;
  else if( data->alignment >=3 && data->alignment <6) // Align to vertcenter
    ty=(ih/2.0)-((dimension.height*scale)/2.0);
  else if( data->alignment >=6 && data->alignment <9) // Align to vertbottom
    ty=ih-(dimension.height*scale);

  if( data->alignment == 0 ||  data->alignment == 3 || data->alignment==6 )
    tx=0;
  else if( data->alignment == 1 ||  data->alignment == 4 || data->alignment==7 )
    tx=(iw/2.0)-((dimension.width*scale)/2.0);
  else if( data->alignment == 2 ||  data->alignment == 5 || data->alignment==8 )
    tx=iw-(dimension.width*scale);

  /* translate to position */
  cairo_translate (cr,-roi_in->x,-roi_in->y);
  cairo_translate (cr,tx,ty);

  /* scale */
  cairo_scale (cr,scale,scale);

  /* translate x and y offset */
  cairo_translate (cr,data->xoffset*iw/roi_out->scale,data->yoffset*ih/roi_out->scale);

  /* render svg into surface*/
  dt_pthread_mutex_lock(&darktable.plugin_threadsafe);
  rsvg_handle_render_cairo (svg,cr);
  dt_pthread_mutex_unlock(&darktable.plugin_threadsafe);

  /* ensure that all operations on surface finishing up */
  cairo_surface_flush (surface);

  /* render surface on output */
  guint8 *sd = image;
  float opacity = data->opacity/100.0;
  /*
  #ifdef _OPENMP
  	#pragma omp parallel for default(none) shared(roi_out, in, out,sd,opacity) schedule(static)
  #endif
  */
  for(int j=0; j<roi_out->height; j++) for(int i=0; i<roi_out->width; i++)
    {
      float alpha = (sd[3]/255.0)*opacity;
      out[0] = ((1.0-alpha)*in[0]) + (alpha*(sd[2]/255.0));
      out[1] = ((1.0-alpha)*in[1]) + (alpha*(sd[1]/255.0));
      out[2] = ((1.0-alpha)*in[2]) + (alpha*(sd[0]/255.0));
      out[3] = in[3];

      out+=ch;
      in+=ch;
      sd+=4;
    }


  /* clean up */
  cairo_surface_destroy (surface);
  g_object_unref (svg);
  g_free (image);

}
Example #9
0
File: svg.c Project: mstorsjo/vlc
/****************************************************************************
 * DecodeBlock: the whole thing
 ****************************************************************************
 * This function must be fed with a complete image.
 ****************************************************************************/
static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
{
    decoder_sys_t *p_sys  = (decoder_sys_t *) p_dec->p_sys;
    picture_t *p_pic = NULL;
    int32_t i_width, i_height;

    RsvgHandle *rsvg = NULL;
    cairo_surface_t *surface = NULL;
    cairo_t *cr = NULL;

    if( p_block == NULL ) /* No Drain */
        return VLCDEC_SUCCESS;

    if( p_block->i_flags & BLOCK_FLAG_CORRUPTED)
    {
        block_Release( p_block );
        return VLCDEC_SUCCESS;
    }

    rsvg = rsvg_handle_new_from_data( p_block->p_buffer, p_block->i_buffer, NULL );
    if( !rsvg )
        goto done;

    RsvgDimensionData dim;
    rsvg_handle_get_dimensions( rsvg, &dim );

    if( p_sys->f_scale > 0.0 )
    {
        i_width  = (int32_t)(p_sys->f_scale * dim.width);
        i_height = (int32_t)(p_sys->f_scale * dim.height);
    }
    else
    {
        /* Keep aspect */
        if( p_sys->i_width < 0 && p_sys->i_height > 0 )
        {
            i_width  = dim.width * p_sys->i_height / dim.height;
            i_height = p_sys->i_height;
        }
        else if( p_sys->i_width > 0 && p_sys->i_height < 0 )
        {
            i_width  = p_sys->i_width;
            i_height = dim.height * p_sys->i_width / dim.height;
        }
        else if( p_sys->i_width > 0 && p_sys->i_height > 0 )
        {
            i_width  = dim.width * p_sys->i_height / dim.height;
            i_height = p_sys->i_height;
        }
        else
        {
            i_width  = dim.width;
            i_height = dim.height;
        }
    }

    p_dec->fmt_out.i_codec =
    p_dec->fmt_out.video.i_chroma = VLC_CODEC_BGRA;
    p_dec->fmt_out.video.i_width  = i_width;
    p_dec->fmt_out.video.i_height = i_height;
    p_dec->fmt_out.video.i_visible_width  = i_width;
    p_dec->fmt_out.video.i_visible_height = i_height;
    p_dec->fmt_out.video.i_sar_num = 1;
    p_dec->fmt_out.video.i_sar_den = 1;
    p_dec->fmt_out.video.i_rmask = 0x80800000; /* Since librsvg v1.0 */
    p_dec->fmt_out.video.i_gmask = 0x0000ff00;
    p_dec->fmt_out.video.i_bmask = 0x000000ff;
    video_format_FixRgb(&p_dec->fmt_out.video);

    /* Get a new picture */
    if( decoder_UpdateVideoFormat( p_dec ) )
        goto done;
    p_pic = decoder_NewPicture( p_dec );
    if( !p_pic )
        goto done;

    /* NOTE: Do not use the stride calculation from cairo, because it is wrong:
     * stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, dim.width);
     * Use the stride from VLC its picture_t::p[0].i_pitch, which is correct.
     */
    memset(p_pic->p[0].p_pixels, 0, p_pic->p[0].i_pitch * p_pic->p[0].i_lines);
    surface = cairo_image_surface_create_for_data( p_pic->p->p_pixels,
                                                   CAIRO_FORMAT_ARGB32,
                                                   i_width, i_height,
                                                   p_pic->p[0].i_pitch );
    if( !surface )
    {
        picture_Release( p_pic );
        p_pic = NULL;
        goto done;
    }

    /* Decode picture */
    cr = cairo_create( surface );
    if( !cr )
    {
        picture_Release( p_pic );
        p_pic = NULL;
        goto done;
    }

    if ( i_width != dim.width || i_height != dim.height )
    {
        double sw, sh;
        if ( p_sys->f_scale > 0.0 && !(p_sys->i_width > 0 || p_sys->i_height > 0) )
            sw = sh = p_sys->f_scale;
        else
        {
            double aspect = (double) (dim.width * p_dec->fmt_out.video.i_sar_num) /
                    (dim.height * p_dec->fmt_out.video.i_sar_den);
            sw = aspect * i_width / dim.width;
            sh = aspect * i_height / dim.height;
        }
        cairo_scale(cr, sw, sh);
    }

    if( !rsvg_handle_render_cairo( rsvg, cr ) )
    {
        picture_Release( p_pic );
        p_pic = NULL;
        goto done;
    }

    p_pic->date = p_block->i_pts != VLC_TICK_INVALID ? p_block->i_pts : p_block->i_dts;

done:
    if( rsvg )
        g_object_unref( G_OBJECT( rsvg ) );
    if( cr )
        cairo_destroy( cr );
    if( surface )
        cairo_surface_destroy( surface );

    block_Release( p_block );
    if( p_pic != NULL )
        decoder_QueueVideo( p_dec, p_pic );
    return VLCDEC_SUCCESS;
}
Example #10
0
static GstFlowReturn
gst_rsvg_decode_image (GstRsvgDec * rsvg, const guint8 * data, guint size,
    GstBuffer ** buffer)
{
  GstFlowReturn ret = GST_FLOW_OK;
  cairo_t *cr;
  cairo_surface_t *surface;
  RsvgHandle *handle;
  GError *error = NULL;
  RsvgDimensionData dimension;
  gdouble scalex, scaley;

  GST_LOG_OBJECT (rsvg, "parsing svg");

  handle = rsvg_handle_new_from_data (data, size, &error);
  if (!handle) {
    GST_ERROR_OBJECT (rsvg, "Failed to parse SVG image: %s", error->message);
    g_error_free (error);
    return GST_FLOW_ERROR;
  }

  rsvg_handle_get_dimensions (handle, &dimension);
  if (rsvg->width != dimension.width || rsvg->height != dimension.height) {
    GstCaps *caps1, *caps2, *caps3;
    GstStructure *s;

    GST_LOG_OBJECT (rsvg, "resolution changed, updating caps");

    caps1 = gst_caps_copy (gst_pad_get_pad_template_caps (rsvg->srcpad));
    caps2 = gst_pad_peer_get_caps (rsvg->srcpad);
    if (caps2) {
      caps3 = gst_caps_intersect (caps1, caps2);
      gst_caps_unref (caps1);
      gst_caps_unref (caps2);
      caps1 = caps3;
      caps3 = NULL;
    }

    if (gst_caps_is_empty (caps1)) {
      GST_ERROR_OBJECT (rsvg, "Unable to negotiate a format");
      gst_caps_unref (caps1);
      g_object_unref (handle);
      return GST_FLOW_NOT_NEGOTIATED;
    }

    caps2 = gst_caps_copy (gst_pad_get_pad_template_caps (rsvg->srcpad));
    s = gst_caps_get_structure (caps2, 0);
    gst_structure_set (s, "width", G_TYPE_INT, dimension.width, "height",
        G_TYPE_INT, dimension.height, "framerate", GST_TYPE_FRACTION, 0, 1,
        NULL);
    caps3 = gst_caps_intersect (caps1, caps2);
    if (!gst_caps_is_empty (caps3)) {
      gst_caps_truncate (caps3);
      gst_pad_set_caps (rsvg->srcpad, caps3);
      gst_caps_unref (caps1);
      gst_caps_unref (caps2);
      gst_caps_unref (caps3);
      rsvg->width = dimension.width;
      rsvg->height = dimension.height;
    } else {
      gst_caps_unref (caps2);
      gst_caps_unref (caps3);
      gst_caps_truncate (caps1);

      s = gst_caps_get_structure (caps1, 0);
      gst_structure_set (s, "framerate", GST_TYPE_FRACTION, 0, 1, NULL);

      if (!gst_caps_is_fixed (caps1)
          && (!gst_structure_fixate_field_nearest_int (s, "width",
                  dimension.width)
              || !gst_structure_fixate_field_nearest_int (s, "height",
                  dimension.height))) {
        g_object_unref (handle);
        GST_ERROR_OBJECT (rsvg, "Failed to fixate caps");
        return GST_FLOW_NOT_NEGOTIATED;
      }
      gst_pad_set_caps (rsvg->srcpad, caps1);
      gst_structure_get_int (s, "width", &rsvg->width);
      gst_structure_get_int (s, "height", &rsvg->height);
      gst_caps_unref (caps1);
    }
  }

  if ((ret = gst_pad_alloc_buffer_and_set_caps (rsvg->srcpad,
              GST_BUFFER_OFFSET_NONE,
              rsvg->width * rsvg->height * 4,
              GST_PAD_CAPS (rsvg->srcpad), buffer)) != GST_FLOW_OK) {
    g_object_unref (handle);
    GST_ERROR_OBJECT (rsvg, "Buffer allocation failed %s",
        gst_flow_get_name (ret));
    return ret;
  }

  GST_LOG_OBJECT (rsvg, "render image at %d x %d", rsvg->height, rsvg->width);

  surface =
      cairo_image_surface_create_for_data (GST_BUFFER_DATA (*buffer),
      CAIRO_FORMAT_ARGB32, rsvg->width, rsvg->height, rsvg->width * 4);

  cr = cairo_create (surface);
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
  cairo_paint (cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);

  scalex = scaley = 1.0;
  if (rsvg->width != dimension.width) {
    scalex = ((gdouble) rsvg->width) / ((gdouble) dimension.width);
  }
  if (rsvg->height != dimension.height) {
    scaley = ((gdouble) rsvg->height) / ((gdouble) dimension.height);
  }
  cairo_scale (cr, scalex, scaley);
  rsvg_handle_render_cairo (handle, cr);

  g_object_unref (handle);
  cairo_destroy (cr);
  cairo_surface_destroy (surface);

  /* Now unpremultiply Cairo's ARGB to match GStreamer's */
  gst_rsvg_decode_unpremultiply (GST_BUFFER_DATA (*buffer), rsvg->width,
      rsvg->height);

  return ret;
}
Example #11
0
static GstFlowReturn
gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer,
    GstVideoCodecFrame * frame)
{
  GstVideoDecoder *decoder = GST_VIDEO_DECODER (rsvg);
  GstFlowReturn ret = GST_FLOW_OK;
  cairo_t *cr;
  cairo_surface_t *surface;
  RsvgHandle *handle;
  GError *error = NULL;
  RsvgDimensionData dimension;
  gdouble scalex, scaley;
  GstMapInfo minfo;
  GstVideoFrame vframe;
  GstVideoCodecState *output_state;

  GST_LOG_OBJECT (rsvg, "parsing svg");

  if (!gst_buffer_map (buffer, &minfo, GST_MAP_READ)) {
    GST_ERROR_OBJECT (rsvg, "Failed to get SVG image");
    return GST_FLOW_ERROR;
  }
  handle = rsvg_handle_new_from_data (minfo.data, minfo.size, &error);
  if (!handle) {
    GST_ERROR_OBJECT (rsvg, "Failed to parse SVG image: %s", error->message);
    g_error_free (error);
    return GST_FLOW_ERROR;
  }

  rsvg_handle_get_dimensions (handle, &dimension);

  output_state = gst_video_decoder_get_output_state (decoder);
  if ((output_state == NULL)
      || GST_VIDEO_INFO_WIDTH (&output_state->info) != dimension.width
      || GST_VIDEO_INFO_HEIGHT (&output_state->info) != dimension.height) {

    /* Create the output state */
    if (output_state)
      gst_video_codec_state_unref (output_state);
    output_state =
        gst_video_decoder_set_output_state (decoder, GST_RSVG_VIDEO_FORMAT,
        dimension.width, dimension.height, rsvg->input_state);
  }

  ret = gst_video_decoder_allocate_output_frame (decoder, frame);

  if (ret != GST_FLOW_OK) {
    g_object_unref (handle);
    gst_video_codec_state_unref (output_state);
    GST_ERROR_OBJECT (rsvg, "Buffer allocation failed %s",
        gst_flow_get_name (ret));
    return ret;
  }

  GST_LOG_OBJECT (rsvg, "render image at %d x %d",
      GST_VIDEO_INFO_HEIGHT (&output_state->info),
      GST_VIDEO_INFO_WIDTH (&output_state->info));


  if (!gst_video_frame_map (&vframe,
          &output_state->info, frame->output_buffer, GST_MAP_READWRITE)) {
    GST_ERROR_OBJECT (rsvg, "Failed to get SVG image");
    g_object_unref (handle);
    gst_video_codec_state_unref (output_state);
    return GST_FLOW_ERROR;
  }
  surface =
      cairo_image_surface_create_for_data (GST_VIDEO_FRAME_PLANE_DATA (&vframe,
          0), CAIRO_FORMAT_ARGB32, GST_VIDEO_FRAME_WIDTH (&vframe),
      GST_VIDEO_FRAME_HEIGHT (&vframe), GST_VIDEO_FRAME_PLANE_STRIDE (&vframe,
          0));

  cr = cairo_create (surface);
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
  cairo_paint (cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);

  scalex = scaley = 1.0;
  if (GST_VIDEO_INFO_WIDTH (&output_state->info) != dimension.width) {
    scalex =
        ((gdouble) GST_VIDEO_INFO_WIDTH (&output_state->info)) /
        ((gdouble) dimension.width);
  }
  if (GST_VIDEO_INFO_HEIGHT (&output_state->info) != dimension.height) {
    scaley =
        ((gdouble) GST_VIDEO_INFO_HEIGHT (&output_state->info)) /
        ((gdouble) dimension.height);
  }
  cairo_scale (cr, scalex, scaley);
  rsvg_handle_render_cairo (handle, cr);

  g_object_unref (handle);
  cairo_destroy (cr);
  cairo_surface_destroy (surface);

  /* Now unpremultiply Cairo's ARGB to match GStreamer's */
  gst_rsvg_decode_unpremultiply (GST_VIDEO_FRAME_PLANE_DATA (&vframe, 0),
      GST_VIDEO_FRAME_WIDTH (&vframe), GST_VIDEO_FRAME_HEIGHT (&vframe));

  gst_video_codec_state_unref (output_state);
  gst_buffer_unmap (buffer, &minfo);
  gst_video_frame_unmap (&vframe);

  return ret;
}
Example #12
0
int main(int argc, char *argv[]) {
    struct passwd *pw;
    char *username;
    char *image_path = NULL;
    char *svg_path = NULL;
    int ret;
    struct pam_conv conv = {conv_callback, NULL};
    int curs_choice = CURS_NONE;
    int o;
    int optind = 0;
    struct option longopts[] = {
        {"version", no_argument, NULL, 'v'},
        {"nofork", no_argument, NULL, 'n'},
        {"beep", no_argument, NULL, 'b'},
        {"dpms", no_argument, NULL, 'd'},
        {"color", required_argument, NULL, 'c'},
        {"pointer", required_argument, NULL, 'p'},
        {"debug", no_argument, NULL, 0},
        {"help", no_argument, NULL, 'h'},
        {"no-unlock-indicator", no_argument, NULL, 'u'},
        {"image", required_argument, NULL, 'i'},
        {"tiling", no_argument, NULL, 't'},
        {"ignore-empty-password", no_argument, NULL, 'e'},
        {"inactivity-timeout", required_argument, NULL, 'I'},
        {"indicator-svg", required_argument, NULL, 's'},
        {"show-failed-attempts", no_argument, NULL, 'f'},
        {NULL, no_argument, NULL, 0}
    };

    if ((pw = getpwuid(getuid())) == NULL)
        err(EXIT_FAILURE, "getpwuid() failed");
    if ((username = pw->pw_name) == NULL)
        errx(EXIT_FAILURE, "pw->pw_name is NULL.\n");

    char *optstring = "hvnbdc:p:ui:teI:s:";
    while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
        switch (o) {
            case 'v':
                errx(EXIT_SUCCESS, "version " VERSION " © 2010 Michael Stapelberg");
            case 'n':
                dont_fork = true;
                break;
            case 'b':
                beep = true;
                break;
            case 'd':
                dpms = true;
                break;
            case 'I': {
                int time = 0;
                if (sscanf(optarg, "%d", &time) != 1 || time < 0)
                    errx(EXIT_FAILURE, "invalid timeout, it must be a positive integer\n");
                inactivity_timeout = time;
                break;
            }
            case 'c': {
                char *arg = optarg;

                /* Skip # if present */
                if (arg[0] == '#')
                    arg++;

                if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", color) != 1)
                    errx(EXIT_FAILURE, "color is invalid, it must be given in 3-byte hexadecimal format: rrggbb\n");

                break;
            }
            case 's':
                svg_path = strdup(optarg);
                break;
            case 'u':
                unlock_indicator = false;
                break;
            case 'i':
                image_path = strdup(optarg);
                break;
            case 't':
                tile = true;
                break;
            case 'p':
                if (!strcmp(optarg, "win")) {
                    curs_choice = CURS_WIN;
                } else if (!strcmp(optarg, "default")) {
                    curs_choice = CURS_DEFAULT;
                } else {
                    errx(EXIT_FAILURE, "i3lock: Invalid pointer type given. Expected one of \"win\" or \"default\".\n");
                }
                break;
            case 'e':
                ignore_empty_password = true;
                break;
            case 0:
                if (strcmp(longopts[optind].name, "debug") == 0)
                    debug_mode = true;
                break;
/*            case 'f':
                show_failed_attempts = true;
                break;*/
            default:
                errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
                                   " [-i image.png] [-t] [-e] [-I] [-f] [-s indicator.svg]");
        }
    }

    /* We need (relatively) random numbers for highlighting a random part of
     * the unlock indicator upon keypresses. */
    srand(time(NULL));

    /* Initialize PAM */
    ret = pam_start("i3lock", username, &conv, &pam_handle);
    if (ret != PAM_SUCCESS)
        errx(EXIT_FAILURE, "PAM: %s", pam_strerror(pam_handle, ret));

/* Using mlock() as non-super-user seems only possible in Linux. Users of other
 * operating systems should use encrypted swap/no swap (or remove the ifdef and
 * run i3lock as super-user). */
#if defined(__linux__)
    /* Lock the area where we store the password in memory, we don’t want it to
     * be swapped to disk. Since Linux 2.6.9, this does not require any
     * privileges, just enough bytes in the RLIMIT_MEMLOCK limit. */
    if (mlock(password, sizeof(password)) != 0)
        err(EXIT_FAILURE, "Could not lock page in memory, check RLIMIT_MEMLOCK");
#endif

    /* Double checking that connection is good and operatable with xcb */
    int screennr;
    if ((conn = xcb_connect(NULL, &screennr)) == NULL ||
        xcb_connection_has_error(conn))
        errx(EXIT_FAILURE, "Could not connect to X11, maybe you need to set DISPLAY?");

    if (xkb_x11_setup_xkb_extension(conn,
                                    XKB_X11_MIN_MAJOR_XKB_VERSION,
                                    XKB_X11_MIN_MINOR_XKB_VERSION,
                                    0,
                                    NULL,
                                    NULL,
                                    &xkb_base_event,
                                    &xkb_base_error) != 1)
        errx(EXIT_FAILURE, "Could not setup XKB extension.");

    static const xcb_xkb_map_part_t required_map_parts =
        (XCB_XKB_MAP_PART_KEY_TYPES |
         XCB_XKB_MAP_PART_KEY_SYMS |
         XCB_XKB_MAP_PART_MODIFIER_MAP |
         XCB_XKB_MAP_PART_EXPLICIT_COMPONENTS |
         XCB_XKB_MAP_PART_KEY_ACTIONS |
         XCB_XKB_MAP_PART_VIRTUAL_MODS |
         XCB_XKB_MAP_PART_VIRTUAL_MOD_MAP);

    static const xcb_xkb_event_type_t required_events =
        (XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY |
         XCB_XKB_EVENT_TYPE_MAP_NOTIFY |
         XCB_XKB_EVENT_TYPE_STATE_NOTIFY);

    xcb_xkb_select_events(
        conn,
        xkb_x11_get_core_keyboard_device_id(conn),
        required_events,
        0,
        required_events,
        required_map_parts,
        required_map_parts,
        0);

    /* When we cannot initially load the keymap, we better exit */
    if (!load_keymap())
        errx(EXIT_FAILURE, "Could not load keymap");

    const char *locale = getenv("LC_ALL");
    if (!locale)
        locale = getenv("LC_CTYPE");
    if (!locale)
        locale = getenv("LANG");
    if (!locale) {
        if (debug_mode)
            fprintf(stderr, "Can't detect your locale, fallback to C\n");
        locale = "C";
    }

    load_compose_table(locale);

    xinerama_init();
    xinerama_query_screens();

    /* if DPMS is enabled, check if the X server really supports it */
    if (dpms) {
        xcb_dpms_capable_cookie_t dpmsc = xcb_dpms_capable(conn);
        xcb_dpms_capable_reply_t *dpmsr;
        if ((dpmsr = xcb_dpms_capable_reply(conn, dpmsc, NULL))) {
            if (!dpmsr->capable) {
                if (debug_mode)
                    fprintf(stderr, "Disabling DPMS, X server not DPMS capable\n");
                dpms = false;
            }
            free(dpmsr);
        }
    }

    screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;

    last_resolution[0] = screen->width_in_pixels;
    last_resolution[1] = screen->height_in_pixels;

    xcb_change_window_attributes(conn, screen->root, XCB_CW_EVENT_MASK,
                                 (uint32_t[]){XCB_EVENT_MASK_STRUCTURE_NOTIFY});

    if (image_path) {
        /* Create a pixmap to render on, fill it with the background color */
        img = cairo_image_surface_create_from_png(image_path);
        /* In case loading failed, we just pretend no -i was specified. */
        if (cairo_surface_status(img) != CAIRO_STATUS_SUCCESS) {
            fprintf(stderr, "Could not load image \"%s\": %s\n",
                    image_path, cairo_status_to_string(cairo_surface_status(img)));
            img = NULL;
        }
    }

    /* Load SVG */
    GError* e = NULL;
    if (svg_path == NULL) {
        svg = rsvg_handle_new_from_data(button_svg, sizeof(button_svg), &e);
    } else {
       svg = rsvg_handle_new_from_file(svg_path, &e);
    }

    if(e != NULL) {
        errx(EXIT_FAILURE, "Could not load indicator SVG: %s", e->message);
    }

    for(;anim_layer_count < 100; anim_layer_count++) {
        char anim_id[9];
        snprintf(anim_id, sizeof(anim_id), "#anim%02d", anim_layer_count);

        if(rsvg_handle_has_sub(svg, anim_id) != TRUE) {
            break;
        }
    }

    if(rsvg_handle_has_sub(svg, "#remove_background") == TRUE) {
        remove_background = true;
    }

    if(rsvg_handle_has_sub(svg, "#sequential_animation") == TRUE) {
        sequential_animation = true;
    }

    /* Pixmap on which the image is rendered to (if any) */
    xcb_pixmap_t bg_pixmap = draw_image(last_resolution);

    /* open the fullscreen window, already with the correct pixmap in place */
    win = open_fullscreen_window(conn, screen, color, bg_pixmap);
    xcb_free_pixmap(conn, bg_pixmap);

    pid_t pid = fork();
    /* The pid == -1 case is intentionally ignored here:
     * While the child process is useful for preventing other windows from
     * popping up while i3lock blocks, it is not critical. */
    if (pid == 0) {
        /* Child */
        close(xcb_get_file_descriptor(conn));
        raise_loop(win);
        exit(EXIT_SUCCESS);
    }

    cursor = create_cursor(conn, screen, win, curs_choice);

    grab_pointer_and_keyboard(conn, screen, cursor);
    /* Load the keymap again to sync the current modifier state. Since we first
     * loaded the keymap, there might have been changes, but starting from now,
     * we should get all key presses/releases due to having grabbed the
     * keyboard. */
    (void)load_keymap();

    turn_monitors_off();

    /* Initialize the libev event loop. */
    main_loop = EV_DEFAULT;
    if (main_loop == NULL)
        errx(EXIT_FAILURE, "Could not initialize libev. Bad LIBEV_FLAGS?\n");

    struct ev_io *xcb_watcher = calloc(sizeof(struct ev_io), 1);
    struct ev_check *xcb_check = calloc(sizeof(struct ev_check), 1);
    struct ev_prepare *xcb_prepare = calloc(sizeof(struct ev_prepare), 1);

    ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
    ev_io_start(main_loop, xcb_watcher);

    ev_check_init(xcb_check, xcb_check_cb);
    ev_check_start(main_loop, xcb_check);

    ev_prepare_init(xcb_prepare, xcb_prepare_cb);
    ev_prepare_start(main_loop, xcb_prepare);

    /* Invoke the event callback once to catch all the events which were
     * received up until now. ev will only pick up new events (when the X11
     * file descriptor becomes readable). */
    ev_invoke(main_loop, xcb_check, 0);
    ev_loop(main_loop, 0);
}
Example #13
0
File: svg.c Project: zmike/compiz
static Bool
svgSet(CompDisplay *d,
       CompAction *action,
       CompActionState state,
       CompOption *option,
       int nOption)
{
    CompWindow *w;
    Window xid;

    xid = getIntOptionNamed(option, nOption, "window", 0);

    w = findWindowAtDisplay(d, xid);
    if (w)
    {
        decor_point_t p[2];
        char *data;
        RsvgHandle *svg = NULL;
        GError *error = NULL;

        SVG_WINDOW(w);

        memset(p, 0, sizeof (p));

        p[0].gravity = getIntOptionNamed(option, nOption, "gravity0",
                                         GRAVITY_NORTH | GRAVITY_WEST);

        p[0].x = getIntOptionNamed(option, nOption, "x0", 0);
        p[0].y = getIntOptionNamed(option, nOption, "y0", 0);

        p[1].gravity = getIntOptionNamed(option, nOption, "gravity1",
                                         GRAVITY_SOUTH | GRAVITY_EAST);

        p[1].x = getIntOptionNamed(option, nOption, "x1", 0);
        p[1].y = getIntOptionNamed(option, nOption, "y1", 0);

        data = getStringOptionNamed(option, nOption, "data", 0);
        if (data)
            svg = rsvg_handle_new_from_data((guint8 *)data, strlen(data),
                                            &error);

        if (sw->source)
        {
            rsvg_handle_free(sw->source->svg);
            sw->source->svg = svg;
        }
        else
        {
            sw->source = malloc(sizeof (SvgSource));
            if (sw->source)
                sw->source->svg = svg;
        }

        if (sw->source && sw->source->svg)
        {
            sw->source->p1 = p[0];
            sw->source->p2 = p[1];

            sw->source->svg = svg;

            rsvg_handle_get_dimensions(svg, &sw->source->dimension);

            updateWindowSvgContext(w, sw->source);
        }
        else
        {
            if (svg)
                rsvg_handle_free(svg);

            if (sw->source)
            {
                free(sw->source);
                sw->source = NULL;
            }

            if (sw->context)
            {
                finiSvgTexture(w->screen, &sw->context->texture[0]);
                free(sw->context);
                sw->context = NULL;
            }
        }
    }

    return FALSE;
}
Example #14
0
void soy_sg_k2_png_converter_sgk2png (soySGK2PNGConverter* self, guchar* sgk_data, int sgk_data_length1) {
	RsvgHandle* handle = NULL;
	cairo_surface_t* surface = NULL;
	cairo_t* context = NULL;
	GError * _inner_error_ = NULL;
#line 29 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
	g_return_if_fail (self != NULL);
#line 138 "sgk2png.c"
	{
		RsvgHandle* _tmp0_ = NULL;
		guchar* _tmp1_ = NULL;
		gint _tmp1__length1 = 0;
		RsvgHandle* _tmp2_ = NULL;
		RsvgHandle* _tmp3_ = NULL;
		gint _tmp4_ = 0;
		gint _tmp5_ = 0;
		RsvgHandle* _tmp6_ = NULL;
		gint _tmp7_ = 0;
		gint _tmp8_ = 0;
		cairo_surface_t* _tmp9_ = NULL;
		cairo_surface_t* _tmp10_ = NULL;
		cairo_t* _tmp11_ = NULL;
		RsvgHandle* _tmp12_ = NULL;
		cairo_t* _tmp13_ = NULL;
		cairo_surface_t* _tmp14_ = NULL;
#line 35 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp1_ = sgk_data;
#line 35 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp1__length1 = sgk_data_length1;
#line 35 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp2_ = rsvg_handle_new_from_data (_tmp1_, _tmp1__length1, &_inner_error_);
#line 35 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp0_ = _tmp2_;
#line 35 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		if (_inner_error_ != NULL) {
#line 166 "sgk2png.c"
			goto __catch9_g_error;
		}
#line 35 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_g_object_unref0 (handle);
#line 35 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		handle = _tmp0_;
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp3_ = handle;
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		g_object_get (_tmp3_, "width", &_tmp4_, NULL);
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp5_ = _tmp4_;
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp6_ = handle;
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		g_object_get (_tmp6_, "height", &_tmp7_, NULL);
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp8_ = _tmp7_;
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp9_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, _tmp5_, _tmp8_);
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_cairo_surface_destroy0 (surface);
#line 36 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		surface = _tmp9_;
#line 37 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp10_ = surface;
#line 37 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp11_ = cairo_create (_tmp10_);
#line 37 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_cairo_destroy0 (context);
#line 37 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		context = _tmp11_;
#line 38 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp12_ = handle;
#line 38 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp13_ = context;
#line 38 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		rsvg_handle_render_cairo (_tmp12_, _tmp13_);
#line 39 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp14_ = surface;
#line 39 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		cairo_surface_write_to_png_stream (_tmp14_, _soy_sg_k2_png_converter_writefunc_cairo_write_func_t, self);
#line 209 "sgk2png.c"
	}
	goto __finally9;
	__catch9_g_error:
	{
		GError* g = NULL;
		FILE* _tmp15_ = NULL;
		GError* _tmp16_ = NULL;
		const gchar* _tmp17_ = NULL;
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		g = _inner_error_;
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_inner_error_ = NULL;
#line 41 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp15_ = stdout;
#line 41 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp16_ = g;
#line 41 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_tmp17_ = _tmp16_->message;
#line 41 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		fprintf (_tmp15_, "Error: %s\n", _tmp17_);
#line 42 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_g_error_free0 (g);
#line 42 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_cairo_destroy0 (context);
#line 42 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_cairo_surface_destroy0 (surface);
#line 42 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_g_object_unref0 (handle);
#line 42 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		return;
#line 240 "sgk2png.c"
	}
	__finally9:
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
	if (_inner_error_ != NULL) {
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_cairo_destroy0 (context);
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_cairo_surface_destroy0 (surface);
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		_g_object_unref0 (handle);
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		g_clear_error (&_inner_error_);
#line 34 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
		return;
#line 257 "sgk2png.c"
	}
#line 44 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
	_cairo_destroy0 (context);
#line 44 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
	_cairo_surface_destroy0 (surface);
#line 44 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
	_g_object_unref0 (handle);
#line 44 "/home/jeff/Documents/libraries/libsoy/src/sgk2png.gs"
	return;
#line 267 "sgk2png.c"
}
Example #15
0
static Bool
svgSet (BananaArgument     *arg,
        int                nArg)
{
	CompWindow *w;
	Window     xid;

	BananaValue *window = getArgNamed ("window", arg, nArg);

	if (window != NULL)
		xid = window->i;
	else
		xid = 0;

	w = findWindowAtDisplay (xid);

	if (w)
	{
		decor_point_t p[2];
		char          *data;
		RsvgHandle    *svg = NULL;
		GError        *error = NULL;

		SVG_WINDOW (w);

		memset (p, 0, sizeof (p));

		BananaValue *gravity0 = getArgNamed ("gravity0", arg, nArg);
		if (gravity0 != NULL)
			p[0].gravity = gravity0->i;
		else
			p[0].gravity =  GRAVITY_NORTH | GRAVITY_WEST;

		BananaValue *x0 = getArgNamed ("x0", arg, nArg);
		if (x0 != NULL)
			p[0].x = x0->i;
		else
			p[0].x =  0;

		BananaValue *y0 = getArgNamed ("y0", arg, nArg);
		if (y0 != NULL)
			p[0].y = y0->i;
		else
			p[0].y =  0;

		BananaValue *gravity1 = getArgNamed ("gravity1", arg, nArg);
		if (gravity1 != NULL)
			p[1].gravity = gravity1->i;
		else
			p[1].gravity =  GRAVITY_SOUTH | GRAVITY_EAST;

		BananaValue *x1 = getArgNamed ("x1", arg, nArg);
		if (x0 != NULL)
			p[1].x = x1->i;
		else
			p[1].x =  0;

		BananaValue *y1 = getArgNamed ("y1", arg, nArg);
		if (y1 != NULL)
			p[1].y = y1->i;
		else
			p[1].y =  0;

		BananaValue *b_data = getArgNamed ("data", arg, nArg);
		if (b_data != NULL)
			data = b_data->s;
		else
			data = NULL;

		if (data)
			svg = rsvg_handle_new_from_data ((guint8 *) data, strlen (data),
			                          &error);

		if (sw->source)
		{
			rsvg_handle_free (sw->source->svg);
			sw->source->svg = svg;
		}
		else
		{
			sw->source = malloc (sizeof (SvgSource));
			if (sw->source)
				sw->source->svg = svg;
		}

		if (sw->source && sw->source->svg)
		{
			sw->source->p1 = p[0];
			sw->source->p2 = p[1];

			sw->source->svg = svg;

			rsvg_handle_get_dimensions (svg, &sw->source->dimension);

			updateWindowSvgContext (w, sw->source);
		}
		else
		{
			if (svg)
				rsvg_handle_free (svg);

			if (sw->source)
			{
				free (sw->source);
				sw->source = NULL;
			}

			if (sw->context)
			{
				finiSvgTexture (w->screen, &sw->context->texture[0]);
				free (sw->context);
				sw->context = NULL;
			}
		}
	}

	return FALSE;
}