diff --git a/ChangeLog b/ChangeLog index 1138038d2..abfb86a34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2005-05-03 Carl Worth + + Originally 2005-04-20 Carl Worth + + * src/cairo.h: + * src/cairo.c: Remove cairo_show_surface. Add new + cairo_set_source_surface. + + * src/cairo-gstate.c: Remove _cairo_gstate_show_surface. + + * test/create-for-png.c: (draw): + * test/pixman-rotate.c: (draw): + * test/move-to-show-surface.c: (draw): + * test/translate-show-surface.c: (draw): Replace calls to + cairo_show_surface with cairo_set_source_surface; cairo_paint. + + * test/cairo-test.c: (cairo_test_real): Fix messages to prefer - + over _. + + * src/cairo-png.c: (cairo_surface_write_to_png): Fix + documentation. + + * test/filter-nearest-offset-ref.png: + * test/filter-nearest-offset.c: + * test/scale-source-surface-paint-ref.png: + * test/scale-source-surface-paint.c: + * test/source-surface-scale-paint-ref.png: + * test/source-surface-scale-paint.c: Three new tests to exercise + set_source_surface more completely, (two of these are expected + failures dues to outstanding bugs). + 2005-05-03 Carl Worth * TODO: Add suggestion for copy-on-write regions to fix clip diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index 017b41d24..e0304a722 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -393,7 +393,7 @@ _cairo_gstate_get_target_surface (cairo_gstate_t *gstate) } cairo_status_t -_cairo_gstate_set_source (cairo_gstate_t *gstate, +_cairo_gstate_set_source (cairo_gstate_t *gstate, cairo_pattern_t *source) { if (source == NULL) @@ -1693,192 +1693,6 @@ _cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path) return CAIRO_STATUS_SUCCESS; } -cairo_status_t -_cairo_gstate_show_surface (cairo_gstate_t *gstate, - cairo_surface_t *surface, - double x, - double y, - double width, - double height) -{ - - /* We are dealing with 6 coordinate spaces in this function. this makes - * it ugly. - * - * - "Image" space is the space of the surface we're reading pixels from. - * it is the surface argument to this function. The surface has a - * matrix attached to it which maps "user" space (see below) into - * image space. - * - * - "Device" space is the space of the surface we're ultimately writing - * pixels to. It is the current surface of the gstate argument to - * this function. - * - * - "User" space is an arbitrary space defined by the user, defined - * implicitly by the gstate's CTM. The CTM maps from user space to - * device space. The CTM inverse (which is also kept at all times) - * maps from device space to user space. - * - * - "Clip" space is the space of the surface being used to clip pixels - * during compositing. Space-wise, it is a bounding box (offset+size) - * within device space. This surface is usually smaller than the device - * surface (and possibly the image surface too) and logically occupies - * a bounding box around the "clip path", situated somewhere in device - * space. The clip path is already painted on the clip surface. - * - * - "Intermediate" space is the subset of the Clip space that the - * drawing will affect, and we allocate an intermediate surface - * of this size so that we can paint in it. - * - * - "Pattern" space is another arbitrary space defined in the pattern - * element of gstate. As pixels are read from image space, they are - * combined with pixels being read from pattern space and pixels - * already existing in device space. User coordinates are converted - * to pattern space, similarly, using a matrix attached to the pattern. - * (in fact, there is a 7th space in here, which is the space of the - * surface acting as a source for the pattern) - * - * To composite these spaces, we temporarily change the image surface - * so that it can be read and written in device coordinates; in a sense - * this makes it "spatially compatible" with the clip and device spaces. - * - * - * There is also some confusion about the interaction between a clip and - * a pattern; it is assumed that in this "show surface" operation a pattern - * is to be used as an auxiliary alpha mask. this might be wrong, but it's - * what we're doing now. - * - * so, to follow the operations below, remember that in the compositing - * model, each operation is always of the form ((src IN mask) OP dst). - * that's the basic operation. - * - * so the compositing we are trying to do here, in general, involves 2 - * steps, going via a temporary surface: - * - * - combining clip and pattern pixels together into a mask channel. - * this will be ((pattern IN clip) SRC temporary). it ignores the - * pixels already in the temporary, overwriting it with the - * pattern, clipped to the clip mask. - * - * - combining temporary and "image" pixels with "device" pixels, - * with a user-provided porter/duff operator. this will be - * ((image IN temporary) OP device). - * - * if there is no clip, the degenerate case is just the second step - * with pattern standing in for temporary. - * - */ - - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_matrix_t image_to_user, image_to_device, image_to_backend; - double backend_x, backend_y; - double backend_width, backend_height; - cairo_surface_pattern_t pattern; - cairo_box_t pattern_extents; - cairo_rectangle_t extents; - double origin_x, origin_y; - int src_x, src_y; - - cairo_surface_get_matrix (surface, &image_to_user); - cairo_matrix_invert (&image_to_user); - cairo_matrix_multiply (&image_to_device, &image_to_user, &gstate->ctm); - if (gstate->surface) { - cairo_matrix_t device_to_backend; - - cairo_matrix_init_translate (&device_to_backend, - gstate->surface->device_x_offset, - gstate->surface->device_y_offset); - cairo_matrix_multiply (&image_to_backend, &image_to_device, &device_to_backend); - } else { - image_to_backend = image_to_device; - } - - backend_x = x; - backend_y = y; - backend_width = width; - backend_height = height; - _cairo_matrix_transform_bounding_box (&image_to_backend, - &backend_x, &backend_y, - &backend_width, &backend_height); - - _cairo_pattern_init_for_surface (&pattern, surface); - - /* inherit surface attributes while surface attribute functions still - exist */ - pattern.base.matrix = surface->matrix; - pattern.base.filter = surface->filter; - if (surface->repeat) - pattern.base.extend = CAIRO_EXTEND_REPEAT; - else - pattern.base.extend = CAIRO_EXTEND_NONE; - - _cairo_gstate_pattern_transform (gstate, &pattern.base); - - pattern_extents.p1.x = _cairo_fixed_from_double (backend_x); - pattern_extents.p1.y = _cairo_fixed_from_double (backend_y); - pattern_extents.p2.x = _cairo_fixed_from_double (backend_x + backend_width); - pattern_extents.p2.y = _cairo_fixed_from_double (backend_y + backend_height); - _cairo_box_round_to_rectangle (&pattern_extents, &extents); - - /* XXX: This offset here isn't very clean, and it isn't even doing - * a perfect job, (there are some rounding issues with - * cairo_show_surface under the influence of cairo_scale). But it - * does address the bug demonstrated in test/translate-show-surface. - * And, this whole cairo_show_surface thing is going to be - * disappearing soon anyway. */ - origin_x = origin_y = 0.0; - _cairo_gstate_user_to_device (gstate, &origin_x, &origin_y); - src_x = (int) (origin_x + 0.5); - src_y = (int) (origin_y + 0.5); - - if (gstate->clip.surface) - { - _cairo_rectangle_intersect (&extents, &gstate->clip.rect); - - /* We only need to composite if the rectangle is not empty. */ - if (!_cairo_rectangle_empty (&extents)) { - cairo_surface_pattern_t clip_pattern; - - _cairo_pattern_init_for_surface (&clip_pattern, - gstate->clip.surface); - - status = _cairo_surface_composite (gstate->operator, - &pattern.base, - &clip_pattern.base, - gstate->surface, - src_x, src_y, - 0, 0, - extents.x, extents.y, - extents.width, extents.height); - - _cairo_pattern_fini (&clip_pattern.base); - } - } - else - { - /* XXX: The rendered size is sometimes 1 or 2 pixels short - * from what I expect. Need to fix this. - * KRH: I'm guessing this was due to rounding error when - * passing double coordinates for integer arguments. Using - * the extents rectangle should fix this, since it's properly - * rounded. Is this still the case? - */ - status = _cairo_surface_composite (gstate->operator, - &pattern.base, - NULL, - gstate->surface, - src_x, src_y, - 0, 0, - extents.x, extents.y, - extents.width, extents.height); - - } - - _cairo_pattern_fini (&pattern.base); - - return status; -} - static void _cairo_gstate_unset_font (cairo_gstate_t *gstate) { diff --git a/src/cairo-png.c b/src/cairo-png.c index 97310497f..8d1c44454 100644 --- a/src/cairo-png.c +++ b/src/cairo-png.c @@ -189,14 +189,15 @@ stdio_write_func (png_structp png, png_bytep data, png_size_t size) * @surface: a #cairo_surface_t with pixel contents * @filename: the name of a file to write to * - * Writes the image surface to the given #FILE pointer. The file - * should be opened in write mode and binary mode if applicable. + * Writes the contents of @surface to a new file @filename as a PNG + * image. * * Return value: CAIRO_STATUS_SUCCESS if the PNG file was written - * successfully. Otherwise, CAIRO_STATUS_NO_MEMORY is returned if - * memory could not be allocated for the operation, + * successfully. Otherwise, CAIRO_STATUS_NO_MEMORY if memory could not + * be allocated for the operation or * CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have - * pixel contents. + * pixel contents, or CAIRO_STATUS_WRITE_ERROR if an I/O error occurs + * while attempting to write the file. **/ cairo_status_t cairo_surface_write_to_png (cairo_surface_t *surface, diff --git a/src/cairo.c b/src/cairo.c index 301f3246e..5bda4124d 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -749,6 +749,34 @@ cairo_set_source_rgba (cairo_t *cr, } DEPRECATE(cairo_set_rgb_color, cairo_set_source_rgb); +void +cairo_set_source_surface (cairo_t *cr, + cairo_surface_t *surface, + double x, + double y) +{ + cairo_pattern_t *pattern; + cairo_matrix_t matrix; + + CAIRO_CHECK_SANITY (cr); + if (cr->status) + return; + + pattern = cairo_pattern_create_for_surface (surface); + if (!pattern) { + cr->status = CAIRO_STATUS_NO_MEMORY; + return; + } + + cairo_matrix_init_translate (&matrix, -x, -y); + cairo_pattern_set_matrix (pattern, &matrix); + + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + CAIRO_CHECK_SANITY (cr); +} + /** * cairo_set_source * @cr: a cairo context @@ -2181,27 +2209,6 @@ cairo_glyph_path (cairo_t *cr, cairo_glyph_t *glyphs, int num_glyphs) CAIRO_CHECK_SANITY (cr); } -void -cairo_show_surface (cairo_t *cr, - cairo_surface_t *surface, - int width, - int height) -{ - double x, y; - - CAIRO_CHECK_SANITY (cr); - if (cr->status) - return; - - cairo_get_current_point (cr, &x, &y); - - cr->status = _cairo_gstate_show_surface (cr->gstate, - surface, - x, y, - width, height); - CAIRO_CHECK_SANITY (cr); -} - /** * cairo_get_operator: * @cr: a cairo context diff --git a/src/cairo.h b/src/cairo.h index 229a1dcdc..654e6d220 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -300,11 +300,6 @@ cairo_set_operator (cairo_t *cr, cairo_operator_t op); void cairo_set_source (cairo_t *cr, cairo_pattern_t *source); -/* XXX: NYI: -void -cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface); -*/ - void cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue); @@ -313,6 +308,12 @@ cairo_set_source_rgba (cairo_t *cr, double red, double green, double blue, double alpha); +void +cairo_set_source_surface (cairo_t *cr, + cairo_surface_t *surface, + double x, + double y); + /* XXX: Currently, the tolerance value is specified by the user in terms of device-space units. If I'm not mistaken, this is the only value in this API that is not expressed in user-space units. I @@ -788,15 +789,6 @@ cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, int num_glyphs, cairo_text_extents_t *extents); -/* Image functions */ - -/* XXX: Eliminate width/height here */ -void -cairo_show_surface (cairo_t *cr, - cairo_surface_t *surface, - int width, - int height); - /* Query functions */ /* XXX: It would be nice if I could find a simpler way to make the diff --git a/test/.cvsignore b/test/.cvsignore index 5c3fde5a4..1e41ef424 100644 --- a/test/.cvsignore +++ b/test/.cvsignore @@ -2,25 +2,33 @@ .libs Makefile Makefile.in +clip-nesting clip-twice coverage create-for-png fill-and-stroke fill-rule +filter-nearest-offset get-and-set gradient-alpha imagediff leaky-polygon line-width linear-gradient +mask move-to-show-surface paint path-data pdf-surface pdf-surface.pdf pixman-rotate -set-source +rel-path +scale-source-surface-paint select-font-no-show-text +self-copy +set-source +source-clip +source-surface-scale-paint surface-finish-twice surface-pattern text-cache-crash diff --git a/test/Makefile.am b/test/Makefile.am index b1a90290c..699965fc4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,64 +1,69 @@ # All test cases go here -TESTS = \ -clip-twice \ -clip-nesting \ -coverage \ -create-for-png \ -fill-and-stroke \ -fill-rule \ -get-and-set \ -gradient-alpha \ -leaky-polygon \ -line-width \ -linear-gradient \ -mask \ -move-to-show-surface \ -paint \ -path-data \ -pdf-surface \ -pixman-rotate \ -select-font-no-show-text\ -self-copy \ -set-source \ -source-clip \ -surface-finish-twice \ -surface-pattern \ -text-cache-crash \ -text-rotate \ -transforms \ -translate-show-surface \ -trap-clip \ -user-data \ +TESTS = \ +clip-nesting \ +clip-twice \ +coverage \ +create-for-png \ +fill-and-stroke \ +fill-rule \ +filter-nearest-offset \ +get-and-set \ +gradient-alpha \ +leaky-polygon \ +line-width \ +linear-gradient \ +mask \ +move-to-show-surface \ +paint \ +path-data \ +pdf-surface \ +pixman-rotate \ +scale-source-surface-paint \ +select-font-no-show-text \ +self-copy \ +set-source \ +source-clip \ +source-surface-scale-paint \ +surface-finish-twice \ +surface-pattern \ +text-cache-crash \ +text-rotate \ +transforms \ +translate-show-surface \ +trap-clip \ +user-data \ rel-path # All tests which have a reference image go here. # I really don't like having to repeat this list. Anyone know a good # way to avoid it? Can I use a wildcard here? -EXTRA_DIST = \ -clip-nesting-ref.png \ -create-for-png-ref.png \ -fill-and-stroke-ref.png \ -fill-rule-ref.png \ -gradient-alpha-ref.png \ -leaky-polygon-ref.png \ -line-width-ref.png \ -linear-gradient-ref.png \ -mask-ref.png \ -move-to-show-surface-ref.png \ -coverage-ref.png \ -clip-twice-ref.png \ -mask-ref.png \ -paint-ref.png \ -path-data-ref.png \ -pixman-rotate-ref.png \ -romedalen.png \ -self-copy-ref.png \ -set-source-ref.png \ -source-clip-ref.png \ -surface-pattern-ref.png \ -transforms-ref.png \ -translate-show-surface-ref.png \ -trap-clip-ref.png \ +EXTRA_DIST = \ +clip-nesting-ref.png \ +clip-twice-ref.png \ +coverage-ref.png \ +create-for-png-ref.png \ +fill-and-stroke-ref.png \ +fill-rule-ref.png \ +filter-nearest-offset-ref.png \ +gradient-alpha-ref.png \ +leaky-polygon-ref.png \ +line-width-ref.png \ +linear-gradient-ref.png \ +mask-ref.png \ +move-to-show-surface-ref.png \ +paint-ref.png \ +path-data-ref.png \ +pixman-rotate-ref.png \ +romedalen.png \ +self-copy-ref.png \ +scale-source-surface-paint-ref.png \ +set-source-ref.png \ +source-clip-ref.png \ +source-surface-scale-paintref.png \ +surface-pattern-ref.png \ +transforms-ref.png \ +translate-show-surface-ref.png \ +trap-clip-ref.png \ rel-path-ref.png # Any test for which the code committed to CVS is expected to fail @@ -74,10 +79,12 @@ rel-path-ref.png # # Also, any test listed here should call cairo_test_expect_failure and # provide an explanation for the expected failure. -XFAIL_TESTS = \ -coverage \ -pixman-rotate \ -self-copy \ +XFAIL_TESTS = \ +coverage \ +filter-nearest-offset \ +pixman-rotate \ +self-copy \ +source-surface-scale-paint \ text-rotate check_PROGRAMS = $(TESTS) @@ -113,6 +120,7 @@ coverage_LDADD = $(LDADDS) create_for_png_LDADD = $(LDADDS) fill_and_stroke_LDADD = $(LDADDS) fill_rule_LDADD = $(LDADDS) +filter_nearest_offset_LDADD = $(LDADDS) get_and_set_LDADD = $(LDADDS) gradient_alpha_LDADD = $(LDADDS) leaky_polygon_LDADD = $(LDADDS) @@ -124,10 +132,12 @@ paint_LDADD = $(LDADDS) path_data_LDADD = $(LDADDS) pdf_surface_LDADD = $(LDADDS) pixman_rotate_LDADD = $(LDADDS) +scale_source_surface_paint_LDADD = $(LDADDS) select_font_no_show_text_LDADD = $(LDADDS) self_copy_LDADD = $(LDADDS) set_source_LDADD = $(LDADDS) source_clip_LDADD = $(LDADDS) +source_surface_scale_paint_LDADD = $(LDADDS) surface_finish_twice_LDADD = $(LDADDS) surface_pattern_LDADD = $(LDADDS) text_cache_crash_LDADD = $(LDADDS) diff --git a/test/cairo-test.c b/test/cairo-test.c index 710e7a2f6..8e7a84742 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -358,7 +358,7 @@ cairo_test_real (cairo_test_t *test, cairo_test_draw_function_t draw) for (i=0; i < sizeof(targets)/sizeof(targets[0]); i++) { cairo_test_target_t *target = &targets[i]; fprintf (stderr, "Testing %s with %s target\n", test->name, target->name); - printf ("%s_%s:\t", test->name, target->name); + printf ("%s-%s:\t", test->name, target->name); status = cairo_test_for_target (test, draw, target); if (status) { printf ("FAIL\n"); diff --git a/test/create-for-png.c b/test/create-for-png.c index 861801501..f77d906c8 100644 --- a/test/create-for-png.c +++ b/test/create-for-png.c @@ -42,7 +42,6 @@ draw (cairo_t *cr, int width, int height) char *srcdir = getenv ("srcdir"); char *filename; cairo_surface_t *surface; - int png_width, png_height; xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", "create-for-png-ref.png"); @@ -55,9 +54,8 @@ draw (cairo_t *cr, int width, int height) return CAIRO_TEST_FAILURE; } - png_width = cairo_image_surface_get_width (surface); - png_height = cairo_image_surface_get_height (surface); - cairo_show_surface (cr, surface, png_width, png_height); + cairo_set_source_surface (cr, surface, 0, 0); + cairo_paint (cr); cairo_surface_destroy (surface); diff --git a/test/create-from-png.c b/test/create-from-png.c index 861801501..f77d906c8 100644 --- a/test/create-from-png.c +++ b/test/create-from-png.c @@ -42,7 +42,6 @@ draw (cairo_t *cr, int width, int height) char *srcdir = getenv ("srcdir"); char *filename; cairo_surface_t *surface; - int png_width, png_height; xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", "create-for-png-ref.png"); @@ -55,9 +54,8 @@ draw (cairo_t *cr, int width, int height) return CAIRO_TEST_FAILURE; } - png_width = cairo_image_surface_get_width (surface); - png_height = cairo_image_surface_get_height (surface); - cairo_show_surface (cr, surface, png_width, png_height); + cairo_set_source_surface (cr, surface, 0, 0); + cairo_paint (cr); cairo_surface_destroy (surface); diff --git a/test/filter-nearest-offset-ref.png b/test/filter-nearest-offset-ref.png new file mode 100644 index 000000000..46092e3c7 Binary files /dev/null and b/test/filter-nearest-offset-ref.png differ diff --git a/test/filter-nearest-offset.c b/test/filter-nearest-offset.c new file mode 100644 index 000000000..74ad47611 --- /dev/null +++ b/test/filter-nearest-offset.c @@ -0,0 +1,107 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth + */ + +#include "cairo-test.h" + +#define STAMP_WIDTH 4 +#define STAMP_HEIGHT 4 +#define PAD 1 + +#define STEPS 10 + +#define IMAGE_WIDTH (PAD + STEPS * (STAMP_WIDTH + PAD) + PAD) +#define IMAGE_HEIGHT (PAD + STEPS * (STAMP_HEIGHT + PAD) + PAD) + +cairo_test_t test = { + "filter-nearest-offset", + "Test sampling offset of CAIRO_FILTER_NEAREST", + IMAGE_WIDTH, IMAGE_HEIGHT +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *surface; + unsigned long 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_ARGB32, + 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_BEST); + cairo_paint (cr); + + cairo_restore (cr); + } + } + + cairo_surface_destroy (surface); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test_expect_failure (&test, draw, + "wrong sampling location for nearest-neighbor filter in libpixman and Render"); +} diff --git a/test/move-to-show-surface.c b/test/move-to-show-surface.c index d90d3edd1..d29b8274d 100644 --- a/test/move-to-show-surface.c +++ b/test/move-to-show-surface.c @@ -64,8 +64,9 @@ draw (cairo_t *cr, int width, int height) for (i=0; i < 4; i++) { surface = cairo_surface_create_for_image ((unsigned char *) &colors[i], CAIRO_FORMAT_ARGB32, 1, 1, 4); - cairo_move_to (cr, i % 2, i / 2); - cairo_show_surface (cr, surface, 1, 1); + cairo_set_source_surface (cr, surface, + i % 2, i / 2); + cairo_paint (cr); cairo_surface_destroy (surface); } diff --git a/test/pixman-rotate.c b/test/pixman-rotate.c index 624bc2f38..e45c5cf23 100644 --- a/test/pixman-rotate.c +++ b/test/pixman-rotate.c @@ -58,7 +58,8 @@ draw (cairo_t *cr, int width, int height) cairo_translate (cr, WIDTH, HEIGHT); #endif - cairo_show_surface (cr, stamp, WIDTH + 2, HEIGHT + 2); + cairo_set_source_surface (cr, stamp, 0, 0); + cairo_paint (cr); cairo_show_page (cr); diff --git a/test/scale-source-surface-paint-ref.png b/test/scale-source-surface-paint-ref.png new file mode 100644 index 000000000..ec3c059fd Binary files /dev/null and b/test/scale-source-surface-paint-ref.png differ diff --git a/test/scale-source-surface-paint.c b/test/scale-source-surface-paint.c new file mode 100644 index 000000000..4b722b418 --- /dev/null +++ b/test/scale-source-surface-paint.c @@ -0,0 +1,65 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth + */ + +#include "cairo-test.h" + +cairo_test_t test = { + "scale-source-surface-paint", + "Test call sequence: cairo_scale; cairo_set_source_surface; cairo_paint", + 12, 12 +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *surface; + unsigned long data[16] = { + 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, + 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, + + 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff, + 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff + }; + int i; + + surface = cairo_image_surface_create_for_data ((unsigned char *) data, + CAIRO_FORMAT_ARGB32, 4, 4, 16); + + cairo_scale (cr, 2, 2); + + cairo_set_source_surface (cr, surface, 1 , 1); + cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); + cairo_paint (cr); + + cairo_surface_destroy (surface); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/source-surface-scale-paint-ref.png b/test/source-surface-scale-paint-ref.png new file mode 100644 index 000000000..ec3c059fd Binary files /dev/null and b/test/source-surface-scale-paint-ref.png differ diff --git a/test/source-surface-scale-paint.c b/test/source-surface-scale-paint.c new file mode 100644 index 000000000..1bf769d28 --- /dev/null +++ b/test/source-surface-scale-paint.c @@ -0,0 +1,65 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth + */ + +#include "cairo-test.h" + +cairo_test_t test = { + "source-surface-scale-paint", + "Test call sequence: cairo_set_source_surface; cairo_scale; cairo_paint", + 12, 12 +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *surface; + unsigned long data[16] = { + 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, + 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000, + + 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff, + 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff + }; + int i; + + surface = cairo_image_surface_create_for_data ((unsigned char *) data, + CAIRO_FORMAT_ARGB32, 4, 4, 16); + + cairo_set_source_surface (cr, surface, 2, 2); + cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); + cairo_scale (cr, 2, 2); + cairo_paint (cr); + + cairo_surface_destroy (surface); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test_expect_failure (&test, draw, + "cairo_set_source needs user space locking semantics"); +} diff --git a/test/translate-show-surface.c b/test/translate-show-surface.c index f0c39037c..57700fc16 100644 --- a/test/translate-show-surface.c +++ b/test/translate-show-surface.c @@ -65,7 +65,8 @@ draw (cairo_t *cr, int width, int height) cairo_save (cr); { cairo_translate (cr, i % 2, i / 2); - cairo_show_surface (cr, surface, 1, 1); + cairo_set_source_surface (cr, surface, 0, 0); + cairo_paint (cr); } cairo_restore (cr); cairo_surface_destroy (surface);