 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Sat Nov 08, 2008 5:22 pm Post subject: Graphics.c question (saveimage) |
|
|
Hi Guys,
For a long time I've used the standard save screen function floating about:
| Code: |
void saveScreen() {
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("ms0:/Snapshot.png",screenShot->data,480,272,PSP_LINE_SIZE,0);
freeImage(screenShot);
}
|
Now I'd just like to save a png image of arbitrary size from memory.
Definitions of the args given in graphics.c for saveImage are rather ambiguous.
| Quote: |
/**
* Save an image or the screen in PNG format.
*
* @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);
|
... particularly the difference between the logical and physical width.
Say I want to save a 134x76 icon0 sized image with alpha that is already declared,
loaded, and named ICON0 in RAM.
| Code: |
saveImage("ms0:/ICON0.png",ICON0->data,134,74,?,1);
|
I've tried all sorts of values here, but seem to end up with a mess of colours that appear in the image.
Cheers, Art. _________________ If not actually, then potentially. |
|
| Back to top |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Sat Nov 08, 2008 7:51 pm Post subject: |
|
|
usually this kind of parameter (linesize) indicate the "alignment" of linear pieces of framebuffer where an image is stored in memory. I mean....if you have to access a color located in point (10, 32) of an image in wich RGBA are stored in 4 consecutive bytes, you have to multiply 4*32*image_width and then add 10. If image_width is a power of two, you can simply use a 4 times faster bit shift. This (and more) is the reason why hardware often require textures' size to be a power of two. PSP allow arbitrary texture size as long as horizontal lines of the image are aligned so previously described trick works. So for an image width being 320, linesize should be first greater two power = 512. Exceeding bytes between logical and physical width (in the example (512-320)*4 bytes) are simply ignored.
Hope i explained it clearly... |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Sat Nov 08, 2008 8:33 pm Post subject: |
|
|
Well I understand until about the last line, but I assume I can calc the parameter with
(512-imagewidth)*4 bytes) ?
Will find out anyway.
It wasn't an immediate need... I figured it was easier to convert a colour in a png
to transparent on the PSP than the Windows paint program I'm using. _________________ If not actually, then potentially. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|