Will you look at that? Here I was just about to post my wonderful color version, and oNyx beats me to it!
Oh well, mine’s better anyway. ;D
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
public class ImageMaker4K
{
public static void main(String[] args) throws Exception
{
int[] buffer = new int[4096];
BufferedImage image;
FileInputStream in;
int data;
int index;
if(args.length < 2)
{
System.out.println("Usage: java 4kImageMaker <input> <output>.png");
return;
}
in = new FileInputStream(args[0]);
index = 0;
while((data = in.read()) >= 0 && index < buffer.length)
{
int Y = ((data & 0xE0) >> 6);
int U = ((data & 0x1C) >> 3);
int V = (data & 0x03);
double R = Math.abs(Y + 1.403 * V);
double G = Math.abs(Y - 0.344 * U - 0.714 * V);
double B = Math.abs(Y + 1.770 * U);
buffer[index] = ((int)(R * 255) << 16) | ((int)(G * 255) << 8) | (int)(B * 255);
index++;
}
image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, 64, 64, buffer, 0, 64);
ImageIO.write(image, "PNG", new File(args[1]+".png"));
}
}
This version works by treating each 8 bit value as a YUV color. While I’m not so sure about my YUV to RGB color conversion, it does produce a 64x64 image that can easily be palletized. It also retains much of the analytical ability of the previous version, allowing you to see “dead spots” in your code.
See attachments for some examples.