Java Code Examples for javax.imageio.stream.FileImageOutputStream#writeByte()
The following examples show how to use
javax.imageio.stream.FileImageOutputStream#writeByte() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UInt16ParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void writeUInt16ParamChoiceToFile(File file, int selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); switch (selector) { case 1: stream.writeByte(value); break; case 2: case 3: case 4: stream.writeShort(value); break; case 5: case 6: break; default: stream.writeInt(value); } stream.close(); }
Example 2
Source File: UInt32ParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void writeUInt32ParamChoiceToFile(File file, long selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); if (selector == 1) { stream.writeByte(value); } else if (selector == 2 || selector == 3 || selector == 4) { stream.writeShort(value); } else if (selector != 5 && selector != 6) { stream.writeInt(value); } stream.close(); }
Example 3
Source File: UInt64ParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void writeUInt64ParamChoiceToFile(File file, BigInteger selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); if (selector.compareTo(new BigInteger("1")) == 0) stream.writeByte(value); else if (selector.compareTo(new BigInteger("2")) == 0 || selector.compareTo(new BigInteger("3")) == 0 || selector.compareTo(new BigInteger("4")) == 0) stream.writeShort(value); else if (selector.compareTo(new BigInteger("5")) == 0 || selector.compareTo(new BigInteger("6")) == 0) ; else stream.writeInt(value); stream.close(); }
Example 4
Source File: DefaultEmptyChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void writeDefaultEmptyChoiceToFile(File file, byte tag, short value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); switch (tag) { case 1: stream.writeByte(value); break; case 2: stream.writeShort(value); break; default: break; } stream.close(); }
Example 5
Source File: FullEnumParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void writeFullEnumParamChoiceToFile(File file, Selector selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); if (selector == Selector.BLACK) stream.writeByte(value); else if (selector == Selector.GREY) stream.writeShort(value); else if (selector == Selector.WHITE) stream.writeInt(value); else fail("Invalid selector: " + selector); stream.close(); }
Example 6
Source File: BoolParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void writeBoolParamChoiceToFile(File file, boolean selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); if (selector) stream.writeByte(value); else stream.writeShort(value); stream.close(); }
Example 7
Source File: EnumParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void writeEnumParamChoiceToFile(File file, Selector selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); if (selector == Selector.BLACK) stream.writeByte(value); else if (selector == Selector.GREY) stream.writeShort(value); else if (selector == Selector.WHITE) stream.writeInt(value); else fail("Invalid selector: " + selector); stream.close(); }
Example 8
Source File: FullBitmaskParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void writeFullBitmaskParamChoiceToFile(File file, Selector selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); if (selector == Selector.Values.BLACK) stream.writeByte(value); else if (selector == Selector.Values.WHITE) stream.writeByte(value); else if (selector == Selector.Values.BLACK_AND_WHITE) stream.writeShort(value); else fail("Invalid selector: " + selector); stream.close(); }
Example 9
Source File: BitmaskParamChoiceTest.java From zserio with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void writeBitmaskParamChoiceToFile(File file, Selector selector, int value) throws IOException { final FileImageOutputStream stream = new FileImageOutputStream(file); if (selector == Selector.Values.BLACK) stream.writeByte(value); else if (selector == Selector.Values.WHITE) stream.writeByte(value); else if (selector == Selector.Values.BLACK_AND_WHITE) stream.writeShort(value); else fail("Invalid selector: " + selector); stream.close(); }
Example 10
Source File: NdviSimpleMain.java From snap-examples with GNU General Public License v3.0 | 4 votes |
/** * Runs this program with the given parameters. */ private static void run(String inputPath, String outputPath) throws IOException { // Read the product (note that only 'nodes' are read, not the entire data!) Product product = ProductIO.readProduct(inputPath); // Get the scene width int w = product.getSceneRasterWidth(); // Get the scene height int h = product.getSceneRasterHeight(); // Get the "low" band Band lowBand = product.getBand("radiance_6"); if (lowBand == null) { throw new IOException("low-band 'radiance_6' not found"); } // Get the "high" band Band hiBand = product.getBand("radiance_10"); if (hiBand == null) { throw new IOException("hi-band 'radiance_10' not found"); } // Print out, what we are going to do... System.out.println("writing NDVI raw image file " + outputPath + " containing " + w + " x " + h + " pixels of type byte (value range 0-255)..."); // Create an output stream for the NDVI raw data FileImageOutputStream outputStream = new FileImageOutputStream(new File(outputPath)); // Create a buffer for reading a single scan line of the low-band float[] lowBandPixels = new float[w]; // Create a buffer for reading a single scan line of the hi-band float[] hiBandPixels = new float[w]; // Hi/Low-band sum and difference of the NDVI quotient float sum, dif; // NDVI value float ndvi; // NDVI value in the range 0 to 255 int ndviByte; // For all scan lines in the product... for (int y = 0; y < h; y++) { // Read low-band pixels for line y lowBand.readPixels(0, y, w, 1, lowBandPixels, new PrintWriterProgressMonitor(System.out)); // Read hi-band pixels for line y hiBand.readPixels(0, y, w, 1, hiBandPixels, new PrintWriterProgressMonitor(System.out)); // Compute NDVI for all x for (int x = 0; x < w; x++) { dif = lowBandPixels[x] - hiBandPixels[x]; sum = lowBandPixels[x] + hiBandPixels[x]; if (sum != 0.0F) { ndvi = dif / sum; } else { ndvi = 0.0F; } if (ndvi < 0.0F) { ndvi = 0.0F; } else if (ndvi > 1.0F) { ndvi = 1.0F; } // Convert NDVI to integer in the range 0 to 255 ndviByte = (int) (255 * ndvi); // write NDVI byte to raw image file outputStream.writeByte(ndviByte); } } // close raw image file outputStream.close(); // Done! System.out.println("OK"); }