1 /*
2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1305 }
1306
1307 /**
1308 * Sets the value of the {@code planar} field.
1309 *
1310 * <p> If this method is called, the {@code beginDecoding}
1311 * method must be called prior to calling any of the decode
1312 * methods.
1313 *
1314 * @param planar {@code true} if the image to be decoded is
1315 * stored in planar format.
1316 */
1317 public void setPlanar(boolean planar) {
1318 this.planar = planar;
1319 }
1320
1321 /**
1322 * Sets the index of the planar configuration band to be decoded. This value
1323 * is ignored for chunky (interleaved) images.
1324 *
1325 * @param the index of the planar band to decode
1326 */
1327 public void setPlanarBand(int planarBand) { this.planarBand = planarBand; }
1328
1329 /**
1330 * Sets the value of the {@code samplesPerPixel} field.
1331 *
1332 * <p> If this method is called, the {@code beginDecoding}
1333 * method must be called prior to calling any of the decode
1334 * methods.
1335 *
1336 * @param samplesPerPixel the number of samples in each source
1337 * pixel.
1338 */
1339 public void setSamplesPerPixel(int samplesPerPixel) {
1340 this.samplesPerPixel = samplesPerPixel;
1341 }
1342
1343 /**
1344 * Sets the value of the {@code bitsPerSample} field.
1345 *
2052 float fval = Float.intBitsToFloat(ival);
2053 f[dstOffset + i] = fval;
2054 }
2055
2056 dstOffset += scanlineStride;
2057 }
2058 }
2059 }
2060
2061 /**
2062 * Decodes the source data into the provided {@code double}
2063 * array {@code f}, starting at the offset given by
2064 * {@code dstOffset}. Each pixel occupies
2065 * {@code bitsPerPixel} bits, with no padding between pixels.
2066 * Scanlines are separated by {@code scanlineStride}
2067 * {@code double}s.
2068 *
2069 * <p> The default implementation calls {@code decodeRaw(byte[] b,
2070 * ...)} and copies the resulting data into {@code f}.
2071 *
2072 * @param f a {@code double} array to be written.
2073 * @param dstOffset the starting offset in {@code f} to be
2074 * written.
2075 * @param bitsPerPixel the number of bits for each pixel.
2076 * @param scanlineStride the number of {@code double}s to
2077 * advance between that starting pixels of each scanline.
2078 *
2079 * @throws IOException if an error occurs reading from the source
2080 * {@code ImageInputStream}.
2081 */
2082 public void decodeRaw(double[] d,
2083 int dstOffset,
2084 int bitsPerPixel,
2085 int scanlineStride) throws IOException {
2086 int numBands = bitsPerPixel/64;
2087 int doublesPerRow = srcWidth*numBands;
2088 int bytesPerRow = doublesPerRow*8;
2089
2090 byte[] b = new byte[bytesPerRow*srcHeight];
2091 decodeRaw(b, 0, bitsPerPixel, bytesPerRow);
2092
|
1 /*
2 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1305 }
1306
1307 /**
1308 * Sets the value of the {@code planar} field.
1309 *
1310 * <p> If this method is called, the {@code beginDecoding}
1311 * method must be called prior to calling any of the decode
1312 * methods.
1313 *
1314 * @param planar {@code true} if the image to be decoded is
1315 * stored in planar format.
1316 */
1317 public void setPlanar(boolean planar) {
1318 this.planar = planar;
1319 }
1320
1321 /**
1322 * Sets the index of the planar configuration band to be decoded. This value
1323 * is ignored for chunky (interleaved) images.
1324 *
1325 * @param planarBand the index of the planar band to decode
1326 */
1327 public void setPlanarBand(int planarBand) { this.planarBand = planarBand; }
1328
1329 /**
1330 * Sets the value of the {@code samplesPerPixel} field.
1331 *
1332 * <p> If this method is called, the {@code beginDecoding}
1333 * method must be called prior to calling any of the decode
1334 * methods.
1335 *
1336 * @param samplesPerPixel the number of samples in each source
1337 * pixel.
1338 */
1339 public void setSamplesPerPixel(int samplesPerPixel) {
1340 this.samplesPerPixel = samplesPerPixel;
1341 }
1342
1343 /**
1344 * Sets the value of the {@code bitsPerSample} field.
1345 *
2052 float fval = Float.intBitsToFloat(ival);
2053 f[dstOffset + i] = fval;
2054 }
2055
2056 dstOffset += scanlineStride;
2057 }
2058 }
2059 }
2060
2061 /**
2062 * Decodes the source data into the provided {@code double}
2063 * array {@code f}, starting at the offset given by
2064 * {@code dstOffset}. Each pixel occupies
2065 * {@code bitsPerPixel} bits, with no padding between pixels.
2066 * Scanlines are separated by {@code scanlineStride}
2067 * {@code double}s.
2068 *
2069 * <p> The default implementation calls {@code decodeRaw(byte[] b,
2070 * ...)} and copies the resulting data into {@code f}.
2071 *
2072 * @param d a {@code double} array to be written.
2073 * @param dstOffset the starting offset in {@code f} to be
2074 * written.
2075 * @param bitsPerPixel the number of bits for each pixel.
2076 * @param scanlineStride the number of {@code double}s to
2077 * advance between that starting pixels of each scanline.
2078 *
2079 * @throws IOException if an error occurs reading from the source
2080 * {@code ImageInputStream}.
2081 */
2082 public void decodeRaw(double[] d,
2083 int dstOffset,
2084 int bitsPerPixel,
2085 int scanlineStride) throws IOException {
2086 int numBands = bitsPerPixel/64;
2087 int doublesPerRow = srcWidth*numBands;
2088 int bytesPerRow = doublesPerRow*8;
2089
2090 byte[] b = new byte[bytesPerRow*srcHeight];
2091 decodeRaw(b, 0, bitsPerPixel, bytesPerRow);
2092
|