Changeset 4815


Ignore:
Timestamp:
02/18/09 09:26:08 (11 years ago)
Author:
melissa
Message:

Fixed how the number of padding bytes is computed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/in/BMPReader.java

    r4648 r4815  
    110110    in.seek(global + rowsToSkip * rowLength); 
    111111 
    112     int pad = getSizeX() % 2; 
    113     int planeSize = (getSizeX() + pad) * getSizeY() * getSizeC(); 
    114     if (planeSize + in.getFilePointer() > in.length()) { 
    115       pad = 0; 
    116       planeSize = getSizeX() * getSizeY() * getSizeC(); 
    117     } 
     112    int pad = ((rowLength * bpp) / 8) % 2; 
     113    if (pad == 0) pad = ((rowLength * bpp) / 8) % 4; 
     114    else pad *= getSizeC(); 
     115    int planeSize = getSizeX() * getSizeC() * getSizeY(); 
    118116    if (bpp >= 8) planeSize *= (bpp / 8); 
    119117    else planeSize /= (8 / bpp); 
     118    planeSize += pad * getSizeY(); 
     119    if (planeSize + in.getFilePointer() > in.length()) { 
     120      planeSize -= (pad * getSizeY()); 
     121      pad = 0; 
     122    } 
     123 
    120124    byte[] rawPlane = new byte[planeSize]; 
    121125    in.read(rawPlane); 
     
    129133          buf[row*w + i] = (byte) (bb.getBits(bpp) & 0xff); 
    130134        } 
    131         if (row > 0) bb.skipBits((getSizeX() - w - x + pad) * bpp); 
     135        if (row > 0) bb.skipBits((getSizeX() - w - x) * bpp + pad * 8); 
    132136      } 
    133137    } 
     
    139143          buf[row*w*getSizeC() + i] = (byte) (bb.getBits(bpp) & 0xff); 
    140144        } 
    141         bb.skipBits(getSizeC() * (getSizeX() - w - x + pad) * bpp); 
     145        bb.skipBits(getSizeC() * bpp * (getSizeX() - w - x)); 
     146        bb.skipBits(pad * 8); 
    142147      } 
    143148      for (int i=0; i<buf.length/getSizeC(); i++) { 
Note: See TracChangeset for help on using the changeset viewer.