Details

[Home]

Issue of the Implementation # S0654

Brief

The gdk_pixbuf_composite_color function uses wrong checkboard offset

Detailed Description

From the description of gdk_pixbuf_composite_color:
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then composites the rectangle (dest_x ,dest_y, dest_width, dest_height) of the resulting image with a checkboard of the colors color1 and color2 and renders it onto the destination image.

There is also a note about the origin of the checkboard in the description of check_x parameter:
origin of checkboard is at -check_x, -check_y

However gdk_pixbuf_composite_color is implemented so, that the checkboard is shifted by dest_x and dest_y before composition with the source image. So the actual position of the checkboard's origin is (dest_x-check_x, dest_y-check_y) when composition is performed.

The example below demonstrates the contradiction between implementation and documentation.

Problem location(s) in the standard

Gdk-pixbuf 2.6.2 API Reference, Scaling

Example

#include <stdio.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

#define FILENAME_1 "checkboard.ico"
#define FILENAME_2 "result.ico"
const int width = 100, height = 100;
const int dest_x = 8, dest_y = 8;
int main()
{
    g_type_init();
    //because overall_alpha will be 0, contents of src don't matter.
    GdkPixbuf *src = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
        width, height);
    gdk_pixbuf_fill(src, 0x000000ff); 
    //dest will be completely rewritten during composition, 
    //so its contents don't matter too    
    GdkPixbuf *dest = gdk_pixbuf_copy(src);
    
    gdk_pixbuf_composite_color(src, dest, 0, 0, width, height,
        0, 0, 1.0, 1.0, GDK_INTERP_NEAREST,
        0,
        0, 0, 16, 0xff0000, 0x00ff00);
    //now dest is a simple checkboard with checksize = 16 and origin at (0,0)
    gdk_pixbuf_save(dest, FILENAME_1, "ico", NULL, NULL);
    //perform composition when dest_x and dest_y are not 0 both.
    gdk_pixbuf_composite_color(src, dest, dest_x, dest_y, 
        width - dest_x, height - dest_y,
        0, 0, 1.0, 1.0, GDK_INTERP_NEAREST,
        0,
        0, 0, 16, 0xff0000, 0x00ff00);
    
    gdk_pixbuf_save(dest, FILENAME_2, "ico", NULL, NULL);
    printf("If the origin of the checkboard has not changed,"
        "the destination image should remain the same\n");
    printf("(%s and %s are the same images).\n", 
        FILENAME_1, FILENAME_2);
}

Component

gtk-gdk-pixbuf 2.6.2 or later

Accepted

Gnome Bugzilla 583029

[Home]