Re: alpha channel in GdkPixbuf



Ron Steinke <rsteinke w-link net> writes:
> Is there any way to extract the alpha channel information from
> a GdkPixbuf (for example, writing it to an array or a grayscale
> pixmap)?
> 

You just iterate over the pixels in the pixbuf.

They are arranged like so for a pixbuf with alpha:

 RGBA RGBA RGBA RGBA RGBA RGBA RGBA PPP
 |             rowstride              |
 |             width               |

like so for one without:
 
 RGB RGB RGB RGB RGB RGB RGB RGB RGB PP
 |             rowstride              |
 |             width                |

Each letter is a byte, 
 R = red
 G = green
 B = blue
 A = alpha channel
 P = padding (rowstride - width bytes of padding at the end of each
              line, it's possible that rowstride == width if so then 
              no pad bytes are present)

So the red channel at row, column is something like:

  pixels[(row * rowstride) + column * bytes_per_pixel]

Where a pixel is an RGB or RGBA group.

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]