2012-04-28 22 views
3

異なるプラットフォームでファイルIOの違いを経験した人はいますか? 100MB以上のTIFFファイルをストリームするLWJGLプログラムを作成しました。ストリーミングは、いくつかのMacとLinuxコンピュータでかなり速く起こるが、私の64ビットWindows 7 Desktopでは、マップの各タイルがロードされるまで数秒かかるようだ。JavaはWindows上でファイルを非常にゆっくり読み込みます

基本的に、私はTileクラスのインスタンスの2D配列を作成します。各タイルはTIFFファイルの512x512 MBの領域であり、レンダリングメソッドはメモリ内のタイルの領域がロードされているかどうかをチェックし、そうでない場合、ロードはThreadPoolExecutorでキューに入れられ、何も起こらなければ何も起こりません。描かれた。 TIFFへのアクセスは、RandomAccessFileインスタンスでファイルを読み取るTIFFクラスによって処理されます。これは、私はそれはあなたがファイルを読んでいる方法で行うことであることを疑う私は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; 
} 
+0

私は混乱しています。読みが遅いと言っているのですか?その場合、データを読み込んでいる様子を表示できますか?変換が遅いですか? –

答えて

0

からタイルを読み取るために使用する機能です。私は、あなたが繰り返し、readByte()seekという名前のメソッドを呼び出していることに気付きました。これらのメソッドがバッファされていないストリーム(またはRandomAccessFileインスタンス)で呼び出しを行っている場合は、膨大な数のシステムコールが発生している可能性があり、メソッドが非常に遅くなります。

これが原因の場合は、画像ファイル全体をbyte[]に読み込んで、配列インデックスを使用して必要なバイト数を取得する必要があります。画像ファイルが大きすぎてそれを行うことができない場合は、コードを再構築してシークを減らし、一度に多くのバイトを読み取る必要があります。

関連する問題