Skip to content

Instantly share code, notes, and snippets.

@moneytoo
Created January 15, 2014 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moneytoo/8446716 to your computer and use it in GitHub Desktop.
Save moneytoo/8446716 to your computer and use it in GitHub Desktop.
msol2png - converting images in MSOL format (6-bit color depth) to PNG. Used by Qualcomm Toq (Mirasol display).
import java.awt.Color;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import javax.imageio.ImageIO;
// WARNING: DIRTY CODE
public class msol2png {
public static void main(String[] args) {
if (args.length <= 0) {
System.out.println("Enter file to convert as parameter");
return;
}
File path = new File(args[0]);
if (path.isDirectory()) {
File[] files = path.listFiles();
for (File file:files)
msol2png(file.getAbsolutePath());
} else
msol2png(args[0]);
}
static void msol2png(String image) {
try {
File file = new File(image);
FileInputStream inputStream = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
inputStream.read(bytes);
inputStream.close();
int width = (bytes[8] & 0xff) + (bytes[9] << 8);
int height = (bytes[10] & 0xff) + (bytes[11] << 8);
System.out.println("width: " + width + ", height: " + height);
BufferedImage bufferedImage = new BufferedImage(width, height, ColorSpace.TYPE_RGB);
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++) {
int rgb = bytes[(16 + width * y + x)] - 3;
int r = rgb >> 6;
int g = (rgb >> 4) & 3;
int b = (rgb >> 2) & 3;
r = (r << 6) & 0xff;
g = (g << 6) & 0xff;
b = (b << 6) & 0xff;
bufferedImage.setRGB(x, y, new Color(r, g, b).getRGB());
}
File outputfile = new File(image + ".png");
ImageIO.write(bufferedImage, "png", outputfile);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment