Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: with create a surface from my own RGBA data

7 views
Skip to first unread message

agraham

unread,
Apr 3, 2012, 4:12:13 PM4/3/12
to sdl-...@perl.org, agr...@g-b.net
Hi Guys,

I am a complete Perl-SDL "newbie" and have spent a few days reading the
docs on CPAN perl-SDL. I'm using version 2.536.

I would like to create a surface from my own RGBA data and there seems
to be no way to do that unless you do it a pixel at a time :(

I am trying to hack Net::VNC so that it uses SDL:: instead of
Image::Imlib2, so for example:

The "raw encoding" from Net::VNC does this:

$socket->read( my $data, $w * $h * 4 );
my $raw = Image::Imlib2->new_using_data( $w, $h, $data );
$raw->has_alpha(0);
$image->blend( $raw, 0, 0, 0, $w, $h, $x, $y, $w, $h );

I need to replicate the above in perl-SDL

There is an map_RGBA function which maps 1 pixel, but not a bunch of
them, so you can do:

$dpixel=SDL::Video::map_RGBA( $display->format, 0, 0, 255);

but not this:

$dpixel=SDL::Video::map_RGBA( $display->format, $data);
SDL::Video::fill_rect( $surface, $srect, $dpixel );

I tried using SDL::RWOps as follows:

$rw = SDL::RWOps->new_const_mem( $data);

but I don't know how to get $rw into the surface!

and
$surface = SDL::Image::load( $rw );
does not work.

Any help would be much appreciated.

Albert

Tobias Leich

unread,
Apr 5, 2012, 1:02:12 PM4/5/12
to agr...@g-b.net, sdl-...@perl.org
Hi, do you know the pixel format of the data you have?

Do you get scanlines that you wanna pass to an SDL::Surface? Or do you
get just the whole image?

May I invite you to irc? Would be much easier than mails... #sdl at
irc.perl.org.

Cheers, FROGGS

agraham

unread,
Apr 5, 2012, 4:04:14 PM4/5/12
to Tobias Leich, sdl-...@perl.org
On 04/05/2012 06:02 PM, Tobias Leich wrote:
> Hi, do you know the pixel format of the data you have?
>
> Do you get scanlines that you wanna pass to an SDL::Surface? Or do you
> get just the whole image?
>
> May I invite you to irc? Would be much easier than mails... #sdl at
> irc.perl.org.
>
> Cheers, FROGGS
>

Hi FROGGS,

I was on IRC and got a lot of help, thank you.

The data is RAW BGR/RGB or RGBA data from the network i.e. VNC rectangle
packets.

The problem I had was it was not obvious how to put this "raw" data into
a surface so that it could be blitted.

The solution (thanks to Scott Walters) was to get the get_pixels_ptr and
fill the area of the surface directly as follows:

$pixels_ptr=$surface->get_pixels_ptr();
substr $$pixels_ptr, 0, length($data), $data;

# $data=raw RGB data.

I hope this information helps others.

Albert




Kartik Thakore

unread,
Apr 5, 2012, 4:24:10 PM4/5/12
to agr...@g-b.net, sdl-...@perl.org, Tobias Leich
Cool! Thats great. Can't wait to see the results. Be sure to do an update()
based on the rect given.
On Apr 5, 2012 4:04 PM, "agraham" <agr...@g-b.net> wrote:

> On 04/05/2012 06:02 PM, Tobias Leich wrote:
>
>> Hi, do you know the pixel format of the data you have?
>>
>> Do you get scanlines that you wanna pass to an SDL::Surface? Or do you
>> get just the whole image?
>>
>> May I invite you to irc? Would be much easier than mails... #sdl at
>> irc.perl.org.
>>
>> Cheers, FROGGS
>>
>>
> Hi FROGGS,
>
> I was on IRC and got a lot of help, thank you.
>
> The data is RAW BGR/RGB or RGBA data from the network i.e. VNC rectangle
> packets.
>
> The problem I had was it was not obvious how to put this "raw" data into a
> surface so that it could be blitted.
>
> The solution (thanks to Scott Walters) was to get the get_pixels_ptr and
> fill the area of the surface directly as follows:
>
> $pixels_ptr=$surface->get_**pixels_ptr();
0 new messages