X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pages%2Fblog-0002.html-inc;h=317d824280cf826a66265ec0842be5fb27b9d59c;hb=6855e5615bff699e656bdd67be71ac965fc77f54;hp=2e202e79e222745e30148733ba74569908ecbd32;hpb=ca0a3441dd72000cbbbb4be484b18d0d305fdb29;p=sdlgit%2FSDL-Site.git diff --git a/pages/blog-0002.html-inc b/pages/blog-0002.html-inc index 2e202e7..317d824 100644 --- a/pages/blog-0002.html-inc +++ b/pages/blog-0002.html-inc @@ -1,81 +1,78 @@

-Providing direct memory access to SDL_Surface's pixels +Grant Progess Reports 1-3: Sept - Nov

-

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 ; 
-
-        SV* sv = newSVpv("a",1); //Make a temp SV* value on the go
-        SvCUR_set(sv, sizeof(Uint32)); //Specify the new CUR length
- SvLEN_set(sv, sizeof(Uint32)); //Specify the LEN length
-        SvPV_set(sv,(char*)u_ptr); // set the actual pixel's pointer as the memory space to use
-
- return sv; //make a modifiable reference using u_ptr's place as the memory :)
-
-}
-

-

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:


+As you know I have received a TPF grant to write a SDL Perl Manual.
+
+

+http://news.perlfoundation.org/2010/08/2010q3-grant-proposal-manual-f.html

-
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
-}
-
-#USING pack
-
-my $green = pack 'b*', '11111111000000000000000000000000';
-substr( $surf32_matrix->[0][0], 0, 8 * 4, $green); #no change
-#substr( $surf32_matrix->[0][0], 0, 8 * 4, 0xFF000000); segfault
-substr( ${$surf32_matrix->[0][0]}, 0, 8 * 4, 0xFF000000); #no change
-#$surf32_matrix->[0][0] = $green; SEGFAULT's cannot write to memory
-${$surf32_matrix->[0][0]} = $green; #no change
-
-
-SDL::Video::unlock_surface($screen_surface)
-  if ( SDL::Video::MUSTLOCK($screen_surface) );
-

-

You can see an example here.


-

Any help will be greatly appreciated.

-


-

\ No newline at end of file +http://news.perlfoundation.org/2010/08/accepted-grants-for-2010q3.html
+
+I have been a bit busy with that and not been able to update my blog. Anyway here are some of the back dated Grant Updates. These updates where also posted on http://news.perlfoundation.org/
+
+
+
+
+
REPORT 1: Sept 2010

+Progress: 2.75 chapters / 11 chapters = approx 25%
+Kartik's work can be followed at:
+
+
+
REPORT 2: October 2010

+
Since last time:
+Chapters:
+Extra:
+Coments:
+Our work can be seen at:
+

+
REPORT 3: November 2010

+This is the progress so far:
+
+- SDL 2.523 Releases:
+        - Adds stability and better memory management for the game loop
+
+- 2 chapters have been completed
+        - Pong Chapter (Contributed by garu)
+        - Additional Modules
+- 1 extra chapter has been added
+        - Puzz(le) Chapter (Contributed by Blaizer)
+
+- 2 Chapters are in the Works
+        - Tetris Code has been mostly done (contributed by FROGGS)
+                - Needs to be fixed
+                - Needs write up
+        - Sound and Music Effects code is done
+                - Needs to be fixed
+                - Needs write up
+
+Our work can be seen at:
http://sdlperl.ath.cx/releases/SDL_Manual.pdf
http://sdlperl.ath.cx/releases/SDL_Manual.html
http://github.com/PerlGameDev/SDL_Manual

+Regards,
+YAPGH
+


+

\ No newline at end of file