screenshot-homebrew related questions

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

Moderators: cheriff, TyRaNiD

Post Reply
Fejwin
Posts: 12
Joined: Wed Sep 19, 2007 6:26 am

screenshot-homebrew related questions

Post by Fejwin »

I'm looking for the source code of a program that runs in the background and can make screenshots of a game while playing.
I know there are several of these programms on the net. I would like to study the source code of the simpliest one to understand how it functions.
I will be very greatful if someone can post that here ))

Thaks in advance!

Fejwin

EDIT:
Most interesting part is, how do I let a program run in the background while other things (like playing games, listen to music etc.) are going on?
Last edited by Fejwin on Wed Sep 26, 2007 5:28 am, edited 2 times in total.
hey there
califrag
Posts: 30
Joined: Wed Apr 04, 2007 4:43 pm

Post by califrag »

i haven't tried this myself but this function in the graphics.c/graphics.h seems like it may work - not sure how fast it may be.


/**
* Save an image or the screen in PNG or JPEG format (depends on the filename suffix).
*
* @pre filename != NULL
* @param filename - filename of the PNG image
* @param data - start of Color type pixel data (can be getVramDisplayBuffer())
* @param width - logical width of the image or SCREEN_WIDTH
* @param height - height of the image or SCREEN_HEIGHT
* @param lineSize - physical width of the image or PSP_LINE_SIZE
* @param saveAlpha - if 0, image is saved without alpha channel
*/
extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha);
Fejwin
Posts: 12
Joined: Wed Sep 19, 2007 6:26 am

Post by Fejwin »

@califrag:
Thanks a lot for help!!
I've just found that little code here in the forum, it has a bit more details in it:

Code: Select all

void saveScreen() { 
         int posX; 
         int posY; 
         Color pixel; 
         Color* vram = getVramDisplayBuffer(); 
         Image* screenShot; 
         screenShot = createImage(480,272); 
         for &#40;posY=0; posY<272; posY++&#41; &#123; 
         for&#40;posX=0; posX<480; posX++&#41; &#123; 
         pixel = vram&#91;PSP_LINE_SIZE * posY + posX&#93;; 
         putPixelImage&#40;pixel,posX,posY,screenShot&#41;; 
         &#125; 
         &#125; 
         saveImage&#40;"ms0&#58;/Snapshot.png",screenShot->data,480,272,PSP_LINE_SIZE,0&#41;; 
         freeImage&#40;screenShot&#41;; 
&#125; 
I think it will do the screen.

But I have some questions about "pixel = vram[PSP_LINE_SIZE * posY + posX];"
How does "PSP_LINE_SIZE * posY + posX" navigate to the right pixel?! It just looks like it multiplicates PSP_LINE_SIZE and posY and then counts everything together... o_O
Does vram[] just save the momentary color of target pixel into the pixel variable? Can I assign a color-index of my choice to each pixel? Or first get the color-index, then check which color it contains and if it has not the color which I want to keep, can I asign it an other one before writing it into ScreenShot?

The other question still remains: How do I let that function loop while doing other things on PSP?

EDIT:
AH!! XD I just got it!! It has to be that getVramDisplayBuffer() uses only one value to navigate to pixels!! AND its going each line from left to right and just jumps back and one line down when it reaches the last pixel of one line ^^ tricky, I admit that ))

Still:
Can I asign my wished color-index to a pixel before writing into ScreenShot?
And how do I let it loop in the background??
hey there
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

The answer is most likely yes you can.
It might help to explain exactly what you're doing.
Overlaying text/sprite to the screenshot?
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

I've edited the function to include an example of editing the pixel colors:

Code: Select all

void saveScreen&#40;&#41;
&#123;
	int posX, posY;
	Color pixel;
	Color* vram = getVramDisplayBuffer&#40;&#41;;
	Image* screenShot;
	screenShot = createImage&#40;480, 272&#41;;
	for &#40;posY = 0; posY < 272; posY++&#41;
	&#123;
		for &#40;posX = 0; posX < 480; posX++&#41;
		&#123;
			pixel = vram&#91;posX + posY * PSP_LINE_SIZE&#93;;
			
			/* change pixel here, assuming 8888 format and Color is a 32-bit int,
			 * then pixel = 0xAABBGGRR with AA set to ff=visible, 00=invisible. */
			
			/* this will change all blue pixels to red */
			if &#40;&#40;pixel >> 16&#41; & 0xff == 255 &&
				&#40;pixel >> 8&#41; & 0xff == 0 &&
				&#40;pixel&#41; & 0xff == 0&#41;
			&#123;
				pixel = 0xff0000ff;
			&#125;
			
			/* this will add a green line down the left side */
			if &#40;posX == 0&#41;
				pixel = 0xff00ff00;
			
			putPixelImage&#40;pixel, posX, posY, screenShot&#41;;
		&#125;
	&#125;
	saveImage&#40;"ms0&#58;/Snapshot.png", screenShot->data, 480, 272, PSP_LINE_SIZE, 0&#41;;
	freeImage&#40;screenShot&#41;;
&#125;
(+[__]%)
Fejwin
Posts: 12
Joined: Wed Sep 19, 2007 6:26 am

Post by Fejwin »

@Smong:
Wow, thanks for that extansion!!
I Think if I study this 8888 format I will be able to change any pixel in any color ) THX
(btw. is this code 3.xx kernel adopted?)

Now the only one quenstion remains:
How can I let my program run in the background and make screenshots (without saving them unless a condition occures) while I'm doing other things on the PSP?? ^^

An answer to this question will get me further really )) Hope someone can help.
hey there
Post Reply