0 Replies - 289 Views - Last Post: 27 September 2013 - 07:43 AM Rate Topic: -----

#1 semichaud1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-September 13

Getting pixel rgb values with SDL

Posted 27 September 2013 - 07:43 AM

Hi guys,

Maybe you can help me with the following. I am trying to get the RGB values of each pixel on a specific portion of the screen and store them in a text file. The portion of the code I am having trouble with is getting the RGB values. Please see my code below. The portion in bold is supposed to get the RGB values and store them in the text file. When I compile my code I get a general protection fault error:


var
 screen,fontface:psdl_surface;
 loaded_font:pointer;
 colour_font:psdl_color;
 test_event:psdl_event;
 source_rect,destination_rect:psdl_rect;
 music:pmix_music=nil;
 o:array[1..40] of integer;
 s:array[1..40] of pchar;
 st:array[1..40] of string;
 keys:array[1..6] of boolean;
 keysassign:array[1..6] of integer;
 x,y,z:integer;
 framerate:pfpsmanager;
 screensize:integer;
 a:array[1..40] of integer;
 t:array[1..4] of text;
 pixelcolor:uint32;
 o2:array[1..3] of puint8;

procedure writesprite;
begin
 o[1]:=1;
 assign(t[1],'tf1.txt');
 rewrite(t[1]);
 writeln(t[1],o[1]);
 sdl_freesurface(screen);
 o[2]:=0;
 repeat
  o[2]:=o[2]+1;
  screen:=sdl_setvideomode(640,480,32,sdl_swsurface);
  x:=50; y:=50;
  if o[2]=1 then scrollsprite;
  sdl_flip(screen);
  [b]o[3]:=0;
  repeat
   o[3]:=o[3]+1;
   o[4]:=0;
   repeat
    o[4]:=o[4]+1;
    sdl_getrgb(pixelcolor,screen^.format,o2[1],o2[2],o2[3]);
    writeln(t[1],smallint(o2[1]));
    writeln(t[1],smallint(o2[2]));
    writeln(t[1],smallint(o2[3]));
   until o[4]=10;
  until o[3]=10;[/b]
  sdl_freesurface(screen);
 until o[2]=o[1];
 writeln('endtotal');
 writeln('endfile');
 close(t[1]);
{;;get pixel 10x10 rgb colors and write in tf}
end;




I highlighted the portion of the code and selected bold but for some reason this forum did not put it in bold but simply inserted .. around the selected portion. Maybe because the code is within [coode]...[/code]

Is This A Good Question/Topic? 0
  • +

Page 1 of 1