GTK2 to GTK3 migration - gdk_draw_indexed_image

I’m migrating code from GTK2 to GTK3 and I came across the following problem:
Function gdk_draw_indexed_image() is used heavily in my app, which reads custom data from binary file and draws it to a GdkPixmap. GdkRgbCmap *cmap argument of gdk_draw_indexed_image() is important in my app, it defines how the data are displayed and app user is allowed to customize the colormap to change the colors of the resulting image.

I can’t seem to find a replacement for this functionality in GTK3 using neither GdkPixbuf(gdk_pixbuf_new_from_data()) nor Cairo library (cairo_image_surface_create_for_data()) .

Can anybody please give me a suggestion how to achieve something like this in GTK3?
Thank you.

There is no replacement: pixel munging is not really part of GDK any more, and that code was tied with Xlib concepts that haven’t been part of GTK for almost two decades.

If you’re taking a grayscale image and replacing gray with a specific color map, you can do that yourself with a GdkPixbuf: load the image blob, get the pixel data and iterate over every pixel to convert the data according to your color map.

If your application’s code is licensed under LGPL or GPL, you could also look into the GDK2 code and follow the same approach.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.