copying pixmap pieces

14 views
Skip to first unread message

r...@amalasoft.com

unread,
Apr 4, 2020, 8:35:56 AM4/4/20
to Eiffel Users Group
Hi All
I hope you and yours are safe, well, and at home.

I'm playing around with pixmaps, pixel buffers and the like and can't seem to find a way to copy or capture a shaped region from an existing pixmap or pixel buffer.  The shape I need to copy would be irregular and not always the same thing, so a rectangle copy (by itself) doesn't suffice.  I can create a pixmap with the shape I want, and can locate it in the right position, but that's about it.  I don't want to modify the original (source) pixmap but I could make a wholesale copy of that if the necessary operation is destructive of course.
Any suggestions using just EV_* functions?
Thanks
R

Karsten Heusser

unread,
Apr 5, 2020, 3:20:54 PM4/5/20
to Eiffel Users
Maybe the following example is helpful.
Although the source (pixel_buffer_colored_radiation) has rectangular shape
its appearance on a target pixmap depends on its pixels' alpha values.
In this case one third of the pixmap is completely transparent white.
With the target pixmap set to 'copy mode' (target_pixmap.set_copy_mode)
- source pixmaps with pixel buffers and
- source pixel buffers
drawn onto the target look the same.

    target_pixmap.set_copy_mode -- Should be the default.
    target_pixmap.draw_sub_pixel_buffer (
        100, 100,
        pixel_buffer_colored_radiation,
        pixel_buffer_colored_radiation.area
    )
    target_pixmap.draw_pixmap (
        200, 200,
        pixel_buffer_colored_radiation.to_pixmap
    )


    pixel_buffer_colored_radiation: EV_PIXEL_BUFFER
            -- 100 x 100 pixel buffer with completely transparent parts.
            --
            -- Appearance:
            --
            --              OOOOOO
            --         OOOOOOOOOOOOOOOO            [r]ed
            --          OOOOOO r OOOOO             [g]reen
            --             OOOOOOOOOO              [b]lue
            --             OOOOOOOO                [a]lpha = 0 (full transparency)
            --        a     OOOOOO     a
            --                OO
            -- OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
            -- OOOOOOOOOOOOOOO  OOOOOOOOOOOOOOO
            --  OOOOO g OOOOO    OOOOO b OOOOO
            --   OOOOOOOOOO   a    OOOOOOOOOO
            --     OOOOOOO          OOOOOOO
            --       OOOO            OOOO
            --         O              O
        local
            l_iterator: EV_PIXEL_BUFFER_ITERATOR
            l_brightness: INTEGER
        do
            create Result.make_with_pixmap (pixmap_colored_radiation)
            Result.lock
            l_iterator := Result.pixel_iterator

            from
                l_iterator.start
            until
                l_iterator.after
            loop
                l_brightness := (
                    l_iterator.item.red.to_integer_32 +
                    l_iterator.item.green.to_integer_32 +
                    l_iterator.item.blue.to_integer_32
                )

                if l_brightness > 500 then
                    l_iterator.item.set_alpha (0)
                            -- Could be much more elaborated
                            -- with e.g. transparency gradients.
                end

                l_iterator.forth
            end

            Result.unlock
        end

    pixmap_colored_radiation: EV_PIXMAP
            -- 100 x 100 radiation symbol with 3 different colors
            -- on white background.
            --
            -- Note: `pixel_buffer_colored_radiation' is a companion
            --       with total transparency instead of white.
            --
            --
            --              OOOOOO                 [w]hite
            --         OOOOOOOOOOOOOOOO            [r]ed
            --          OOOOOO r OOOOO             [g]reen
            --             OOOOOOOOOO              [b]lue
            --             OOOOOOOO                [a]lpha (not used)
            --        w     OOOOOO     w
            --                OO
            -- OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
            -- OOOOOOOOOOOOOOO  OOOOOOOOOOOOOOO
            --  OOOOO g OOOOO    OOOOO b OOOOO
            --   OOOOOOOOOO   w    OOOOOOOOOO
            --     OOOOOOO          OOOOOOO
            --       OOOO            OOOO
            --         O              O
        local
            pi: REAL_32
            angle: REAL_32
        do
            create Result.make_with_size (100, 100)
                    -- Background is white by default.
            pi := 3.1416

            angle := -pi/3.0

            across 1 |..| 3 as cur loop
                angle := angle + pi/1.5

                inspect
                    cur.item
                when 1 then
                    Result.set_foreground_color (
                        create {EV_COLOR}.make_with_rgb (1.0, 0.0, 0.0)
                    )
                when 2 then
                    Result.set_foreground_color (
                        create {EV_COLOR}.make_with_rgb (0.0, 1.0, 0.0)
                    )
                when 3 then
                    Result.set_foreground_color (
                        create {EV_COLOR}.make_with_rgb (0.0, 0.0, 1.0)
                    )
                end

                Result.fill_pie_slice (0, 0, 100, 100, angle, pi/3.0)
            end -- across
        end

Best,
Karsten

r...@amalasoft.com

unread,
Apr 6, 2020, 7:25:51 AM4/6/20
to eiffel...@googlegroups.com
Hi Karsten

That looks like it might work.  Might have a chance to try it later today.
Of course, I was hoping for something like pixel_buffer.do_whatever_I_want, but ... :)
Thanks!
R
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/ae15d36e-b089-4deb-93e7-60d1e16772df%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages