| View previous topic :: View next topic |
| Author |
Message |
Josh1billion

Joined: 12 Jul 2005 Posts: 32 Location: Wisconsin, USA
|
Posted: Tue Jul 12, 2005 3:08 pm Post subject: Image conversion (BMP2PSP / BMP2c) resulting in corruption? |
|
|
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. _________________ Josh1billion - PHP, C++, PSP programmer. |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Tue Jul 12, 2005 8:40 pm Post subject: |
|
|
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 _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
Tim
Joined: 12 Jul 2005 Posts: 38
|
Posted: Wed Jul 13, 2005 2:59 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
cwbowron

Joined: 06 May 2005 Posts: 76 Location: East Lansing, MI
|
Posted: Wed Jul 13, 2005 3:26 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
Posted: Wed Jul 13, 2005 3:35 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Wed Jul 13, 2005 3:37 am Post subject: |
|
|
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:
| Code: |
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();
}
}
}
|
Then your makefile could look like this and all png files are converted to .o-files and linked to your application:
| Code: |
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 $<
|
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:
| Code: |
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++;
}
}
}
|
with "#define IS_ALPHA(value) (((value)&0xff000000)==0)". |
|
| Back to top |
|
 |
Josh1billion

Joined: 12 Jul 2005 Posts: 32 Location: Wisconsin, USA
|
Posted: Wed Jul 13, 2005 6:55 am Post subject: |
|
|
Thanks, that worked perfectly. :) _________________ Josh1billion - PHP, C++, PSP programmer. |
|
| Back to top |
|
 |
|