0

I am trying to understand the basics behind Pixbuf and its factory methods new_from_data and new_from_stream.

new_from_data requires a string of bytes containing the image data, and other information such as bits per sample, with and height of image.

What I don't understand is why new_from_stream does not require those additional image information. Then, how can the Pixbuf know how to render the image new_from_stream does not provide any additional information other than the Gio.InputStream ?

fstab
  • 4,801
  • 8
  • 34
  • 66

1 Answers1

1

new_from_stream() expects to get a stream of a supported image file, equivalent to new_from_file(). All the image formats contain metadata like height and width.

new_from_data() on the other hand expects a pixel buffer, which is essentially just an array of pixels without any metadata.

Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54
  • Thank you for the answer. I was wondering: would it be possible (and efficient) to keep a pixbuf and changing the data ( data similar to the one provided by `new_from_data`)? This because I fear that `new_from_stream` is less fast as it needs to parse an image format, hence might not be suitable for displaying videos generated on-the-fly. – fstab Nov 17 '16 at 16:30
  • If you need to somehow touch the picture often (like every draw cycle) then modifying the data definitely sounds a _lot_ better than creating a new pixbuf everytime: memory allocation takes a while... Maybe `get_pixels()` is useful for you. – Jussi Kukkonen Nov 17 '16 at 16:52
  • isn't a "bytes" object (the one returned by `get_pixels()` ) immutable in python? – fstab Nov 17 '16 at 21:28