Changeset 3299


Ignore:
Timestamp:
10/18/07 13:09:23 (12 years ago)
Author:
melissa
Message:

Alpha channel is now handled correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/in/BMPReader.java

    r3197 r3299  
    9595    } 
    9696 
     97    /* debug */ System.out.println("global offset : " + global); 
     98 
    9799    in.seek(global); 
    98100 
     
    104106    else { 
    105107      for (int y=core.sizeY[0]-1; y>=0; y--) { 
    106         in.read(buf, y*core.sizeX[0]*3, core.sizeX[0]*3); 
    107       } 
    108       for (int i=0; i<buf.length/3; i++) { 
    109         byte tmp = buf[i*3 + 2]; 
    110         buf[i*3 + 2] = buf[i*3]; 
    111         buf[i*3] = tmp; 
     108        in.read(buf, y*core.sizeX[0]*core.sizeC[0], core.sizeX[0]*core.sizeC[0]); 
     109      } 
     110      for (int i=0; i<buf.length/core.sizeC[0]; i++) { 
     111        byte tmp = buf[i*core.sizeC[0] + 2]; 
     112        buf[i*core.sizeC[0] + 2] = buf[i*core.sizeC[0]]; 
     113        buf[i*core.sizeC[0]] = tmp; 
    112114      } 
    113115    } 
     
    183185    addMeta("Y resolution", "" + pixelSizeY); 
    184186    int nColors = in.readInt(); 
     187    if (nColors == 0 && bpp != 32 && bpp != 24) { 
     188      nColors = bpp < 8 ? 1 << bpp : 256; 
     189    } 
    185190    in.skipBytes(4); 
    186191 
    187192    // read the palette, if it exists 
    188193 
    189     if (offset != in.getFilePointer() && nColors > 0) { 
     194    /* debug */ System.out.println("offset=" + offset + ", fp=" + 
     195      in.getFilePointer() + ", nColors=" + nColors); 
     196 
     197    if (nColors != 0) { 
    190198      palette = new byte[3][nColors]; 
    191199 
    192200      for (int i=0; i<nColors; i++) { 
    193         for (int j=palette.length; j>0; j--) { 
     201        for (int j=palette.length-1; j>=0; j--) { 
    194202          palette[j][i] = in.readByte(); 
    195203        } 
     
    199207 
    200208    global = in.getFilePointer(); 
     209 
    201210    addMeta("Indexed color", palette == null ? "false" : "true"); 
    202211 
     
    204213 
    205214    core.sizeC[0] = (palette == null && bpp == 8) ? 1 : 3; 
    206     if (bpp > 8) bpp /= 3; 
     215    if (bpp == 32) core.sizeC[0] = 4; 
     216    if (bpp > 8) bpp /= core.sizeC[0]; 
    207217    while (bpp % 8 != 0) bpp++; 
    208218 
     
    219229    } 
    220230 
    221     if (core.sizeX[0] % 2 == 1) core.sizeX[0]++; 
     231    core.sizeX[0] = (int) ((in.length() - global) / 
     232      (core.sizeY[0] * (bpp / 8) * (palette != null ? 1 : core.sizeC[0]))); 
     233 
    222234    core.rgb[0] = core.sizeC[0] > 1; 
    223235    core.littleEndian[0] = true; 
Note: See TracChangeset for help on using the changeset viewer.