[cairo] Call to cairo_paint triggers an assertion

Tim Corio tcorio at rochester.rr.com
Wed Jan 6 10:46:09 PST 2010


Once again, My Bad.  I forgot to include the current code.


#include <gtk/gtk.h>
#include <logging.h>

#define WIDTH  200
#define HEIGHT 200


static void destroy( GtkWidget *widget,
                     gpointer   data )
{
  gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{
  GtkWidget *window;
  GtkWidget *box_image;

  GdkPixbuf *pxb_orig;
  GdkPixmap *pxm_dest;

  GtkImage  *img_orig;
  GtkImage  *img_dest;

  GError *gerror = NULL;

  cairo_t   *cr = NULL;

  GdkColor blue;
  GdkColor black;
  GdkColor white;

  gtk_init (&argc, &argv);

  blue.red   =0x0000; blue.green   =0x0000; blue.blue   =0xffff;
  black.red  =0x0000; black.green  =0x0000; black.blue  =0x0000;
  white.red  =0xffff; white.green  =0xffff; white.blue  =0xffff;
 
  gdk_color_alloc(gdk_colormap_get_system(),&blue);
  gdk_color_alloc(gdk_colormap_get_system(),&black);
  gdk_color_alloc(gdk_colormap_get_system(),&white);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window),
                    "destroy",
                    G_CALLBACK (destroy),
                    NULL);
  gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow
example");
  gtk_container_set_border_width (GTK_CONTAINER (window), 5);
  gtk_widget_set_size_request (window, 700, 300);

  box_image = gtk_hbox_new (TRUE, 5);

  pxb_orig = gdk_pixbuf_new_from_file("orig.jpg", &gerror);
  img_orig = (GtkImage *)gtk_image_new_from_pixbuf (pxb_orig);

  gtk_container_add (GTK_CONTAINER (window), box_image);

  gtk_box_pack_start (GTK_BOX (box_image), GTK_WIDGET(img_orig), FALSE,
FALSE, 0);

  img_dest    = (GtkImage *)gtk_image_new_from_file ("blank.jpg");

  gtk_box_pack_start (GTK_BOX (box_image), GTK_WIDGET(img_dest), FALSE,
FALSE, 0);

  gtk_widget_show ((GtkWidget *)img_dest);
  gtk_widget_show ((GtkWidget *)img_orig);
  gtk_widget_show (box_image);
  gtk_widget_show (window);


  /* ************************************************** */
  /* Draw to the output image. */

  guchar          *data;
  int              datasize;
  GdkColorspace    colorspace;
  cairo_surface_t *surface_source;

  datasize   = WIDTH * HEIGHT * 4;
  data       = g_malloc0 (datasize);
  colorspace = gdk_pixbuf_get_colorspace (pxb_orig);

  surface_source = cairo_image_surface_create_for_data (
                         gdk_pixbuf_get_pixels(pxb_orig),
                         CAIRO_FORMAT_RGB24,
                         WIDTH,
                         HEIGHT,
                         gdk_pixbuf_get_rowstride(pxb_orig));

  pxm_dest = gdk_pixmap_create_from_data (window->window, /* drawable */
                                          data,    /* data */
                                          WIDTH,   /* width */
                                          HEIGHT,  /* height */
                                          24,      /* depth */
                                          &black,  /* forground */
                                          &white); /* background */

  gdk_drawable_set_colormap (pxm_dest, gdk_colormap_get_system());

  cr = gdk_cairo_create (pxm_dest);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_set_source_surface (cr, surface_source, 0, 0);
  cairo_paint(cr);

  gtk_image_set_from_pixmap (GTK_IMAGE(img_dest), pxm_dest, NULL);

  /* ************************************************** */

  gtk_main();
}


On Wed, 2010-01-06 at 13:43 -0500, Tim Corio wrote:
> My bad.  I've been working with a few variations of this code and got a
> bit lost when I wrote my last note.  The actual, current code is below.
> The actual symptom is the white background from the pixmap is drawn in
> the destination image, but the source image is not copied.
> 
> Chris Wilson, I'll look into the NO_WINDOW GtkMisc.  Can you show a
> small sample of its use?
> 
> In researching this problem I find that others have tried to implement
> rotation by an arbitrary amount in a GTK application.  I assume they've
> all eventually found a working solution, but none was posted.  Once I
> get this working I'll post the program here to help out the next person
> with this problem.
> 
> Thank You,
> Tim
> 
> On Wed, 2010-01-06 at 16:42 +0000, Chris Wilson wrote:
> > On Wed, 06 Jan 2010 11:14:41 -0500, Tim Corio <tcorio at rochester.rr.com> wrote:
> > > Now, it no longer crashes, but the resulting image is garbled.  It may
> > > be a very skewed copy of the original.
> > > 
> > > If each line was skewed by one pixel the image would be recognizable,
> > > but at a 45 degree tilt.  In this case the image is unrecognizable, but
> > > the mix of pixel colors look about right.
> > 
> > Almost as if you tried to use a 24-bpp packed pixel representation as a
> > 32-bit xRGB surface...
> > 
> > To put it mildly you have fallen foul of GTK+'s poor integration of
> > Cairo and GdkPixbuf. Hmm, I actually hope that the current version of
> > Cairo throws an error given these inputs.
> > 
> > Personally, I just subclass a plain NO_WINDOW GtkMisc widget for my Cairo
> > drawing routines.
> > -ickle
> > 



More information about the cairo mailing list