static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_surface_t *surface; uint32_t data[16] = { 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff }; surface = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_RGB24, 4, 4, 16); /* We use a non-zero offset larger than the source surface size to * stress cairo out a bit more. */ cairo_set_source_surface (cr, surface, 10, 10); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); cairo_paint (cr); cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_surface_t *image; cairo_t *cr2; image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 2, 2); /* Fill with an opaque background to avoid a separate rgb24 ref image */ cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); /* First check handling of pattern extents > surface extents */ cairo_save (cr); cairo_scale (cr, width/2., height/2.); /* Create a solid black source to merge with the background */ cr2 = cairo_create (image); cairo_set_source_rgb (cr2, 0, 0 ,0); cairo_paint (cr2); cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0); cairo_destroy (cr2); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR); cairo_paint (cr); cairo_restore (cr); /* Then scale to smaller so we can see the full bilinear extents */ cairo_save (cr); cairo_translate (cr, PAD, PAD); cairo_scale (cr, SCALE, SCALE); cairo_translate (cr, 0.5, 0.5); /* Create a 2x2 blue+red checkerboard source */ cr2 = cairo_create (image); cairo_set_source_rgb (cr2, 1, 0 ,0); /* red */ cairo_paint (cr2); cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */ cairo_rectangle (cr2, 0, 1, 1, 1); cairo_rectangle (cr2, 1, 0, 1, 1); cairo_fill (cr2); cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0); cairo_destroy (cr2); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR); cairo_paint (cr); cairo_restore (cr); cairo_surface_destroy (image); return CAIRO_TEST_SUCCESS; }
void CairoDevice::PushPenColor( const VGColor & color) { double r, g, b, a; cairo_pattern_get_rgba (cairo_get_source(fNativeDevice), &r, &g, &b, &a); fPenColorStack.push (VGColor(cc2c(r), cc2c(g), cc2c(b), cc2c(a))); SelectPenColor (color); }
cairo_surface_t * BitmapSource::GetSurface (cairo_t *cr) { if (image_surface == NULL) return NULL; if (native_surface) return native_surface; if (cr == NULL) return image_surface; native_surface = cairo_surface_create_similar (cairo_get_group_target (cr), cairo_surface_get_content (image_surface), GetPixelWidth (), GetPixelHeight ()); cairo_t *context = cairo_create (native_surface); cairo_set_source_surface (context, image_surface, 0, 0); cairo_pattern_set_filter (cairo_get_source (context), CAIRO_FILTER_FAST); cairo_paint (context); cairo_destroy (context); return native_surface; }
/* Scale the surface with the width and height requested */ cairo_surface_t * scale_surface (cairo_surface_t *surface, gdouble width, gdouble height) { gdouble old_width = cairo_image_surface_get_width (surface); gdouble old_height = cairo_image_surface_get_height (surface); cairo_surface_t *new_surface = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR_ALPHA, width, height); cairo_t *cr = cairo_create (new_surface); /* Scale *before* setting the source surface (1) */ cairo_scale (cr, width / old_width, height / old_height); cairo_set_source_surface (cr, surface, 0, 0); /* To avoid getting the edge pixels blended with 0 alpha, which would * occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2) */ cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_REFLECT); /* Replace the destination with the source instead of overlaying */ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); /* Do the actual drawing */ cairo_paint (cr); cairo_destroy (cr); return new_surface; }
value lime_cairo_get_source (value handle) { cairo_pattern_t* pattern = cairo_get_source ((cairo_t*)val_data (handle)); cairo_pattern_reference (pattern); return CFFIPointer (pattern, gc_cairo_pattern); }
static VALUE cr_get_source (VALUE self) { VALUE rb_source = Qnil; cairo_pattern_t *source; source = cairo_get_source (_SELF); if (source) { rb_cairo_check_status (cairo_pattern_status (source)); rb_source = rb_ivar_get (self, cr_id_source); if (NIL_P (rb_source) || RVAL2CRPATTERN (rb_source) != source) { rb_source = CRPATTERN2RVAL (source); rb_ivar_set (self, cr_id_source, rb_source); } } else { rb_source = Qnil; rb_ivar_set (self, cr_id_source, rb_source); } return rb_source; }
static void matenu_menu_bar_reset_bg_pixmap (MatenuMenuBar* self) { GdkPixmap* pixmap; cairo_t* cairo; cairo_pattern_t* pattern; GtkStyle* style; GdkPixmap* _tmp0_; g_return_if_fail (self != NULL); if (matenu_menu_bar_get_background (self)->type != MATENU_BACKGROUND_TYPE_PIXMAP) { return; } if (!GTK_WIDGET_REALIZED ((GtkWidget*) self)) { return; } g_assert (GDK_IS_DRAWABLE (((GtkWidget*) self)->window)); g_assert (GDK_IS_DRAWABLE (self->priv->_background->pixmap)); pixmap = gdk_pixmap_new ((GdkDrawable*) ((GtkWidget*) self)->window, ((GtkWidget*) self)->allocation.width, ((GtkWidget*) self)->allocation.height, -1); g_assert (GDK_IS_DRAWABLE (pixmap)); cairo = gdk_cairo_create ((GdkDrawable*) pixmap); g_assert (cairo != NULL); gdk_cairo_set_source_pixmap (cairo, self->priv->_background->pixmap, (double) (-self->priv->_background->offset_x), (double) (-self->priv->_background->offset_y)); pattern = cairo_get_source (cairo); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_rectangle (cairo, (double) 0, (double) 0, (double) ((GtkWidget*) self)->allocation.width, (double) ((GtkWidget*) self)->allocation.height); cairo_fill (cairo); style = _g_object_ref0 (gtk_widget_get_style ((GtkWidget*) self)); style->bg_pixmap[(gint) GTK_STATE_NORMAL] = (_tmp0_ = _g_object_ref0 (pixmap), _g_object_unref0 (style->bg_pixmap[(gint) GTK_STATE_NORMAL]), _tmp0_); gtk_style_set_background (style, ((GtkWidget*) self)->window, GTK_STATE_NORMAL); gtk_widget_queue_draw ((GtkWidget*) self); _g_object_unref0 (style); _cairo_destroy0 (cairo); _g_object_unref0 (pixmap); }
static cairo_surface_t * _cairo_image_surface_scale_bilinear_2x2 (cairo_surface_t *image, int new_width, int new_height) { cairo_surface_t *output; cairo_t *cr; output = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, new_width, new_height); cr = cairo_create (output); cairo_scale (cr, (double) new_width / cairo_image_surface_get_width (image), (double) new_height / cairo_image_surface_get_height (image)); cairo_set_source_surface (cr, image, 0.0, 0.0); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR); cairo_rectangle (cr, 0.0, 0.0, cairo_image_surface_get_width (image), cairo_image_surface_get_height (image)); cairo_fill (cr); cairo_surface_flush (output); cairo_destroy (cr); return output; }
cairo_surface_t* Win32UIBinding::ScaleCairoSurface( cairo_surface_t* oldSurface, int newWidth, int newHeight) { cairo_matrix_t scaleMatrix; cairo_matrix_init_scale(&scaleMatrix, (double) cairo_image_surface_get_width(oldSurface) / (double) newWidth, (double) cairo_image_surface_get_height(oldSurface) / (double) newHeight); cairo_pattern_t* surfacePattern = cairo_pattern_create_for_surface(oldSurface); cairo_pattern_set_matrix(surfacePattern, &scaleMatrix); cairo_pattern_set_filter(surfacePattern, CAIRO_FILTER_BEST); cairo_surface_t* newSurface = cairo_surface_create_similar( oldSurface, CAIRO_CONTENT_COLOR_ALPHA, newWidth, newHeight); cairo_t* cr = cairo_create(newSurface); cairo_set_source(cr, surfacePattern); /* To avoid getting the edge pixels blended with 0 alpha, which would * occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2) */ cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REFLECT); /* Replace the destination with the source instead of overlaying */ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); /* Do the actual drawing */ cairo_paint(cr); cairo_destroy(cr); return newSurface; }
static JSBool getSource_func(JSContext *context, unsigned argc, jsval *vp) { JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JSObject *obj = JSVAL_TO_OBJECT(rec.thisv()); cairo_t *cr; cairo_pattern_t *pattern; JSObject *pattern_wrapper; if (argc > 0) { gjs_throw(context, "Context.getSource() takes no arguments"); return JS_FALSE; } cr = gjs_cairo_context_get_context(context, obj); pattern = cairo_get_source(cr); if (!gjs_cairo_check_status(context, cairo_status(cr), "context")) return JS_FALSE; /* pattern belongs to the context, so keep the reference */ pattern_wrapper = gjs_cairo_pattern_from_pattern(context, pattern); if (!pattern_wrapper) { gjs_throw(context, "failed to create pattern"); return JS_FALSE; } rec.rval().set(OBJECT_TO_JSVAL(pattern_wrapper)); return JS_TRUE; }
static gboolean pp_piksl_draw(GtkWidget* widget, cairo_t* cr) { ppPiksl* piksl = PP_PIKSL(widget); cairo_set_source(cr, PP_APP->checker); cairo_rectangle(cr, 0, 0, piksl->img_width*piksl->zoom, piksl->img_height*piksl->zoom); cairo_fill(cr); // Render the graphics data... // Zoom the surface cairo_scale(cr, piksl->zoom, piksl->zoom); // Render each layer guint i; ppLayer* layer = NULL; for (i = 0; i < piksl->layers->len; ++i) { layer = g_ptr_array_index(piksl->layers, i); cairo_set_source_surface(cr, layer->surface, layer->x, layer->y); // Disable the gaussian filtering to preserve pixels cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); cairo_paint(cr); } return FALSE; }
static bool getSource_func(JSContext *context, unsigned argc, JS::Value *vp) { GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv); cairo_t *cr = priv ? priv->cr : NULL; cairo_pattern_t *pattern; JSObject *pattern_wrapper; if (argc > 0) { gjs_throw(context, "Context.getSource() takes no arguments"); return false; } pattern = cairo_get_source(cr); if (!gjs_cairo_check_status(context, cairo_status(cr), "context")) return false; /* pattern belongs to the context, so keep the reference */ pattern_wrapper = gjs_cairo_pattern_from_pattern(context, pattern); if (!pattern_wrapper) { gjs_throw(context, "failed to create pattern"); return false; } rec.rval().setObject(*pattern_wrapper); return true; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_surface_t *surface; uint32_t data[16] = { 0x80808080, 0x80808080, 0x80800000, 0x80800000, 0x80808080, 0x80808080, 0x80800000, 0x80800000, 0x80008000, 0x80008000, 0x80000080, 0x80000080, 0x80008000, 0x80008000, 0x80000080, 0x80000080 }; surface = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_ARGB32, 4, 4, 16); cairo_test_paint_checkered (cr); cairo_scale (cr, 4, 4); cairo_set_source_surface (cr, surface, 2 , 2); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; }
static gint on_draw(GtkWidget *widget, cairo_t *cr, gpointer userdata) { GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_new_from_file("/usr/share/themes/Ambiance/gtk-2.0/apps/img/panel.png", NULL); if (!pixbuf) { pixbuf = gdk_pixbuf_new_from_file("/usr/share/lxpanel/images/lubuntu-background.png", NULL); } if (!pixbuf) { pixbuf = gdk_pixbuf_new_from_file("/usr/share/themes/Greybird/ubiquity-panel-bg.png", NULL); } if (!pixbuf) { pixbuf = gdk_pixbuf_new_from_file("/usr/share/budgie-desktop/ubiquity-panel-bg.png", NULL); } if (!pixbuf) { pixbuf = gdk_pixbuf_new_from_file("/usr/share/ubiquity/pixmaps/panel.png", NULL); } if (pixbuf) { gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_PAD); cairo_paint(cr); g_object_unref(pixbuf); } else { g_warning("Could not find background image."); } struct { GtkWidget *container; cairo_t *cr; } data; data.container = widget; data.cr = cr; gtk_container_forall (GTK_CONTAINER(widget), draw_child, &data); return FALSE; }
WidgetRenderingContext::~WidgetRenderingContext() { // We do not need to blit back to the target in the fallback case. See above. RenderThemeGtk* theme = static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get()); if (!theme->m_themePartsHaveRGBAColormap && m_graphicsContext->gdkWindow()) return; // Don't paint the results back if there was an error. if (m_hadError) { scheduleScratchBufferPurge(); return; } // FIXME: It's unclear if it is necessary to preserve the current source here. cairo_t* cairoContext = m_graphicsContext->platformContext()->cr(); RefPtr<cairo_pattern_t> previousSource(cairo_get_source(cairoContext)); // The blit rectangle is the original target rectangle adjusted for any extra space. IntRect fullTargetRect(m_targetRect); fullTargetRect.inflateX(m_extraSpace.width()); fullTargetRect.inflateY(m_extraSpace.height()); gdk_cairo_set_source_pixmap(cairoContext, gScratchBuffer, fullTargetRect.x(), fullTargetRect.y()); cairo_rectangle(cairoContext, fullTargetRect.x(), fullTargetRect.y(), fullTargetRect.width(), fullTargetRect.height()); cairo_fill(cairoContext); cairo_set_source(cairoContext, previousSource.get()); scheduleScratchBufferPurge(); }
static JSBool getSource_func(JSContext *context, uintN argc, jsval *vp) { JSObject *obj = JS_THIS_OBJECT(context, vp); cairo_t *cr; cairo_pattern_t *pattern; JSObject *pattern_wrapper; if (argc > 0) { gjs_throw(context, "Context.getSource() takes no arguments"); return JS_FALSE; } cr = gjs_cairo_context_get_context(context, obj); pattern = cairo_get_source(cr); if (!gjs_cairo_check_status(context, cairo_status(cr), "context")) return JS_FALSE; /* pattern belongs to the context, so keep the reference */ pattern_wrapper = gjs_cairo_pattern_from_pattern(context, pattern); if (!pattern_wrapper) { gjs_throw(context, "failed to create pattern"); return JS_FALSE; } JS_SET_RVAL(context, vp, OBJECT_TO_JSVAL(pattern_wrapper)); return JS_TRUE; }
static cairo_test_status_t record_replay (cairo_t *cr, cairo_t *(*func)(cairo_t *, cairo_surface_t *(*pattern)(cairo_t *)), cairo_surface_t *(*pattern)(cairo_t *), int width, int height) { cairo_surface_t *surface; int x, y; surface = record_get (func (record_create (cr), pattern)); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_surface (cr, surface, 0, 0); cairo_surface_destroy (surface); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_NONE); for (y = 0; y < height; y += 2) { for (x = 0; x < width; x += 2) { cairo_rectangle (cr, x, y, 2, 2); cairo_clip (cr); cairo_paint (cr); cairo_reset_clip (cr); } } return CAIRO_TEST_SUCCESS; }
static void byzanz_layer_cursor_render (ByzanzLayer *layer, cairo_t * cr) { ByzanzLayerCursor *clayer = BYZANZ_LAYER_CURSOR (layer); XFixesCursorImage *cursor = clayer->cursor; cairo_surface_t *cursor_surface; if (clayer->cursor == NULL) return; cursor_surface = cairo_image_surface_create_for_data ((guchar *) cursor->pixels, CAIRO_FORMAT_ARGB32, cursor->width * sizeof (unsigned long) / 4, cursor->height, cursor->width * sizeof (unsigned long)); cairo_save (cr); cairo_translate (cr, clayer->cursor_x - cursor->xhot, clayer->cursor_y - cursor->yhot); /* This is neeed to map an unsigned long array to a uint32_t array */ cairo_scale (cr, 4.0 / sizeof (unsigned long), 1); #if G_BYTE_ORDER == G_BIG_ENDIAN cairo_translate (cr, (4.0 - sizeof (unsigned long)) / sizeof (unsigned long), 0); #endif cairo_set_source_surface (cr, cursor_surface, 0, 0); /* Next line is also neeed for mapping the unsigned long array to a uint32_t array */ cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); cairo_restore (cr); cairo_surface_destroy (cursor_surface); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); char *filename; cairo_surface_t *surface; xasprintf (&filename, "%s/%s", ctx->srcdir, "create-from-png.ref.png"); surface = cairo_image_surface_create_from_png (filename); if (cairo_surface_status (surface)) { cairo_test_status_t result; result = cairo_test_status_from_status (ctx, cairo_surface_status (surface)); if (result == CAIRO_TEST_FAILURE) { cairo_test_log (ctx, "Error reading PNG image %s: %s\n", filename, cairo_status_to_string (cairo_surface_status (surface))); } free (filename); return result; } cairo_set_source_surface (cr, surface, 0, 0); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); cairo_surface_destroy (surface); free (filename); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { int i, j; cairo_surface_t *surface; surface = cairo_image_surface_create_for_data ((unsigned char *) &black_pixel, CAIRO_FORMAT_ARGB32, 1, 1, 4); /* Fill background white */ cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); /* Draw in black */ cairo_set_source_rgb (cr, 0, 0, 0); cairo_translate (cr, PAD, PAD); cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); for (i = 0; i < POINTS; i++) for (j = 0; j < POINTS; j++) { cairo_set_source_surface (cr, surface, 2 * i + i * STEP, 2 * j + j * STEP); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); } cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; }
static GdkPixmap * tile_pixmap (GdkPixmap *pixmap, int width, int height) { GdkPixmap *copy; cairo_t *cr; copy = gdk_pixmap_new (pixmap, width, height, pixmap == NULL? 24 : -1); cr = gdk_cairo_create (copy); if (pixmap != NULL) { cairo_pattern_t *pattern; gdk_cairo_set_source_pixmap (cr, pixmap, 0.0, 0.0); pattern = cairo_get_source (cr); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); } else { GtkStyle *style; style = gtk_widget_get_default_style (); gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); } cairo_paint (cr); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { g_object_unref (copy); copy = NULL; } cairo_destroy (cr); return copy; }
cairo_surface_t * ev_document_misc_surface_rotate_and_scale (cairo_surface_t *surface, gint dest_width, gint dest_height, gint dest_rotation) { cairo_surface_t *new_surface; cairo_t *cr; gint width, height; gint new_width = dest_width; gint new_height = dest_height; width = cairo_image_surface_get_width (surface); height = cairo_image_surface_get_height (surface); if (dest_width == width && dest_height == height && dest_rotation == 0) { return cairo_surface_reference (surface); } if (dest_rotation == 90 || dest_rotation == 270) { new_width = dest_height; new_height = dest_width; } new_surface = cairo_surface_create_similar (surface, cairo_surface_get_content (surface), new_width, new_height); cr = cairo_create (new_surface); switch (dest_rotation) { case 90: cairo_translate (cr, new_width, 0); break; case 180: cairo_translate (cr, new_width, new_height); break; case 270: cairo_translate (cr, 0, new_height); break; default: cairo_translate (cr, 0, 0); } cairo_rotate (cr, dest_rotation * G_PI / 180.0); if (dest_width != width || dest_height != height) { cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR); cairo_scale (cr, (gdouble)dest_width / width, (gdouble)dest_height / height); } cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_destroy (cr); return new_surface; }
void cairo_test_paint_checkered (cairo_t *cr) { cairo_surface_t *check; check = _draw_check (12, 12); cairo_save (cr); cairo_set_source_surface (cr, check, 0, 0); cairo_surface_destroy (check); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); cairo_paint (cr); cairo_restore (cr); }
static int cr_get_source (lua_State *L) { cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT); cairo_pattern_t **pattern = create_pattern_userdata(L); *pattern = cairo_get_source(*obj); cairo_pattern_reference(*pattern); return 1; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_surface_t *surface; uint32_t data[STAMP_WIDTH * STAMP_HEIGHT] = { 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff }; int i, j; /* Draw reference lines where the jump should be. */ cairo_move_to (cr, PAD + STEPS / 2 * (STAMP_WIDTH + PAD), 0); cairo_rel_line_to (cr, 0, IMAGE_HEIGHT); cairo_move_to (cr, 0, PAD + STEPS / 2 * (STAMP_HEIGHT + PAD)); cairo_rel_line_to (cr, IMAGE_WIDTH, 0); cairo_set_line_width (cr, 2.0); cairo_stroke (cr); surface = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_RGB24, STAMP_WIDTH, STAMP_HEIGHT, STAMP_WIDTH * 4); for (j=0; j < STEPS; j++) { double j_step; for (i=0; i < STEPS; i++) { double i_step; #define GENERATE_REFERENCE_IMAGE 0 #if GENERATE_REFERENCE_IMAGE i_step = i >= STEPS / 2 ? 1 : 0; j_step = j >= STEPS / 2 ? 1 : 0; #else i_step = i * 1.0 / STEPS; j_step = j * 1.0 / STEPS; #endif cairo_save (cr); cairo_set_source_surface (cr, surface, PAD + i * (STAMP_WIDTH + PAD) + i_step, PAD + j * (STAMP_HEIGHT + PAD) + j_step); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); cairo_restore (cr); } } cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; }
static void hippo_canvas_image_paint_below_children(HippoCanvasBox *box, cairo_t *cr, HippoRectangle *damaged_box) { HippoCanvasImage *image = HIPPO_CANVAS_IMAGE(box); int x, y, w, h; int image_width, image_height; double xscale; double yscale; if (image->surface == NULL) return; image_width = cairo_image_surface_get_width(image->surface); image_height = cairo_image_surface_get_height(image->surface); /* Immediately short-circuit 0-sized image or scaled image, * which saves special cases in the math later on, in addition * to saving work */ if (image_width == 0 || image_height == 0 || image->scale_width == 0 || image->scale_height == 0) return; if (image->scale_width >= 0) { w = image->scale_width; xscale = image->scale_width / (double) image_width; } else { w = image_width; xscale = 1.0; } if (image->scale_height >= 0) { h = image->scale_height; yscale = image->scale_height / (double) image_height; } else { h = image_height; yscale = 1.0; } /* note that if an alignment is FILL the w/h will be increased * beyond the image's natural size, which will result in * a tiled image */ hippo_canvas_box_align(box, w, h, &x, &y, &w, &h); cairo_rectangle(cr, x, y, w, h); cairo_clip(cr); cairo_scale (cr, xscale, yscale); cairo_translate (cr, x, y); cairo_set_source_surface(cr, image->surface, 0, 0); cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); cairo_paint(cr); /* g_debug("cairo status %s", cairo_status_to_string(cairo_status(cr))); */ }
static cairo_surface_t * get_surface_from_pixbuf (GdkPixbuf *pixbuf, MetaImageFillType fill_type, gdouble width, gdouble height, gboolean vertical_stripes, gboolean horizontal_stripes) { gdouble pixbuf_width; gdouble pixbuf_height; cairo_surface_t *surface; cairo_content_t content; cairo_surface_t *copy; cairo_t *cr; pixbuf_width = gdk_pixbuf_get_width (pixbuf); pixbuf_height = gdk_pixbuf_get_height (pixbuf); surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL); if (pixbuf_width == width && pixbuf_height == height) { return surface; } if (fill_type != META_IMAGE_FILL_TILE) { cairo_surface_t *scaled; scaled = scale_surface (surface, pixbuf_width, pixbuf_height, width, height, vertical_stripes, horizontal_stripes); cairo_surface_destroy (surface); surface = scaled; } content = CAIRO_CONTENT_COLOR_ALPHA; width = ceil (width); height = ceil (height); copy = cairo_surface_create_similar (surface, content, width, height); cr = cairo_create (copy); cairo_set_source_surface (cr, surface, 0, 0); if (fill_type == META_IMAGE_FILL_TILE || vertical_stripes || horizontal_stripes) { cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); } cairo_paint (cr); cairo_destroy (cr); cairo_surface_destroy (surface); return copy; }
void TiledBackingStoreBackend::paintCheckerPattern(GraphicsContext* context, const FloatRect& target) { PlatformContextCairo* platformContext = context->platformContext(); cairo_t* cr = platformContext->cr(); cairo_set_source_surface(cr, checkeredSurface(), 0, 0); cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); cairo_rectangle(cr, target.x(), target.y(), target.width(), target.height()); cairo_fill(cr); }
void CairoRenderer::Stroke(void) { double r, g, b, a; cairo_pattern_get_rgba(cairo_get_source(m_pCairo), &r, &g, &b, &a); cairo_set_source_rgba(m_pCairo, m_pStrokeColor[0], m_pStrokeColor[1], m_pStrokeColor[2], 1.0); cairo_stroke(m_pCairo); cairo_set_source_rgba(m_pCairo, r, g, b, 1.0); }