Graphics.c question (saveimage)

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

Moderators: cheriff, TyRaNiD

Post Reply
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Graphics.c question (saveimage)

Post by Art »

Hi Guys,
For a long time I've used the standard save screen function floating about:

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;
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.
/**
* 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: Select all

saveImage&#40;"ms0&#58;/ICON0.png",ICON0->data,134,74,?,1&#41;;
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.
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

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...
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

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.
Post Reply