|
14 | 14 | import java.nio.ByteBuffer; |
15 | 15 | import java.nio.ByteOrder; |
16 | 16 | import java.nio.FloatBuffer; |
| 17 | +import java.nio.IntBuffer; |
| 18 | +import java.nio.ShortBuffer; |
17 | 19 | import java.nio.channels.FileChannel; |
18 | 20 | import java.nio.charset.StandardCharsets; |
19 | 21 | import java.util.ArrayList; |
@@ -191,6 +193,54 @@ int writeData(byte[] data, int imageNumber) throws IOException { |
191 | 193 | return nextOverflowData; |
192 | 194 | } |
193 | 195 |
|
| 196 | + int writeData(short[] data, int imageNumber) throws IOException { |
| 197 | + if (file == null) |
| 198 | + init(); |
| 199 | + |
| 200 | + if (imageNumber == 1) |
| 201 | + channel.position(headerSize); |
| 202 | + else |
| 203 | + channel.position(nextOverflowData); |
| 204 | + |
| 205 | + // no way around making a copy |
| 206 | + ByteBuffer direct = ByteBuffer.allocateDirect(2 * data.length); |
| 207 | + ShortBuffer buffer = direct.asShortBuffer(); |
| 208 | + buffer.put(data); |
| 209 | + // buffer.flip(); |
| 210 | + channel.write(direct); |
| 211 | + |
| 212 | + if (imageNumber == 1) |
| 213 | + firstIFD = headerSize + 2 * data.length; |
| 214 | + else |
| 215 | + firstIFD = 2 * data.length + nextOverflowData; |
| 216 | + |
| 217 | + return nextOverflowData; |
| 218 | + } |
| 219 | + |
| 220 | + int writeData(int[] data, int imageNumber) throws IOException { |
| 221 | + if (file == null) |
| 222 | + init(); |
| 223 | + |
| 224 | + if (imageNumber == 1) |
| 225 | + channel.position(headerSize); |
| 226 | + else |
| 227 | + channel.position(nextOverflowData); |
| 228 | + |
| 229 | + // no way around making a copy |
| 230 | + ByteBuffer direct = ByteBuffer.allocateDirect(4 * data.length); |
| 231 | + IntBuffer buffer = direct.asIntBuffer(); |
| 232 | + buffer.put(data); |
| 233 | + // buffer.flip(); |
| 234 | + channel.write(direct); |
| 235 | + |
| 236 | + if (imageNumber == 1) |
| 237 | + firstIFD = headerSize + 4 * data.length; |
| 238 | + else |
| 239 | + firstIFD = 4 * data.length + nextOverflowData; |
| 240 | + |
| 241 | + return nextOverflowData; |
| 242 | + } |
| 243 | + |
194 | 244 | int writeData(float[] data, int imageNumber) throws IOException { |
195 | 245 | if (file == null) |
196 | 246 | init(); |
|
0 commit comments