X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=sdlgit%2FSDL-Site.git;a=blobdiff_plain;f=pages%2Fblog-0015.html-inc;h=2e202e79e222745e30148733ba74569908ecbd32;hp=2bd84fc7f40913acd9708e68ac8f58773c028455;hb=e785862422f3e827a242fc244bd57b23443887ce;hpb=879fff64432f43c80083c7b45da72611be9dca4b diff --git a/pages/blog-0015.html-inc b/pages/blog-0015.html-inc index 2bd84fc..2e202e7 100644 --- a/pages/blog-0015.html-inc +++ b/pages/blog-0015.html-inc @@ -1,40 +1,81 @@
In an attempt to make pixel access easier on SDL_Surface pixels. I have started work on SDLx::Surface. So far I have only start on the 32 bpp surfaces.
The general idea is to make Pointer Values (PV) of each pixel in the surface and place them into a 2D matrix. First I make pointer values like this:
SV * get_pixel32 (SDL_Surface *surface, int x, int y) +{ + //Convert the pixels to 32 bit + Uint32 *pixels = (Uint32 *)surface->pixels; + + //Get the requested pixel + Uint32* u_ptr = pixels + ( y * surface->w ) + x ; -
Next I loop through all the pixels and put them in a 2D array format, shown below:
AV * construct_p_matrix ( SDL_Surface *surface ) +{ + AV * matrix = newAV(); + int i, j; + for( i =0 ; i < surface->w; i++) + { + AV * matrix_row = newAV(); + for( j =0 ; j < surface->h; j++) + { + av_push(matrix_row, get_pixel32(surface, i,j) ); + } + av_push(matrix, newRV_noinc((SV*) matrix_row) ); + } + + return matrix; +} +
You can see the complete here.
In Perl I can do a get access on this pixel using:
my $surf32_matrix = SDLx::Surface::pixel_array($screen_surface); + print unpack 'b*', $surf32_matrix->[0][0]; # pixel value at x = 0 and y =0 +#OUTPUT: +# 11111111000000000000000000000000 +
The structure of the PV is using Devel::Peek is :
print Dump $surf32_matrix->[0][0]; +#OUTPUT: +#SV = PV(0xed0dbc) at 0xeb5344 +# REFCNT = 1 +# FLAGS = (POK,pPOK) +# PV = 0x9e04ac "\0\0\377\0" +# CUR = 4 +# LEN = 4 +
The problem is in setting the value of this pointer value. I have tried the following things with no success:
if ( SDL::Video::MUSTLOCK($screen_surface) ) { + return if ( SDL::Video::lock_surface($screen_surface) < 0 ); #required for pixel operations +} -
You can see an example here.
Any help will be greatly appreciated.
+ \ No newline at end of file