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 BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const FloatRect& src, CompositeOperator op) { FloatRect srcRect(src); FloatRect dstRect(dst); if (dstRect.width() == 0.0f || dstRect.height() == 0.0f || srcRect.width() == 0.0f || srcRect.height() == 0.0f) return; startAnimation(); cairo_surface_t* image = frameAtIndex(m_currentFrame); if (!image) // If it's too early we won't have an image yet. return; if (mayFillWithSolidColor()) { fillWithSolidColor(context, dstRect, solidColor(), op); return; } IntSize selfSize = size(); cairo_t* cr = context->platformContext(); cairo_save(cr); // Set the compositing operation. if (op == CompositeSourceOver && !frameHasAlphaAtIndex(m_currentFrame)) context->setCompositeOperation(CompositeCopy); else context->setCompositeOperation(op); // If we're drawing a sub portion of the image or scaling then create // a pattern transformation on the image and draw the transformed pattern. // Test using example site at http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image); // To avoid the unwanted gradient effect (#14017) we use // CAIRO_FILTER_NEAREST now, but the real fix will be to have // CAIRO_EXTEND_PAD implemented for surfaces in Cairo allowing us to still // use bilinear filtering cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST); float scaleX = srcRect.width() / dstRect.width(); float scaleY = srcRect.height() / dstRect.height(); cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, srcRect.x(), srcRect.y() }; cairo_pattern_set_matrix(pattern, &matrix); // Draw the image. cairo_translate(cr, dstRect.x(), dstRect.y()); cairo_set_source(cr, pattern); cairo_pattern_destroy(pattern); cairo_rectangle(cr, 0, 0, dstRect.width(), dstRect.height()); cairo_clip(cr); cairo_paint_with_alpha(cr, context->getAlpha()); cairo_restore(cr); if (imageObserver()) imageObserver()->didDraw(this); }
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_pattern_t * _cairo_film_pattern_create (void) { static cairo_pattern_t *film_pattern = NULL; cairo_pattern_t *pattern; static GMutex mutex; g_mutex_lock (&mutex); if (film_pattern == NULL) { char *filename; cairo_surface_t *surface; filename = g_build_filename (GTHUMB_ICON_DIR, "filmholes.png", NULL); surface = cairo_image_surface_create_from_png (filename); film_pattern = cairo_pattern_create_for_surface (surface); cairo_pattern_set_filter (film_pattern, CAIRO_FILTER_GOOD); cairo_pattern_set_extend (film_pattern, CAIRO_EXTEND_REPEAT); cairo_surface_destroy (surface); g_free (filename); } pattern = cairo_pattern_reference (film_pattern); g_mutex_unlock (&mutex); return pattern; }
cairo_pattern_t * ink_cairo_pattern_create_checkerboard() { int const w = 6; int const h = 6; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2*w, 2*h); cairo_t *ct = cairo_create(s); cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgb(ct, 0.75, 0.75, 0.75); cairo_paint(ct); cairo_set_source_rgb(ct, 0.5, 0.5, 0.5); cairo_rectangle(ct, 0, 0, w, h); cairo_rectangle(ct, w, h, w, h); cairo_fill(ct); cairo_destroy(ct); cairo_pattern_t *p = cairo_pattern_create_for_surface(s); cairo_pattern_set_extend(p, CAIRO_EXTEND_REPEAT); cairo_pattern_set_filter(p, CAIRO_FILTER_NEAREST); cairo_surface_destroy(s); return p; }
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; }
static void render_border (cairo_t *cr, cairo_surface_t *surface, guint side, gdouble x, gdouble y, gdouble width, gdouble height, GtkSliceSideModifier modifier) { cairo_pattern_t *pattern; cairo_matrix_t matrix; cairo_save (cr); cairo_rectangle (cr, x, y, width, height); cairo_clip (cr); pattern = cairo_pattern_create_for_surface (surface); if (modifier == GTK_SLICE_REPEAT) { cairo_matrix_init_translate (&matrix, - x, - y); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source (cr, pattern); cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); } else { /* Use nearest filter so borders aren't blurred */ cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); if (side == SIDE_TOP || side == SIDE_BOTTOM) { gint w = cairo_image_surface_get_width (surface); cairo_translate (cr, x, y); cairo_scale (cr, width / w, 1.0); } else { gint h = cairo_image_surface_get_height (surface); cairo_translate (cr, x, y); cairo_scale (cr, 1.0, height / h); } cairo_set_source (cr, pattern); cairo_rectangle (cr, x, y, width, height); cairo_paint (cr); } cairo_restore (cr); cairo_pattern_destroy (pattern); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_pattern_t *source; int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2); /* Use a gray (neutral) background, so we can spot if the backend pads * with any other colour. */ cairo_set_source_rgb (cr, .5, .5, .5); cairo_paint (cr); cairo_translate(cr, SIZE/2, SIZE/2); cairo_rotate (cr, M_PI / 4.0); cairo_translate (cr, -surface_size/2, -surface_size/2); source = create_image_source (surface_size); cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST); cairo_set_source(cr, source); cairo_pattern_destroy (source); cairo_paint (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 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 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) { cairo_surface_t *source; cairo_pattern_t *pattern; cairo_paint (cr); source = create_source (cairo_get_target (cr), 2560, 1280); pattern = cairo_pattern_create_for_surface (source); cairo_surface_destroy (source); cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE); draw_grid (cr, pattern, 50, 0); draw_grid (cr, pattern, 130, 0); draw_grid (cr, pattern, 210, 0); draw_grid (cr, pattern, 290, 0); draw_grid (cr, pattern, 50, 230); draw_grid (cr, pattern, 130, 230); draw_grid (cr, pattern, 210, 230); draw_grid (cr, pattern, 290, 230); cairo_pattern_destroy (pattern); return CAIRO_TEST_SUCCESS; }
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; }
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 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 VALUE cr_pattern_set_filter (VALUE self, VALUE filter) { cairo_pattern_set_filter (_SELF (self), RVAL2CRFILTER (filter)); cr_pattern_check_status (_SELF (self)); return self; }
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; }
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; }
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 int m_pattern_set_filter(lua_State * L) { struct lpattern_t * pattern = luaL_checkudata(L, 1, MT_PATTERN); cairo_filter_t filter = (cairo_filter_t)luaL_checkinteger(L, 2); cairo_pattern_set_filter(pattern->pattern, filter); lua_pushlightuserdata(L, pattern); luaL_setmetatable(L, MT_PATTERN); return 1; }
/* cairo pattern */ static int lcairo_pattern_set_filter(lua_State *L){ cairo_pattern_t *p=luaT_checkudata(L,1,tPattern_id); /* enum... */ cairo_pattern_set_filter(p, CAIRO_FILTER_NEAREST); lua_settop(L,1); return 1; }
int edit_fac() { int nlu,temwh,i,temet; width = 0; height=0; nbpol =0; temwh = 0; temet = 0; ydeb=0; dy=0; nuli=0; for ( i=0; i < CSFnco; ++i) parlf[i].y = 0; while ( (nlu=lect_fis()) > 0 ) { if ( strncmp(ze, "PAGSUIV",7) == 0) break; if ( ze[0] == '#') { nmot = isolmot(ze,nlu); memopol(); continue; } else if ( ze[0] == '$') { nmot = isolmot(ze,nlu); temet = entete(); continue; } // param lu active cairo if (temwh == 0 && width != 0 && height != 0) { surface = cairo_pdf_surface_create(nomfic, width,height); status = cairo_surface_status(surface); if (!surface || status!=CAIRO_STATUS_SUCCESS) { // printf("erreur cairo fic pdf\n"); message(25); return -1; } cr = cairo_create(surface); if ( temet == 1) { // active en tete cairo_save(cr); //cairo_scale(cr, 1./dpp, 1./dpp); pattern = cairo_pattern_create_for_surface(etsurf); cairo_translate(cr,0,0); cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST); cairo_set_source(cr,pattern); cairo_paint(cr); cairo_restore(cr); } cairo_set_source_rgb(cr, 0, 0, 0); temwh = 1; } if (temwh == 0) continue; // cr,surface non crees // ou erreur ligne avant creation cairo systematique 1er lig windows fic txt nmot = isolmot(ze,nlu); interp(); } // fin boucle lect fgets if (temwh == 0) return -1; // cr, surface non crees for ( i=0; i < CSFnco; ++i) { if (parlf[i].y == 1) { i=-1; break; } // y a-t-il des cde lignes ? } if ( i == -1) implf(); // imprim lignes details cairo_destroy(cr); cairo_surface_destroy(surface); return 0; }
static PyObject * surface_pattern_set_filter (PycairoSurfacePattern *o, PyObject *args) { int filter; if (!PyArg_ParseTuple (args, "i:SurfacePattern.set_filter", &filter)) return NULL; cairo_pattern_set_filter (o->pattern, filter); Py_RETURN_NONE; }
void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& srcRect, GraphicsContext* context) { // If we're drawing a sub portion of the image or scaling then create // a pattern transformation on the image and draw the transformed pattern. // Test using example site at http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(surface)); ASSERT(m_state); switch (m_state->m_imageInterpolationQuality) { case InterpolationNone: case InterpolationLow: cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_FAST); break; case InterpolationMedium: case InterpolationHigh: cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_BILINEAR); break; case InterpolationDefault: cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_BILINEAR); break; } cairo_pattern_set_extend(pattern.get(), CAIRO_EXTEND_PAD); float scaleX = srcRect.width() / destRect.width(); float scaleY = srcRect.height() / destRect.height(); cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, srcRect.x(), srcRect.y() }; cairo_pattern_set_matrix(pattern.get(), &matrix); ShadowBlur& shadow = context->platformContext()->shadowBlur(); if (shadow.type() != ShadowBlur::NoShadow) { if (GraphicsContext* shadowContext = shadow.beginShadowLayer(context, destRect)) { drawPatternToCairoContext(shadowContext->platformContext()->cr(), pattern.get(), destRect, 1); shadow.endShadowLayer(context); } } cairo_save(m_cr.get()); drawPatternToCairoContext(m_cr.get(), pattern.get(), destRect, globalAlpha()); cairo_restore(m_cr.get()); }
void S9xGTKDisplayDriver::output (void *src, int src_pitch, int x, int y, int width, int height, int dst_width, int dst_height) { if (last_known_width != dst_width || last_known_height != dst_height) { clear (); last_known_width = dst_width; last_known_height = dst_height; } cairo_t *cr = window->get_cairo (); cairo_surface_t *surface; surface = cairo_image_surface_create_for_data ((unsigned char *) src, CAIRO_FORMAT_RGB16_565, width, height, src_pitch); cairo_set_source_surface (cr, surface, 0, 0); if (width != dst_width || height != dst_height) { cairo_matrix_t matrix; cairo_pattern_t *pattern = cairo_get_source (cr);; cairo_matrix_init_identity (&matrix); cairo_matrix_scale (&matrix, (double) width / (double) dst_width, (double) height / (double) dst_height); cairo_matrix_translate (&matrix, -x, -y); cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_filter (pattern, Settings.BilinearFilter ? CAIRO_FILTER_BILINEAR : CAIRO_FILTER_NEAREST); } cairo_rectangle (cr, x, y, dst_width, dst_height); cairo_fill (cr); cairo_surface_finish (surface); cairo_surface_destroy (surface); window->release_cairo (); window->set_mouseable_area (x, y, width, height); }
static int ui_set_source_surface(lua_State *L) { struct context *c = lua_touserdata(L, 1); struct window *w = lua_touserdata(L, 2); int filter_nearest = lua_toboolean(L, 3); cairo_set_source_surface(c->cr, w->surface, 0, 0); if (filter_nearest) { cairo_pattern_set_filter (cairo_get_source (c->cr), CAIRO_FILTER_NEAREST); } return 0; }
int renderTileCairo(imageObj *img, imageObj *tile, double x, double y) { cairo_renderer *r = CAIRO_RENDERER(img); cairo_surface_t *im = CAIRO_RENDERER(tile)->surface; int w = cairo_image_surface_get_width (im); int h = cairo_image_surface_get_height (im); cairo_save(r->cr); cairo_translate(r->cr, MS_NINT(x-0.5 * w), MS_NINT(y -0.5 * h)); cairo_set_source_surface(r->cr, im, 0, 0); cairo_pattern_set_filter (cairo_get_source (r->cr), CAIRO_FILTER_NEAREST); cairo_paint(r->cr); cairo_restore(r->cr); return MS_SUCCESS; }
static int m_display_draw_texture(lua_State * L) { struct ldisplay_t * display = luaL_checkudata(L, 1, MT_DISPLAY); struct lobject_t * object = luaL_checkudata(L, 2, MT_OBJECT); struct ltexture_t * texture = luaL_checkudata(L, 3, MT_TEXTURE); cairo_t * cr = display->cr[display->index]; cairo_save(cr); cairo_set_matrix(cr, &object->__transform_matrix); cairo_set_source_surface(cr, texture->surface, 0, 0); cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_FAST); cairo_paint_with_alpha(cr, object->alpha); cairo_restore(cr); return 0; }
void composite_checker (cairo_perf_t *perf, cairo_t *cr, int width, int height) { cairo_surface_t *image; if (! cairo_perf_can_run (perf, "composite-checker")) return; /* Create the checker pattern. We don't actually need to draw * anything on it since that wouldn't affect performance. */ image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, PAT_SIZE, PAT_SIZE); checkerboard = cairo_pattern_create_for_surface (image); cairo_pattern_set_filter (checkerboard, CAIRO_FILTER_NEAREST); cairo_pattern_set_extend (checkerboard, CAIRO_EXTEND_REPEAT); cairo_surface_destroy (image); /* Create the image source pattern. Again we use the NEAREST * filtering which should be fastest. */ image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, SRC_SIZE, SRC_SIZE); src_pattern = cairo_pattern_create_for_surface (image); cairo_pattern_set_filter (src_pattern, CAIRO_FILTER_NEAREST); cairo_surface_destroy (image); cairo_perf_run (perf, "composite-checker", do_composite_checker); cairo_pattern_destroy (checkerboard); cairo_pattern_destroy (src_pattern); }
bool LinearGradient::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const { bool loop=param_loop.get(bool()); Point p1=param_p1.get(Point()); Point p2=param_p2.get(Point()); Gradient gradient=param_gradient.get(Gradient()); cairo_save(cr); cairo_pattern_t* pattern=cairo_pattern_create_linear(p1[0], p1[1], p2[0], p2[1]); bool cpoints_all_opaque=compile_gradient(pattern, gradient); if(loop) cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); if(quality>8) cairo_pattern_set_filter(pattern, CAIRO_FILTER_FAST); else if(quality>=4) cairo_pattern_set_filter(pattern, CAIRO_FILTER_GOOD); else cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST); if( ! (is_solid_color() || (cpoints_all_opaque && get_blend_method()==Color::BLEND_COMPOSITE && get_amount()==1.f)) ) { // Initially render what's behind us if(!context.accelerated_cairorender(cr,quality,renddesc,cb)) { if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Cairo Renderer Failure",__LINE__)); return false; } } cairo_set_source(cr, pattern); cairo_paint_with_alpha_operator(cr, get_amount(), get_blend_method()); cairo_pattern_destroy(pattern); // Not needed more cairo_restore(cr); return true; }