window_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
#endif
{
    IMAGE *img = (IMAGE *)user_data;
    if (img && img->window && img->buf) {
        GdkPixbuf *pixbuf = NULL;
        int color = img->format & DISPLAY_COLORS_MASK;
        int depth = img->format & DISPLAY_DEPTH_MASK;
#if !GTK_CHECK_VERSION(3, 0, 0)
        cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
        gdk_cairo_region(cr, event->region);
        cairo_clip(cr);
#endif
        gdk_cairo_set_source_color(cr, &gtk_widget_get_style(widget)->bg[GTK_STATE_NORMAL]);
        cairo_paint(cr);
            switch (color) {
                case DISPLAY_COLORS_NATIVE:
                    if (depth == DISPLAY_DEPTH_8 && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    else if ((depth == DISPLAY_DEPTH_16) && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
                case DISPLAY_COLORS_GRAY:
                    if (depth == DISPLAY_DEPTH_8 && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
                case DISPLAY_COLORS_RGB:
                    if (depth == DISPLAY_DEPTH_8) {
                        if (img->rgbbuf)
                            pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                                GDK_COLORSPACE_RGB, FALSE, 8,
                                img->width, img->height, img->width*3,
                                NULL, NULL);
                        else
                            pixbuf = gdk_pixbuf_new_from_data(img->buf,
                                GDK_COLORSPACE_RGB, FALSE, 8,
                                img->width, img->height, img->rowstride,
                                NULL, NULL);
                    }
                    break;
                case DISPLAY_COLORS_CMYK:
                    if (((depth == DISPLAY_DEPTH_1) ||
                        (depth == DISPLAY_DEPTH_8)) && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
                case DISPLAY_COLORS_SEPARATION:
                    if ((depth == DISPLAY_DEPTH_8) && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
            }
            if (pixbuf) gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
            cairo_paint(cr);
#if !GTK_CHECK_VERSION(3, 0, 0)
            cairo_destroy(cr);
#endif
            if (pixbuf) g_object_unref(pixbuf);
    }
    return TRUE;
}
window_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
#endif
{
    IMAGE *img = (IMAGE *)user_data;
    if (img && img->window && img->buf) {
        GdkPixbuf *pixbuf = NULL;
        int color = img->format & DISPLAY_COLORS_MASK;
        int depth = img->format & DISPLAY_DEPTH_MASK;
#if !GTK_CHECK_VERSION(3, 0, 0)
        cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
        gdk_cairo_region(cr, event->region);
        cairo_clip(cr);
#endif
        gdk_cairo_set_source_color(cr, &gtk_widget_get_style(widget)->bg[GTK_STATE_NORMAL]);
        cairo_paint(cr);
            switch (color) {
                case DISPLAY_COLORS_NATIVE:
                    if (depth == DISPLAY_DEPTH_8 && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    else if ((depth == DISPLAY_DEPTH_16) && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
                case DISPLAY_COLORS_GRAY:
                    if (depth == DISPLAY_DEPTH_8 && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
                case DISPLAY_COLORS_RGB:
                    if (depth == DISPLAY_DEPTH_8) {
                        if (img->rgbbuf)
                            pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                                GDK_COLORSPACE_RGB, FALSE, 8,
                                img->width, img->height, img->width*3,
                                NULL, NULL);
                        else
                            pixbuf = gdk_pixbuf_new_from_data(img->buf,
                                GDK_COLORSPACE_RGB, FALSE, 8,
                                img->width, img->height, img->rowstride,
                                NULL, NULL);
                    }
                    break;
                case DISPLAY_COLORS_CMYK:
                    if (((depth == DISPLAY_DEPTH_1) ||
                        (depth == DISPLAY_DEPTH_8)) && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
                case DISPLAY_COLORS_SEPARATION:
                    if ((depth == DISPLAY_DEPTH_8) && img->rgbbuf)
                        pixbuf = gdk_pixbuf_new_from_data(img->rgbbuf,
                            GDK_COLORSPACE_RGB, FALSE, 8,
                            img->width, img->height, img->width*3,
                            NULL, NULL);
                    break;
            }
            if (pixbuf) gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
            cairo_paint(cr);
#if !GTK_CHECK_VERSION(3, 0, 0)
            cairo_destroy(cr);
#endif
            if (pixbuf) g_object_unref(pixbuf);
    }
    return TRUE;
}