Results 1 to 4 of 4

Thread: gtk.gdk.pixbuf_new_from_data() and rowstride trouble

  1. #1
    Join Date
    May 2005
    Location
    Auckland, New Zealand
    Beans
    223

    gtk.gdk.pixbuf_new_from_data() and rowstride trouble

    Hi,

    I am playing around with a program that stores images as binary strings in a sqlite3 db. I load the images using gtk.gdk.pixbuf_new_from_data().

    This works flawlessly for 95% of all images loaded. However, some render skewed as i calculate an incorrect rowstride.



    Above is an example of a 50px by 50px RGB jpeg, which i have calculated a rowstride of 150 (50 wide x 3 deep (RGB)).

    Now when i load the same image as a pixbuf using gtk.gdk.pixbuf_new_from_file(), pixbuf.get_rowstride() reports a rowstride of 152. Now i cannot understand how this can be, as 152 divided by 50 does not produce a whole number.

    gtk.gdk.pixbuf_new_from_data() will not allow a rowstride of 152 int his case as it reports that the amount of pixel data is less than required by the paramaters.

    Anyone have any expierience with this issue?
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: gtk.gdk.pixbuf_new_from_data() and rowstride trouble

    It pads each row with 0s untill it fills complete words. And by word I mean 4 or 8 bytes (depending on your platform)

    150 bytes % 4 bytes == 2
    152 bytes % 4 bytes == 0

  3. #3
    Join Date
    May 2005
    Location
    Auckland, New Zealand
    Beans
    223

    Re: gtk.gdk.pixbuf_new_from_data() and rowstride trouble

    ok,thanks for that info.

    So i have to pad the end of each row with the appropriate number of zeros, 2 in this case?
    I have been using PIL's tostring() to generate the raw data to be stored. So is it easier for me just to resize the image to dimensions that will fall on a 4 byte boundary (say, 48 x 48 ) than to try to add zeros to the end of each row. Seems id have to write my own functional equivalent to tostring() but including the right amount of padding at the end of each row. This seems like a pain and possibly slowwwww to do in python also.
    Last edited by | MM |; June 26th, 2008 at 08:49 AM.

  4. #4
    Join Date
    May 2005
    Location
    Auckland, New Zealand
    Beans
    223

    Re: gtk.gdk.pixbuf_new_from_data() and rowstride trouble

    Ok, its pretty hacky but i'll just resize to the appropriate size prior to using tostring(), thanks for your advice!
    Last edited by | MM |; June 26th, 2008 at 10:10 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •