Very confused with pixbufs, pixmaps, images, rgbs and drawables

2005-08-08 Thread Chris Seaton
I want to be pragmatically creating some off screen images, just some 
text rendering. I'm not using Gtk+ for this part of the application.
I have a vague idea I want to create either a GdkPixmap or a GdkImage, 
do my rendering using the base GdkDrawable, and then call 
gdk_pixbuf_get_from_drawable to convert to a GdkPixbuf to access 
individual pixels. How do I choose between GdkImage and GdkPixmap? Both 
of them are drawables (inherit from GdkDrawable).


The names are really really confusing. I know the difference between 
GdkPixmap and GdkPixbuf, but the names seem completely arbitary! If you 
switched the names you could still argue they made sense. How about 
GdkClientPixmap and GdkServerPixmap? GtkImage - that sounds like it 
should be the base class of all image classes, but it's something else 
entirely! And then there's GdkRGB!


GdkPixmap - server side pixel map
GdkBitmap - server side pixel map, 1bpp
GdkPixbuf - client side pixel map
GdkImage - not really sure, but it says it's redundant to GdkRGB
GdkRGB - seems to render raw pixel data from a simple pointer

Is that right? Please set me straight. What are they all for? And which 
do I want to solve my problem in the first paragraph?


Chris Seaton
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: Very confused with pixbufs, pixmaps, images, rgbs and drawables

2005-08-08 Thread Chris Seaton

Great. Thanks for the clarification.

If these names (any many of the classes themselves) are only around 
because of the history of X, when are we planning to update them? At the 
moment the entire architecture of the image system in Gdk reflects the 
history of one supported platform. That can't be good.


Chris

John Cupitt wrote:

A lot of the names come from Xlib and ancient history.

On 8/8/05, Chris Seaton <[EMAIL PROTECTED]> wrote:


GdkPixmap - server side pixel map
GdkBitmap - server side pixel map, 1bpp



Bingo! Exactly right. Names from X history. Bitmap was the original,
pixmap was added later when the first colour displays appeared. They
are close to the hardware, so they have a bunch of extra stuff like
visuals and colormaps associated with them.



GdkPixbuf - client side pixel map



The big thing here is that pixbuf is not so close to the hardware.
It's just a 24 bit RGB buffer (they have some hooks for other colour
spaces, but I don't know if there are plans to add them).

Pixbuf is a nice clean (fairly) high level API added by the gtk team
that hides client-side complexity from you.



GdkImage - not really sure, but it says it's redundant to GdkRGB



XImage is what used to be used for client-side images. It is close to
the hardware and changes annoying between different displays. Just
awful to work with, avoid it if you possibly can.



GdkRGB - seems to render raw pixel data from a simple pointer



This is (sort of) the thing GdkPixbuf uses to hide the insides of
GdkImage from you. You can (sometimes) get a little speed by using it
directly, but usually you should go through GdkPixbuf.



Is that right? Please set me straight. What are they all for? And which
do I want to solve my problem in the first paragraph?



Summary: use GdkPixbuf client-side and GdkPixmap server-side.



___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: [Rhythmbox-devel] Longer seek control

2005-08-11 Thread Chris Seaton

Christophe Fergeau wrote:

A longer seek slider in the main UI looks really ugly, especially since
there probably are not many people using it. A pop-up window which can
be triggered through a keyboard shortcut or a menu entry containing a
longer slider and a way to enter a specific time using the keyboard
might be better.


Ugly? That's how every other media player I can think of works. Plus in
most Gnome apps the controls resize to fill the window. Why does
Rhythmbox do it differently?

Chris

___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Getting an alpha channel from text rendering

2005-08-11 Thread Chris Seaton

Hello everyone,

I need to render text into a pixbuf, getting the alpha channel of the rendered
text as well as just the colour.

I can't see any way to do this simply, as pixmaps don't have an alpha channel.
You can blend into them, but they don't store alpha. When I render a Pango
layout into one I get the text blended onto the background colour.

Currently I'm rendering into one pixmap with colour, then rendering into
another with black and white and then copying those black and white values into
my pixbuf's alpha channel, and the colour I'm just copying straight across.

I've included my code below as it's very simple and I think quite readable.

Is there a better way to do this?

Ideally I'd like the same effect as if I'd rendered using SDL_ttf with the
blended function, if that means anything to anyone.

My results are a little messy due I think to sub pixel anti aliasing, and
rendering everything twice is not ideal. I don't want to go too low level with
Pango if that can be avoided.

Thanks for your time.

Chris

Texture::Texture(Glib::ustring text, Colour colour, int size)
{
/*
This is a little complicated because I can't see a way to render text
with an alpha channel.

We render twice, once in colour and then again in black and white. The
latter is then used as the alpha channel when creating a finished
pixbuf with alpha channel.
*/

// Create Pango context and layout

Glib::RefPtr context = Glib::wrap(gdk_pango_context_get());
g_assert(context);

Glib::RefPtr layout = Pango::Layout::create(context);
g_assert(layout);

// Measure

Glib::ustring basic_text = "" + text + 
"";

layout->set_markup(basic_text);

int width;
int height;

layout->get_pixel_size(width, height);

// Render the beauty pass

layout->set_markup("" + basic_text + 
"");

Glib::RefPtr beauty_pass_pixmap = 
Gdk::Pixmap::create(Glib::RefPtr(NULL), width, height, 24);
g_assert(beauty_pass_pixmap);

beauty_pass_pixmap->draw_layout(Gdk::GC::create(beauty_pass_pixmap), 0, 0, 
layout);

Glib::RefPtr beauty_pass_pixbuf = 
Gdk::Pixbuf::create(Glib::RefPtr(beauty_pass_pixmap), 
beauty_pass_pixmap->get_colormap(), 0, 0, 0, 0, width, height);
g_assert(beauty_pass_pixbuf);

// Render the mask pass

layout->set_markup("" + basic_text + 
"");

Glib::RefPtr mask_pass_pixmap = 
Gdk::Pixmap::create(Glib::RefPtr(NULL), width, height, 24);
g_assert(mask_pass_pixmap);

mask_pass_pixmap->draw_layout(Gdk::GC::create(mask_pass_pixmap), 0, 0, 
layout);

Glib::RefPtr mask_pass_pixbuf = 
Gdk::Pixbuf::create(Glib::RefPtr(mask_pass_pixmap), 
mask_pass_pixmap->get_colormap(), 0, 0, 0, 0, width, height);
g_assert(mask_pass_pixbuf);

// Create a pixbuf to contain the composite of the two passes

Glib::RefPtr pixbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, 
true, 8, width, height);
g_assert(pixbuf);

// Copy in colour from the beauty pass and alpha from the mask pass

for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
guint8 red;
guint8 green;
guint8 blue;

get_pixel(beauty_pass_pixbuf, x, y, &red, &green, &blue, NULL);

guint8 alpha_red;
guint8 alpha_green;
guint8 alpha_blue;

get_pixel(mask_pass_pixbuf, x, y, &alpha_red, &alpha_green, 
&alpha_blue, NULL);

guint8 alpha = (alpha_red + alpha_green + alpha_blue) / 3;

set_pixel(pixbuf, x, y, red, green, blue, alpha);
}
}

// Create the texture from that

create(pixbuf);
}
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: scribble with background image

2005-08-15 Thread Chris Seaton

Morton Cody wrote:
I am developing a GUI app in Linux to draw arbitrary shapes on a 
background image. It's just like the scribble tutorial, with the 
addition that I want to set a jpeg image as the background, and then 
draw on it.
 
The tutorial uses a DrawingArea widget. The user is completely 
responsible for drawing the  contents of this widget. What would I need 
to do to set an image as the background. Is there some other widget to 
be used for this ?


Yeah, you want to be using the GtkDrawingAreaWithAJPEGAsABackground 
widget...


Just load the JPEG into a pixbuf (gdk_pixbuf_new_from_file), and render 
the pixbuf into the drawing area before the user starts to scribble 
(gdk_draw_pixbuf(widget->window, NULL, my_pixbuf...)). How much more 
obvious could it be?


Chris Seaton
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: Menu bar doesn't use Theme

2005-08-28 Thread Chris Seaton
It looks like your application is using Gtk 1.x. Notice how the text is 
not antialised in your program, but it is in the other. Make sure all 
your calls to pkg-config or whatever are refering to version 2.


Chris Seaton

Wolfgang Meyerle wrote:

Hi,

I wanted to program a little cd-burning application with most of the 
functionality like k3b because I'm missing such an application in gnome.
As I'm a beginner in gtk programming I wonder why all other gtk+ 
applications show me my theme as menu background and my application not.

You can see this by watching the icluded images.
Image of an application where menu's are working with themesImage of my 
application where things don't work with menu's


What do I have to do to make this working?

___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: Trying to draw text on a pixbuf

2005-09-10 Thread Chris Seaton

I was doing this a while ago.

Specifically, I was using Pango to create text for OpenGL textures, but 
I needed to have rendered text with an alpha channel to do that, just 
like you do.


Pango is pretty shit in that it won't (as far as I can tell) render an 
alpha channel. I mean how basic is that?


You can't just render onto a black background and then set black to be 
transparent, as remember that the text could be antialised.


What I did was to render white text on a black background into a pixbuf, 
add an alpha channel (there's a function for that) then itterate through 
each pixel in the pixbuf, copying the red channel into the alpha channel 
(remember we rendered white on black, so the text will be opaque and the 
background transparent), and then setting the red green and blue 
channels to be whatever colour I wanted.


You can then render that pixbuf.

There will be some very slight artifacts does to sub pixel 
antialisiaing, so I wouldn'e be writing GIMP's text tool using this. 
Anyone not knowledgeable about antialiasing will probably not notice it 
though.


Chris

Frédéric Terraza wrote:

Hello,

this is my first post ever on a mailing-list, I hope I'm doing it the 
right way. My apologies if not so.


I'd like to draw text on a pixbuf. I first tried :
- to write text in a PangoLayout
- to render the layout in a pixmap
- to copy the pixmap in the pixbuf

It worked, but the text has a black background that overlap the 
previously drawn things on the pixbuf. And I can't change the background 
color (with a gdk_gc_set_background for example).


So, I tried :
- to render the pixmap in a temporary pixbuf
- to add alpha to this pixbuf, making black become transparent
- to copy this temporary pixbuf in my final pixbuf.

Same results. And I don't know why.

Maybe alpha isn't taken into account by gdk_pixbuf_copy_area ? If so, I 
suppose it's not too hard to make another version of this primitive 
doing that (but slow).
And since it bothers me to have black as background color (what will I 
do if the foreground color is also black ? It may happen with text), do 
you have an idea for how to change the background color ?


Thanks in advance. And excuse my english, school is far away now...

Fred
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list



___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: Trying to draw text on a pixbuf

2005-09-10 Thread Chris Seaton
Well I did get it working just fine, so I know it's possible. I'd show 
you my code if I hadn't binned it. It was quite succint as well, now I 
think about it.


It looks like you're accessing the pixbuf pixels wrong somehow. I can't 
see what it is.


Try dumping the pixbuf to the console before you starting messing with 
it. That part of the code might be in error.


Frédéric Terraza wrote:

Thanks for your answer. It is much uneasy than I thought.

I wrote that, thinking I was following your advices, but I got such 
weird results that I think I missed something :


void gdk_pixbuf_draw_text( GdkPixbuf *pixbuf, GtkWidget *widget, gchar 
*text, int x, int y) {

 GdkPixmap *temp_pixmap ;
 GdkPixbuf *temp_pixbuf ;
 PangoLayout *layout ;
 GdkGC *gc ;
 GdkColormap *cmap ;
 int sx, sy ;
 int i, j, rowstride ;
 guchar *pixels, *p ;

 /* render layout to temp_pixmap */
 layout = gtk_widget_create_pango_layout(widget, text) ;
 pango_layout_get_pixel_size(layout, &sx, &sy) ;
 temp_pixmap = gdk_pixmap_new(NULL, sx, sy, 24) ;
 gc = gdk_gc_new(temp_pixmap) ;

 gdk_gc_set_foreground(gc, base->white) ;
 gdk_gc_set_background(gc, base->black) ;
 gdk_draw_layout( temp_pixmap, gc, 0, 0, layout) ;

 /* render temp_pixmap to temp_pixbuf */
 cmap = gdk_colormap_get_system() ;
 temp_pixbuf = gdk_pixbuf_get_from_drawable(NULL, temp_pixmap, cmap, 0, 
0, 0, 0, sx, sy) ;


 /* add alpha and modify it */
 gdk_pixbuf_add_alpha(temp_pixbuf, FALSE, 0, 0, 0) ;  rowstride = 
gdk_pixbuf_get_rowstride(temp_pixbuf) ;

 pixels = gdk_pixbuf_get_pixels(temp_pixbuf) ;
 p = pixels ;

 printf("begin loop (%i, %i)\n", sx, sy) ;
 for (j=0 ; jHere's what I get on my console when calling  
gdk_pixbuf_draw_text(pixbuf, drawing_area, "aze", 10, 20) ; :


begin loop (21, 16)
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00
80 80 80 80 80 00 ff ff ff ff 00 00 ff ff ff 00 00 ff 00 00 ff
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff
80 80 80 80 80 00 00 00 ff 00 00 00 ff ff ff 00 00 ff 00 00 ff
80 80 80 80 80 00 00 ff 00 00 00 00 00 00 00 00 00 ff 00 ff ff
80 80 80 80 80 00 00 ff 00 00 00 00 00 00 00 00 00 00 ff 00 ff
80 80 80 80 80 00 ff ff ff ff 00 00 ff ff ff 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 a9 70 00 00 00
end loop

My pixels pointer doesn't seem to point the beginning of my pixbuf, 
since the "ff" are more or less looking like "zea" and not "aze".

Also, I don't understand where these weird "80" comes from.
Curiouser, if I change "p[3] = p[0]" to "p[3]=p[1]" or "p[3]=p[2]", the 
results are quite different (but I can see the "zea"), whereas I'd have 
thought that all channels would be the same, since I use white as 
foreground color.
Last, the "graphics" results are awful. I can hardly recognize the "aze" 
(but it's "aze", not "zea").


I'm quite upset. There are too much weird things for blaming GTK. It 
must be my fault, but I don't see...




Chris Seaton a écrit :


I was doing this a while ago.

Specifically, I was using Pango to create text for OpenGL textures, 
but I needed to have rendered text with an alpha channel to do that, 
just like you do.


Pango is pretty shit in that it won't (as far as I can tell) render an 
alpha channel. I mean how basic is that?


You can't just render onto a black background and then set black to be 
transparent, as remember that the text could be antialised.


What I did was to render white text on a black background into a 
pixbuf, add an alpha channel (there's a function for that) then 
itterate through each pixel in the pixbuf, copying the red channel 
into the alpha channel (remember we rendered white on black, so the 
text will be opaque and the background transparent), and then setting 
the red green and blue channels to be whatever colour I wanted.


You can then render that pixbuf.

There will be some very slight artifacts does to sub pixel 
antialisiaing, so I wouldn'e be writing GIMP's text tool using this. 
Anyone not knowledgeable about antialiasing will probably not notice 
it though.


Chris






___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Point of GtkDrawingArea?

2005-09-14 Thread Chris Seaton
What's the point of GtkDrawingArea? I want to write my own widget, and 
the docs say that's what GtkDrawingArea is for, but what does 
subclassing it add over just subclassing GtkWidget?


I looked at the source code in gtkdrawingarea.c and there's less than a 
screen of code! What's the point of this class? Is subclassing it the 
correct thing to do when writing your own widget?


Thanks

Chris Seaton
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Default mono space font?

2005-09-16 Thread Chris Seaton
Many Gtk applications such as gnome-terminal refer to a default mono 
space font. My Gnome desktop has an applet to set these default fonts, 
but the Gtk style object only has one default font.


Where do I get the default mono space font from?

Thanks

Chris Seaton
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Scrolling widget tutorial

2005-09-17 Thread Chris Seaton
What's the point of the two integer values in GtkWidgetClass, 
activate_signal and set_scroll_adjustments_signal? Why aren't these just 
implemented as function pointers like realize, expose_event and so on? 
What's special about them?


Thanks

Chris Seaton
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list