Esempio n. 1
0
static JSBool
maskSurface_func(JSContext *context,
                 unsigned   argc,
                 jsval     *vp)
{
    JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
    JSObject *obj = JSVAL_TO_OBJECT(argv.thisv());

    JSObject *surface_wrapper;
    double x, y;
    cairo_surface_t *surface;
    cairo_t *cr;

    if (!gjs_parse_call_args(context, "maskSurface", "off", argv,
                        "surface", &surface_wrapper,
                        "x", &x,
                        "y", &y))
        return JS_FALSE;

    surface = gjs_cairo_surface_get_surface(context, surface_wrapper);
    if (!surface) {
        gjs_throw(context, "first argument to maskSurface() should be a surface");
        return JS_FALSE;
    }

    cr = gjs_cairo_context_get_context(context, obj);

    cairo_mask_surface(cr, surface, x, y);

    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return JS_FALSE;

    argv.rval().set(JSVAL_VOID);
    return JS_TRUE;
}
Esempio n. 2
0
static void
panel_launcher_redraw_handler(struct widget *widget, void *data)
{
    struct panel_launcher *launcher = data;
    cairo_surface_t *surface;
    struct rectangle allocation;
    cairo_t *cr;

    surface = window_get_surface(launcher->panel->window);
    cr = cairo_create(surface);

    widget_get_allocation(widget, &allocation);
    if (launcher->pressed) {
        allocation.x++;
        allocation.y++;
    }

    cairo_set_source_surface(cr, launcher->icon,
                             allocation.x, allocation.y);
    cairo_paint(cr);

    if (launcher->focused) {
        cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4);
        cairo_mask_surface(cr, launcher->icon,
                           allocation.x, allocation.y);
    }

    cairo_destroy(cr);
}
Esempio n. 3
0
/* @brief Draw an image at the given offset.
 *
 * @param cr A cairo context for drawing to the screen.
 * @param file The image to be drawn.
 * @return The advance in the x direction.
 */
static uint32_t draw_image(cairo_t *cr, const char *file, offset_t offset) {
  wordexp_t expanded_file;
  if (wordexp(file, &expanded_file, 0)) {
    fprintf(stderr, "Error expanding file %s\n", file);
  } else {
    file = expanded_file.we_wordv[0];
  }

  if (access(file, F_OK) == -1) {
    fprintf(stderr, "Cannot open image file %s\n", file);
    return 0;
  }

  cairo_surface_t *img;
  img = cairo_image_surface_create_from_png(file);
  int w = cairo_image_surface_get_width(img);
  int h = cairo_image_surface_get_height(img);
  int neww = (int)(((float)(settings.height) * ((float)(w) / (float)(h))) + 0.49999999);
  img = scale_surface (img, w, h, neww, settings.height);
  h = settings.height;
  w = neww;
  /* Attempt to center the image if it is not the height of the line. */ 
  int image_offset = (h - settings.height) / 2;
  cairo_set_source_surface(cr, img, offset.x, offset.image_y - h + image_offset);
  cairo_mask_surface(cr, img, offset.x, offset.image_y - h + image_offset);

  return w;
}
Esempio n. 4
0
static void
draw_mask (cairo_t *cr, int x, int y)
{
    cairo_surface_t *mask_surface;
    cairo_t *cr2;

    double width = (int)(0.9 * WIDTH);
    double height = (int)(0.9 * HEIGHT);
    x += 0.05 * WIDTH;
    y += 0.05 * HEIGHT;

    mask_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
						 CAIRO_CONTENT_ALPHA,
						 width, height);
    cr2 = cairo_create (mask_surface);
    cairo_surface_destroy (mask_surface);

    cairo_save (cr2);
    cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */
    cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr2);
    cairo_restore (cr2);

    cairo_set_source_rgb (cr2, 1, 1, 1); /* white */

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI);
    cairo_fill (cr2);

    cairo_mask_surface (cr, cairo_get_target (cr2), x, y);
    cairo_destroy (cr2);
}
Esempio n. 5
0
static void
draw_mask (cairo_t *cr)
{
    cairo_surface_t *surface;
    cairo_t *cr2;

    surface = cairo_surface_create_similar (cairo_get_group_target (cr),
	                                    CAIRO_CONTENT_ALPHA,
					    50, 50);
    cr2 = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_rectangle (cr2,
	             0, 0,
	             40, 40);
    cairo_rectangle (cr2,
	             10, 10,
	             40, 40);
    cairo_clip (cr2);

    cairo_move_to (cr2, 0, 25);
    cairo_line_to (cr2, 50, 25);
    cairo_move_to (cr2, 25, 0);
    cairo_line_to (cr2, 25, 50);
    cairo_set_source_rgb (cr2, 1, 1, 1);
    cairo_stroke (cr2);

    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_mask_surface (cr, cairo_get_target (cr2), 50, 50);
    cairo_destroy (cr2);
}
Esempio n. 6
0
static void
draw_mask (cairo_t *cr, int x, int y)
{
    cairo_surface_t *mask_surface;
    cairo_t *cr2;

    double width = (int)(0.9 * WIDTH);
    double height = (int)(0.9 * HEIGHT);
    x += 0.05 * WIDTH;
    y += 0.05 * HEIGHT;

    mask_surface = cairo_surface_create_similar (cairo_get_target (cr),
						 CAIRO_CONTENT_ALPHA,
						 width, height);
    cr2 = cairo_create (mask_surface);

    cairo_set_source_rgb (cr2, 1, 1, 1); /* white */

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI);
    cairo_fill (cr2);

    cairo_destroy (cr2);

    cairo_mask_surface (cr, mask_surface, x, y);

    cairo_surface_destroy (mask_surface);
}
Esempio n. 7
0
   static void
   paint (GtkWidget      *widget,
          GdkEventExpose *eev,
          void * dd)
   {
      //gint width, height;

    Detect * d = (Detect *) dd;
    cairo_t *cr;
    cairo_t *ci;

    //width  = widget->allocation.width;
    //height = widget->allocation.height;

    // vykreslení kreslící plochy
    ci = cairo_create (surface);
    paint_selection (ci, d);
    cairo_destroy (ci);

    cr = gdk_cairo_create (widget->window);

    // nastavení pozadí kreslící plochy
    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);

    cairo_paint (cr);

    cairo_set_source_surface(cr, surface, 0, 0);
    cairo_mask_surface(cr, surface, 0, 0);

    cairo_destroy(cr);
}
Esempio n. 8
0
static JSBool
maskSurface_func(JSContext *context,
                 uintN      argc,
                 jsval     *vp)
{
    jsval *argv = JS_ARGV(context, vp);
    JSObject *obj = JS_THIS_OBJECT(context, vp);
    JSObject *surface_wrapper;
    double x, y;
    cairo_surface_t *surface;
    cairo_t *cr;

    if (!gjs_parse_args(context, "maskSurface", "off", argc, argv,
                        "surface", &surface_wrapper,
                        "x", &x,
                        "y", &y))
        return JS_FALSE;

    surface = gjs_cairo_surface_get_surface(context, surface_wrapper);
    if (!surface) {
        gjs_throw(context, "first argument to maskSurface() should be a surface");
        return JS_FALSE;
    }

    cr = gjs_cairo_context_get_context(context, obj);

    cairo_mask_surface(cr, surface, x, y);

    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return JS_FALSE;

    JS_SET_RVAL(context, vp, JSVAL_VOID);
    return JS_TRUE;
}
Esempio n. 9
0
static bool
maskSurface_func(JSContext *context,
                 unsigned   argc,
                 JS::Value *vp)
{
    GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
    JS::RootedObject surface_wrapper(context);
    double x, y;
    cairo_surface_t *surface;
    cairo_t *cr = priv ? priv->cr : NULL;

    if (!gjs_parse_call_args(context, "maskSurface", argv, "off",
                             "surface", &surface_wrapper,
                             "x", &x,
                             "y", &y))
        return false;

    surface = gjs_cairo_surface_get_surface(context, surface_wrapper);
    if (!surface) {
        gjs_throw(context, "first argument to maskSurface() should be a surface");
        return false;
    }

    cairo_mask_surface(cr, surface, x, y);

    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return false;

    argv.rval().setUndefined();
    return true;
}
Esempio n. 10
0
static int
cr_mask (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    void *p;
    cairo_pattern_t **pattern;
    cairo_surface_t **surface;

    /* This is needed to make sure the stack positions for the optional
     * arguments stay nil after we start pushing other things on. */
    lua_settop(L, 4);

    if ((p = lua_touserdata(L, 2))) {
        if (lua_getmetatable(L, 2)) {
            lua_getfield(L, LUA_REGISTRYINDEX, OOCAIRO_MT_NAME_PATTERN);
            if (lua_rawequal(L, -1, -2)) {
                pattern = p;
                cairo_mask(*obj, *pattern);
                return 0;
            }
            lua_pop(L, 1);

            lua_getfield(L, LUA_REGISTRYINDEX, OOCAIRO_MT_NAME_SURFACE);
            if (lua_rawequal(L, -1, -2)) {
                surface = p;
                cairo_mask_surface(*obj, *surface,
                                   luaL_optnumber(L, 3, 0),
                                   luaL_optnumber(L, 4, 0));
                return 0;
            }
            lua_pop(L, 2);
        }
    }

    return luaL_typerror(L, 2, "Cairo pattern or surface object");
}
Esempio n. 11
0
cairo_t *
gsk_cairo_blur_finish_drawing (cairo_t         *cr,
                               float            radius,
                               const GdkRGBA   *color,
                               GskBlurFlags     blur_flags)
{
  cairo_t *original_cr;
  cairo_surface_t *surface;
  gdouble x_scale;

  if (!needs_blur (radius))
    return cr;

  original_cr = cairo_get_user_data (cr, &original_cr_key);

  /* Blur the surface. */
  surface = cairo_get_target (cr);

  x_scale = 1;
  cairo_surface_get_device_scale (cairo_get_target (cr), &x_scale, NULL);

  gsk_cairo_blur_surface (surface, x_scale * radius, blur_flags);

  gdk_cairo_set_source_rgba (original_cr, color);
  if (blur_flags & GSK_BLUR_REPEAT)
    mask_surface_repeat (original_cr, surface);
  else
    cairo_mask_surface (original_cr, surface, 0, 0);

  cairo_destroy (cr);

  cairo_surface_destroy (surface);

  return original_cr;
}
Esempio n. 12
0
File: a1-fill.c Progetto: AZed/cairo
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *a1;
    cairo_t *cr2;

    a1 = cairo_image_surface_create (CAIRO_FORMAT_A1, 100, 100);
    cr2 = cairo_create (a1);
    cairo_surface_destroy (a1);

    cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
    cairo_rectangle (cr2, 10, 10, 80, 80);
    cairo_set_source_rgb (cr2, 1, 1, 1);
    cairo_fill (cr2);
    cairo_rectangle (cr2, 20, 20, 60, 60);
    cairo_set_source_rgb (cr2, 0, 0, 0);
    cairo_fill (cr2);

    a1 = cairo_surface_reference (cairo_get_target (cr2));
    cairo_destroy (cr2);

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_mask_surface (cr, a1, 0, 0);
    cairo_surface_destroy (a1);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 13
0
static void do_drawing(cairo_t *cr) {
	cairo_t *ic;

	static gint count = 0;

	ic = cairo_create(glob.surface);

	gint i, j;

	for (i = 0; i <= glob.img_height; i += 7) {
		for (j = 0; j < count; j++) {
			cairo_move_to(ic, 0, i + j);
			cairo_line_to(ic, glob.img_width, i + j);
		}
	}

	count++;

	if (count == 8)
		glob.timer = FALSE;

	cairo_set_source_surface(cr, glob.image, 10, 10);
	cairo_mask_surface(cr, glob.surface, 10, 10);
	cairo_stroke(ic);

	cairo_destroy(ic);
}
GdkPixbuf *
f_pixbuf_from_cairo_surface (cairo_surface_t *source)
{
  gint width = cairo_image_surface_get_width (source);
  gint height = cairo_image_surface_get_height (source);
  GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
				      TRUE,
				      8,
				      width,
				      height);

  guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
  int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
  int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
  cairo_format_t format;
  cairo_surface_t *surface;
  cairo_t *ctx;
  static const cairo_user_data_key_t key;
  int j;

  format = f_image_surface_get_format (source);
  surface = cairo_image_surface_create_for_data (gdk_pixels,
						 format,
						 width, height, gdk_rowstride);
  ctx = cairo_create (surface);
  cairo_set_source_surface (ctx, source, 0, 0);
  if (format == CAIRO_FORMAT_ARGB32)
	  cairo_mask_surface (ctx, source, 0, 0);
  else
	  cairo_paint (ctx);

  for (j = height; j; j--)
    {
      guchar *p = gdk_pixels;
      guchar *end = p + 4 * width;
      guchar tmp;

      while (p < end)
	{
	  tmp = p[0];
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
	  p[0] = p[2];
	  p[2] = tmp;
#else	  
	  p[0] = p[1];
	  p[1] = p[2];
	  p[2] = p[3];
	  p[3] = tmp;
#endif
	  p += 4;
	}

      gdk_pixels += gdk_rowstride;
    }

  cairo_destroy (ctx);
  cairo_surface_destroy (surface);
  return pixbuf;
}
Esempio n. 15
0
static VALUE
cr_mask_surface (VALUE self, VALUE surface, VALUE x, VALUE y)
{
  cairo_mask_surface (_SELF, RVAL2CRSURFACE (surface),
                      NUM2DBL (x), NUM2DBL (y));
  cr_check_status (_SELF);
  return self;
}
Esempio n. 16
0
int spectro_draw() {
	cairo_t *c = xlib_context();
	cairo_set_source_rgba(c,1.0,1.0,1.0,1.0);
	cairo_rectangle(c,0,0,spect->fft_w,spect->fft_h);
	cairo_fill(c);
	set_color(c,RGBA_SPECT);
	cairo_mask_surface(c,spect->m_spec,0,0);
	if (conf.layers) {
		set_color(c,RGBA_THRESH);
		cairo_mask_surface(c,spect->m_thresh,0,0);
		cairo_scale(c,1.0/conf.scale,1.0/conf.scale);
		cairo_set_source_surface(c,spect->s_points,0,0);
		cairo_paint(c);
	}
	cairo_destroy(c);
	return 0;
}
static gboolean
hd_bookmark_shortcut_expose_event (GtkWidget *widget,
                                   GdkEventExpose *event)
{
  HDBookmarkShortcutPrivate *priv = HD_BOOKMARK_SHORTCUT (widget)->priv;
  cairo_t *cr;
  cairo_surface_t *bg;
  cairo_surface_t *thumbnail_icon;

  cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
  gdk_cairo_region (cr, event->region);
  cairo_clip (cr);

  if (priv->button_pressed)
    bg = priv->bg_active;
  else
    bg = priv->bg_image;

  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);

  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
  cairo_paint (cr);

  if (priv->thumbnail_icon)
    thumbnail_icon = priv->thumbnail_icon;
  else
    {
      create_default_thumbnail (HD_BOOKMARK_SHORTCUT (widget),
                                bg);
      thumbnail_icon = priv->default_thumbnail_icon;
    }

  if (thumbnail_icon)
    {
      cairo_set_source_surface (cr,
                                thumbnail_icon,
                                BORDER_WIDTH_LEFT,
                                BORDER_WIDTH_TOP);
      if (priv->thumb_mask)
        cairo_mask_surface (cr,
                            priv->thumb_mask,
                            BORDER_WIDTH_LEFT,
                            BORDER_WIDTH_TOP);
    }

  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

  if (bg)
    {
      cairo_set_source_surface (cr, bg, 0.0, 0.0);
      cairo_paint (cr);
    }

  cairo_destroy (cr);

  return GTK_WIDGET_CLASS (hd_bookmark_shortcut_parent_class)->expose_event (widget,
                                                                             event);
}
Esempio n. 18
0
static void gtk_plot_cairo_draw_pixmap                (GtkPlotPC *pc,
                                                      GdkPixmap *pixmap,
                                                      GdkBitmap *mask,
                                                      gint xsrc, gint ysrc,
                                                      gint xdest, gint ydest,
                                                      gint width, gint height,
                                                      gdouble scale_x, 
                                                      gdouble scale_y)
{
  cairo_surface_t *image_surface = NULL;
  cairo_surface_t *mask_surface = NULL;
  cairo_t *cr;
/* TODO: USE MASK */

  image_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
  cr = cairo_create(image_surface);
  cairo_scale(cr,scale_x,scale_y);
  gdk_cairo_set_source_pixmap(cr,pixmap,xsrc,ysrc);
  cairo_paint(cr);
  cairo_destroy(cr);

/*
  mask_surface = cairo_image_surface_create(CAIRO_CONTENT_COLOR_ALPHA, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
  cr = cairo_create(image_surface);
  cairo_scale(cr,scale_x,scale_y);
  gdk_cairo_set_source_pixmap(cr,mask,xsrc,ysrc);
  cairo_paint(cr);
  cairo_destroy(cr);
*/
  if(mask){
    mask_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
    cr = cairo_create(mask_surface);
    cairo_set_source_rgb(cr,0,0,0);
    cairo_scale(cr,scale_x,scale_y);
    gdk_cairo_set_source_pixmap(cr,pixmap,xsrc,ysrc);
    cairo_mask_surface(cr,mask_surface,0,0);
    cairo_fill(cr);
    cairo_destroy(cr);
  }

  cairo_save(GTK_PLOT_CAIRO(pc)->cairo);
/*
  cairo_rectangle(GTK_PLOT_CAIRO(pc)->cairo,xdest,ydest,(width-xsrc)*scale_x,(height-ysrc)*scale_y);
  cairo_clip(GTK_PLOT_CAIRO(pc)->cairo);
*/
/*
  if(mask) cairo_mask_surface(GTK_PLOT_CAIRO(pc)->cairo,mask_surface,xdest,ydest);
*/
  cairo_set_source_surface(GTK_PLOT_CAIRO(pc)->cairo,image_surface,xdest,ydest);
  cairo_paint(GTK_PLOT_CAIRO(pc)->cairo);
  
  cairo_restore(GTK_PLOT_CAIRO(pc)->cairo);
  cairo_surface_destroy(image_surface);
  cairo_surface_destroy(mask_surface);
}
Esempio n. 19
0
static int cairo_mask_surface_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );
  lua_cairo_surface_t* lcs = lua_cairo_surface_check( L, 2 );

  cairo_mask_surface( lc->cairo,
                      lcs->surface,               /* surface */
                      luaL_checknumber( L, 3 ),   /* x */
                      luaL_checknumber( L, 4 ) ); /* y */

  return( 0 );
}
Esempio n. 20
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *mask;
    cairo_pattern_t *pattern;
    cairo_t *cr2;
    cairo_text_extents_t extents;

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
                                         CAIRO_CONTENT_ALPHA,
                                         width, height);
    cr2 = cairo_create (mask);
    cairo_surface_destroy (mask);

    cairo_save (cr2);
    {
        cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
        cairo_paint (cr2);
    }
    cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    cairo_select_font_face (cr2,
                            CAIRO_TEST_FONT_FAMILY " Sans",
                            CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size (cr2, 0.5 * height);

    cairo_text_extents (cr2, "cairo", &extents);
    cairo_move_to (cr2,
                   floor ((width - extents.width) / 2 + 0.5) - extents.x_bearing,
                   floor ((height - extents.height) / 2 - 0.5) - extents.y_bearing);
    cairo_show_text (cr2, "cairo");

    cairo_set_source_rgb (cr, 1.0, 0, 0);
    cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0);
    cairo_destroy (cr2);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 21
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    uint32_t data[] = {
	0xaa000000, 0x55000000,
	0x55000000, 0xaa000000,
    };

    cairo_surface_t *mask, *mask2;
    cairo_pattern_t *pattern;
    cairo_t *cr2;

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
				         CAIRO_CONTENT_ALPHA,
					 width, height);
    cr2 = cairo_create (mask);

    cairo_save (cr2); {
	cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr2);
    } cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    mask2 = cairo_image_surface_create_for_data ((unsigned char *) data,
						CAIRO_FORMAT_ARGB32, 2, 2, 8);
    pattern = cairo_pattern_create_for_surface (mask2);
    cairo_surface_destroy (mask2);
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
    cairo_mask (cr2, pattern);
    cairo_pattern_destroy (pattern);
    cairo_destroy (cr2);

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    cairo_set_source_rgb (cr, 1.0, 0, 0);
    cairo_mask_surface (cr, mask, 0, 0);
    cairo_surface_destroy (mask);

    return CAIRO_TEST_SUCCESS;
}
static PyObject *
pycairo_mask_surface (PycairoContext *o, PyObject *args)
{
    PycairoSurface *s;
    double surface_x = 0.0, surface_y = 0.0;

    if (!PyArg_ParseTuple (args, "O!|dd:Context.mask_surface",
			   &PycairoSurface_Type, &s, &surface_x, &surface_y))
	return NULL;

    cairo_mask_surface (o->ctx, s->surface, surface_x, surface_y);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Esempio n. 23
0
static PyObject *
pycairo_mask_surface (PycairoContext *o, PyObject *args) {
  PycairoSurface *s;
  double surface_x = 0.0, surface_y = 0.0;

  if (!PyArg_ParseTuple (args, "O!|dd:Context.mask_surface",
			 &PycairoSurface_Type, &s, &surface_x, &surface_y))
    return NULL;

  Py_BEGIN_ALLOW_THREADS;
  cairo_mask_surface (o->ctx, s->surface, surface_x, surface_y);
  Py_END_ALLOW_THREADS;
  RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
  Py_RETURN_NONE;
}
Esempio n. 24
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *mask;
    uint32_t data[] = {
	0x80000000, 0x80000000,
	0x80000000, 0x80000000,
    };

    mask = cairo_image_surface_create_for_data ((unsigned char *) data,
						CAIRO_FORMAT_ARGB32, 2, 2, 8);

    cairo_set_source_rgb (cr, 1.0, 0, 0);

    /* We can translate with the CTM, with the mask_surface offset, or
     * with both. */

    /* 1. CTM alone. */
    cairo_save (cr);
    {
	cairo_translate (cr, 2, 2);
	cairo_mask_surface (cr, mask, 0, 0);
    }
    cairo_restore (cr);

    /* 2. Offset alone. */
    cairo_mask_surface (cr, mask, 4, 4);

    /* 3. CTM + offset */
    cairo_translate (cr, 2, 2);
    cairo_mask_surface (cr, mask, 4, 4);

    cairo_surface_destroy (mask);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 25
0
int img_draw() {
	cairo_surface_t *img;
	img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, spect->fft_w*conf.scale, spect->fft_h*conf.scale * 4);
	cairo_t *ctx;
	ctx = cairo_create(img);
	cairo_scale(ctx,conf.scale,-4.0 * conf.scale);
	cairo_translate(ctx, 0, -1.0 * spect->fft_h);
	cairo_set_source_rgba(ctx,1.0,1.0,1.0,1.0);
	cairo_rectangle(ctx,0,0,spect->fft_w,spect->fft_h);
	cairo_fill(ctx);
	set_color(ctx,RGBA_SPECT);
	cairo_mask_surface(ctx,spect->m_spec,0,0);
	cairo_surface_write_to_png(img,"/tmp/img1.png");
	cairo_destroy(ctx);
	cairo_surface_destroy(img);
	img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, spect->fft_w*conf.scale, spect->fft_h*conf.scale * 4);
	ctx = cairo_create(img);
	cairo_scale(ctx,conf.scale,-4.0 * conf.scale);
	cairo_translate(ctx, 0, -1.0 * spect->fft_h);
	cairo_set_source_rgba(ctx, conf.col[RGBA_THRESH].r, conf.col[RGBA_THRESH].g,
		conf.col[RGBA_THRESH].b, 0.8);
	cairo_mask_surface(ctx,spect->m_thresh,0,0);
	cairo_surface_write_to_png(img,"/tmp/img2.png");
	cairo_destroy(ctx);
	cairo_surface_destroy(img);
	img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, spect->fft_w*conf.scale, spect->fft_h*conf.scale * 4);
	ctx = cairo_create(img);
	cairo_scale(ctx, 1.0, -4.0);
	cairo_translate(ctx, 0, -1.0 * spect->fft_h * conf.scale);
	cairo_set_source_surface(ctx,spect->s_points, 0, 0);
	cairo_paint_with_alpha(ctx, 0.8);
	cairo_surface_write_to_png(img,"/tmp/img3.png");
	cairo_destroy(ctx);
	cairo_surface_destroy(img);
	return 0;
}
void guac_rdp_glyph_draw(rdpContext* context, rdpGlyph* glyph, int x, int y) {

    guac_client* client = ((rdp_freerdp_context*) context)->client;
    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;

    /* Do not attempt to draw glyphs if glyph drawing is not begun */
    if (guac_client_data->glyph_cairo == NULL)
        return;

    /* Use glyph as mask */
    cairo_mask_surface(
            guac_client_data->glyph_cairo,
            ((guac_rdp_glyph*) glyph)->surface, x, y);

}
Esempio n. 27
0
void PlatformContextCairo::restore()
{
    const ImageMaskInformation& maskInformation = m_state->m_imageMaskInformation;
    if (maskInformation.isValid()) {
        const FloatRect& maskRect = maskInformation.maskRect();
        cairo_pop_group_to_source(m_cr.get());
        cairo_mask_surface(m_cr.get(), maskInformation.maskSurface(), maskRect.x(), maskRect.y());
    }

    m_stateStack.removeLast();
    ASSERT(!m_stateStack.isEmpty());
    m_state = &m_stateStack.last();

    cairo_restore(m_cr.get());
}
Esempio n. 28
0
static void
render_card (cairo_t *cr, int x, int y, int c, int color)
{
	if (!render_init)
		return;
	assert (0 <= c && c < 52);

	gdk_cairo_set_source_pixbuf (cr, card_pixbuf[c], x, y);
	cairo_paint (cr);

	if (color == HAND_DISPLAY_OLD_CARD) { /* grey out old card */
		cairo_set_source_rgb (cr, HAND_DISPLAY_GREY_FONT);
		cairo_mask_surface (cr, grey_surface, x, y);
	}
	return;
}
Esempio n. 29
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *mask;
    cairo_pattern_t *pattern;
    cairo_t *cr2;

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
				         CAIRO_CONTENT_ALPHA,
					 width, height);
    cr2 = cairo_create (mask);
    cairo_surface_destroy (mask);

    cairo_save (cr2); {
	cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr2);
    } cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    cairo_paint (cr2);

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    pattern = cairo_pattern_create_radial (
	    0.5 * width, 0.5 * height, 0,
	    0.5 * width, 0.5 * height, 0.5 *height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 0., 0., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 0., 0., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 1., 0., 0., 1.);
    cairo_set_source (cr, pattern);
    cairo_pattern_destroy (pattern);

    cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0);
    cairo_destroy (cr2);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 30
0
char* handle_icon(GdkPixbuf* icon, gboolean use_board)
{
    int left_offset = 0;
    int top_offset = 0;

    if (_board== NULL) {
        _board = cairo_image_surface_create_from_png(BOARD_PATH);
        _board_mask = cairo_image_surface_create_from_png(BOARD_MASK_PATH);
    }
    g_assert(_board_mask != NULL);

    cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
                                                          BOARD_WIDTH,
                                                          BOARD_HEIGHT);
    cairo_t* cr  = cairo_create(surface);

    if (use_board) {
        double r, g, b;
        calc_dominant_color_by_pixbuf(icon, &r, &g, &b);
        cairo_set_source_rgb(cr, r, g, b);
        cairo_mask_surface(cr, _board_mask, 0, BOARD_OFFSET);
        /*cairo_paint(cr);*/

        left_offset = (IMG_WIDTH - gdk_pixbuf_get_width(icon)) / 2;
        top_offset = (IMG_HEIGHT - gdk_pixbuf_get_height(icon)) / 2;

        gdk_cairo_set_source_pixbuf(cr, icon, MARGIN_LEFT + left_offset,
                                    MARGIN_TOP-1 + top_offset);
    } else {
        gdk_cairo_set_source_pixbuf(cr, icon, left_offset, top_offset);
    }

    cairo_paint(cr);

    if (use_board) {
        cairo_set_source_surface(cr, _board, 0, BOARD_OFFSET);
        cairo_paint(cr);
    }

    char* data = get_data_uri_by_surface(surface);

    cairo_surface_destroy(surface);
    cairo_destroy(cr);
    return data;
}