Re: How to render 8-bit raster graphics
Michael J M Thomson <[email protected]> Mon, 17 Jan 2005 15:14:20 +1100
| Newsgroups | gmane.comp.gnome.gnomemm,gmane.comp.gnome.gtkmm |
|---|---|
| Organization | Little, if any. |
| Message-ID | <[email protected]> |
Janet Mini wrote:
> Hello all,
>
> I'm new to gtkmm.
> I have some 8-bit grayscale images that I want to display in a gtkmm
> application.
> I want to display them as a sequence of frames as an animation like a
> movie playback.
> And I will also add some texts on top of the animation.
>
> Does anybody have any good idea how to do it properly with performance
> (speed)?
>
> Shall I use the gnome canvas widget?
> I tested that I could use a look up table and duplicate my 8-bit data
> for each of the RGB channel and create a RGB pixbuf.
> But is it possible that I use the grayscale visual and display just my
> 8-bit grayscale images on the canvas instead of using RGB?
>
> Thank you in advance for any help and suggestion.
>
> Regards,
> Janet
Gdk::Pixbuf will load data from most file formats for you, converting as it
goes from whatever depth to its RGB[A] colorspace using optimized C and lookup
tables and such (looks the same as XFree's code actually). I'd go with letting
pixbufs do this work for you, rather than bothering with grayscale or 8-bit
visuals (which aren't always available or are done in software by X anyway).
It's then easy to render your pixbufs to say a Gtk::DrawingArea (a canvas for
just one image at a time is overkill), with
da.get_window()->draw_pixbuf(da.get_style()->get_bg_gc(0), pixbufs[i], ...)
Rendering into pixbuf isn't the API's strong suit though, maybe just draw your
pixbuf to the window first, then e.g. a Pango::Layout separately after that for
the text, with da.get_window()->draw_layout(...).
Draw each frame of the animation from a Glib::signal_timeout() callback (don't
worry about handling drawingarea exposes, double buffering will take care of
it), and there you are.
--
Michael J M Thomson
main(){int/* gcc m.c -o matrix */i=0,j,s[40]={0,},l[40];for(;;){s[i]||(l[i]=s[i
]=rand()%10);for(j=0;j<25;++j){printf("\x1b[%d;%dH\x1b[%sm%c",s[i]+j,i*2+1,j<l[
i]?(l[i]==j+1?"1;37":(l[i]-j<3?"0;37":(l[i]-j<6?"1;32":(l[i]-j<16?"0;32":(l[i]-
j<21?"1;30":"0;30"))))):"",j<l[i]?rand()%93+33:32);}s[i]*=++l[i]<25;i=++i%40;}}