Changeset 6812


Ignore:
Timestamp:
08/18/10 14:42:49 (9 years ago)
Author:
melissa
Message:

Reverse the order of the rows if a negative height was stored in the file. This also fixes a few problems with reading sub-sections of BMP images.

Files:
2 edited

Legend:

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

    r6808 r6812  
    7272  private long global; 
    7373 
     74  private boolean invertY = false; 
     75 
    7476  // -- Constructor -- 
    7577 
     
    108110    } 
    109111 
    110     int rowsToSkip = getSizeY() - (h + y); 
     112    int rowsToSkip = invertY ? y : getSizeY() - (h + y); 
    111113    int rowLength = getSizeX() * (isIndexed() ? 1 : getSizeC()); 
    112114    in.seek(global + rowsToSkip * rowLength); 
     
    130132 
    131133    int effectiveC = palette != null && palette[0].length > 0 ? 1 : getSizeC(); 
    132     for (int row=h-1; row>=y; row--) { 
     134    for (int row=h-1; row>=0; row--) { 
     135      int rowIndex = invertY ? h - 1 - row : row; 
    133136      bb.skipBits(x * bpp * effectiveC); 
    134137      for (int i=0; i<w*effectiveC; i++) { 
    135         buf[row * w * effectiveC + i] = (byte) (bb.getBits(bpp) & 0xff); 
     138        buf[rowIndex * w * effectiveC + i] = (byte) (bb.getBits(bpp) & 0xff); 
    136139      } 
    137       if (row > y) { 
     140      if (row > 0) { 
    138141        bb.skipBits((getSizeX() - w - x) * bpp * effectiveC + pad*8); 
    139142      } 
     
    153156      global = 0; 
    154157      palette = null; 
     158      invertY = false; 
    155159    } 
    156160  } 
     
    190194      LOGGER.trace("Invalid height: {}; using the absolute value", getSizeY()); 
    191195      core[0].sizeY = Math.abs(getSizeY()); 
     196      invertY = true; 
    192197    } 
    193198 
  • trunk/components/bio-formats/src/loci/formats/in/BMPReader.java

    r6808 r6812  
    7272  private long global; 
    7373 
     74  private boolean invertY = false; 
     75 
    7476  // -- Constructor -- 
    7577 
     
    108110    } 
    109111 
    110     int rowsToSkip = getSizeY() - (h + y); 
     112    int rowsToSkip = invertY ? y : getSizeY() - (h + y); 
    111113    int rowLength = getSizeX() * (isIndexed() ? 1 : getSizeC()); 
    112114    in.seek(global + rowsToSkip * rowLength); 
     
    130132 
    131133    int effectiveC = palette != null && palette[0].length > 0 ? 1 : getSizeC(); 
    132     for (int row=h-1; row>=y; row--) { 
     134    for (int row=h-1; row>=0; row--) { 
     135      int rowIndex = invertY ? h - 1 - row : row; 
    133136      bb.skipBits(x * bpp * effectiveC); 
    134137      for (int i=0; i<w*effectiveC; i++) { 
    135         buf[row * w * effectiveC + i] = (byte) (bb.getBits(bpp) & 0xff); 
     138        buf[rowIndex * w * effectiveC + i] = (byte) (bb.getBits(bpp) & 0xff); 
    136139      } 
    137       if (row > y) { 
     140      if (row > 0) { 
    138141        bb.skipBits((getSizeX() - w - x) * bpp * effectiveC + pad*8); 
    139142      } 
     
    153156      global = 0; 
    154157      palette = null; 
     158      invertY = false; 
    155159    } 
    156160  } 
     
    190194      LOGGER.trace("Invalid height: {}; using the absolute value", getSizeY()); 
    191195      core[0].sizeY = Math.abs(getSizeY()); 
     196      invertY = true; 
    192197    } 
    193198 
Note: See TracChangeset for help on using the changeset viewer.