Is it possible?
I'm under the impression that sceGuCopyImage will handle the source pixel format and convert it for the current display mode.
I just want to copy an 8888 image to VRAM in-game using sceGuCopyImage.
If it doesn't then I assume I'll have to write code to convert the source image into the current pixel format and write it to VRAM manually? Any one have some sample code to do this?
I blitting stuff to VRAM now, but for blitting an image the pixel format becomes a problem depending on what mode the game is using, so I though the GU functions would handle that.
[Solved] (Blit image to VRAM) sceGuCopyImage in Kernel mode?
[Solved] (Blit image to VRAM) sceGuCopyImage in Kernel mode?
Last edited by Torch on Sun Nov 16, 2008 1:23 am, edited 1 time in total.
I threw together something to blit 8888 RGBA images to VRAM, with automatic conversion to target pixel format with alpha blending. Its based off someones's screenshot plugin.
Code: Select all
//Globals
int pmode, pwidth, pheight, bufferwidth, pixelformat;
unsigned int* vram32;
unsigned short* vram16;
//Somewhere in your code
...
sceDisplayGetMode(&pmode, &pwidth, &pheight);
sceDisplayGetFrameBuf((void*)&vram32, &bufferwidth, &pixelformat, PSP_DISPLAY_SETBUF_IMMEDIATE);
vram16 = (unsigned short*) vram32;
drawimage(smiley, smiley_w, smiley_h, 20, 20);
...
void drawimage(unsigned char * image, unsigned int srcw, unsigned int srch, unsigned int destx, unsigned int desty)
{
#define sbpp 4 //Source bytes-per-pixel (RGBA=4)
unsigned int x, y, pos = 0;
sceDisplayWaitVblankStart();
for(y = desty; y < desty+srch; y++){
for(x = destx; x < destx+srcw; x++){
unsigned int color, offset = x + y*bufferwidth;
unsigned char r = 0, g = 0, b = 0;
switch (pixelformat) {
case 0: // 16-bit RGB 5:6:5
color = vram16[offset];
r = (color & 0x1f) << 3;
g = ((color >> 5) & 0x3f) << 2;
b = ((color >> 11) & 0x1f) << 3;
r = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*r + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp]) >> 3;
g = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*g + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 1]) >> 2;
b = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*b + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 2]) >> 3;
vram16[offset] = (b << 11)|(g << 5)|r;
break;
case 1:// 16-bit RGBA 5:5:5:1
color = vram16[offset];
r = (color & 0x1f) << 3;
g = ((color >> 5) & 0x1f) << 3;
b = ((color >> 10) & 0x1f) << 3;
r = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*r + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp]) >> 3;
g = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*g + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 1]) >> 3;
b = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*b + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 2]) >> 3;
vram16[offset] = (b << 10)|(g << 5)|r;
break;
case 2:// 16-bit RGBA 4:4:4:4
color = vram16[offset];
r = (color & 0xf) << 4;
g = ((color >> 4) & 0xf) << 4;
b = ((color >> 8) & 0xf) << 4;
r = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*r + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp]) >> 4;
g = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*g + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 1]) >> 4;
b = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*b + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 2]) >> 4;
vram16[offset] = (b << 8)|(g << 4)|r;
break;
case 3:// 32-bit RGBA 8:8:8:8
color = vram32[offset];
r = color & 0xff;
g = (color >> 8) & 0xff;
b = (color >> 16) & 0xff;
r = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*r + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp]);
g = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*g + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 1]);
b = (unsigned char)(((255.0f - image[pos*sbpp + 3])/255.0f)*b + (image[pos*sbpp + 3]/255.0f)*image[pos*sbpp + 2]);
vram32[offset] = (b << 16)|(g << 8)|r;
break;
}
pos++;
}
}
sceKernelDcacheWritebackAll();
}
-
- Posts: 12
- Joined: Thu Oct 04, 2007 12:33 am
The char * image[] should contain raw 8888 RGBA data. I'm not loading any image in my app, I've directly saved the RGBA data in the source code as an array.
You can export an image as raw data using GIMP (by choosing RAW in the Save As options).
If you have images in PNG, BMP etc, then you can use already available code to load it. Then just pass the array of the image data after loading.
You can export an image as raw data using GIMP (by choosing RAW in the Save As options).
If you have images in PNG, BMP etc, then you can use already available code to load it. Then just pass the array of the image data after loading.