Tiled rendering produce different results with image surface
Taekyun Kim <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
Hi all, When I draw something into a memory buffer with several vertically tiled image surfaces, it does not produce the same result with drawing through one big image surface. You can see the difference using image diff tools. Please check the attached file. -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo
tile.c
(text/x-csrc, 1.6 KB)
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#define WIDTH 40
#define HEIGHT 40
#define NUM_TILES 2
void draw (cairo_t *cr)
{
cairo_set_source_rgba (cr, 1, 1, 1, 1);
cairo_paint (cr);
cairo_set_source_rgba (cr, 1, 0, 0, 1);
cairo_set_line_width (cr, 10);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, WIDTH, HEIGHT);
cairo_stroke (cr);
}
int main ()
{
unsigned char *buffer;
cairo_surface_t *surface;
cairo_t *cr;
int i;
int tile_height;
buffer = malloc (WIDTH * 4 * HEIGHT);
memset (buffer, 0x00, WIDTH * 4 * HEIGHT);
surface = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_ARGB32,
WIDTH, HEIGHT, WIDTH * 4);
cr = cairo_create (surface);
draw (cr);
cairo_destroy (cr);
cairo_surface_flush (surface);
cairo_surface_write_to_png (surface, "non_tiled_result.png");
tile_height = HEIGHT / NUM_TILES;
memset (buffer, 0x00, WIDTH * 4 * HEIGHT);
for (i = 0; i < NUM_TILES; i++)
{
int height;
cairo_surface_t *tile_surface;
if (i == NUM_TILES - 1)
height = HEIGHT - i * tile_height;
else
height = tile_height;
tile_surface = cairo_image_surface_create_for_data (buffer + WIDTH * 4 * tile_height * i,
CAIRO_FORMAT_ARGB32,
WIDTH, height, WIDTH * 4);
cr = cairo_create (tile_surface);
cairo_translate (cr, 0, -i * tile_height);
draw (cr);
cairo_destroy (cr);
cairo_surface_destroy (tile_surface);
}
cairo_surface_write_to_png (surface, "tiled_result.png");
cairo_surface_destroy (surface);
return 0;
}