Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aktortest;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- public class Aktortest {
- /* CONSTANT VALUES */
- private final static int cColorCount = 3;
- private final static int cRedOffset = 0;
- private final static int cGreenOffset = 1;
- private final static int cBlueOffset = 2;
- private final static boolean cIsVerbose = true;
- /* ################################################################################################### */
- /* WORKING METHODS */
- /**
- * Executes the Split Pixel exercise
- * @param input = byte array, with pixels to split
- * @param pRedFileName = string of filename where the red pixels have to saved to
- * @param pGreenFileName = string of filename where the green pixels have to saved to
- * @param pBlueFileName = string of filename where the blue pixels have to saved to
- * @throws IOException
- */
- public static void SplitPixel(byte[] input, String pRedFileName, String pGreenFileName, String pBlueFileName) throws IOException
- {
- /* DECLARING THE NEEDED VARIABLES */
- int lArrayLength = input.length;
- byte[] lRedPixel = new byte[lArrayLength /cColorCount];
- byte[] lGreenPixel = new byte[lArrayLength /cColorCount];
- byte[] lBluePixel = new byte[lArrayLength /cColorCount];
- if(cIsVerbose)
- System.out.println("Starting splitting an array of Length: " + lArrayLength);
- /* DO THE ACTUAL SPLITTING */
- for(int i = 0; i < lArrayLength; i += cColorCount)
- {
- lRedPixel[i /cColorCount] = input[i +cRedOffset];
- lGreenPixel[i /cColorCount] = input[i +cGreenOffset];
- lBluePixel[i /cColorCount] = input[i +cBlueOffset];
- }
- /* WRITE RESULTS TO THE GIVEN FILES */
- writeBinaryFile(pRedFileName, lRedPixel);
- writeBinaryFile(pGreenFileName, lGreenPixel);
- writeBinaryFile(pBlueFileName, lBluePixel);
- if(cIsVerbose)
- System.out.println("Splitted the Array succesfully.\n" +
- "Wrote the results to: " + pRedFileName + " (red pixels), "
- + pGreenFileName + "(green pixels), "
- + pBlueFileName + "(blue pixels)");
- }
- /* ################################################################################################### */
- /* ################################################################################################### */
- /* BINARY FILE METHODS */
- /**
- * Read in the given Binary file
- * @param aFileName
- * @return array of read bytes
- * @throws IOException
- */
- static byte[] readBinaryFile(String aFileName) throws IOException {
- Path path = Paths.get(aFileName);
- return Files.readAllBytes(path);
- }
- /**
- * Writes the given array to the specified File
- * @param aFileName
- * @param pContent
- * @throws IOException
- */
- static void writeBinaryFile(String aFileName, byte[] pContent) throws IOException {
- Path path = Paths.get(aFileName);
- Files.write(path, pContent);
- }
- /* ################################################################################################### */
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) {
- if(args[0].equals("-d"))
- {
- /*
- * args[0] = "-d"
- * args[1] = input file
- * args[2] = red output file
- * args[3] = green output file
- * args[4] = blue output file
- */
- try {
- /* READ IN ALL BYTES */
- if(cIsVerbose)
- System.out.println("Read the file: " + args[1]);
- byte[] buffer = readBinaryFile(args[1]);
- /* WRITE TO THE ACCORDING FILES */
- if(cIsVerbose)
- System.out.println("Successfully read the file.");
- SplitPixel(buffer, args[2], args[3], args[4]);
- } catch (Exception e)
- {
- System.out.println(e);
- }
- }
- else if(args[0].equals("-c"))
- {
- /*
- * args[0] = "-c"
- */
- /* DO WHATEVER -c HAS TO DO */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement