From: Kartik Thakore <[email protected]>
Date: June 25, 2010 5:52:57 PM EDT
To: David Mertens <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: Interfacing SDL Surface with a piddle

Hi,

Again I think I have found out why PDL piddle cannot seem to write to SDL
surface. During the slice the PV is changed. I have attached the script
that will produce the following output (please update your SDL to
http://github.com/kthakore/SDL_perl ).

Here is what I have found:

So how can I make the piddle not swap out the PV ?


###################  PIDDLE BEFORE ######################
SV = RV(0x142ac70) at 0x142ac64
 REFCNT = 1
 FLAGS = (PADMY,ROK)
 RV = 0x142b354
 SV = PV(0x1287abc) at 0x142b354
   REFCNT = 2
   FLAGS = (POK,pPOK)
   PV = 0xcebefc "\0"\0
   CUR = 1
   LEN = 4

#################### SURFACE PIXELS ##############
SV = RV(0x142b330) at 0x142b324
 REFCNT = 1
 FLAGS = (TEMP,ROK)
 RV = 0x3e90fc
 SV = PV(0x1287a9c) at 0x3e90fc
   REFCNT = 1
   FLAGS = (POK,pPOK)
   PV = 0xcea408 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
   CUR = 16
   LEN = 0

##################### PIDDLE AFTER REASSIGN ###############
SV = RV(0x142ac70) at 0x142ac64
 REFCNT = 1
 FLAGS = (PADMY,ROK)
 RV = 0x142b324
 SV = PV(0x1287a9c) at 0x142b324
   REFCNT = 1
   FLAGS = (POK,pPOK)
   PV = 0xcea408 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
   CUR = 16
   LEN = 0

##################### PIDDLE AFTER upd_data ###############
SV = RV(0x142ac70) at 0x142ac64
 REFCNT = 1
 FLAGS = (PADMY,ROK)
 RV = 0x142b324
 SV = PV(0x1287a9c) at 0x142b324
   REFCNT = 1
   FLAGS = (POK,pPOK)
   PV = 0xcea408 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
   CUR = 16
   LEN = 0

##################### PIDDLE AFTER SLICE ###############
SV = RV(0x142b350) at 0x142b344
 REFCNT = 1
 FLAGS = (TEMP,ROK)
 RV = 0x142b354
 SV = PV(0x1287abc) at 0x142b354
   REFCNT = 2
   FLAGS = (POK,pPOK)
   PV = 0x9e1384 "\377\3607\0\0\0\0\0\0\0\0\0\0\0\0\0" <== ***CHANGED
   CUR = 16
   LEN = 16

##################### SURFACE AFTER manual writing ###############
SV = RV(0x142b3b0) at 0x142b3a4
 REFCNT = 1
 FLAGS = (TEMP,ROK)
 RV = 0x142b344
 SV = PV(0x1287ad4) at 0x142b344
   REFCNT = 1
   FLAGS = (POK,pPOK)
   PV = 0xcea408 "\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0"
   CUR = 16
   LEN = 0



    use strict;
    use warnings;
    use SDL 2.408; 
    
    use SDLx::App; #this is in the github repo.
    use SDL::Event;
    use SDL::Events;
    use SDL::Rect;
    use SDL::Video;
    use Devel::Peek;
    
     use PDL;
     use PDL::NiceSlice;

    my $app = SDLx::App->new(
        -title  => 'Application Title',
        -width  => 640,
        -height => 480,
        -depth  => 32
    );

    load_app();

    my $surface = load_surface();
    my $piddle = surface_to_piddle($surface);
    
    my $event = SDL::Event->new;    # create a new event
    
    while(1) {
        SDL::Events::pump_events();

        while ( SDL::Events::poll_event($event) ) {
            my $type = $event->type();    # get event type
            exit if $type == SDL_QUIT;
        }
        update($piddle);
        

        SDL::Video::update_rect( $app, 0, 0, $app->w, $app->h );
    }

    sub load_app {

        my $mapped_color =
          SDL::Video::map_RGB( $app->format(), 0, 0, 0 );    # blue

        SDL::Video::fill_rect( $app, SDL::Rect->new( 0, 0, $app->w, $app->h ),
            $mapped_color );
        return $app;
    }

    sub load_surface {

        my $surface =
          SDL::Surface->new( SDL_ANYFORMAT, 2, 2, 32, 0, 0, 0, 0 );
        my $mapped_color =
          SDL::Video::map_RGBA( $surface->format(), 0, 0, 0, 0 );    # blue

        SDL::Video::fill_rect( $surface,
            SDL::Rect->new( 0, 0, $surface->w, $surface->h ),
            $mapped_color );
        return $surface;
    }
    
    sub surface_to_piddle
    {
        my $surface = shift;
        
        my $piddle = byte(0);
        
        my $pointer = $piddle->get_dataref;
        print "\n###################  PIDDLE BEFORE ######################\n";
        Dump $pointer;
        print "\n#################### SURFACE PIXELS ##############\n";
        Dump $surface->get_pixels_ptr;
        $pointer = $surface->get_pixels_ptr;
        print "\n##################### PIDDLE AFTER REASSIGN ###############\n";
        Dump $pointer;
        $piddle->setdims([4, $surface->w, $surface->h]);
        
        $piddle->upd_data();
        print "\n##################### PIDDLE AFTER upd_data ###############\n";
        Dump $pointer;
        return $piddle;
        
    }
    
    sub update {
        my $piddle = shift;
        load_app();
        
           SDL::Video::lock_surface( $surface );
        
        #   print sprintf ( "%x",  $surface->get_pixel(0)); #=> gets ff0000
          
          # print $piddle(:, 0, 0);   # -> gets [ [ 0 0 255 0] ]  
           
           $piddle(:, 0 , 0) .= pdl( 255, 240, 55, 0 );
           print "\n##################### PIDDLE AFTER SLICE ###############\n";
           Dump $piddle->get_dataref;
          # print $piddle(:, 0,0);    #-> gets [ [ 0 240 55 0] ]  
           $surface->set_pixels(2, 0xffff0000);
           
           print "\n##################### SURFACE AFTER manual writing 
###############\n";
           Dump $surface->get_pixels_ptr;
           
           
           die sprintf ( "%x",  $surface->get_pixel(0) );  #-> get 000000
           sprintf ( "%x",  $surface->get_pixel(1) );  #-> get 000000
           
           
           
           SDL::Video::unlock_surface( $surface );
       
          #die  sprintf ( "%x",  $surface->get_pixel(0));  #-> get ff0000
        SDL::Video::blit_surface( $surface, SDL::Rect->new( 0, 0, $surface->w, 
$surface->h ),
                                      $app, SDL::Rect->new( ($app->w - 
$surface->w)/2 , ($app->h - $surface->h)/2, $app->w, $app->h ));
    }

Reply via email to