I am trying to convert a bitmap image to the PSP-compatible unsigned short array format.
I have used two applications (from different sources but they do the same thing basically): BMP2PSP (which came with some SDK I downloaded I think) and BMP2c ( from http://www.ice-d.com/products/products_bmp2c.html ).
Both have resulted in the same problem: the image is nearly flawless, except some pixels are out of place in this way: I have an image of a simple circle/ball, and it looks like the ball was cut in half diagonally and the halves' positions were swapped.
I have used the JPG 2 PSP converter here: http://www.psp.to/tools/ and it does not have that problem. The only problem with using the JPG converter is that JPG images get blurred when you save them as most of you will know (in Windows, not just on the PSP of course). That means the pixels will not be crystal-clear, which is a problem because I'm trying to use transparency in my Breakout game.
Thanks in advance.
Image conversion (BMP2PSP / BMP2c) resulting in corruption?
- Josh1billion
- Posts: 32
- Joined: Tue Jul 12, 2005 8:45 am
- Location: Wisconsin, USA
- Contact:
Image conversion (BMP2PSP / BMP2c) resulting in corruption?
Josh1billion - PHP, C++, PSP programmer.
bmp's not a very nice format. I see that bmp2c only works on 256 colour bitmaps. bmp (in a file) has a requirement that each scanline is padded to 32bits (4 pixels). bmp2c doesn't do this properly. The only way to fix it without changing bmp2c is to make your graphic a multiple of 4 pixels wide. That should fix it.
Jim
Jim
ector's got a program he wrote for doing texture conversions: http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip
I haven't gotten a chance to play around with it much yet, but it might be what you're looking for.
I haven't gotten a chance to play around with it much yet, but it might be what you're looking for.
I use ConvImage16 but I do not know who wrote it, or where I got it. It converts from a variety of formats to a unsigned short array suitable for the psp.
You can grab it at http://www.cse.msu.edu/~bowronch/ConvImage16.zip
You can grab it at http://www.cse.msu.edu/~bowronch/ConvImage16.zip
If you choose 1 mipmap, the right 16bit color format and disable swizzling, my texture converter can be used for regular bitmaps to copy to the framebuffer if you also strip off or ignore the header, which should be 32 bytes in this case. I should probably add functionality to export raw bitmaps and maybe C files too in addition to my texture format.
Another solution is to load the free Java SDK from Sun and use this class, like in my Snake game, which can convert JPG, PNG (which you should use, if you want lossless image quality with alpha channel information) and all other graphics formats, which are supported by Java:
Then your makefile could look like this and all png files are converted to .o-files and linked to your application:
From within your application just add a "extern u32 background_start[]" in your source, if you have an image with the name "background.png". For drawing with transparency, you can write something like this:
with "#define IS_ALPHA(value) (((value)&0xff000000)==0)".
Code: Select all
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
public class GraphicsTo32BitRaw {
public static void main(String args[]) throws Exception {
// check arguments
if (args.length != 1) {
System.out.println("Usage: java GraphicsTo16BitRaw pic.png");
return;
}
// load image
String filename = args[0];
Image image = ImageIO.read(new File(filename));
// determine pixels
int w = image.getWidth(null);
int h = image.getHeight(null);
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
}
// save as raw data
try {
// create pixels buffer
byte [] outBuffer = new byte[w*h*4];
int i = 0;
for (int y = 0; y < h; y++) {
StringBuffer line = new StringBuffer();
for (int x = 0; x < w; x++) {
int color = pixels[y * w + x];
int blue = color & 0xff;
int green = (color >> 8) & 0xff;
int red = (color >> 16) & 0xff;
int alpha = color >> 24;
int value = red | (green << 8) | (blue << 16) | (alpha << 24);
outBuffer[i++] = (byte) red;
outBuffer[i++] = (byte) green;
outBuffer[i++] = (byte) blue;
outBuffer[i++] = (byte) alpha;
}
}
// write
String name = filename.substring(0, filename.length() - 4);
FileOutputStream out = new FileOutputStream(name + ".raw");
out.write(outBuffer);
out.close();
} catch (IOException e) {
System.out.println("error while writing");
e.printStackTrace();
}
}
}
Code: Select all
TARGET = snake
OBJS = snake.o \
background.o apple.o fly.o \
bodyLB.o bodyLT.o bodyRT.o bodyLR.o bodyRB.o bodyTB.o \
headB.o headR.o headL.o headT.o \
tailB.o tailR.o tailL.o tailT.o
INCDIR =
CFLAGS = -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS =
LDFLAGS =
EXTRA_TARGETS = GraphicsTo32BitRaw.class EBOOT.PBP
PSP_EBOOT_TITLE = Snake v1.1
PSP_EBOOT_ICON = title-icon.png
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
.SUFFIXES: .png .java .class
.png.o:
java GraphicsTo32BitRaw $<
bin2o -i $*.raw $@ $*
.java.class:
javac $<
Code: Select all
void plotCellImage(int x, int y, u32* image)
{
u32* vram = pgGetVramAddr(x * 16, y * 16);
int xo, yo;
for (yo = 0; yo < 16; yo++) {
for (xo = 0; xo < 16; xo++) {
if (!IS_ALPHA(*image)) {
vram[xo + yo * PSP_LINE_SIZE] = *image;
} else vram[xo + yo * PSP_LINE_SIZE] = background_start[16*x + xo + (16*y + yo) * SCREEN_WIDTH];
image++;
}
}
}
- Josh1billion
- Posts: 32
- Joined: Tue Jul 12, 2005 8:45 am
- Location: Wisconsin, USA
- Contact:
Thanks, that worked perfectly. :)cwbowron wrote:I use ConvImage16 but I do not know who wrote it, or where I got it. It converts from a variety of formats to a unsigned short array suitable for the psp.
You can grab it at http://www.cse.msu.edu/~bowronch/ConvImage16.zip
Josh1billion - PHP, C++, PSP programmer.