Skip to content
Snippets Groups Projects
Commit 98e0f45c authored by sr1g19's avatar sr1g19
Browse files

Upload New File

parent b6114155
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment