@Override
    protected IIOMetadataNode getStandardChromaNode() {
        IIOMetadataNode chroma = new IIOMetadataNode("Chroma");

        // Handle ColorSpaceType (RGB/CMYK/YCbCr etc)...
        Entry photometricTag = ifd.getEntryById(TIFF.TAG_PHOTOMETRIC_INTERPRETATION);
        int photometricValue = getValueAsInt(photometricTag); // No default for this tag!
        int numChannelsValue = getSamplesPerPixelWithFallback();

        IIOMetadataNode colorSpaceType = new IIOMetadataNode("ColorSpaceType");
        chroma.appendChild(colorSpaceType);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_MASK: // It's really a transparency mask/alpha channel, but...
                colorSpaceType.setAttribute("name", "GRAY");
                break;
            case TIFFBaseline.PHOTOMETRIC_RGB:
            case TIFFBaseline.PHOTOMETRIC_PALETTE:
                colorSpaceType.setAttribute("name", "RGB");
                break;
            case TIFFExtension.PHOTOMETRIC_YCBCR:
                colorSpaceType.setAttribute("name", "YCbCr");
                break;
            case TIFFExtension.PHOTOMETRIC_CIELAB:
            case TIFFExtension.PHOTOMETRIC_ICCLAB:
            case TIFFExtension.PHOTOMETRIC_ITULAB:
                colorSpaceType.setAttribute("name", "Lab");
                break;
            case TIFFExtension.PHOTOMETRIC_SEPARATED:
                // TODO: May be CMYK, or something else... Consult InkSet and NumberOfInks!
                if (numChannelsValue == 3) {
                    colorSpaceType.setAttribute("name", "CMY");
                }
                else {
                    colorSpaceType.setAttribute("name", "CMYK");
                }
                break;
            case TIFFCustom.PHOTOMETRIC_LOGL: // ..?
            case TIFFCustom.PHOTOMETRIC_LOGLUV:
                colorSpaceType.setAttribute("name", "Luv");
                break;
            case TIFFCustom.PHOTOMETRIC_CFA:
            case TIFFCustom.PHOTOMETRIC_LINEAR_RAW: // ...or is this RGB?
                colorSpaceType.setAttribute("name", "3CLR");
                break;
            default:
                colorSpaceType.setAttribute("name", Integer.toHexString(numChannelsValue) + "CLR");
                break;
        }

        // NumChannels
        IIOMetadataNode numChannels = new IIOMetadataNode("NumChannels");
        chroma.appendChild(numChannels);
        if (photometricValue == TIFFBaseline.PHOTOMETRIC_PALETTE) {
            numChannels.setAttribute("value", "3");
        }
        else {
            numChannels.setAttribute("value", Integer.toString(numChannelsValue));
        }

        // BlackIsZero (defaults to TRUE)
        IIOMetadataNode blackIsZero = new IIOMetadataNode("BlackIsZero");
        chroma.appendChild(blackIsZero);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
                blackIsZero.setAttribute("value", "FALSE");
                break;
            default:
                break;
        }

        Entry colorMapTag = ifd.getEntryById(TIFF.TAG_COLOR_MAP);

        if (colorMapTag != null) {
            int[] colorMapValues = (int[]) colorMapTag.getValue();

            IIOMetadataNode palette = new IIOMetadataNode("Palette");
            chroma.appendChild(palette);

            int count = colorMapValues.length / 3;
            for (int i = 0; i < count; i++) {
                IIOMetadataNode paletteEntry = new IIOMetadataNode("PaletteEntry");
                paletteEntry.setAttribute("index", Integer.toString(i));

                // TODO: See TIFFImageReader createIndexColorModel, to detect 8 bit colorMap
                paletteEntry.setAttribute("red", Integer.toString((colorMapValues[i] >> 8) & 0xff));
                paletteEntry.setAttribute("green", Integer.toString((colorMapValues[i + count] >> 8) & 0xff));
                paletteEntry.setAttribute("blue", Integer.toString((colorMapValues[i + count * 2] >> 8) & 0xff));

                palette.appendChild(paletteEntry);
            }
        }

        return chroma;
    }
@ Override protected IIOMetadataNode getStandardChromaNode ( ) { IIOMetadataNode chroma = new IIOMetadataNode ( "Chroma" ) ; Entry photometricTag = ifd . getEntryById ( TIFF . TAG_PHOTOMETRIC_INTERPRETATION ) ; int photometricValue = getValueAsInt ( photometricTag ) ; int numChannelsValue = getSamplesPerPixelWithFallback ( ) ; IIOMetadataNode colorSpaceType = new IIOMetadataNode ( "ColorSpaceType" ) ; chroma . appendChild ( colorSpaceType ) ; switch ( photometricValue ) { case TIFFBaseline . PHOTOMETRIC_WHITE_IS_ZERO : case TIFFBaseline . PHOTOMETRIC_BLACK_IS_ZERO : case TIFFBaseline . PHOTOMETRIC_MASK : colorSpaceType . setAttribute ( "name" , "GRAY" ) ; break ; case TIFFBaseline . PHOTOMETRIC_RGB : case TIFFBaseline . PHOTOMETRIC_PALETTE : colorSpaceType . setAttribute ( "name" , "RGB" ) ; break ; case TIFFExtension . PHOTOMETRIC_YCBCR : colorSpaceType . setAttribute ( "name" , "YCbCr" ) ; break ; case TIFFExtension . PHOTOMETRIC_CIELAB : case TIFFExtension . PHOTOMETRIC_ICCLAB : case TIFFExtension . PHOTOMETRIC_ITULAB : colorSpaceType . setAttribute ( "name" , "Lab" ) ; break ; case TIFFExtension . PHOTOMETRIC_SEPARATED : if ( numChannelsValue == 3 ) { colorSpaceType . setAttribute ( "name" , "CMY" ) ; } else { colorSpaceType . setAttribute ( "name" , "CMYK" ) ; } break ; case TIFFCustom . PHOTOMETRIC_LOGL : case TIFFCustom . PHOTOMETRIC_LOGLUV : colorSpaceType . setAttribute ( "name" , "Luv" ) ; break ; case TIFFCustom . PHOTOMETRIC_CFA : case TIFFCustom . PHOTOMETRIC_LINEAR_RAW : colorSpaceType . setAttribute ( "name" , "3CLR" ) ; break ; default : colorSpaceType . setAttribute ( "name" , Integer . toHexString ( numChannelsValue ) + "CLR" ) ; break ; } IIOMetadataNode numChannels = new IIOMetadataNode ( "NumChannels" ) ; chroma . appendChild ( numChannels ) ; if ( photometricValue == TIFFBaseline . PHOTOMETRIC_PALETTE ) { numChannels . setAttribute ( "value" , "3" ) ; } else { numChannels . setAttribute ( "value" , Integer . toString ( numChannelsValue ) ) ; } IIOMetadataNode blackIsZero = new IIOMetadataNode ( "BlackIsZero" ) ; chroma . appendChild ( blackIsZero ) ; switch ( photometricValue ) { case TIFFBaseline . PHOTOMETRIC_WHITE_IS_ZERO : blackIsZero . setAttribute ( "value" , "FALSE" ) ; break ; default : break ; } Entry colorMapTag = ifd . getEntryById ( TIFF . TAG_COLOR_MAP ) ; if ( colorMapTag != null ) { int [ ] colorMapValues = ( int [ ] ) colorMapTag . getValue ( ) ; IIOMetadataNode palette = new IIOMetadataNode ( "Palette" ) ; chroma . appendChild ( palette ) ; int count = colorMapValues . length / 3 ; for ( int i = 0 ; i < count ; i ++ ) { IIOMetadataNode paletteEntry = new IIOMetadataNode ( "PaletteEntry" ) ; paletteEntry . setAttribute ( "index" , Integer . toString ( i ) ) ; paletteEntry . setAttribute ( "red" , Integer . toString ( ( colorMapValues [ i ] > > 8 ) & 0xff ) ) ; paletteEntry . setAttribute ( "green" , Integer . toString ( ( colorMapValues [ i + count ] > > 8 ) & 0xff ) ) ; paletteEntry . setAttribute ( "blue" , Integer . toString ( ( colorMapValues [ i + count * 2 ] > > 8 ) & 0xff ) ) ; palette . appendChild ( paletteEntry ) ; } } return chroma ; }
See: http://download.java.net/media/jai-imageio/javadoc/1.1/com/sun/media/imageio/plugins/tiff/package-summary.html