Does anyone have experience with differences in IO file on different platforms? I wrote a LWJGL program that translates a TIFF file with 100 MB. Streaming is pretty fast on several Mac and Linux computers, but on my 64-bit Windows 7 Desktop it takes a few seconds to load each tile on the map.
Basically, I create a 2D array of instances of the Tile class. Each fragment represents a 512x512 MB region of a TIFF file, and the visualization method checks to see if the tile region was loaded in memory, if not, the load is queued in ThreadPoolExecutor if it has been queued, nothing happens if it is loaded it is painted. Access to TIFF is handled by the TIFF class, which reads a file with an instance of RandomAccessFile. This is the function I use to read fragments from TIFF
public BufferedImage getRasterTile(Rectangle area) {
BufferedImage image = new BufferedImage(area.width, area.height,
BufferedImage.TYPE_INT_RGB);
try {
long[] bytesPerSample = new long[bitsPerSample.length];
for (int i = 0; i < bytesPerSample.length; i++) {
bytesPerSample[i] += bitsPerSample[i] / 8 + bitsPerSample[i]
% 8 == 0 ? 0 : 1;
}
long bytesPerPixel = 0;
for (long bits : bitsPerSample) {
bytesPerPixel += bits / 8 + bits % 8 == 0 ? 0 : 1;
}
long bytesPerRow = bytesPerPixel * imageWidth;
int strip, color;
byte red, green, blue;
for (int i = area.x; i < area.x + area.width; i++) {
for (int u = area.y; u < area.y + area.height; u++) {
if (i > 0 && u > 0 && i < imageWidth && u < imageLength) {
switch (planarConfiguration) {
case Chunky:
strip = (int) (u / rowsPerStrip);
seek(stripOffsets[strip]
+ (u - strip * rowsPerStrip)
* bytesPerRow + i * bytesPerPixel);
red = readByte();
green = readByte();
blue = readByte();
color = (red & 0x0ff) << 16 | (green & 0x0ff) << 8
| (blue & 0x0ff);
image.setRGB(i - area.x, u - area.y, color);
break;
case Planar:
strip = (u / (int) rowsPerStrip);
seek(stripOffsets[strip] + i);
red = readByte();
seek(stripOffsets[strip + (int) imageLength] + i);
green = readByte();
seek(stripOffsets[strip + 2 * (int) imageLength]
+ i);
blue = readByte();
color = (red & 0x0ff) << 16 | (green & 0x0ff) << 8
| (blue & 0x0ff);
image.setRGB(i - area.x, u - area.y, color);
break;
}
} else {
image.setRGB(i - area.x, u - area.y, 0);
}
}
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
return image;
}
source
share