0

I am trying to port a Clean graphics library (specifically, ObjectIO) to Linux with GDK. The library consists of a non-OS-specific part, which I don't want to touch because of compatibility issues, and an OS-specific part which I can touch.

One of the functions I have to implement is one that takes raw data from a .bmp file and has to build a GdkPixbuf from this. This function has to be written in C.

I am aware of the function gdk_pixbuf_new_from_file(), but I do not get the file name (and can't change that, as it's in the non-OS-specific part of the library). I only get the raw data.

I saw this manual entry, and I guess I could use gdk_pixbuf_new_from_data(), but this requires that you know the row stride of the image, of which I'm unsure how to get it.

Is there a way to get the row stride from the file? If not, the only possibility I see is to create a temporary file with the data and then call gdk_pixbuf_new_from_file() - but that would be really ugly.

  • I wouldn’t be surprised if the row stride was always equal to the width. – icktoofay Aug 23 '15 at 22:35
  • @icktoofay at first, I thought width * 3 (you need three bytes for a 24-bit image), but that doesn't show good results yet. I also tried numbers around that. It doesn't seem to be that simple, unfortunately ... –  Aug 23 '15 at 22:50

1 Answers1

1

You want to use the function:

int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, ImageWidth);
Des Horsley
  • 1,858
  • 20
  • 43
Paul
  • 663
  • 7
  • 11