Ok, just wrote this function and it originally just saved a black image 480x272... I then relalized this was because the getPixelScreen function was getting the pixel from the buffer which had been swapped by the flipScreen function that was called before the saveScreen function was called later on in my code...
I added a flipScreen before I take the screenshot and one after to swap them back and it works but for a split second you see the previous screen whilst it swaps the one I want back into the buffer that can be read...
Is there a way to "copy" rather than swap the buffers so that on screen buffer and the "behind the scenes" buffer (that I can read) are the same so this flicker doesn't happen...?
Code: Select all
void saveScreen(char* filename) {
int posX;
int posY;
Color pixel;
Image* screenShot;
screenShot = createImage(480,272);
flipScreen();
for (posY=0; posY<272; posY++) {
for(posX=0; posX<480; posX++) {
pixel = getPixelScreen(posX,posY);
putPixelImage(pixel,posX,posY,screenShot);
}
}
flipScreen();
saveImage(filename,screenShot->data,480,272,PSP_LINE_SIZE,0);
freeImage(screenShot);
}
EDIT: Great, worked it out... I just needed to get the Display Buffer rather than the Draw buffer and now it works perfectly...
Here is a simple screenshot function if anyone wants it... Obviously requires the graphics.c include files...
Code: Select all
void saveScreen(char* filename) {
int posX;
int posY;
Color pixel;
Color* vram = getVramDisplayBuffer();
Image* screenShot;
screenShot = createImage(480,272);
for (posY=0; posY<272; posY++) {
for(posX=0; posX<480; posX++) {
pixel = vram[PSP_LINE_SIZE * posY + posX];
putPixelImage(pixel,posX,posY,screenShot);
}
}
saveImage(filename,screenShot->data,480,272,PSP_LINE_SIZE,0);
freeImage(screenShot);
}
EDIT2: Probably better to split this function into 2 and allow people to grab sections of the screen aswell as save the whole thing...
Code: Select all
Image* grabScreen(int x1, int y1, int x2, int y2) {
int posX;
int posY;
Color pixel;
Color* vram = getVramDisplayBuffer();
Image* screenShot;
screenShot = createImage(x2-x1,y2-y1);
for (posY=y1; posY<y2; posY++) {
for(posX=x1; posX<x2; posX++) {
pixel = vram[PSP_LINE_SIZE * posY + posX];
putPixelImage(pixel,posX,posY,screenShot);
}
}
return screenShot;
}
void saveScreen(char* filename) {
Image* screenShot;
screenShot = grabScreen(0,0,480,272);
saveImage(filename,screenShot->data,480,272,PSP_LINE_SIZE,0);
freeImage(screenShot);
}