Log In  

Cart #10516 | 2015-05-06 | Code ▽ | Embed ▽ | No License
5

After writing a small image converter for pomppo's 1-bit sprites I hacked together a color image "importer".

It reads a 128x128, 16 color image, and spits out something you can paste in a p8 file, in the gfx section.
The cartridge here just displays it.

I don't know if there is any point in doing this... a "fullscreen" 128x128 image takes up Pico-8's all gfx memory, so after that there are no more room for any sprites...
One use case would be importing a sprite sheet, so an artist can work in his/her favorite editor program, or something.

Anyway here is it.
It is a (really-really-really hacky) Processing program.

Just change the image name, run the sketch, and the data is copied to the clipboard (or if not, you can copy it from the console window).

Paste it over the gfx data in the p8 cartrigde file, and the sprites will be replaced by your picture.

import java.awt.;
import java.awt.event.
;
import java.awt.datatransfer.;
import javax.swing.
;
import java.io.*;

PImage img, dimg;
HashMap<Integer, String> converter;

void setup() {
img = loadImage("sonofman.png");
size(img.width, img.height);
dimg = createImage(img.width, img.height, RGB);
dimg.copy(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height);

converter = new HashMap<Integer, String>();
converter.put(0xFE000000, "0");
converter.put(0xFE1C2A52, "1");
converter.put(0xFE7D2452, "2");
converter.put(0xFE008650, "3");

converter.put(0xFEAA5135, "4");
converter.put(0xFE5E564E, "5");
converter.put(0xFEC1C2C6, "6");
converter.put(0xFEFEF0E7, "7");

converter.put(0xFEFE004C, "8");
converter.put(0xFEFEA200, "9");
converter.put(0xFEFEFE26, "a");
converter.put(0xFE00E655, "b");

converter.put(0xFE28ACFE, "c");
converter.put(0xFE82759B, "d");
converter.put(0xFEFE76A7, "e");
converter.put(0xFEFECBA9, "f");

mousePressed();
}

void draw() {
image(dimg, 0, 0);
}

void mousePressed() {
String simg = "";
int counter = 0;
dimg.loadPixels();
for (int i = 0; i<dimg.pixels.length; i++) {
Integer s = dimg.pixels[i];
simg += converter.get(s);
//println("Got: "+hex(s)+" -> "+converter.get(s));

counter++;
if (counter==img.width) {
  for (int o = counter; o<128; o++) {
    simg += "0";
  }
  simg += "\n";
  counter = 0;
}

}

StringSelection data = new StringSelection(simg);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(data, data);

println(simg);
}

As I mentioned this is really hacky - the stupidest thing is that looks for exactly same colors, so it is a good idea to use the following palette.
This is a photoshop .act file, load as the color table of your indexed image.

0000 00ff ff27 fff1 e8ff ccaa ffa3 00ff
77a8 ff00 4dc2 c3c7 ab52 3683 769c 7e25
535f 574f 29ad ff1d 2b53 00e7 5600 8751
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0010 ffff

P#10517 2015-05-06 17:52 ( Edited 2015-05-06 21:52)


[Please log in to post a comment]