CAIRO_ARGB32 is the right colorspace

On Sun, Apr 12, 2009 at 10:12 AM, Dov Grobgeld <[email protected]>wrote:

> Regarding the gtk-list subscription, see:
>
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
> for details.
>
> About the strange colors, it is most likely that your pixbuf has an alpha
> channel, which is different from my tutorial example where I hardcoded the
> assumption that GtkImageViewer always passes a 24-bit pixbuf in the annotate
> signal. If you use alpha channel, then you should use
> cairo_image_surface_create_for_data with CAIRO_FORMAT_ARGB32 instead. I'm
> not sure whether it is enough for to switch R and B in such a case though.
> Check the documentation or just check if it works.
>
> Regards,
> Dov
>
> 2009/4/12 Eduardo J. Andres <[email protected]>
>
>> Hello Dov,
>>
>> Thanks fo the answer.
>> I am trying to know how to reply you by the gtk-list, but even I have done
>> my suscription to it, I do not know yet how to do it, therefore, I write you
>> again to same "gmail". Would you be able to explain me how to reply you
>> there.
>>
>> I shall look to the giv code, but in the meantime, I have seen that it is
>> not an issue with your software/widget, it is the same with GtkImageView,
>> for example. I would like to note you at that point that I am doing all my
>> testing under XP.
>>
>> So, if you have a pixbuf on a widget (whatever the widget may be), and you
>> make a cairo_surfacet_t from that pixbuf, when you draw with cairo to the
>> surface, you alway lose the color and get a line or arc with strange
>> effects.
>>
>> That´s what I would like to know, why??
>>
>> Best regards
>> Eduardo
>>
>> 2009/4/12 Dov Grobgeld <[email protected]>
>>
>> Hello Eduardo,
>>>
>>> Thanks for the feedback.
>>>
>>> Regarding the drawing of polygons, I have had the same problem and the
>>> solution I made is outside the GtkImageViewer. Please download my program
>>> giv at giv.sf.net and have a look at the the pair of files
>>> giv_backstore.[ch] that provide a way of quickly storing all the information
>>> under a line and then restoring it. By tieing it to the button press and
>>> motion events it is possible to get a rubberband effect with only minimal
>>> flicker. (I'm considering a rewrite that eliminates flicker all together).
>>> See giv's use of it for details. (I agree it is also worthy of a tutorial.
>>> We'll see if I'll get around to it.)
>>>
>>> Once you have a fixed line of the polygon, I add it to the lines drawn by
>>> the annotate callback, since update time is no longer an issue.
>>>
>>> Regarding why your example doesn't work, I don't know, but it might have
>>> to do with the fact that you fix the pixbuf format to RGB24 without checking
>>> whether your pixbuf has an alpha channel.
>>>
>>> Good luck!
>>>
>>> Also, next time, please send the questions to the gtk-list. I take the
>>> freedom of CC:ing it.
>>>
>>> Regards,
>>> Dov
>>>
>>> 2009/4/10 Eduardo J. Andres <[email protected]>
>>>
>>> Dear Dov
>>>>
>>>> I have been working with the widget during last days and have had  not
>>>> success to get my requirement.
>>>>
>>>> It is to draw with cairo and the mouse  poligons and lines as overlay of
>>>> the image pixbuf. Poligons will have a lot of points so the best aproach I
>>>> have seen is to draw them on the pixbuf an draw the new pixbuf to the 
>>>> image.
>>>> But it is so slow doing it on the "image_annotate" handler.
>>>>
>>>>  I have seen a number of issues at that point, for example the idea to
>>>> get the cairo surface from your tutorial
>>>>
>>>> int img_width = gdk_pixbuf_get_width(pixbuf);
>>>>
>>>>
>>>>
>>>>
>>>>   int img_height = gdk_pixbuf_get_height(pixbuf);
>>>>
>>>>
>>>>
>>>>
>>>>   cairo_surface_t *surface
>>>>     = cairo_image_surface_create_for_data(gdk_pixbuf_get_pixels(pixbuf),
>>>>
>>>>
>>>>
>>>>
>>>>                                           CAIRO_FORMAT_RGB24,
>>>>                                           img_width,
>>>>                                           img_height,
>>>>
>>>>
>>>>
>>>>
>>>>                                           
>>>> gdk_pixbuf_get_rowstride(pixbuf));
>>>>
>>>>
>>>>
>>>>
>>>>   cairo_t *cr = cairo_create (surface);
>>>>
>>>>
>>>>
>>>>
>>>>   cairo_translate(cr, -shift_x, -shift_y);
>>>>
>>>>
>>>>
>>>>
>>>>   cairo_scale(cr, scale_x, scale_y);
>>>>
>>>>
>>>>
>>>>
>>>>   // Now do any cairo commands you want, but you have to swap
>>>>   // R and B in set_source_rgba() commands because of cairo and
>>>>
>>>>
>>>>
>>>>
>>>>   // pixbuf incompabilitities.
>>>>   cairo_set_source_rgba (cr, 0,0,1.0,0.5);
>>>>
>>>>
>>>>
>>>>
>>>>   cairo_arc(cr,
>>>>             -1, 0,
>>>>
>>>>
>>>>
>>>>
>>>>             3, 0.0, 2*G_PI);
>>>>
>>>>
>>>>
>>>>
>>>>   cairo_fill(cr);
>>>>
>>>>   cairo_set_source_rgba (cr, 1.0,0,0,0.5);
>>>>
>>>> only works when you do inside the image annotate. In any other
>>>> situation, the cairo drawing does not get the color. I have got, for
>>>> example, the cairo surface from the pixbuf inside the 
>>>> gtk_image_viewer_new()
>>>> function and draw directly there , but it gets a wrong color. It doesn´t
>>>> matter the swapping in betweem the R and B colors. On the attached image,
>>>> the rect line is has been drawn direcly with the code above, inside the the
>>>> new() function. The symbol, drawnd on the GtkImageViewer->window, inside
>>>> gtk_image_viever_expose().
>>>>
>>>> Would you be kind to indicate me any sugesstion how to do it.
>>>>
>>>> Thanks
>>>> Eduardo
>>>>
>>>
>>>
>>
>
> _______________________________________________
> gtk-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
>


-- 
Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.
[Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung zufolge
jeder elektronische Kontakt mit mir sechs Monate lang gespeichert wird.]
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to