static void * draw_thread (void *arg) { const char *text = "Hello world. "; thread_data_t *thread_data = arg; cairo_surface_t *surface; cairo_font_extents_t extents; cairo_t *cr; int i; cr = cairo_create (thread_data->target); cairo_surface_destroy (thread_data->target); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, NUM_ITERATIONS); cairo_font_extents (cr, &extents); cairo_move_to (cr, 1, HEIGHT - extents.descent - 1); for (i = 0; i < NUM_ITERATIONS; i++) { char buf[2]; cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, i); buf[0] = text[i%strlen(text)]; buf[1] = '\0'; cairo_show_text (cr, buf); } surface = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); return surface; }
static cairo_status_t _cairo_qt_surface_acquire_source_image (void *abstract_surface, cairo_image_surface_t **image_out, void **image_extra) { cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; D(fprintf(stderr, "q[%p] acquire_source_image\n", abstract_surface)); *image_extra = NULL; if (qs->image_equiv) { *image_out = (cairo_image_surface_t*) cairo_surface_reference (qs->image_equiv); return CAIRO_STATUS_SUCCESS; } if (qs->pixmap) { QImage *qimg = new QImage(qs->pixmap->toImage()); cairo_surface_t *image; cairo_status_t status; image = cairo_image_surface_create_for_data (qimg->bits(), _cairo_format_from_qimage_format (qimg->format()), qimg->width(), qimg->height(), qimg->bytesPerLine()); status = _cairo_user_data_array_set_data (&image->user_data, (const cairo_user_data_key_t *)&_qimg_destroy, qimg, _qimg_destroy); if (status) { cairo_surface_destroy (image); return status; } *image_out = (cairo_image_surface_t *) image; return CAIRO_STATUS_SUCCESS; } return _cairo_error (CAIRO_STATUS_NO_MEMORY); }
void _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other) { clip->mode = other->mode; clip->surface = cairo_surface_reference (other->surface); clip->surface_rect = other->surface_rect; clip->serial = other->serial; if (other->region == NULL) { clip->region = other->region; } else { clip->region = pixman_region_create (); pixman_region_copy (clip->region, other->region); } clip->path = _cairo_clip_path_reference (other->path); }
cairo_surface_t * _cairo_surface_create_for_rectangle_int (cairo_surface_t *target, const cairo_rectangle_int_t *extents) { cairo_surface_subsurface_t *surface; if (unlikely (target->status)) return _cairo_surface_create_in_error (target->status); if (unlikely (target->finished)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); assert (target->backend->type != CAIRO_SURFACE_TYPE_SUBSURFACE); surface = malloc (sizeof (cairo_surface_subsurface_t)); if (unlikely (surface == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&surface->base, &_cairo_surface_subsurface_backend, NULL, /* device */ target->content, target->is_vector); surface->extents = *extents; surface->extents.x *= target->device_transform.xx; surface->extents.y *= target->device_transform.yy; surface->extents.width *= target->device_transform.xx; surface->extents.height *= target->device_transform.yy; surface->extents.x += target->device_transform.x0; surface->extents.y += target->device_transform.y0; surface->target = cairo_surface_reference (target); surface->base.type = surface->target->type; surface->snapshot = NULL; cairo_surface_set_device_scale (&surface->base, target->device_transform.xx, target->device_transform.yy); return &surface->base; }
static cairo_pattern_t * _cairo_default_context_pop_group (void *abstract_cr) { cairo_default_context_t *cr = abstract_cr; cairo_surface_t *group_surface; cairo_pattern_t *group_pattern; cairo_surface_t *parent_surface; cairo_matrix_t group_matrix; cairo_status_t status; /* Verify that we are at the right nesting level */ if (unlikely (! _cairo_gstate_is_group (cr->gstate))) return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_POP_GROUP); /* Get a reference to the active surface before restoring */ group_surface = _cairo_gstate_get_target (cr->gstate); group_surface = cairo_surface_reference (group_surface); status = _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist); assert (status == CAIRO_STATUS_SUCCESS); parent_surface = _cairo_gstate_get_target (cr->gstate); group_pattern = cairo_pattern_create_for_surface (group_surface); status = group_pattern->status; if (unlikely (status)) goto done; _cairo_gstate_get_matrix (cr->gstate, &group_matrix); cairo_pattern_set_matrix (group_pattern, &group_matrix); /* If we have a current path, we need to adjust it to compensate for * the device offset just removed. */ _cairo_path_fixed_translate (cr->path, _cairo_fixed_from_int (parent_surface->device_transform.x0 - group_surface->device_transform.x0), _cairo_fixed_from_int (parent_surface->device_transform.y0 - group_surface->device_transform.y0)); done: cairo_surface_destroy (group_surface); return group_pattern; }
static void set_surface(HippoCanvasImage *image, cairo_surface_t *surface) { if (surface != image->surface) { int old_width, old_height; gboolean request_changed = FALSE; #if 0 /* The FC5 version of Cairo doesn't have this API */ if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_IMAGE) { g_warning("Image canvas item only supports image surfaces"); return; } #endif old_width = image->surface ? cairo_image_surface_get_width(image->surface) : 0; old_height = image->surface ? cairo_image_surface_get_height(image->surface) : 0; if (surface) cairo_surface_reference(surface); if (image->surface) cairo_surface_destroy(image->surface); image->surface = surface; if (image->scale_width < 0) { int width = image->surface ? cairo_image_surface_get_width(image->surface) : 0; if (width != old_width) request_changed = TRUE; } if (image->scale_height < 0) { int height = image->surface ? cairo_image_surface_get_height(image->surface) : 0; if (height != old_height) request_changed = TRUE; } if (request_changed) hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(image)); hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(image), 0, 0, -1, -1); g_object_notify(G_OBJECT(image), "image"); } }
static void generate_reference (double ppi_x, double ppi_y, const char *filename) { cairo_surface_t *surface, *target; cairo_t *cr; cairo_status_t status; surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE*ppi_x/72, SIZE*ppi_y/72); cr = cairo_create (surface); cairo_surface_destroy (surface); #if SET_TOLERANCE cairo_set_tolerance (cr, 3.0); #endif cairo_save (cr); { cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); } cairo_restore (cr); cairo_scale (cr, ppi_x/72., ppi_y/72.); draw (cr, SIZE, SIZE); surface = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); target = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE); cr = cairo_create (target); cairo_scale (cr, 72./ppi_x, 72./ppi_y); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); status = cairo_surface_write_to_png (cairo_get_target (cr), filename); cairo_destroy (cr); if (status) { fprintf (stderr, "Failed to generate reference image '%s': %s\n", filename, cairo_status_to_string (status)); exit (1); } }
/* For each of circle and fallback_circle we draw: * - two overlapping * - one isolated * - one off the page * - one overlapping the edge of the page. * * We also draw a circle and fallback_circle overlapping each other. * * Circles are drawn in green. An opaque color and CAIRO_OPERATOR_OVER * is used to ensure they will be emitted as a vectors in PS/PDF. * * Fallback circles are drawn in red. CAIRO_OPERATOR_ADD is used to * ensure they will be emitted as a fallback image in PS/PDF. * * In order to trigger a fallback for SVG, we need to use a surface with * REFLECT. */ static cairo_surface_t * surface_create (cairo_t *target) { cairo_surface_t *surface; cairo_t *cr; surface = cairo_surface_create_similar (cairo_get_target (target), CAIRO_CONTENT_COLOR_ALPHA, CIRCLE_SIZE, CIRCLE_SIZE); cr = cairo_create (surface); cairo_surface_destroy (surface); cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); draw_circle (cr, CIRCLE_SIZE/2, CIRCLE_SIZE/2); surface = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); return surface; }
Element* Image::clone() { XOJ_CHECK_TYPE(Image); Image* img = new Image(); img->x = this->x; img->y = this->y; img->setColor(this->getColor()); img->width = this->width; img->height = this->height; img->data = (unsigned char*)g_malloc(this->dLen); img->dLen = this->dLen; memcpy(img->data, this->data, this->dLen); img->image = cairo_surface_reference(this->image); return img; }
/** * gjs_cairo_surface_construct: * @context: the context * @object: object to construct * @surface: cairo_surface to attach to the object * * Constructs a surface wrapper giving an empty JSObject and a * cairo surface. A reference to @surface will be taken. * * This is mainly used for subclasses where object is already created. */ void gjs_cairo_surface_construct(JSContext *context, JSObject *object, cairo_surface_t *surface) { GjsCairoSurface *priv; g_return_if_fail(context != NULL); g_return_if_fail(object != NULL); g_return_if_fail(surface != NULL); priv = g_slice_new0(GjsCairoSurface); g_assert(priv_from_js(context, object) == NULL); JS_SetPrivate(context, object, priv); priv->context = context; priv->object = object; priv->surface = cairo_surface_reference(surface); }
cairo_surface_t * display_get_pointer_surface(struct display *display, int pointer, int *width, int *height, int *hotspot_x, int *hotspot_y) { cairo_surface_t *surface; surface = display->pointer_surfaces[pointer]; #if HAVE_CAIRO_EGL *width = cairo_gl_surface_get_width(surface); *height = cairo_gl_surface_get_height(surface); #else *width = cairo_image_surface_get_width(surface); *height = cairo_image_surface_get_height(surface); #endif *hotspot_x = pointer_images[pointer].hotspot_x; *hotspot_y = pointer_images[pointer].hotspot_y; return cairo_surface_reference(surface); }
static ScaleData * scale_data_new (cairo_surface_t *image, int new_width, int new_height, scale_filter_t quality, GCancellable *cancellable) { ScaleData *scale_data; scale_data = g_new0 (ScaleData, 1); scale_data->original = cairo_surface_reference (image); scale_data->new_width = new_width; scale_data->new_height = new_height; scale_data->quality = quality; scale_data->scaled = NULL; scale_data->task = gth_async_task_new (NULL, NULL, NULL, NULL, NULL); gth_task_set_cancellable (scale_data->task, cancellable); return scale_data; }
static cairo_surface_t * clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface) { cairo_t *cr; cairo_surface_t *similar; similar = cairo_surface_create_similar (target, cairo_surface_get_content (surface), cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface)); cr = cairo_create (similar); cairo_surface_destroy (similar); cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); similar = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); return similar; }
static cairo_surface_t * pixbuf_to_cairo_surface (GdkPixbuf *pixbuf) { cairo_surface_t *dummy_surface; cairo_pattern_t *pattern; cairo_surface_t *surface; cairo_t *cr; dummy_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); cr = cairo_create (dummy_surface); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); pattern = cairo_get_source (cr); cairo_pattern_get_surface (pattern, &surface); cairo_surface_reference (surface); cairo_destroy (cr); cairo_surface_destroy (dummy_surface); return surface; }
static cairo_status_t radeon_surface_acquire_source_image (void *abstract_surface, cairo_image_surface_t **image_out, void **image_extra) { radeon_surface_t *surface = abstract_surface; cairo_surface_t *image; cairo_status_t status; /* XXX batch flush */ if (surface->base.fallback != NULL) { image = surface->base.fallback; goto DONE; } image = _cairo_surface_has_snapshot (&surface->base.base, &_cairo_image_surface_backend); if (image != NULL) goto DONE; if (surface->base.base.backend->flush != NULL) { status = surface->base.base.backend->flush (surface); if (unlikely (status)) return status; } image = radeon_bo_get_image (to_radeon_device (surface->base.base.device), to_radeon_bo (surface->base.bo), &surface->base); status = image->status; if (unlikely (status)) return status; _cairo_surface_attach_snapshot (&surface->base.base, image, cairo_surface_destroy); DONE: *image_out = (cairo_image_surface_t *) cairo_surface_reference (image); *image_extra = NULL; return CAIRO_STATUS_SUCCESS; }
GpStatus gdip_texture_clone (GpBrush *brush, GpBrush **clonedBrush) { GpTexture *result; GpTexture *texture; GpStatus status; if (!brush || !clonedBrush) return InvalidParameter; result = gdip_texture_new (); if (!result) return OutOfMemory; texture = (GpTexture *) brush; result->base = texture->base; result->wrapMode = texture->wrapMode; /* Let the clone create its own pattern. */ result->pattern = NULL; result->base.changed = TRUE; gdip_cairo_matrix_copy (&result->matrix, &texture->matrix); result->rectangle.X = texture->rectangle.X; result->rectangle.Y = texture->rectangle.Y; result->rectangle.Width = texture->rectangle.Width; result->rectangle.Height = texture->rectangle.Height; result->image = NULL; status = GdipCloneImage (texture->image, &result->image); if (status != Ok) { GdipDeleteBrush ((GpBrush *) result); *clonedBrush = NULL; return status; } else { cairo_surface_reference (result->image->surface); } *clonedBrush = (GpBrush *) result; return status; }
static void cairogen_end_page(GVJ_t * job) { cairo_t *cr = (cairo_t *) job->context; cairo_surface_t *surface; cairo_status_t status; switch (job->render.id) { #ifdef CAIRO_HAS_PNG_FUNCTIONS case FORMAT_PNG: surface = cairo_get_target(cr); cairo_surface_write_to_png_stream(surface, writer, job); break; #endif case FORMAT_PS: case FORMAT_PDF: case FORMAT_SVG: cairo_show_page(cr); surface = cairo_surface_reference(cairo_get_target(cr)); cairo_surface_finish(surface); status = cairo_surface_status(surface); cairo_surface_destroy(surface); if (status != CAIRO_STATUS_SUCCESS) fprintf(stderr, "cairo: %s\n", cairo_status_to_string(status)); break; case FORMAT_CAIRO: default: surface = cairo_get_target(cr); if (cairo_image_surface_get_width(surface) == 0 || cairo_image_surface_get_height(surface) == 0) { /* apparently cairo never allocates a surface if nothing was ever written to it */ /* but suppress this error message since a zero area surface seems to happen during normal operations, particular in -Tx11 fprintf(stderr, "ERROR: cairo surface has zero area, this may indicate some problem during rendering shapes.\n"); - jce */ } job->imagedata = (char *)(cairo_image_surface_get_data(surface)); break; /* formatting will be done by gvdevice_format() */ } }
static cairo_status_t _cairo_skia_surface_clone_similar (void *asurface, cairo_surface_t *src, cairo_content_t content, int src_x, int src_y, int width, int height, int *clone_offset_x, int *clone_offset_y, cairo_surface_t **clone_out) { if (src->type == CAIRO_SURFACE_TYPE_SKIA || _cairo_surface_is_image (src)) { *clone_offset_x = 0; *clone_offset_y = 0; *clone_out = cairo_surface_reference (src); return CAIRO_STATUS_SUCCESS; } return (cairo_status_t) CAIRO_INT_STATUS_UNSUPPORTED; }
static cairo_surface_t * create_mask (cairo_t *dst, int width, int height) { cairo_surface_t *mask; cairo_t *cr; mask = cairo_surface_create_similar (cairo_get_target (dst), CAIRO_CONTENT_ALPHA, width, height); cr = cairo_create (mask); cairo_surface_destroy (mask); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_rectangle (cr, width/4, height/4, width/2, height/2); cairo_fill (cr); mask = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); return mask; }
cairo_surface_t * _cairo_analysis_surface_create (cairo_surface_t *target) { cairo_analysis_surface_t *surface; cairo_status_t status; status = target->status; if (unlikely (status)) return _cairo_surface_create_in_error (status); surface = malloc (sizeof (cairo_analysis_surface_t)); if (unlikely (surface == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); /* I believe the content type here is truly arbitrary. I'm quite * sure nothing will ever use this value. */ _cairo_surface_init (&surface->base, &cairo_analysis_surface_backend, NULL, /* device */ CAIRO_CONTENT_COLOR_ALPHA, target->is_vector); cairo_matrix_init_identity (&surface->ctm); surface->has_ctm = FALSE; surface->target = cairo_surface_reference (target); surface->first_op = TRUE; surface->has_supported = FALSE; surface->has_unsupported = FALSE; _cairo_region_init (&surface->supported_region); _cairo_region_init (&surface->fallback_region); surface->page_bbox.p1.x = 0; surface->page_bbox.p1.y = 0; surface->page_bbox.p2.x = 0; surface->page_bbox.p2.y = 0; return &surface->base; }
static cairo_surface_t* cairo_loadimage(GVJ_t * job, usershape_t *us) { cairo_surface_t *surface = NULL; /* source surface */ assert(job); assert(us); assert(us->name); assert(us->name[0]); if (us->data) { if (us->datafree == cairo_freeimage) surface = (cairo_surface_t*)(us->data); /* use cached data */ else { us->datafree(us); /* free incompatible cache data */ us->datafree = NULL; us->data = NULL; } } if (!surface) { /* read file into cache */ if (!gvusershape_file_access(us)) return NULL; assert(us->f); switch (us->type) { #ifdef CAIRO_HAS_PNG_FUNCTIONS case FT_PNG: surface = cairo_image_surface_create_from_png_stream(reader, us->f); cairo_surface_reference(surface); break; #endif default: surface = NULL; } if (surface) { us->data = (void*)surface; us->datafree = cairo_freeimage; } gvusershape_file_release(us); } return surface; }
static void testGetFavicon(FaviconDatabaseTest* test) { // We need to load the page first to ensure the icon data will be // in the database in case there's an associated favicon. test->loadURI(kServer->getURIForPath("/foo").data()); test->waitUntilFaviconChanged(); CString faviconURI = kServer->getURIForPath("/icon/favicon.ico"); // Check the API retrieving a valid favicon. test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/foo").data()); g_assert(test->m_favicon); g_assert_cmpstr(test->m_faviconURI.data(), ==, faviconURI.data()); g_assert(!test->m_error); // Check that width and height match those from blank.ico (16x16 favicon). g_assert_cmpint(cairo_image_surface_get_width(test->m_favicon), ==, 16); g_assert_cmpint(cairo_image_surface_get_height(test->m_favicon), ==, 16); // Check that another page with the same favicon return the same icon. cairo_surface_t* favicon = cairo_surface_reference(test->m_favicon); test->loadURI(kServer->getURIForPath("/bar").data()); // It's a new page in the database, so favicon will change twice, first to reset it // and then when the icon is loaded. test->waitUntilFaviconChanged(); test->waitUntilFaviconChanged(); test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/bar").data()); g_assert(test->m_favicon); g_assert_cmpstr(test->m_faviconURI.data(), ==, faviconURI.data()); g_assert(test->m_favicon == favicon); g_assert(!test->m_error); cairo_surface_destroy(favicon); // Check the API retrieving an invalid favicon. test->loadURI(kServer->getURIForPath("/nofavicon").data()); test->waitUntilFaviconChanged(); test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/nofavicon").data()); g_assert(!test->m_favicon); g_assert(test->m_error); }
static cairo_status_t _cairo_image_surface_clone_similar (void *abstract_surface, cairo_surface_t *src, int src_x, int src_y, int width, int height, int *clone_offset_x, int *clone_offset_y, cairo_surface_t **clone_out) { cairo_image_surface_t *surface = abstract_surface; if (src->backend == surface->base.backend) { *clone_offset_x = *clone_offset_y = 0; *clone_out = cairo_surface_reference (src); return CAIRO_STATUS_SUCCESS; } return CAIRO_INT_STATUS_UNSUPPORTED; }
LsmFilterSurface * lsm_filter_surface_new_with_content (const char *name, unsigned int x0, unsigned int y0, cairo_surface_t *surface) { LsmFilterSurface *filter_surface; g_return_val_if_fail (surface != NULL, NULL); g_return_val_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE, NULL); g_return_val_if_fail (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32, NULL); cairo_surface_reference (surface); filter_surface = g_new (LsmFilterSurface, 1); filter_surface->name = g_strdup (name); filter_surface->x0 = x0; filter_surface->y0 = y0; filter_surface->x1 = x0 + cairo_image_surface_get_width (surface); filter_surface->y1 = y0 + cairo_image_surface_get_height (surface); filter_surface->surface = surface; filter_surface->ref_count = 1; return filter_surface; }
static cairo_status_t _cairo_recording_surface_acquire_source_image (void *abstract_surface, cairo_image_surface_t **image_out, void **image_extra) { cairo_status_t status; cairo_recording_surface_t *surface = abstract_surface; cairo_surface_t *image; image = _cairo_surface_has_snapshot (&surface->base, &_cairo_image_surface_backend); if (image != NULL) { *image_out = (cairo_image_surface_t *) cairo_surface_reference (image); *image_extra = NULL; return CAIRO_STATUS_SUCCESS; } image = _cairo_image_surface_create_with_content (surface->content, surface->extents.width, surface->extents.height); if (unlikely (image->status)) return image->status; cairo_surface_set_device_offset (image, -surface->extents.x, -surface->extents.y); status = _cairo_recording_surface_replay (&surface->base, image); if (unlikely (status)) { cairo_surface_destroy (image); return status; } _cairo_surface_attach_snapshot (&surface->base, image, NULL); *image_out = (cairo_image_surface_t *) image; *image_extra = NULL; return CAIRO_STATUS_SUCCESS; }
cairo_surface_t * _rescaleTo(cairo_surface_t * surf, double width, double height) { cairo_surface_t * dest; #if 0 dest = cairo_surface_create_similar(surf, CAIRO_CONTENT_COLOR_ALPHA, width, height); UT_ASSERT(CAIRO_SURFACE_TYPE_IMAGE == cairo_surface_get_type(surf)); double ow = cairo_image_surface_get_width(surf); double oh = cairo_image_surface_get_height(surf); cairo_t *cr = cairo_create(dest); cairo_set_source_surface(cr, dest, 0, 0); cairo_scale(cr, width/ow, height/oh); cairo_paint(cr); cairo_destroy(cr); #else // NO-OP as this do not work. cairo_surface_reference(surf); dest = surf; #endif return dest; }
static cairo_surface_t * gdk_quartz_ref_cairo_surface (GdkDrawable *drawable) { GdkDrawableImplQuartz *impl = GDK_DRAWABLE_IMPL_QUARTZ (drawable); if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable) && GDK_WINDOW_DESTROYED (impl->wrapper)) return NULL; if (!impl->cairo_surface) { int width, height; gdk_drawable_get_size (drawable, &width, &height); impl->cairo_surface = _gdk_windowing_create_cairo_surface (drawable, width, height); } else cairo_surface_reference (impl->cairo_surface); return impl->cairo_surface; }
static void update_image_surface (GthImageRotator *self) { GtkAllocation allocation; cairo_surface_t *image; int max_size; int width; int height; cairo_surface_t *preview_image; if (self->priv->preview_image != NULL) { cairo_surface_destroy (self->priv->preview_image); self->priv->preview_image = NULL; } image = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (self->priv->viewer)); if (image == NULL) return; self->priv->original_width = cairo_image_surface_get_width (image); self->priv->original_height = cairo_image_surface_get_height (image); width = self->priv->original_width; height = self->priv->original_height; gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation); max_size = MAX (allocation.width, allocation.height) / G_SQRT2 + 2; if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE)) preview_image = _cairo_image_surface_scale_bilinear (image, width, height); else preview_image = cairo_surface_reference (image); self->priv->preview_zoom = (double) width / self->priv->original_width; self->priv->preview_image = preview_image; self->priv->preview_image_area.width = width; self->priv->preview_image_area.height = height; self->priv->preview_image_area.x = MAX ((allocation.width - self->priv->preview_image_area.width) / 2 - 0.5, 0); self->priv->preview_image_area.y = MAX ((allocation.height - self->priv->preview_image_area.height) / 2 - 0.5, 0); _gth_image_rotator_update_tranformation_matrix (self); }
static cairo_status_t _cairo_xcb_surface_clone_similar (void *abstract_surface, cairo_surface_t *src, cairo_surface_t **clone_out) { cairo_xcb_surface_t *surface = abstract_surface; cairo_xcb_surface_t *clone; if (src->backend == surface->base.backend ) { cairo_xcb_surface_t *xcb_src = (cairo_xcb_surface_t *)src; if (_cairo_xcb_surface_same_screen(surface, xcb_src)) { *clone_out = cairo_surface_reference (src); return CAIRO_STATUS_SUCCESS; } } else if (_cairo_surface_is_image (src)) { cairo_image_surface_t *image_src = (cairo_image_surface_t *)src; cairo_content_t content = _cairo_content_from_format (image_src->format); if (surface->base.status) return surface->base.status; clone = (cairo_xcb_surface_t *) _cairo_xcb_surface_create_similar (surface, content, image_src->width, image_src->height); if (clone->base.status) return CAIRO_STATUS_NO_MEMORY; _draw_image_surface (clone, image_src, 0, 0); *clone_out = &clone->base; return CAIRO_STATUS_SUCCESS; } return CAIRO_INT_STATUS_UNSUPPORTED; }
static void gth_file_tool_adjust_contrast_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; cairo_surface_t *image; AdjustContrastData *adjust_contrast_data; GthTask *task; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); image = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (viewer)); if (image == NULL) return; adjust_contrast_data = g_new0 (AdjustContrastData, 1); adjust_contrast_data->viewer_page = g_object_ref (viewer_page); adjust_contrast_data->source = cairo_surface_reference (image); adjust_contrast_data->lowest = NULL; adjust_contrast_data->highest = NULL; adjust_contrast_data->factor = NULL; task = gth_image_task_new (_("Applying changes"), NULL, adjust_contrast_exec, adjust_contrast_after, adjust_contrast_data, adjust_contrast_data_free); g_signal_connect (task, "completed", G_CALLBACK (image_task_completed_cb), base); gth_browser_exec_task (GTH_BROWSER (window), task, FALSE); }