X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=sdlgit%2FSDL-Site.git;a=blobdiff_plain;f=pages%2Fblog-0013.html-inc;h=4c366da9655f0706e833bbc242ab0e3902d77a9f;hp=2e202e79e222745e30148733ba74569908ecbd32;hb=e785862422f3e827a242fc244bd57b23443887ce;hpb=879fff64432f43c80083c7b45da72611be9dca4b diff --git a/pages/blog-0013.html-inc b/pages/blog-0013.html-inc index 2e202e7..4c366da 100644 --- a/pages/blog-0013.html-inc +++ b/pages/blog-0013.html-inc @@ -1,81 +1,26 @@

-Providing direct memory access to SDL_Surface's pixels +The Build Process of SDL Perl

-

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:


+

A while ago I had a long chat with mst on why SDL uses Module::Build rather then Make. I told him it is a simple matter of code inertia. The existing Module::Build system has worked well for us so far. Never the less, he convinced me that switching to Make will improve debugging the Build system. But to be able to switch we will need to completely replace the Build system. I am not prepared to do that so I will just present the requirements so mst or someone else can at least attempt to switch.



-
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 +

The Build Process


+ Alien::SDL
+
+

SDL Perl depends on a few C libraries for a complete install. This is handled by Alien::SDL. First we look for existing SDL libraries and dependencies by doing a File::Find for headers. If these headers are found we present and option for the user to use those. We then store these locations in Alien::SDL->config options 'cflags', 'prefix' and 'libs'. If we do not have libraries available even for a minimum SDL installed ( SDL.h is not found). We provide several platform specific options.


+

For windows we have a simpler process. We download prebuilt binaries ( and checksum ) based on the user's selection and just copy them in to the right location. Again the 'prefix', 'cflags', and 'libs' is saved in Alien::SDL->config.


+

For *nix/MacOSX we download sources and attempt to compile them. To be able to do this we download several other dependencies like libpng, jpeg and pango. You can see how we do this using hashes here. During the compile process we also apply patches as needed for the sources. Once this is done we can head to SDL Build.PL


+ SDL Perl dependency resolution
+
+SDL's Build is responsible for linking the right libraries to the correct XS. If libraries are missing it will disable the component (not put it in SDL->config).
+
+

For example to build Image.xs we require libsdl, libsdl_image and lib[jpg|png|tiff]. So we would check for these headers in the prefix provided by Alien::SDL->config. If they are not provided we will disable the SDL::Image module.


+

More over the availability of each library is specified as a -DMACRO to the gcc compiler. This way we can prevent XS failures due to missing libraries using #DEFINES. Here the SDL_image macro is defined and used. The availability of the module is then available from SDL::Config->has()
+
+
+ Conclusion
+

This is a high level overview of our Build process, because frankly I hate traumatizing my brain with this again. Credits have to go to FROGGS and kmx for helping with this Build scheme. Hopefully my post have helped people at the very least appreciate the problem scope of this Build system. That said I believe a fresh written build system, with these requirements in mind, will be more then welcome.
+

+


+

\ No newline at end of file