Created
January 15, 2014 23:19
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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