Bitmap Maker

<< Retour au projet Arduino Game

Exemple d'entrée :

Exemple de sortie :

#ifndef PMCLOGO_H
#define PMCLOGO_H
 
#include <avr/pgmspace.h>
 
PROGMEM const unsigned char pmclogo[] = {
96,20,
0xFF,0xF8,0x1,0xE0,0x0,0xF0,0x0,0xFF,0xC0,0x0,0x0,0x0,
0xFF,0xFE,0x7,0xFC,0x3,0xFC,0x3,0xFF,0xC0,0x0,0x0,0x0,
0xFF,0xFF,0x7,0xFC,0x3,0xFC,0x7,0xFF,0xC0,0x0,0x0,0x0,
0xFF,0xFF,0xF,0xBE,0x7,0xFE,0xF,0x80,0x0,0x0,0x0,0x0,
0x0,0x7,0x8F,0x3E,0x7,0x9E,0x1E,0x0,0x0,0x0,0x0,0x0,
0x0,0x7,0x8E,0x3E,0x7,0x1E,0x1C,0x0,0x0,0x0,0x0,0x0,
0x0,0x7,0x9E,0x3E,0xF,0x1E,0x1C,0x0,0x0,0x0,0x0,0x0,
0x0,0x7,0x9E,0x3E,0xF,0x1E,0x1C,0x0,0x0,0x0,0x0,0x0,
0x1F,0xFF,0x1C,0x3E,0xE,0x1E,0x3C,0x0,0x0,0x0,0x0,0x0,
0x7F,0xFE,0x3C,0x3E,0x1E,0x1E,0x3C,0x0,0x1,0x80,0x20,0x7E,
0x7F,0xFC,0x3C,0x3E,0x1E,0x1E,0x3C,0x0,0x1,0x80,0x60,0x43,
0x7F,0xFC,0x3C,0x3E,0x1E,0x1E,0x3C,0x0,0x1,0x80,0x60,0x43,
0xF0,0x0,0x38,0x3E,0x1C,0x1E,0x1C,0x0,0x1,0x80,0x50,0x41,
0xF0,0x0,0x78,0x3E,0x3C,0x1E,0x1C,0x0,0x1,0x80,0x50,0x41,
0xF0,0x0,0x70,0x3E,0x3C,0x1E,0x1C,0x0,0x1,0x80,0x98,0x7E,
0xF0,0x0,0x70,0x3E,0x38,0x1E,0x1E,0x0,0x1,0x80,0x88,0x67,
0xF0,0x0,0xF0,0x3E,0x78,0x1E,0x1F,0x0,0x1,0x80,0x88,0x41,
0xF0,0x0,0xF0,0x1F,0xF8,0x1E,0xF,0xFF,0xC1,0x81,0xFC,0x41,
0xF0,0x1,0xE0,0x1F,0xF0,0x1E,0x7,0xFF,0xC1,0x81,0x4,0x41,
0xF0,0x1,0xE0,0x3,0xE0,0x1E,0x0,0xFF,0xC1,0xFF,0x4,0x7E
};
 
#endif

Code de l'outil :

package fr.karang.TFTFontMaker;
 
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
 
import javax.imageio.ImageIO;
 
public class BitmapMaker {
	private final BufferedImage image;
	private final int MAX_BYTE_PER_LINE = 12;
 
	public BitmapMaker(String in, String out, String bitmapname) throws IOException {
		image = ImageIO.read(new File(in));
		System.out.println("Image loaded : ("+image.getWidth()+", "+image.getHeight()+")");
 
		if ((image.getWidth()%8)!=0) {
			System.out.println("La largeur doit être un multiple de 8.");
			return;
		}
 
		File file = new File(out);
 
		if (!file.exists()) {
			file.createNewFile();
		}
 
		FileWriter fw = new FileWriter(file.getAbsoluteFile());
		BufferedWriter bw = new BufferedWriter(fw);
 
		bw.write("#ifndef "+bitmapname.toUpperCase()+"_H\n");
		bw.write("#define "+bitmapname.toUpperCase()+"_H\n\n");
 
		bw.write("#include <avr/pgmspace.h>\n\n");
 
		bw.write("PROGMEM const unsigned char "+bitmapname+"[] = {\n");
		bw.write(image.getWidth()+","+image.getHeight()+",\n");
 
		int i=0;
		for (int y=0 ; y<image.getHeight() ; y++) {
			for (int x=0 ; x<image.getWidth()/8 ; x++) {
				int v = 0;
				for (int j=0 ; j<8 ; j++) {
					v = v<<1;
					if (image.getRGB(x*8+j, y)==-1) v |= 1;
				}
				bw.write("0x"+Integer.toHexString(v).toUpperCase());
				if (y!=(image.getHeight()-1) || x!=(image.getWidth()/8-1)) {
					bw.write(",");
				}
				i++;
				if ((i%MAX_BYTE_PER_LINE)==0) {
					bw.write("\n");
				}
			}
		}
 
		bw.write("};\n\n");
		bw.write("#endif");
 
		bw.close();
 
		System.out.println((i+2)+" bytes");
		System.out.println("Done");
	}
 
	public static void main(String[] args) {
		try {
			new BitmapMaker("res/in/pmclogo.png", "res/out/pmclogo.h", "pmclogo");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}

<< Retour au projet Arduino Game