screenshot snippet

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

screenshot snippet

Post by weak »

just made a function to grab the psp's framebuffer and write a screenshot to memory stick (as 24 bit bmp file). thought some of you may have some use for it.

i was just looking to make it work, feel free to improve it ;)

Code: Select all

unsigned char  bmpHeader24[] = { 0x42, 0x4d, 0x38, 0xfa, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
unsigned char  buffer[SCREEN_WIDTH*3];
unsigned char  r,g,b;
int                  bufferIndex = 0;
unsigned short p;

file = sceIoOpen(savePath,O_CREAT | O_TRUNC | O_RDWR, 0777);  // savePath should hold the path to your file

// write bmp header
sceIoWrite(file,bmpHeader24,54);
   
// write bmp data
vptr0 = pgGetVramAddr(0,271);   // you can find this function in NEM's sources
for&#40;i=0; i<272; i++&#41;
&#123;		
  vptr=vptr0;
  for&#40;e=0; e<480; e++&#41;
  &#123;
    p = *&#40;unsigned short *&#41;vptr;
    r = &#40;p<<3&#41;&0xf8;
    g = &#40;p>>2&#41;&0xf8;
    b = &#40;p>>7&#41;&0xf8;         
         
    buffer&#91;bufferIndex&#93; = b;
    bufferIndex++;         
    buffer&#91;bufferIndex&#93; = g;
    bufferIndex++;         
    buffer&#91;bufferIndex&#93; = r;
    bufferIndex++;

    vptr+=PIXELSIZE*2;
  &#125;
  // write chunk
  sceIoWrite&#40;file,buffer,SCREEN_WIDTH*3&#41;;
  bufferIndex=0;
  vptr0-=LINESIZE*2;
&#125;

// bmp end
unsigned char end&#91;&#93; = &#123; 0x00, 0x00 &#125;;
sceIoWrite&#40;file,end,2&#41;;

sceIoClose&#40;file&#41;;
here are two screenshots from our current project (just for illustration ;))

Image

Image

greetz, weak
cable16
Posts: 22
Joined: Tue Mar 22, 2005 9:43 am
Contact:

Post by cable16 »

that game looks quite nice :)
Guest

Post by Guest »

This is fantastic!

Keep in mind one real good use for this ...

Say you make a game. And you want to make a cool splash screen with a little running animation, just like the commercial PSP games ?

Use this method while running a special "debug" version of the program to save every X frames to the memory stick...

THEN

Distill the frames into a movie of the proper size, and merge back into your EBOOT.PBP file, with your splash screen.

Voila!
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

thx a lot! credits go to pimpot who made the artwork. i'm just writing the code ;)

i'll grab a small ingame movie soon if someone's interested. demo's coming too :)
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

This must be good iv never seen gorim so excited
Guest

Post by Guest »

Squall333 wrote:This must be good iv never seen gorim so excited
Hehe ;)

Well I was gearing up to port a favorite game and been thinking about the splashscreen issue. Saved me some effort. ;)
laxer3a
Posts: 23
Joined: Wed May 11, 2005 1:09 am

Post by laxer3a »

Hey weak,

You could improve the quality of the screenshots by using 32 items lookup table and promote each 5 bit component into 8 bit correctly (normalize) :
For the moment your whites are not white :-P

To create the table, just do (n*255)/31 for each value between 0 and 31.

Still quite usefull anyway.. thats cool !
numchuckskills
Posts: 35
Joined: Wed May 04, 2005 4:48 pm

Post by numchuckskills »

im a n00b... where do i throw this code to make it work?

thanks for your patience in advance...
Not with a bang, but a whisper.
This is the way the world ends.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

TGA is a bit shorter, because it has a 16 bit format, with only the rgb components switched in the 16 bit PSP graphics mode:

http://forums.ps2dev.org/viewtopic.php?p=16942#16942
User avatar
Yoshihiro
Posts: 12
Joined: Sat May 14, 2005 12:17 am

Re: screenshot snippet

Post by Yoshihiro »

weak wrote:just made a function to grab the psp's framebuffer and write a screenshot to memory stick (as 24 bit bmp file). thought some of you may have some use for it.

i was just looking to make it work, feel free to improve it ;)

Code: Select all

unsigned char  bmpHeader24&#91;&#93; = &#123; 0x42, 0x4d, 0x38, 0xfa, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 &#125;;
unsigned char  buffer&#91;SCREEN_WIDTH*3&#93;;
unsigned char  r,g,b;
int                  bufferIndex = 0;
unsigned short p;

file = sceIoOpen&#40;savePath,O_CREAT | O_TRUNC | O_RDWR, 0777&#41;;  // savePath should hold the path to your file

// write bmp header
sceIoWrite&#40;file,bmpHeader24,54&#41;;
   
// write bmp data
vptr0 = pgGetVramAddr&#40;0,271&#41;;   // you can find this function in NEM's sources
for&#40;i=0; i<272; i++&#41;
&#123;		
  vptr=vptr0;
  for&#40;e=0; e<480; e++&#41;
  &#123;
    p = *&#40;unsigned short *&#41;vptr;
    r = &#40;p<<3&#41;&0xf8;
    g = &#40;p>>2&#41;&0xf8;
    b = &#40;p>>7&#41;&0xf8;         
         
    buffer&#91;bufferIndex&#93; = b;
    bufferIndex++;         
    buffer&#91;bufferIndex&#93; = g;
    bufferIndex++;         
    buffer&#91;bufferIndex&#93; = r;
    bufferIndex++;

    vptr+=PIXELSIZE*2;
  &#125;
  // write chunk
  sceIoWrite&#40;file,buffer,SCREEN_WIDTH*3&#41;;
  bufferIndex=0;
  vptr0-=LINESIZE*2;
&#125;

// bmp end
unsigned char end&#91;&#93; = &#123; 0x00, 0x00 &#125;;
sceIoWrite&#40;file,end,2&#41;;

sceIoClose&#40;file&#41;;
here are two screenshots from our current project (just for illustration ;))

Image

Image

greetz, weak

Weak after when you have the new psptoolchain you can use my simple code for make 2000 screenshot very easy :=) .

Code: Select all

int ScrenshotGen&#40;&#41;
&#123;
int fd;
char filename&#91;56&#93;;

for&#40;int i=0; i<2000; i++&#41;
&#123;
sprintf&#40;filename, "ms0&#58;/psp/game/Screenshot/screenshot%03d.bmp", i&#41;;
fd = sceIoOpen&#40;filename,O_RDONLY&#41;; 
if&#40;fd < 0&#41;
&#123;
break;
&#125;
sceIoClose&#40;fd&#41;;
&#125;
//Your string for make screenshot
YourScrenshotCode&#40; filename&#41;;	
return 0;
&#125;
Image
User avatar
sq377
Posts: 87
Joined: Mon Apr 11, 2005 3:30 am

Post by sq377 »

I believe this has been included in the snes emulator.... Sort of. When you save your state, it takes a screenshot and saves the thumbnail.
Post Reply