Changeset 5969 for branches/cleanup


Ignore:
Timestamp:
02/26/10 11:52:38 (10 years ago)
Author:
callan
Message:

#466 Converting PhotoInterp into a Java 1.5+ enum

Location:
branches/cleanup/components/bio-formats/src/loci/formats
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/bio-formats/src/loci/formats/gui/AWTTiffTools.java

    r5966 r5969  
    118118    if (ifd.getIFDValue(IFD.PHOTOMETRIC_INTERPRETATION) == null) 
    119119    { 
    120       int photometricInterpretation = indexed ? PhotoInterp.RGB_PALETTE : 
    121         nChannels == 1 ? PhotoInterp.BLACK_IS_ZERO : PhotoInterp.RGB; 
     120      PhotoInterp photometricInterpretation =  
     121        indexed ? PhotoInterp.RGB_PALETTE : nChannels == 1 ? 
     122            PhotoInterp.BLACK_IS_ZERO : PhotoInterp.RGB; 
    122123      ifd.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION, 
    123124        photometricInterpretation); 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/BaseTiffReader.java

    r5958 r5969  
    103103    put("Compression", comp.getCodecName()); 
    104104 
    105     int photo = firstIFD.getPhotometricInterpretation(); 
    106     String photoInterp = PhotoInterp.getPIName(photo); 
    107     String metaDataPhotoInterp = PhotoInterp.getPIMeta(photo); 
     105    PhotoInterp photo = firstIFD.getPhotometricInterpretation(); 
     106    String photoInterp = photo.getName(); 
     107    String metaDataPhotoInterp = photo.getMetadataType(); 
    108108    put("PhotometricInterpretation", photoInterp); 
    109109    put("MetaDataPhotometricInterpretation", metaDataPhotoInterp); 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/ImaconReader.java

    r5958 r5969  
    100100      IFD ifd = ifds.get(i); 
    101101 
    102       int photo = ifd.getPhotometricInterpretation(); 
     102      PhotoInterp photo = ifd.getPhotometricInterpretation(); 
    103103      int samples = ifd.getSamplesPerPixel(); 
    104104      core[i].rgb = samples > 1 || photo == PhotoInterp.RGB || 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/MetamorphReader.java

    r5956 r5969  
    787787      if (stripsPerImage * rowsPerStrip != getSizeY()) stripsPerImage++; 
    788788 
    789       int check = firstIFD.getPhotometricInterpretation(); 
     789      PhotoInterp check = firstIFD.getPhotometricInterpretation(); 
    790790      if (check == PhotoInterp.RGB_PALETTE) { 
    791791        firstIFD.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION, 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/MinimalTiffReader.java

    r5958 r5969  
    315315    IFD firstIFD = ifds.get(0); 
    316316 
    317     int photo = firstIFD.getPhotometricInterpretation(); 
     317    PhotoInterp photo = firstIFD.getPhotometricInterpretation(); 
    318318    int samples = firstIFD.getSamplesPerPixel(); 
    319319    core[0].rgb = samples > 1 || photo == PhotoInterp.RGB; 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/NikonReader.java

    r5958 r5969  
    137137    long[] byteCounts = ifd.getStripByteCounts(); 
    138138    long[] offsets = ifd.getStripOffsets(); 
    139     long[] rowsPerStrip = ifd.getRowsPerStrip(); 
    140  
    141     float bytesPerSample = (float) dataSize / 8; 
     139 
    142140    boolean maybeCompressed = ifd.getCompression() == TiffCompression.NIKON; 
    143141    boolean compressed = vPredictor != null && curve != null && maybeCompressed; 
     
    261259 
    262260    IFD firstIFD = ifds.get(0); 
    263     int photo = firstIFD.getPhotometricInterpretation(); 
     261    PhotoInterp photo = firstIFD.getPhotometricInterpretation(); 
    264262    int samples = firstIFD.getSamplesPerPixel(); 
    265263    core[0].rgb = samples > 1 || photo == PhotoInterp.RGB || 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/OMETiffReader.java

    r5938 r5969  
    513513          core[s].dimensionOrder = omexmlMeta.getPixelsDimensionOrder(i, p); 
    514514          core[s].orderCertain = true; 
    515           int photo = firstIFD.getPhotometricInterpretation(); 
     515          PhotoInterp photo = firstIFD.getPhotometricInterpretation(); 
    516516          core[s].rgb = samples > 1 || photo == PhotoInterp.RGB; 
    517517          if ((samples != core[s].sizeC && (samples % core[s].sizeC) != 0 && 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/SVSReader.java

    r5761 r5969  
    115115    for (int s=0; s<core.length; s++) { 
    116116      IFD ifd = ifds.get(s); 
    117       int p = ifd.getPhotometricInterpretation(); 
     117      PhotoInterp p = ifd.getPhotometricInterpretation(); 
    118118      int samples = ifd.getSamplesPerPixel(); 
    119119      core[s].rgb = samples > 1 || p == PhotoInterp.RGB; 
  • branches/cleanup/components/bio-formats/src/loci/formats/in/ZeissLSMReader.java

    r5958 r5969  
    432432    tiffParser = new TiffParser(in); 
    433433 
    434     int photo = ifd.getPhotometricInterpretation(); 
     434    PhotoInterp photo = ifd.getPhotometricInterpretation(); 
    435435    int samples = ifd.getSamplesPerPixel(); 
    436436 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/IFD.java

    r5964 r5969  
    687687   * @throws FormatException if there is a problem parsing the IFD metadata. 
    688688   */ 
    689   public int getPhotometricInterpretation() throws FormatException { 
    690     int photoInterp = getIFDIntValue(PHOTOMETRIC_INTERPRETATION, true, 0); 
    691     PhotoInterp.checkPI(photoInterp); 
    692     return photoInterp; 
     689  public PhotoInterp getPhotometricInterpretation() throws FormatException { 
     690    return PhotoInterp.get(getIFDIntValue(PHOTOMETRIC_INTERPRETATION, true, 0)); 
    693691  } 
    694692 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/PhotoInterp.java

    r5956 r5969  
    2424package loci.formats.tiff; 
    2525 
    26 import loci.formats.FormatException; 
     26import java.util.EnumSet; 
     27import java.util.HashMap; 
     28import java.util.Map; 
     29 
     30import loci.common.CodedEnum; 
    2731 
    2832/** 
     
    3842 * @author Chris Allan callan at blackcat.ca 
    3943 */ 
    40 public final class PhotoInterp { 
     44public enum PhotoInterp implements CodedEnum { 
    4145 
    42   // -- Constants -- 
     46  WHITE_IS_ZERO(0, "WhiteIsZero", "Monochrome"), 
     47  BLACK_IS_ZERO(1, "BlackIsZero", "Monochrome"), 
     48  RGB(2, "RGB", "RGB"), 
     49  RGB_PALETTE(3, "Palette", "Monochrome"), 
     50  TRANSPARENCY_MASK(4, "Transparency Mask", "RGB"), 
     51  CMYK(5, "CMYK", "CMYK"), 
     52  Y_CB_CR(6, "YCbCr", "RGB"), 
     53  CIE_LAB(8, "CIELAB", "RGB"), 
     54  CFA_ARRAY(32803, "Color Filter Array", "RGB"); 
    4355 
    44   // TODO: Investigate using Java 1.5 enum instead of int enumeration. 
    45   //       http://javahowto.blogspot.com/2008/04/java-enum-examples.html 
    46   public static final int WHITE_IS_ZERO = 0; 
    47   public static final int BLACK_IS_ZERO = 1; 
    48   public static final int RGB = 2; 
    49   public static final int RGB_PALETTE = 3; 
    50   public static final int TRANSPARENCY_MASK = 4; 
    51   public static final int CMYK = 5; 
    52   public static final int Y_CB_CR = 6; 
    53   public static final int CIE_LAB = 8; 
    54   public static final int CFA_ARRAY = 32803; 
     56  /** Code for the IFD type in the actual TIFF file. */ 
     57  private int code; 
     58 
     59  /** Given name of the photometric interpretation. */ 
     60  private String name; 
     61 
     62  /** Metadata type of the photometric interpretation. */ 
     63  private String metadataType; 
     64 
     65  private static final Map<Integer,PhotoInterp> lookup = 
     66    new HashMap<Integer,PhotoInterp>(); 
     67 
     68  /** Reverse lookup of code to IFD type enumerate value. */ 
     69  static { 
     70    for(PhotoInterp v : EnumSet.allOf(PhotoInterp.class)) { 
     71      lookup.put(v.getCode(), v); 
     72    } 
     73  } 
    5574 
    5675  // -- Constructor -- 
    5776 
    58   private PhotoInterp() { } 
     77  /** 
     78   * Default constructor. 
     79   * @param code Integer "code" for the photometric interpretation. 
     80   * @param name Given name of the photometric interpretation. 
     81   * @param metadataType Metadata type of the photometric interpretation. 
     82   */ 
     83  private PhotoInterp(int code, String name, String metadataType) { 
     84    this.code = code; 
     85    this.name = name; 
     86    this.metadataType = metadataType; 
     87  } 
    5988 
    6089  // -- PhotoInterp methods -- 
    6190 
    62   /** Returns the name of the given photometric interpretation. */ 
    63   public static String getPIName(int photoInterp) { 
    64     switch (photoInterp) { 
    65       case WHITE_IS_ZERO: 
    66         return "WhiteIsZero"; 
    67       case BLACK_IS_ZERO: 
    68         return "BlackIsZero"; 
    69       case RGB: 
    70         return "RGB"; 
    71       case RGB_PALETTE: 
    72         return "Palette"; 
    73       case TRANSPARENCY_MASK: 
    74         return "Transparency Mask"; 
    75       case CMYK: 
    76         return "CMYK"; 
    77       case Y_CB_CR: 
    78         return "YCbCr"; 
    79       case CIE_LAB: 
    80         return "CIELAB"; 
    81       case CFA_ARRAY: 
    82         return "Color Filter Array"; 
    83     } 
    84     return null; 
     91  /** 
     92   * Retrieves a photometric interpretation by reverse lookup of its "code". 
     93   * @param code The code to look up. 
     94   * @return The <code>PhotoInterp</code> instance for the 
     95   * <code>code</code> or <code>null</code> if it does not exist. 
     96   */ 
     97  public static PhotoInterp get(int code) {  
     98    return lookup.get(code); 
     99    //throw new FormatException("Unknown PhotometricInterpretation (" + 
     100    //    photoInterp + ")"); 
     101  } 
     102 
     103  /* (non-Javadoc) 
     104   * @see loci.common.CodedEnum#getCode() 
     105   */ 
     106  public int getCode() { 
     107    return code; 
    85108  } 
    86109 
    87110  /** 
    88    * Returns the metadata type for the given photometric interpretation. 
    89    * 
    90    * @return One of the following values:<ul> 
    91    *  <li>Monochrome</li> 
    92    *  <li>RGB</li> 
    93    * </ul> 
     111   * Retrieves the given name of the photometric interpretation.  
     112   * @return See above. 
    94113   */ 
    95   public static String getPIMeta(int photoInterp) { 
    96     switch (photoInterp) { 
    97       case WHITE_IS_ZERO: 
    98         return "Monochrome"; 
    99       case BLACK_IS_ZERO: 
    100         return "Monochrome"; 
    101       case RGB: 
    102         return "RGB"; 
    103       case RGB_PALETTE: 
    104         return "Monochrome"; 
    105       case TRANSPARENCY_MASK: 
    106         return "RGB"; 
    107       case CMYK: 
    108         return "CMYK"; 
    109       case Y_CB_CR: 
    110         return "RGB"; 
    111       case CIE_LAB: 
    112         return "RGB"; 
    113       case CFA_ARRAY: 
    114         return "RGB"; 
    115     } 
    116     return null; 
     114  public String getName() { 
     115    return name; 
    117116  } 
    118117 
    119118  /** 
    120    * Verifies that the given photometric interpretation is supported. 
    121    * 
    122    * @throws FormatException if the photometric interpretation 
    123    *   is unsupported or unknown. 
     119   * Retrieves the metadata type of the photometric interpretation. 
     120   * @return See above. 
    124121   */ 
    125   public static void checkPI(int photoInterp) throws FormatException { 
    126     if (photoInterp != WHITE_IS_ZERO && 
    127       photoInterp != BLACK_IS_ZERO && 
    128       photoInterp != RGB && 
    129       photoInterp != RGB_PALETTE && 
    130       photoInterp != CMYK && 
    131       photoInterp != Y_CB_CR && 
    132       photoInterp != CFA_ARRAY) 
    133     { 
    134       String piName = getPIName(photoInterp); 
    135       if (piName == null) { 
    136         throw new FormatException("Unknown PhotometricInterpretation (" + 
    137           photoInterp + ")"); 
    138       } 
    139       else { 
    140         throw new FormatException("Sorry, " + piName + 
    141           " PhotometricInterpretation is not supported."); 
    142       } 
    143     } 
     122  public String getMetadataType() { 
     123    return metadataType; 
    144124  } 
    145125 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r5966 r5969  
    582582    long numTileCols = ifd.getTilesPerRow(); 
    583583 
    584     int photoInterp = ifd.getPhotometricInterpretation(); 
     584    PhotoInterp photoInterp = ifd.getPhotometricInterpretation(); 
    585585    int planarConfig = ifd.getPlanarConfiguration(); 
    586586    int pixel = ifd.getBytesPerSample()[0]; 
     
    721721    int bitsPerSample = ifd.getBitsPerSample()[0]; 
    722722    boolean littleEndian = ifd.isLittleEndian(); 
    723     int photoInterp = ifd.getPhotometricInterpretation(); 
     723    PhotoInterp photoInterp = ifd.getPhotometricInterpretation(); 
    724724 
    725725    for (int j=0; j<bytes.length / realBytes; j++) { 
     
    756756 
    757757    TiffCompression compression = ifd.getCompression(); 
    758     int photoInterp = ifd.getPhotometricInterpretation(); 
     758    PhotoInterp photoInterp = ifd.getPhotometricInterpretation(); 
    759759    if (compression == TiffCompression.JPEG) photoInterp = PhotoInterp.RGB; 
    760760 
Note: See TracChangeset for help on using the changeset viewer.