diff --git a/ImageToUINT_Tool/Main.java b/ImageToUINT_Tool/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..0962a923171bbd940b2560ef1ad14cf84e226bc3 --- /dev/null +++ b/ImageToUINT_Tool/Main.java @@ -0,0 +1,75 @@ +import java.awt.image.*; +import java.awt.*; +import java.nio.file.*; +import javax.imageio.ImageIO; +import java.io.*; +import java.util.*; + +public class Main{ + public static void main(String[] args) { + if (args.length == 0) + System.exit(1); + try{ + for(String s : args){ + errorCentral(s); + } + } catch (Exception e){ + + } + } + + public static void errorCentral(String filePath) throws Exception{ + BufferedImage img = null; + File imgFile = new File(filePath); + img = ImageIO.read(imgFile); + + if(img == null) + System.exit(1); + + int width = img.getWidth(); + int height = img.getHeight(); + ColorModel colorModel = img.getColorModel(); + Raster imgRaster = img.getRaster(); + + /* + int[] colorData = new int[height*width*3]; + + for(int yDisp = 0; yDisp < height; yDisp++) + for(int xDisp = 0; xDisp < width; xDisp++){ + Object pix = imgRaster.getDataElements(xDisp, yDisp, null); + colorData[yDisp*width*3 + xDisp*3] = colorModel.getRed(pix) >>> 3; + colorData[yDisp*width*3 + xDisp*3 + 1] = colorModel.getGreen(pix) >>> 2; + colorData[yDisp*width*3 + xDisp*3 + 2] = colorModel.getBlue(pix) >>> 3; + } + */ + + + + int[] colorData = new int[height*width]; + + for(int yDisp = 0; yDisp < height; yDisp++) + for(int xDisp = 0; xDisp < width; xDisp++){ + Object pix = imgRaster.getDataElements(xDisp, yDisp, null); + int redData = colorModel.getRed(pix) >>> 3; + int greenData = colorModel.getGreen(pix) >>> 2; + int blueData = colorModel.getBlue(pix) >>> 3; + colorData[yDisp * width + xDisp] = (redData << 11) + (greenData << 5) + blueData; + } + + + String finalOutput = ""; + finalOutput += "File Name: " + imgFile.getName(); + finalOutput += "\nImgWidth: " + width + "\nImgHeight: " + height; + String finalFormatArray = Arrays.toString(colorData).replace("[", "").replace("]", ""); + finalOutput += "\nData: \nuint16_t[] = {" + finalFormatArray + "};"; + + //Create stuff + File newFile = new File(imgFile.getName() + ".txt"); + newFile.createNewFile(); + FileWriter outputStrm = new FileWriter(imgFile.getName() + ".txt"); + outputStrm.write(finalOutput); + outputStrm.close(); + + System.out.println(finalOutput); + } +} \ No newline at end of file