static gboolean gwy_color_axis_expose(GtkWidget *widget, GdkEventExpose *event) { GwyColorAxis *axis; GdkGC *mygc; gwy_debug(""); g_return_val_if_fail(widget != NULL, FALSE); g_return_val_if_fail(GWY_IS_COLOR_AXIS(widget), FALSE); g_return_val_if_fail(event != NULL, FALSE); if (event->count > 0) return FALSE; axis = GWY_COLOR_AXIS(widget); gdk_window_clear_area(widget->window, 0, 0, widget->allocation.width, widget->allocation.height); mygc = gdk_gc_new(widget->window); if (axis->orientation == GTK_ORIENTATION_HORIZONTAL) gdk_pixbuf_render_to_drawable(axis->pixbuf, widget->window, mygc, 0, 0, 0, axis->par.textarea, widget->allocation.width, widget->allocation.height - axis->par.textarea, GDK_RGB_DITHER_NONE, 0, 0); else gdk_pixbuf_render_to_drawable(axis->pixbuf, widget->window, mygc, 0, 0, 0, 0, widget->allocation.width - axis->par.textarea, widget->allocation.height, GDK_RGB_DITHER_NONE, 0, 0); g_object_unref((GObject *)mygc); gwy_color_axis_draw_label(widget); return FALSE; }
/** gdk_pixbuf_render_to_drawable is deprecated since GTK+ 2.2.0 */ static void gdk_draw_pixbuf(GdkDrawable *drawable, GdkGC *gc, GdkPixbuf *pixbuf, gint src_x, gint src_y, gint dest_x, gint dest_y, gint width, gint height, GdkRgbDither dither, gint x_dither, gint y_dither) { gdk_pixbuf_render_to_drawable(pixbuf, drawable, gc, src_x, src_y, dest_x, dest_y, width, height, dither, x_dither, y_dither); }
gboolean expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) { GdkPixbuf *dest; gdk_window_set_back_pixmap (widget->window, NULL, FALSE); dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height); gdk_pixbuf_composite_color (pixbuf, dest, 0, 0, event->area.width, event->area.height, -event->area.x, -event->area.y, (double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf), (double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf), interp_type, overall_alpha, event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555); gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], 0, 0, event->area.x, event->area.y, event->area.width, event->area.height, GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y); gdk_pixbuf_unref (dest); return TRUE; }
static MT_PIXMAP *_mt_pixmap_new_from_image(MT_IMAGE *img) { GdkPixmap *pixmap; int width, height; width = gdk_pixbuf_get_width((GdkPixbuf *)img); height = gdk_pixbuf_get_height((GdkPixbuf *)img); pixmap = gdk_pixmap_new(gdk_get_default_root_window(), width, height, GTK_STYLE(mt_style)->depth); gdk_pixbuf_render_to_drawable((GdkPixbuf *)img, pixmap, NULL, 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, 0, 0); return (MT_PIXMAP *)pixmap; }
void Fenetre::afficheImage(Image img, int x, int y) { // image à partir d'un objet if (existe) { GdkPixbuf * image = img.getPixbub(); if (image!=NULL) { gdk_pixbuf_render_to_drawable(image, dessin, fenetre->style->fg_gc[GTK_WIDGET_STATE(fenetre)], 0,0,x,y,-1,-1,GDK_RGB_DITHER_MAX,0,0); gtk_widget_queue_draw(fenetre); traiteEvenements(); } } }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_copyAndScalePixmap (JNIEnv *env, jobject obj, jobject offscreen, jboolean flip_x, jboolean flip_y, jint src_x, jint src_y, jint src_width, jint src_height, jint dest_x, jint dest_y, jint dest_width, jint dest_height) { struct graphics *g1, *g2; GdkPixbuf *buf_src, *buf_dest; g1 = (struct graphics *) NSA_GET_PTR (env, obj); g2 = (struct graphics *) NSA_GET_PTR (env, offscreen); gdk_threads_enter (); buf_src = gdk_pixbuf_get_from_drawable (NULL, g2->drawable, g2->cm, src_x, src_y, 0, 0, src_width, src_height); buf_dest = gdk_pixbuf_scale_simple (buf_src, dest_width, dest_height, GDK_INTERP_BILINEAR); if (flip_x || flip_y) { flip_pixbuf (buf_dest, flip_x, flip_y, dest_width, dest_height); } gdk_pixbuf_render_to_drawable (buf_dest, g1->drawable, g1->gc, 0, 0, dest_x, dest_y, dest_width, dest_height, GDK_RGB_DITHER_NORMAL, 0, 0); g_object_unref (G_OBJECT (buf_src)); g_object_unref (G_OBJECT (buf_dest)); gdk_threads_leave (); }
void ZLGtkPaintContext::drawImage(int x, int y, const ZLImageData &image, int width, int height, ScalingType type) { GdkPixbuf *imageRef = ((const ZLGtkImageData&)image).pixbuf(); if (imageRef == 0) { return; } const int realWidth = imageWidth(image, width, height, type); const int realHeight = imageHeight(image, width, height, type); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(imageRef, realWidth, realHeight, GDK_INTERP_BILINEAR); if (imageRef != 0) { gdk_pixbuf_render_to_drawable( scaled, myPixmap, 0, 0, 0, x, y - realHeight, realWidth, realHeight, GDK_RGB_DITHER_NONE, 0, 0 ); } gdk_pixbuf_unref(scaled); }
void Fenetre::afficheImage(const char * nom, int x, int y) { // image à partir d'un fichier if (existe) { // Les lignes mises en commentaire correspondent à la version utilisant des fichiers // au format XMP seulement (format de base de gtk) /* GdkPixmap * image=gdk_pixmap_create_from_xpm(fenetre->window, NULL, &fenetre->style->bg[GTK_STATE_NORMAL],nom); gdk_draw_pixmap(dessin, fenetre->style->fg_gc[GTK_WIDGET_STATE(fenetre)], image,0,0,0,0,-1,-1); */ // version pour tous types de fichiers GdkPixbuf * image = gdk_pixbuf_new_from_file(nom, NULL); if (image!=NULL) { gdk_pixbuf_render_to_drawable(image, dessin, fenetre->style->fg_gc[GTK_WIDGET_STATE(fenetre)], 0,0,x,y,-1,-1,GDK_RGB_DITHER_MAX,0,0); gtk_widget_queue_draw(fenetre); gdk_pixbuf_unref(image); // gdk_pixmap_unref(image); utilisé dans la version pour XMP traiteEvenements(); } } }
/* ------------------------------------------------------------ */ static void ghid_draw_bg_image (void) { static GdkPixbuf *pixbuf; GdkInterpType interp_type; gint x, y, w, h, w_src, h_src; static gint w_scaled, h_scaled; render_priv *priv = gport->render_priv; if (!ghidgui->bg_pixbuf) return; w = PCB->MaxWidth / gport->view.coord_per_px; h = PCB->MaxHeight / gport->view.coord_per_px; x = gport->view.x0 / gport->view.coord_per_px; y = gport->view.y0 / gport->view.coord_per_px; if (w_scaled != w || h_scaled != h) { if (pixbuf) g_object_unref (G_OBJECT (pixbuf)); w_src = gdk_pixbuf_get_width (ghidgui->bg_pixbuf); h_src = gdk_pixbuf_get_height (ghidgui->bg_pixbuf); if (w > w_src && h > h_src) interp_type = GDK_INTERP_NEAREST; else interp_type = GDK_INTERP_BILINEAR; pixbuf = gdk_pixbuf_scale_simple (ghidgui->bg_pixbuf, w, h, interp_type); w_scaled = w; h_scaled = h; } if (pixbuf) gdk_pixbuf_render_to_drawable (pixbuf, gport->drawable, priv->bg_gc, x, y, 0, 0, w - x, h - y, GDK_RGB_DITHER_NORMAL, 0, 0); }
static void sample_expose (GtkWidget *darea, GdkEventExpose *expose) { GdkPixbuf *pixbuf = g_object_get_data (G_OBJECT (darea), "sample-pixbuf"); int width = gdk_pixbuf_get_width (pixbuf); int height = gdk_pixbuf_get_height (pixbuf); int x = (darea->allocation.width - width) / 2; int y = (darea->allocation.height - height) / 2; gdk_draw_rectangle (darea->window, darea->style->white_gc, TRUE, 0, 0, darea->allocation.width, darea->allocation.height); gdk_draw_rectangle (darea->window, darea->style->black_gc, FALSE, 0, 0, darea->allocation.width - 1, darea->allocation.height - 1); gdk_pixbuf_render_to_drawable (pixbuf, darea->window, NULL, 0, 0, x, y, width, height, GDK_RGB_DITHER_NORMAL, 0, 0); }
static VALUE pixbuf_render_to_drawable(int argc, VALUE *argv, VALUE self) { VALUE gc, src_x, src_y, dest_x, dest_y, width, height, dither, x_dither, y_dither; #if GTK_CHECK_VERSION(2,2,0) rb_warn("Gdk::Pixbuf#render_to_drawable is obsolete. Use Gdk::Drawable#draw_pixbuf instead."); #endif rb_scan_args(argc, argv, "73", &gc, &src_x, &src_y, &dest_x, &dest_y, &width, &height, &dither, &x_dither, &y_dither); if (NIL_P(gc)) rb_raise(rb_eArgError, "arguments 1 must be non nil"); if (NIL_P(src_x)) rb_raise(rb_eArgError, "arguments 2 must be non nil"); if (NIL_P(src_y)) rb_raise(rb_eArgError, "arguments 3 must be non nil"); if (NIL_P(dest_x)) rb_raise(rb_eArgError, "arguments 4 must be non nil"); if (NIL_P(dest_y)) rb_raise(rb_eArgError, "arguments 5 must be non nil"); if (NIL_P(width)) rb_raise(rb_eArgError, "arguments 6 must be non nil"); if (NIL_P(height)) rb_raise(rb_eArgError, "arguments 7 must be non nil"); gdk_pixbuf_render_to_drawable(_SELF(self), GDK_DRAWABLE(RVAL2GOBJ(self)), GDK_GC(RVAL2GOBJ(gc)), NUM2INT(src_x), NUM2INT(src_y), NUM2INT(dest_x), NUM2INT(dest_y), NUM2INT(width), NUM2INT(height), NIL_P(dither) ? GDK_RGB_DITHER_NONE : RVAL2GENUM(dither, GDK_TYPE_RGB_DITHER), NIL_P(x_dither) ? 0 : NUM2INT(x_dither), NIL_P(y_dither) ? 0 : NUM2INT(y_dither)); return self; }
void GtkPaintContext::drawImage(int x, int y, const ZLImageData &image) { GdkPixbuf *imageRef = ((GtkImageData&)image).pixbuf(); if (imageRef != 0) { gdk_pixbuf_render_to_drawable( imageRef, myPixmap, 0, 0, 0, x + leftMargin(), y + topMargin() - gdk_pixbuf_get_height(imageRef), -1, -1, GDK_RGB_DITHER_NONE, 0, 0 ); } // for gtk+ v2.2 // gdk_draw_pixbuf( // myPixmap, 0, imageRef, 0, 0, // x + leftMargin(), y + topMargin() - gdk_pixbuf_get_height(imageRef), // -1, -1, GDK_RGB_DITHER_NONE, 0, 0 // ); // // COMMENTS: // 0 -- we have no clipping (do we need it?) // 0, 0 -- offset in the image // -1, -1 -- use the whole // GDK_RGB_DITHER_NONE -- no dithering, hopefully, (0, 0) after it does not harm }
int x_tile_render_to_drawable(GdkDrawable *drawable, GdkGC *gc, int tile, int sx, int sy, int dest_x, int dest_y, int width, int height) { int srcx, srcy; srcx = (tile % tiles_per_row) * Tile->unit_width; srcy = (tile / tiles_per_row) * Tile->unit_height; if (sx < 0) { dest_x -= sx; width += sx; sx = 0; } if (sy < 0) { dest_y -= sy; height += sy; sy = 0; } if (sx + width > Tile->unit_width) width = Tile->unit_width - sx; if (sy + height > Tile->unit_height) height = Tile->unit_height - sy; if (tile_image) gdk_draw_image(drawable, gc, tile_image, srcx + sx, srcy + sy, dest_x, dest_y, width, height); else if (tile_pixbuf) gdk_pixbuf_render_to_drawable(tile_pixbuf, drawable, gc, srcx + sx, srcy + sy, dest_x, dest_y, width, height, GDK_RGB_DITHER_NORMAL, 0, 0); else gdk_draw_drawable(drawable, gc, tile_pixmap, srcx + sx, srcy + sy, dest_x, dest_y, width, height); return 1; }
void pintar() { GdkPixbuf * pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,buffer_out->ancho, buffer_out->alto); guchar * p = gdk_pixbuf_get_pixels (pixbuf); guchar * b = buffer_out->tipo_orden; int ancho = buffer_out->ancho * buffer_out->bytes; int i, j; for(j = 0; j < buffer_out->alto; ++j) { BYTE * aux = &p[(j + 1) * ancho]; for(i = 0; i < ancho; ++i) { *--aux = *b++; } } if(pixbuf) { gdk_pixbuf_render_to_drawable(pixbuf, ventana->window, gc, 0, 0, 0, 0, buffer_out->ancho, buffer_out->alto, GDK_RGB_DITHER_NONE, 0, 0); gdk_pixbuf_unref(pixbuf); } }
void loadimage (char *filename) { GdkPixbuf *pixbuf, *pixbuf_scaled, *pixbuf_skin; GError *error = NULL; pixbuf=pixbuf_scaled=pixbuf_skin=NULL; int new_cover_width,new_cover_height, org_cover_width,org_cover_height, cover_offset_x,cover_offset_y; if (mainwindow_data.loading_skin) return; // Load image if (filename) { // Load in our "base" skin pixbuf_skin = gdk_pixbuf_copy (plugin_config->skin_base_custom_pixbuf); pixbuf = gdk_pixbuf_new_from_file (filename, &error); org_cover_width = gdk_pixbuf_get_width (pixbuf); org_cover_height = gdk_pixbuf_get_height (pixbuf); // Figure out if we should be rescaling at all if (org_cover_width > plugin_config->skin_cover_width || org_cover_height > plugin_config->skin_cover_height) { // Calculate the rescale if (plugin_config->preserve_aspectratio) { // Resize and preserve the apsect ratio new_cover_width = plugin_config->skin_cover_width; new_cover_height = (org_cover_height * new_cover_width) / org_cover_width; if (new_cover_height>plugin_config->skin_cover_height) { new_cover_height = plugin_config->skin_cover_height; new_cover_width = (org_cover_width * new_cover_height) / org_cover_height; } if (new_cover_height > plugin_config->skin_cover_height || new_cover_width > plugin_config->skin_cover_width) { // mmh ... somehting went wrong DPRINT (__DEBUG_GENERAL__,"Resize did not work for %dx%d -> %dx%d", org_cover_width,org_cover_height, plugin_config->skin_cover_width, plugin_config->skin_cover_height) new_cover_width = plugin_config->skin_cover_width; new_cover_height = plugin_config->skin_cover_height; } } else { // Just a brutal rescale to fit in the target area new_cover_width = plugin_config->skin_cover_width; new_cover_height = plugin_config->skin_cover_height; } } else { new_cover_width = org_cover_width; new_cover_height = org_cover_height; } cover_offset_x = (plugin_config->skin_cover_width - new_cover_width) / 2; cover_offset_y = (plugin_config->skin_cover_height - new_cover_height) / 2; // Now scale the cover pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, // source pixbuf new_cover_width, // Target width new_cover_height, // Target height GDK_INTERP_BILINEAR); // Flags // Copy loaded cover onto the skin gdk_pixbuf_copy_area (pixbuf_scaled, // Source pixbuf 0,0, // Source x,y new_cover_width, // Width to copy new_cover_height, // Width to copy pixbuf_skin, // Destination pixbuf plugin_config->skin_coverx + cover_offset_x, // Desination x,y plugin_config->skin_covery + cover_offset_y); // Desination x,y // free the original pictures g_object_unref (pixbuf); g_object_unref (pixbuf_scaled); } else { // Load in the skin that has "no cover" information pixbuf_skin = gdk_pixbuf_copy (plugin_config->skin_nocover_custom_pixbuf); } // Copy image-data to the double-buffer gdk_pixbuf_render_to_drawable (pixbuf_skin, // A Pixbuf mainwindow_data.dbuf_pixmap, // Destination drawable mainwindow_data.window->style->fg_gc[GTK_STATE_NORMAL], // GC 0,0, // Source X/Y in pixbuf 0,0, // Dest X/Y plugin_config->skin_width, // Dest. height plugin_config->skin_height, // Dest. height GDK_RGB_DITHER_NORMAL,0,0); // Dithermode and Offset for dither g_object_unref (pixbuf_skin); // Repaint the new cover repaint_cover(); }
//! Draws the square (x, y). On the board it is shown at (real_x, real_y) void board_refresh_cell_real (int x, int y, int real_x, int real_y) { GdkGC *gc; int parity = (board_wid * board_heit + x + y + 1) % 2; int thepiece; if (opt_quiet) return; if (!cur_pos.board) return; gc = board_area->style->bg_gc[GTK_STATE_NORMAL]; gdk_gc_set_clip_mask (gc, NULL); gdk_gc_set_clip_origin (gc, real_x * cell_size, real_y * cell_size); thepiece = cur_pos.board[y * board_wid + x] -1 + num_pieces * parity; if ((cur_pos.render[y * board_wid + x] & 0xFF) == RENDER_REPLACE) thepiece = (cur_pos.render[y * board_wid + x] >> 8) -1 + num_pieces * parity; if ((cur_pos.board[y * board_wid + x] != 0 || (cur_pos.render[y * board_wid + x] & 0xFF) == RENDER_REPLACE) && !board_suspended) { /* FIXME: current impl is that if bgimage is set then bgcolor is irrelevant. Maybe we should change it so that bgimage is layered on top of bgcolor */ if (board_bgimage) { gdk_draw_pixmap (board_area->window, gc, (GdkDrawable *) board_bgimage, real_x * cell_size, real_y * cell_size, real_x * cell_size, real_y * cell_size, cell_size, cell_size ); gdk_gc_set_clip_mask (gc, piece_masks [thepiece]); gdk_gc_set_clip_origin (gc, real_x * cell_size, real_y * cell_size); } gdk_draw_pixmap (board_area->window, gc, (GdkDrawable *) pieces [thepiece], 0, 0, real_x * cell_size, real_y * cell_size, -1, -1); } else { if (board_bgimage) { gdk_draw_pixmap (board_area->window, gc, (GdkDrawable *) board_bgimage, real_x * cell_size, real_y * cell_size, real_x * cell_size, real_y * cell_size, cell_size, cell_size ); } else gdk_draw_rectangle (board_area->window, board_gcs[parity], 1, real_x * cell_size, real_y * cell_size, cell_size, cell_size); } if (cur_pos.render[y * board_wid + x] == RENDER_SHADE1 && cur_pos.board[y * board_wid + x] != 0 && !board_suspended) { #if GTK_MAJOR_VERSION > 1 GdkPixbuf *pixbuf; int i; guchar *pixels; pixbuf = gdk_pixbuf_get_from_drawable (NULL, pieces[thepiece], NULL, 0, 0, 0, 0, cell_size, cell_size); pixels = gdk_pixbuf_get_pixels (pixbuf); for (i=0; i<3*cell_size*cell_size; i++) pixels[i] = (pixels[i] + 127)/2; gdk_pixbuf_render_to_drawable (pixbuf, board_area->window, gc, 0, 0, real_x * cell_size, real_y * cell_size, cell_size, cell_size, GDK_RGB_DITHER_NONE, 0, 0); // FIXME: find out the correct way to free it g_free (pixels); g_free (pixbuf); #else fprintf (stderr, "Warning: RENDER_SHADE currently unimplemented in gtk1 version\n"); #endif } if (game_draw_cell_boundaries) { if (real_x > 0) gdk_draw_line (board_area->window, board_gcs[2], real_x * cell_size, real_y * cell_size, real_x * cell_size, (real_y + 1) * cell_size); if (real_y > 0) gdk_draw_line (board_area->window, board_gcs[2], real_x * cell_size, real_y * cell_size, (real_x + 1) * cell_size, real_y * cell_size); } // TODO: do HIGHLIGHT2 and 3 also if (cur_pos.render[y * board_wid + x] == RENDER_HIGHLIGHT1 && !board_suspended) { int incr = game_draw_cell_boundaries ? 1 : 0; gdk_draw_line (board_area->window, board_highlight_gcs[0], real_x * cell_size + incr, real_y * cell_size + incr, real_x * cell_size + incr, (real_y + 1) * cell_size - 1); gdk_draw_line (board_area->window, board_highlight_gcs[0], real_x * cell_size + incr, real_y * cell_size + incr, (real_x + 1) * cell_size - 1, real_y * cell_size + incr); gdk_draw_line (board_area->window, board_highlight_gcs[0], (real_x + 1) * cell_size - 1, real_y * cell_size + incr, (real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1); gdk_draw_line (board_area->window, board_highlight_gcs[0], real_x * cell_size + incr, (real_y + 1) * cell_size - 1, (real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1); } if (cur_pos.render[y * board_wid + x] == RENDER_BUTTONIZE && !board_suspended) { int incr = game_draw_cell_boundaries ? 1 : 0; gdk_draw_line (board_area->window, board_buttonize_gcs[0], real_x * cell_size + incr, real_y * cell_size + incr, real_x * cell_size + incr, (real_y + 1) * cell_size - 1); gdk_draw_line (board_area->window, board_buttonize_gcs[0], real_x * cell_size + incr, real_y * cell_size + incr, (real_x + 1) * cell_size - 1, real_y * cell_size + incr); gdk_draw_line (board_area->window, board_buttonize_gcs[1], (real_x + 1) * cell_size - 1, real_y * cell_size + incr, (real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1); gdk_draw_line (board_area->window, board_buttonize_gcs[1], real_x * cell_size + incr, (real_y + 1) * cell_size - 1, (real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1); } }
static enum xshm_map_mode x_tile_set_map_mode(TileTab *t, NhGtkProgressWindow *w) { int i; enum xshm_map_mode mode; GdkPixbuf *copy; guchar *pixels; GdkGC *gc; if (!t->spread && !t->transparent) mode = XSHM_MAP_PIXMAP; else mode = getenv("HACKPIXBUF") ? XSHM_MAP_PIXBUF : XSHM_MAP_IMAGE; /* * Pixbufs use so much memory that it's not unexpected for us to * fail to generate the alpha channel correctly. This is not a * great problem since we carefully avoid using it ourselves * (preferring to use the transparent colour directly), but might * cause gdk_pixbuf_render_to_drawable() to get slightly confused * when it dithers the tile (the transparent colour may bleed into * the glyph). We therefore issue a warning. * * Note: It's not clear that gdk_pixbuf_render_to_drawable() * actually uses this information, but what more can we do? * There's little point using gdk_pixbuf_render_to_drawable_alpha() * since all that does is take care not to draw transparent pixels * (which we don't care about anyway; we'll never read them). */ if (mode == XSHM_MAP_PIXBUF && gdk_pixbuf_get_has_alpha(tile_pixbuf)) { /* We can't trust the XPM alpha channel & it will * overide if we don't get rid of it here */ copy = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(tile_pixbuf), FALSE, gdk_pixbuf_get_bits_per_sample(tile_pixbuf), t->tilemap_width, t->tilemap_height); nh_gtk_progress_window_stage_set_fraction(w, 0.25); if (copy) { gdk_pixbuf_copy_area(tile_pixbuf, 0, 0, t->tilemap_width, t->tilemap_height, copy, 0, 0); gdk_pixbuf_unref(tile_pixbuf); tile_pixbuf = copy; nh_gtk_progress_window_stage_set_fraction(w, 0.5); } else { pline("Warning: Not enough memory: Tiles may be degraded"); mode = XSHM_MAP_IMAGE; nh_gtk_progress_window_stage_set_fraction(w, 0.0); } } if (mode == XSHM_MAP_PIXBUF && !gdk_pixbuf_get_has_alpha(tile_pixbuf)) { pixels = gdk_pixbuf_get_pixels(tile_pixbuf); nh_gtk_progress_window_stage_set_fraction(w, 0.75); copy = gdk_pixbuf_add_alpha(tile_pixbuf, TRUE, pixels[0], pixels[1], pixels[2]); if (copy) { gdk_pixbuf_unref(tile_pixbuf); tile_pixbuf = copy; } else { pline("Warning: Not enough memory: Tiles may be degraded"); mode = XSHM_MAP_IMAGE; nh_gtk_progress_window_stage_set_fraction(w, 0.0); } } tmp_pixbuf = NULL; if (mode != XSHM_MAP_PIXBUF) { tile_pixmap = gdk_pixmap_new(main_window->window, t->tilemap_width, t->tilemap_height, -1); if (!tile_pixmap) panic("Not enough memory to load tiles!"); nh_gtk_progress_window_stage_set_fraction(w, mode == XSHM_MAP_IMAGE ? 0.025 : 0.3); gc = gdk_gc_new(tile_pixmap); gdk_pixbuf_render_to_drawable(tile_pixbuf, tile_pixmap, gc, 0, 0, 0, 0, t->tilemap_width, t->tilemap_height, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_gc_unref(gc); if (mode == XSHM_MAP_IMAGE) { int step = total_tiles_used >= 100 ? total_tiles_used / 100 : 1; nh_gtk_progress_window_stage_set_fraction(w, 0.1); tile_transp = (struct tile_transp *) alloc(total_tiles_used * sizeof(*tile_transp)); for(i = 0; i < total_tiles_used; i++) { calc_tile_transp(t, tile_pixbuf, i); if (i % step == 0) nh_gtk_progress_window_stage_set_fraction(w, 0.1 + (i * 0.8) / total_tiles_used); } calc_tile_transp(t, tile_pixbuf, -1); nh_gtk_progress_window_stage_set_fraction(w, 0.9); /* TODO: Creating an image via a pixmap is very inefficient; * this should be done directly from pixbuf, even if GTK+ doesn't * provide any easy way to do this. */ tile_image = gdk_image_get((GdkWindow *)tile_pixmap, 0, 0, t->tilemap_width, t->tilemap_height); if (!tile_image) panic("Not enough memory to load tiles!"); gdk_pixmap_unref(tile_pixmap); tile_pixmap = NULL; nh_gtk_progress_window_stage_set_fraction(w, 0.975); tmp_img = gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), t->unit_width, t->unit_height); if (!tmp_img) panic("Not enough memory to load tiles!"); #if GTK_CHECK_VERSION(1,3,3) tile_bits_per_pixel = tile_image->bits_per_pixel; #else /* * Technically, this could give an incorrect result. However, as * long as the bitmap_pad is no more than 32 bits (max. X11 allows); * the bytes/line is not larger than necessary; and the width is * at least 32 pixels, then it will be correct. */ tile_bits_per_pixel = tile_image->bpl * 8 / t->tilemap_width; #endif } else tmp_img = tile_image = NULL; gdk_pixbuf_unref(tile_pixbuf); tile_pixbuf = NULL; } nh_gtk_progress_window_stage_set_fraction(w, 1.0); return mode; }