|
|
> Zoltan Phelps wrote:
>
> >>
> >> On 16 Mar 2008, at 22:31, Zoltan Phelps wrote:
> >>
> >> > I searched the forum but didn't find any suitable thread.
> >> > In my application i would like to show two images, one "original"
> >> > version and one "altered" version (e.g. after LUT conversion).
> >> > My question is - how can i access the pixel data of an Fl_RGB_Image
> >> > directly? The source code reveals only the "const char * const *data
> >> > ();" member function but as it is constant i'm not able to change
> >> > anything. Is there another suitable way? Or is it better to just
> >> > keep an unsigned char array with the pixel data, change it as
> >> > desired and redraw it with the fl_draw_image function without
> >> > creating any Fl_()_Image object? I'm a bit confused because with
> >> > different libraries i used to create an image object and to alter
> >> > its pixel data there had always been an access member function.
> >> > Thanks in advance!
> >>
> >> http://www.fltk.org/articles.php?L466
> >>
> >> http://www.fltk.org/articles.php?L468
> >>
> >>
> >>
> >
> > Hey, these two links are a great help! Thanks a lot, that was what i've
> > been looking for.
>
> Just a tip. Fl_Image::data() returns an _array_ of image buffers. I've
> forgotten this a few times and spent far too long in a debugger trying to
> figure out why I was getting segfaults.
>
> For example,
>
> Fl_Shared_Image *img = Fl_Shared_Image::get("somepic.png");
>
> const char *img_data = img->data();
>
> That is wrong if you try to access the pixel values in img_data. Doing so
> will eventually segfault.
>
> The correct way is:
>
> const char *img_data = img->data()[0];
>
> Another tip, after manipulating img_data, use Fl_Image::uncache() before
> calling redraw() on the widget. Again, I spent far too long in a debugger
> when my changes to img_data were not being displayed. I think this applies
> only if you display img before you manipulate the pixels though.
>
> --
> Alvin
Thanks for the hints, i studied the sources of Fl_Image.* and found that uncache() thing already inside the desaturate() or color_average() functions.
That img->data() returns a char array wasn't clear until i read the articles #466 and #468. Since i'm only using the Fl_RGB_Image class i found an easier way by just typing
unsigned char * pixels = (unsigned char *) img->array;
because array is a public pointer to the pixel data. (Is that good coding style? ;))
ZP
[ Direct Link to Message ] | |
|
| |