transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER

9 Messages Forum Options Options
Embed this topic
Permalink
BK
transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
Hi,

How is it (or is it at all) possible to load png (or other) files with
transparency (alpha) channel (RGBA pixels, a pixel can have any
transparency value not just fully opaque or fully transparent)? It
seems that EV_PIXEL_BUFFER has a set_with_named_file method but the
results look somehow strange ("half-transparent" pixels have strange
colors). I draw the loaded image on an EV_PIXMAP and then I see these
somewhat strange results.

I would like to load .png files and display these on EV_PIXMAP (or
other widgets) and use these for icons (toolbars, tree view icons,
...) in my application. These images have "partially transparent"
pixels. If nothing else works I guess iterating over the pixels in the
pixel buffer and drawing these on the pixmap could work (if loading of
the image into the EV_PIXEL_BUFFER works correct) but this solution
would be inefficient. Also to obtain real "transparent" pixmaps the
window background color could be drawn onto the pixmap blended with
the icon pixels. Again, simply creating the pixmap from the .png file
or experiments with EV_PIXEL_BUFFER did not work as expected.

(By the way, a minor problem with EiffelStudio GUI is that the icons
do not look nice on non-grey, especially dark, background.)

Balázs Kéri

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

larryliuming
Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink

>
> How is it (or is it at all) possible to load png (or other) files with
> transparency (alpha) channel (RGBA pixels, a pixel can have any
> transparency value not just fully opaque or fully transparent)? It
> seems that EV_PIXEL_BUFFER has a set_with_named_file method but the
> results look somehow strange ("half-transparent" pixels have strange
> colors). I draw the loaded image on an EV_PIXMAP and then I see these
> somewhat strange results.
>

Yes, EV_PIXEL_BUFFER can load image which contain alpha channel data.
What do you mean by the strange color of "half-transparent" pixels?
Could you give me a snapshot?

We can use EV_PIXEL_BUFFER to load an image, and then use
{EV_PIXEL_BUFFER}.to_pixmap to get an EV_PIXMAP. In this way, (if the
desktop color depth is 32bits on Windows, the EV_PIXMAP is 32bit DIB
bitmap actually), the EV_PIXMAP contain all RGBA data. However, if the
desktop color depth is less than 32bits (24bits, 16bits or...), than
Windows system will automatically convert the EV_PIXMAP to a new
bitmap which don't have alpha channel data (since desktop color depth
is not enough).

> I would like to load .png files and display these on EV_PIXMAP (or
> other widgets) and use these for icons (toolbars, tree view icons,
> ...) in my application. These images have "partially transparent"
> pixels. If nothing else works I guess iterating over the pixels in the
> pixel buffer and drawing these on the pixmap could work (if loading of
> the image into the EV_PIXEL_BUFFER works correct) but this solution
> would be inefficient. Also to obtain real "transparent" pixmaps the
> window background color could be drawn onto the pixmap blended with
> the icon pixels. Again, simply creating the pixmap from the .png file
> or experiments with EV_PIXEL_BUFFER did not work as expected.
>

Have you tried this way?

1. Load an image through EV_PIXEL_BUFFER
2. Use {EV_PIXEL_BUFFER}.to_pixmap, then you get an EV_PIXMAP
3. Draw the EV_PIXMAP on an EV_DRAWABLE.

If your desktop color depth is 32bits, the EV_PIXMAP drawn should
per-pixel alpha blended. At least, this way works very well (per-pixel
alpha blend) on my Windows system...

> (By the way, a minor problem with EiffelStudio GUI is that the icons
> do not look nice on non-grey, especially dark, background.)
>

Could you tell me the icons which not look nice exactly?

I can send you demo project if needed, my email address is
larryl@.... Please let me know if you have any comments.

Good luck~




------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

BK
Re: Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
Hi,

2008/6/18 larryliuming <larryliuming@...>:

> Yes, EV_PIXEL_BUFFER can load image which contain alpha channel data.
> What do you mean by the strange color of "half-transparent" pixels?
> Could you give me a snapshot?
>
> We can use EV_PIXEL_BUFFER to load an image, and then use
> {EV_PIXEL_BUFFER}.to_pixmap to get an EV_PIXMAP. In this way, (if the
> desktop color depth is 32bits on Windows, the EV_PIXMAP is 32bit DIB
> bitmap actually), the EV_PIXMAP contain all RGBA data. However, if the
> desktop color depth is less than 32bits (24bits, 16bits or...), than
> Windows system will automatically convert the EV_PIXMAP to a new
> bitmap which don't have alpha channel data (since desktop color depth
> is not enough).
>
> Have you tried this way?
>
> 1. Load an image through EV_PIXEL_BUFFER
> 2. Use {EV_PIXEL_BUFFER}.to_pixmap, then you get an EV_PIXMAP
> 3. Draw the EV_PIXMAP on an EV_DRAWABLE.
>
I did not tell that I am using EiffelStudio on DesktopBSD. I can try
it on Windows too but don't want to install (upgrade my previous
version) EiffelStudio only for this reason. Possibly on BSD (or Linux)
image display is different than on Windows?
I have attached a snapshot of a window produced by the following code
(a simple default EiffelVision application) (the pixmaps inserted here
are following from left to right in the window):

        build_main_container is
                        -- Create and populate `main_container'.
                require
                        main_container_not_yet_created: main_container = Void
                local
                        pixmap: EV_PIXMAP
                        pixel_buffer: EV_PIXEL_BUFFER
                do
                        create main_container

                        create pixmap
                        pixmap.set_with_named_file ("test1.png")
                        main_container.extend (pixmap)

                        create pixel_buffer
                        pixel_buffer.set_with_named_file ("test1.png")
                        create pixmap.make_with_size (100,100)
                        pixmap.draw_pixmap (0,0,pixel_buffer.to_pixmap)
                        main_container.extend (pixmap)

                        create pixmap.make_with_pixel_buffer (pixel_buffer)
                        main_container.extend (pixmap)
                ensure
                        main_container_created: main_container /= Void
                end

All the three cases have a different result but none is correct. In
the first image it looks like that there is some garbage displayed
"behind" the image (this differs at every run), so the image is
displayed correctly (with transparency) over a "garbage" background.
In the other cases the image is displayed correctly over a black
background (?) until the transparency becomes 50%, then nothing at all
is drawn. This is possibly a bug? The source code of the application
is attached, you can try how it looks on your system.
>
> Could you tell me the icons which not look nice exactly?
I have attached another snapshot, of EiffelStudio with a dark
background color (I don't use such color normally but here we can see
the icon issues). Especially at the breakpoint icons and some of the
class view icons there are white pixels at the edge.

Balazs Keri


[Non-text portions of this message have been removed]


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

larryliuming
Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
Hello, Balazs,

The images you attached seems blocked by Yahoo automatically... (The
message say [Non-text portions of this message have been removed])
Could you send them to my email (larryl@...) again?

Thanks



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

ebenss
Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
In reply to this post by larryliuming
I am having a similar problem: when I create a EV_PIXEL_BUFFER with
{EV_PIXEL_BUFFER}.set_with_named_file from an ICO file, and then
create a EV_PIXMAP using {EV_PIXMAP}.make_with_pixel_buffer or
{EV_PIXEL_BUFFER}.to_pixmap to create a pixmap, when the pixmap is
displayed the transparent pixels display as black, regardless of the
background. In the same application if I load the same file with
{EV_PIXMAP}.set_with_named_file the pixmap displays properly, with
transparency working.

ebenss
Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
Here is some code that demonstrates the problem. I am running in
Windows XP.

    test_pixmaps
        local
    l_pixmap1, l_pixmap2 : EV_PIXMAP
    l_pix_buf : EV_PIXEL_BUFFER
    do
                create
l_pixmap1.set_with_named_file("C:\install\common\icon\account.ico")
                create l_pix_buf
                l_pix_buf.set_with_named_file ("C:\install\common\icon\account.ico")
                create l_pixmap2.make_with_pixel_buffer (l_pix_buf)
                if l_pixmap1 /= Void and l_pixmap2 /= Void then
                        show_pixmaps (l_pixmap1, l_pixmap2)
                end
    end

    show_pixmaps (a_pixmap1, a_pixmap2 : EV_PIXMAP)
    local
    l_dlg : EV_DIALOG
    l_vbox : EV_VERTICAL_BOX
    l_button : EV_BUTTON
    do
    create l_dlg.make_with_title ("Test")
    l_dlg.set_size (100, 200)
    create l_vbox
    l_vbox.set_border_width (10)
    l_vbox.set_padding (10)
    l_dlg.extend (l_vbox)
    l_vbox.extend (a_pixmap1)
    l_vbox.extend (a_pixmap2)
    create l_button.make_with_text_and_action ("Ok", agent hide_dlg
(l_dlg))
    l_vbox.extend (l_button)
    l_vbox.disable_item_expand (l_button)
    l_dlg.show_modal_to_window (main_window)
    l_dlg.destroy
    end


--- In eiffel_software@..., "ebenss" <eben@...> wrote:

>
> I am having a similar problem: when I create a EV_PIXEL_BUFFER with
> {EV_PIXEL_BUFFER}.set_with_named_file from an ICO file, and then
> create a EV_PIXMAP using {EV_PIXMAP}.make_with_pixel_buffer or
> {EV_PIXEL_BUFFER}.to_pixmap to create a pixmap, when the pixmap is
> displayed the transparent pixels display as black, regardless of the
> background. In the same application if I load the same file with
> {EV_PIXMAP}.set_with_named_file the pixmap displays properly, with
> transparency working.
>


larryliuming
Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
Hi, Eben,

If you use EV_DRAWING_AREA instead of EV_PIXMAP to show the pixmap,
the problem will be fixed. The problem is actually caused by something
wrong when chaning EV_PIXMAP from memory image state to widget state.

The fixed codes changed are:

test_pixmaps
                --
        local
                l_pixmap1, l_pixmap2 : EV_PIXMAP
                l_pix_buf : EV_PIXEL_BUFFER
        do
                create l_pixmap1
                l_pixmap1.set_with_named_file("C:\install\common\icon\account.ico")
                create l_pix_buf
                l_pix_buf.set_with_named_file ("C:\install\common\icon\account.ico")
                create l_pixmap2.make_with_pixel_buffer (l_pix_buf)
                if l_pixmap1 /= Void and l_pixmap2 /= Void then
                        show_pixmaps (l_pixmap1, l_pixmap2)
                end
        end

drawing_area: EV_DRAWING_AREA
                -- Use drawing area instead of EV_PIXMAP widget

show_pixmaps (a_pixmap1, a_pixmap2 : EV_PIXMAP)
                --
        local
                l_dlg : EV_DIALOG
                l_vbox : EV_VERTICAL_BOX
                l_button : EV_BUTTON
        do
                create l_dlg.make_with_title ("Test")
                l_dlg.set_size (100, 200)
                create l_vbox
                l_vbox.set_border_width (10)
                l_vbox.set_padding (10)
                l_dlg.extend (l_vbox)
                l_vbox.extend (a_pixmap1)

-- l_vbox.extend (a_pixmap2) -- Use a EV_DRAWING_AREA to draw `a_pixmap2'
                create drawing_area
                drawing_area.set_minimum_size (80, 40)
                drawing_area.expose_actions.force_extend (agent (a_pixmap_inner:
EV_PIXMAP) do
                                                                                                                                drawing_area.clear
                                                                                                                                drawing_area.draw_pixmap (0, 0, a_pixmap_inner)
                                                                                                                        end (a_pixmap2))
                l_vbox.extend (drawing_area)

                create l_button.make_with_text_and_action ("Ok", agent l_dlg.hide)
                l_vbox.extend (l_button)
                l_vbox.disable_item_expand (l_button)
                l_dlg.show_modal_to_window (Current)
                l_dlg.destroy
        end


Hope it helps.


ebenss
Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
Larry,

Thanks for your help. Unfortunately this work around won't work for
me. My code is supplying pixmaps to higher level code which doesn't
know how the pixmap was created, so can't know when to do special
display logic. I guess I really need a fix to the widget promotion
problem.

--- In eiffel_software@..., "larryliuming"
<larryliuming@...> wrote:

>
> Hi, Eben,
>
> If you use EV_DRAWING_AREA instead of EV_PIXMAP to show the pixmap,
> the problem will be fixed. The problem is actually caused by something
> wrong when chaning EV_PIXMAP from memory image state to widget state.
>
> The fixed codes changed are:
>
> test_pixmaps
> --
> local
> l_pixmap1, l_pixmap2 : EV_PIXMAP
> l_pix_buf : EV_PIXEL_BUFFER
> do
> create l_pixmap1
> l_pixmap1.set_with_named_file("C:\install\common\icon\account.ico")
> create l_pix_buf
> l_pix_buf.set_with_named_file ("C:\install\common\icon\account.ico")
> create l_pixmap2.make_with_pixel_buffer (l_pix_buf)
> if l_pixmap1 /= Void and l_pixmap2 /= Void then
> show_pixmaps (l_pixmap1, l_pixmap2)
> end
> end
>
> drawing_area: EV_DRAWING_AREA
> -- Use drawing area instead of EV_PIXMAP widget
>
> show_pixmaps (a_pixmap1, a_pixmap2 : EV_PIXMAP)
> --
> local
> l_dlg : EV_DIALOG
> l_vbox : EV_VERTICAL_BOX
> l_button : EV_BUTTON
> do
> create l_dlg.make_with_title ("Test")
> l_dlg.set_size (100, 200)
> create l_vbox
> l_vbox.set_border_width (10)
> l_vbox.set_padding (10)
> l_dlg.extend (l_vbox)
> l_vbox.extend (a_pixmap1)
>
> -- l_vbox.extend (a_pixmap2) -- Use a EV_DRAWING_AREA to draw
`a_pixmap2'

> create drawing_area
> drawing_area.set_minimum_size (80, 40)
> drawing_area.expose_actions.force_extend (agent (a_pixmap_inner:
> EV_PIXMAP) do
> drawing_area.clear
> drawing_area.draw_pixmap (0, 0, a_pixmap_inner)
> end (a_pixmap2))
> l_vbox.extend (drawing_area)
>
> create l_button.make_with_text_and_action ("Ok", agent l_dlg.hide)
> l_vbox.extend (l_button)
> l_vbox.disable_item_expand (l_button)
> l_dlg.show_modal_to_window (Current)
> l_dlg.destroy
> end
>
>
> Hope it helps.
>


larryliuming
Re: transparent icons, EV_PIXMAP and EV_PIXEL_BUFFER
Reply Threaded More
Print post
Permalink
This bug is fixed in revision#74790 :)