< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageReader.java

Print this page




 713             // Create the ITS and cache if for later use so that this method
 714             // always returns an Iterator containing the same ITS objects.
 715             seekToImage(imageIndex);
 716             ImageTypeSpecifier itsRaw
 717                     = TIFFDecompressor.getRawImageTypeSpecifier(photometricInterpretation,
 718                             compression,
 719                             samplesPerPixel,
 720                             bitsPerSample,
 721                             sampleFormat,
 722                             extraSamples,
 723                             colorMap);
 724 
 725             // Check for an ICCProfile field.
 726             TIFFField iccProfileField
 727                     = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_ICC_PROFILE);
 728 
 729             // If an ICCProfile field is present change the ImageTypeSpecifier
 730             // to use it if the data layout is component type.
 731             if (iccProfileField != null
 732                     && itsRaw.getColorModel() instanceof ComponentColorModel) {







 733                 // Create a ColorSpace from the profile.
 734                 byte[] iccProfileValue = iccProfileField.getAsBytes();
 735                 ICC_Profile iccProfile
 736                         = ICC_Profile.getInstance(iccProfileValue);
 737                 ICC_ColorSpace iccColorSpace
 738                         = new ICC_ColorSpace(iccProfile);
 739 
 740                 // Get the raw sample and color information.
 741                 ColorModel cmRaw = itsRaw.getColorModel();
 742                 ColorSpace csRaw = cmRaw.getColorSpace();
 743                 SampleModel smRaw = itsRaw.getSampleModel();























 744 
 745                 // Get the number of samples per pixel and the number
 746                 // of color components.
 747                 int numBands = smRaw.getNumBands();
 748                 int numComponents = iccColorSpace.getNumComponents();
 749 
 750                 // Replace the ColorModel with the ICC ColorModel if the
 751                 // numbers of samples and color components are amenable.
 752                 if (numBands == numComponents
 753                         || numBands == numComponents + 1) {
 754                     // Set alpha flags.
 755                     boolean hasAlpha = numComponents != numBands;
 756                     boolean isAlphaPre
 757                             = hasAlpha && cmRaw.isAlphaPremultiplied();
 758 
 759                     // Create a ColorModel of the same class and with
 760                     // the same transfer type.
 761                     ColorModel iccColorModel
 762                             = new ComponentColorModel(iccColorSpace,
 763                                     cmRaw.getComponentSize(),




 713             // Create the ITS and cache if for later use so that this method
 714             // always returns an Iterator containing the same ITS objects.
 715             seekToImage(imageIndex);
 716             ImageTypeSpecifier itsRaw
 717                     = TIFFDecompressor.getRawImageTypeSpecifier(photometricInterpretation,
 718                             compression,
 719                             samplesPerPixel,
 720                             bitsPerSample,
 721                             sampleFormat,
 722                             extraSamples,
 723                             colorMap);
 724 
 725             // Check for an ICCProfile field.
 726             TIFFField iccProfileField
 727                     = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_ICC_PROFILE);
 728 
 729             // If an ICCProfile field is present change the ImageTypeSpecifier
 730             // to use it if the data layout is component type.
 731             if (iccProfileField != null
 732                     && itsRaw.getColorModel() instanceof ComponentColorModel) {
 733                 // Get the raw sample and color information.
 734                 ColorModel cmRaw = itsRaw.getColorModel();
 735                 ColorSpace csRaw = cmRaw.getColorSpace();
 736                 SampleModel smRaw = itsRaw.getSampleModel();
 737                 
 738                 ColorSpace iccColorSpace = null;
 739                 try {
 740                     // Create a ColorSpace from the profile.
 741                     byte[] iccProfileValue = iccProfileField.getAsBytes();
 742                     ICC_Profile iccProfile
 743                         = ICC_Profile.getInstance(iccProfileValue);
 744                     iccColorSpace = new ICC_ColorSpace(iccProfile);

 745 
 746                     // Workaround for JDK-8145241: test a conversion and fall
 747                     // back to a standard ColorSpace if it fails. This
 748                     // workaround could be removed if JDK-8145241 is fixed.
 749                     float[] rgb =
 750                         iccColorSpace.toRGB(new float[] {1.0F, 1.0F, 1.0F});
 751                 } catch (Exception iccProfileException) {
 752                     processWarningOccurred("Superseding bad ICC profile: "
 753                         + iccProfileException.getMessage());
 754 
 755                     if (iccColorSpace != null) {
 756                         switch (iccColorSpace.getType()) {
 757                             case ColorSpace.TYPE_GRAY:
 758                                 iccColorSpace =
 759                                     ColorSpace.getInstance(ColorSpace.CS_GRAY);
 760                                 break;
 761                             case ColorSpace.TYPE_RGB:
 762                                 iccColorSpace =
 763                                     ColorSpace.getInstance(ColorSpace.CS_sRGB);
 764                                 break;
 765                             default:
 766                                 iccColorSpace = csRaw;
 767                                 break;
 768                         }
 769                     } else {
 770                         iccColorSpace = csRaw;
 771                     }
 772                 }
 773 
 774                 // Get the number of samples per pixel and the number
 775                 // of color components.
 776                 int numBands = smRaw.getNumBands();
 777                 int numComponents = iccColorSpace.getNumComponents();
 778 
 779                 // Replace the ColorModel with the ICC ColorModel if the
 780                 // numbers of samples and color components are amenable.
 781                 if (numBands == numComponents
 782                         || numBands == numComponents + 1) {
 783                     // Set alpha flags.
 784                     boolean hasAlpha = numComponents != numBands;
 785                     boolean isAlphaPre
 786                             = hasAlpha && cmRaw.isAlphaPremultiplied();
 787 
 788                     // Create a ColorModel of the same class and with
 789                     // the same transfer type.
 790                     ColorModel iccColorModel
 791                             = new ComponentColorModel(iccColorSpace,
 792                                     cmRaw.getComponentSize(),


< prev index next >