 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Fabre
Joined: 22 May 2005 Posts: 18
|
Posted: Wed Jun 22, 2005 11:22 pm Post subject: Recommendations for a good BMP>C app? |
|
|
Hi, I have programmed for the GP32 and PC (and a little on the GBA) in the past, but I feel that the GP32 is a dying system, so I am moving to the PSP. My first project will be a PSP version of my GP32 Sudoku game. Sudoku is an insanely addictive puzzle game (go to http://www.sudoku.com if you want to learn more about it)
Getting back on topic, I have set up my PSP development environment, and successfully built the HelloPSP example. I am now moving on to making my game. The problem that I am not sure what program I should use to convert my BMPs into C files. What is the best converter to use? (and yes, I have looked around already)
As a little gift for reading my post, here's a preview of my game :D
 |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Wed Jun 22, 2005 11:44 pm Post subject: |
|
|
It's quite easy to build up your own using SDL for example, by using SDL_LoadBMP then parsing'n'writing down the created surface. _________________ pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Wed Jun 22, 2005 11:46 pm Post subject: Re: Recommendations for a good BMP>C app? |
|
|
| Fabre wrote: | The problem that I am not sure what program I should use to convert my BMPs into C files. What is the best converter to use?
|
If you have Linux or Gimp, you can save it as XPM, which is simply a C program. If you want to store it in some other format, you can use for example the little Java program below, which can read PNG, GIF and all other formats, which are supported by Java. It writes it as a special compressed format with a palette, initially programmed by me, because a customer doesn't want to include GIF graphics in an Java-Applet, but you can change the write block without problems (and if not, don't think writing a PSP game is easier :-)
| Code: |
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import sun.net.www.content.image.gif;
public class gif2fgf {
public static void main(String args[]) {
// check arguments
if (args.length != 1) {
System.out.println("Usage: gif2fgf pic.gif");
return;
}
// load GIF, PNG or JPG file
Frame dummy = new Frame();
String filename = args[0];
Image gif = Toolkit.getDefaultToolkit().getImage(filename);
MediaTracker tracker = new MediaTracker(dummy);
tracker.addImage(gif, 0);
try {
tracker.waitForID(0);
} catch (Exception e) {
}
// determine pixels
int w = gif.getWidth(dummy);
int h = gif.getHeight(dummy);
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(gif, 0, 0, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
}
// calculate palette
HashSet palUnique = new HashSet();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int pixel = pixels[y * w + x];
palUnique.add(new Integer(pixel));
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
}
}
Object pal[] = palUnique.toArray();
if (pal.length > 255) {
System.out.println("internal error: too many palette colors");
return;
}
HashMap palLookup = new HashMap();
for (int i = 0; i < pal.length; i++)
palLookup.put(pal[i], new Integer(i));
// save as FGF (Frank's Grafik Fileformat)
try {
// open zlib output stream
FileOutputStream fileOut =
new FileOutputStream(filename.substring(0, filename.length() - 4) + ".fgf");
DeflaterOutputStream out = new DeflaterOutputStream(fileOut);
// write dimension
out.write(w & 255);
out.write((w >> 8) & 255);
out.write(h & 255);
out.write((h >> 8) & 255);
// write palette
out.write(pal.length);
for (int i = 0; i < pal.length; i++) {
int pixel = ((Integer) pal[i]).intValue();
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
out.write(alpha);
out.write(red);
out.write(green);
out.write(blue);
}
// write pixels
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int pixelIndex =
((Integer) palLookup.get(new Integer(pixels[y * w + x]))).intValue();
out.write(pixelIndex);
}
}
out.close();
} catch (IOException e) {
System.out.println("error while writing");
e.printStackTrace();
}
System.exit(0);
}
/*
* Use this method in Applets to load an image.
*/
/*
private Image loadFGF(String imageName)
{
try {
InputStream fileIn = (new URL(getDocumentBase(), imageName)).openStream();
InflaterInputStream in = new InflaterInputStream(fileIn);
// read dimension
int w = in.read();
w |= in.read() << 8;
int h = in.read();
w |= in.read() << 8;
// read palette
int palCount = in.read();
int pal[] = new int[palCount];
for (int i = 0; i < palCount; i++) {
int alpha = in.read();
int red = in.read();
int green = in.read();
int blue = in.read();
pal[i] = blue | (green << 8) | (red << 16) | (alpha << 24);
}
// read pixels
int pixels[] = new int[w * h];
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
pixels[x + y * w] = pal[in.read()];
}
}
// return new image
return Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(w, h, ColorModel.getRGBdefault(), pixels, 0, w)
);
} catch (IOException e) {
System.out.println("error while reading");
e.printStackTrace();
}
return null;
}
*/
}
|
|
|
| Back to top |
|
 |
alonetrio

Joined: 15 May 2005 Posts: 34
|
Posted: Thu Jun 23, 2005 1:04 am Post subject: |
|
|
or even more simple : http://www.psp.to/tools
this an online jpg -> C converter ;)
AloneTrio |
|
| Back to top |
|
 |
Fabre
Joined: 22 May 2005 Posts: 18
|
Posted: Thu Jun 23, 2005 6:38 am Post subject: |
|
|
| I may write my own converter some time in the future, but for now, I prefer to just use an existing tool, and the http://www.psp.to/tools website has just what I want. Thanks to everyone who replied! |
|
| 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
|