예제 #1
0
 IIOMetadataNode getNativeNode() {
   IIOMetadataNode node = new IIOMetadataNode("app2ICC");
   if (profile != null) {
     node.setUserObject(ICC_Profile.getInstance(profile));
   }
   return node;
 }
예제 #2
0
 /**
  * Create a Java colorspace for this colorspace.
  *
  * @return A color space that can be used for Java AWT operations.
  * @throws IOException If there is an error creating the color space.
  */
 public ColorSpace createColorSpace() throws IOException {
   InputStream profile = null;
   ColorSpace cSpace = null;
   try {
     profile = stream.getUnfilteredStream();
     ICC_Profile iccProfile = ICC_Profile.getInstance(profile);
     cSpace = new ICC_ColorSpace(iccProfile);
   } finally {
     if (profile != null) {
       profile.close();
     }
   }
   return cSpace;
 }
예제 #3
0
  public static void main(String args[]) {
    try {
      ICC_Profile inProfile =
          ICC_Profile.getInstance("/System/Library/ColorSync/Profiles/AdobeRGB1998.icc");
      ICC_Profile outProfile =
          ICC_Profile.getInstance("/Library/ColorSync/Profiles/CIE 1931 D50 Gamma 1.icm");

      Profile cmsOutProfile = new Profile(outProfile);
      Profile cmsInProfile = new Profile(inProfile);

      BufferedImage inputImage = ImageIO.read(new File("/Stuff/Reference/small-q60-adobergb.TIF"));
      ShortInterleavedRaster inputRaster = (ShortInterleavedRaster) inputImage.getTile(0, 0);

      ColorSpace outCS = new ICC_ColorSpace(outProfile);
      ColorModel outCM =
          new ComponentColorModel(outCS, false, false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT);
      ShortInterleavedRaster outputRaster =
          (ShortInterleavedRaster)
              outCM.createCompatibleWritableRaster(inputImage.getWidth(), inputImage.getHeight());
      BufferedImage outputImage = new BufferedImage(outCM, outputRaster, false, null);

      Transform cmsTransform =
          new Transform(
              cmsInProfile, TYPE_RGB_16, cmsOutProfile, TYPE_RGB_16, INTENT_PERCEPTUAL, 0);

      cmsTransform.doTransform(inputRaster, outputRaster);

      ImageIO.write(outputImage, "TIF", new File("/Stuff/small-q60-CIED65.TIF"));

      cmsTransform.dispose();
      cmsOutProfile.dispose();
      cmsInProfile.dispose();
      // System.out.println("Profile: " + hProfile + ", " + );
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #4
0
  private static ICC_Profile readProfileFromPath(final String profilePath) {
    if (profilePath != null) {
      if (DEBUG) {
        System.out.println("Loading profile from: " + profilePath);
      }

      try {
        return ICC_Profile.getInstance(profilePath);
      } catch (IOException ignore) {
        if (DEBUG) {
          ignore.printStackTrace();
        }
      }
    }

    return null;
  }
예제 #5
0
  public synchronized void init() {
    if (inited) {
      return;
    }

    byte[] in;
    try {
      stream.init();
      in = stream.getDecodedStreamBytes(0);
      if (logger.isLoggable(Level.FINEST)) {
        String content = Utils.convertByteArrayToByteString(in);
        logger.finest("Content = " + content);
      }
      if (in != null) {
        ICC_Profile profile = ICC_Profile.getInstance(in);
        colorSpace = new ICC_ColorSpace(profile);
      }
    } catch (Exception e) {
      logger.log(Level.FINE, "Error Processing ICCBased Colour Profile", e);
    }
    inited = true;
  }
예제 #6
0
  private static ICC_Profile readProfileFromClasspathResource(final String profilePath) {
    InputStream stream = ColorSpaces.class.getResourceAsStream(profilePath);

    if (stream != null) {
      if (DEBUG) {
        System.out.println("Loading profile from classpath resource: " + profilePath);
      }

      try {

        return ICC_Profile.getInstance(stream);
      } catch (IOException ignore) {
        if (DEBUG) {
          ignore.printStackTrace();
        }
      } finally {
        FileUtil.close(stream);
      }
    }

    return null;
  }
  /**
   * Method called by the processAllColorSpace if the ColorSpace to check is a ICCBased color space.
   * Because this kind of ColorSpace can have alternate color space, the processAllColorSpace is
   * called to check this alternate color space. (Pattern is forbidden as Alternate Color Space)
   *
   * @param colorSpace the color space object to check.
   */
  protected void processICCBasedColorSpace(PDColorSpace colorSpace) {
    PDICCBased iccBased = (PDICCBased) colorSpace;
    try {
      ICC_Profile.getInstance(iccBased.getPDStream().createInputStream());
      PDColorSpace altpdcs = iccBased.getAlternateColorSpace();
      if (altpdcs != null) {
        ColorSpaces altCsId = ColorSpaces.valueOf(altpdcs.getName());
        if (altCsId == ColorSpaces.Pattern) {
          context.addValidationError(
              new ValidationError(
                  ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN,
                  "Pattern is forbidden as AlternateColorSpace of a ICCBased"));
        }

        /*
         * According to the ISO-19005-1:2005
         *
         * A conforming reader shall render ICCBased colour spaces as specified by the ICC specification,
         * and shall not use the Alternate colour space specified in an ICC profile stream dictionary
         *
         * We don't check the alternate ColorSpaces
         */
      }
    } catch (IllegalArgumentException e) {
      // this is not a ICC_Profile
      context.addValidationError(
          new ValidationError(
              ERROR_GRAPHIC_INVALID_COLOR_SPACE_ICCBASED,
              "ICCBased color space is invalid: " + e.getMessage(),
              e));
    } catch (IOException e) {
      context.addValidationError(
          new ValidationError(
              ERROR_GRAPHIC_INVALID_COLOR_SPACE,
              "Unable to read ICCBase color space: " + e.getMessage(),
              e));
    }
  }
예제 #8
0
  public Iterator getImageTypes(int imageIndex) throws IIOException {
    List l; // List of ImageTypeSpecifiers

    Integer imageIndexInteger = new Integer(imageIndex);
    if (imageTypeMap.containsKey(imageIndexInteger)) {
      // Return the cached ITS List.
      l = (List) imageTypeMap.get(imageIndexInteger);
    } else {
      // Create a new ITS List.
      l = new ArrayList(1);

      // Create the ITS and cache if for later use so that this method
      // always returns an Iterator containing the same ITS objects.
      seekToImage(imageIndex);
      ImageTypeSpecifier itsRaw =
          TIFFDecompressor.getRawImageTypeSpecifier(
              photometricInterpretation,
              compression,
              samplesPerPixel,
              bitsPerSample,
              sampleFormat,
              extraSamples,
              colorMap);

      // Check for an ICCProfile field.
      TIFFField iccProfileField = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_ICC_PROFILE);

      // If an ICCProfile field is present change the ImageTypeSpecifier
      // to use it if the data layout is component type.
      if (iccProfileField != null && itsRaw.getColorModel() instanceof ComponentColorModel) {
        // Create a ColorSpace from the profile.
        byte[] iccProfileValue = iccProfileField.getAsBytes();
        ICC_Profile iccProfile = ICC_Profile.getInstance(iccProfileValue);
        ICC_ColorSpace iccColorSpace = new ICC_ColorSpace(iccProfile);

        // Get the raw sample and color information.
        ColorModel cmRaw = itsRaw.getColorModel();
        ColorSpace csRaw = cmRaw.getColorSpace();
        SampleModel smRaw = itsRaw.getSampleModel();

        // Get the number of samples per pixel and the number
        // of color components.
        int numBands = smRaw.getNumBands();
        int numComponents = iccColorSpace.getNumComponents();

        // Replace the ColorModel with the ICC ColorModel if the
        // numbers of samples and color components are amenable.
        if (numBands == numComponents || numBands == numComponents + 1) {
          // Set alpha flags.
          boolean hasAlpha = numComponents != numBands;
          boolean isAlphaPre = hasAlpha && cmRaw.isAlphaPremultiplied();

          // Create a ColorModel of the same class and with
          // the same transfer type.
          ColorModel iccColorModel =
              new ComponentColorModel(
                  iccColorSpace,
                  cmRaw.getComponentSize(),
                  hasAlpha,
                  isAlphaPre,
                  cmRaw.getTransparency(),
                  cmRaw.getTransferType());

          // Prepend the ICC profile-based ITS to the List. The
          // ColorModel and SampleModel are guaranteed to be
          // compatible as the old and new ColorModels are both
          // ComponentColorModels with the same transfer type
          // and the same number of components.
          l.add(new ImageTypeSpecifier(iccColorModel, smRaw));

          // Append the raw ITS to the List if and only if its
          // ColorSpace has the same type and number of components
          // as the ICC ColorSpace.
          if (csRaw.getType() == iccColorSpace.getType()
              && csRaw.getNumComponents() == iccColorSpace.getNumComponents()) {
            l.add(itsRaw);
          }
        } else { // ICCProfile not compatible with SampleModel.
          // Append the raw ITS to the List.
          l.add(itsRaw);
        }
      } else { // No ICCProfile field or raw ColorModel not component.
        // Append the raw ITS to the List.
        l.add(itsRaw);
      }

      // Cache the ITS List.
      imageTypeMap.put(imageIndexInteger, l);
    }

    return l.iterator();
  }
예제 #9
0
 private static class LINEAR_RGB {
   private static final byte[] header =
       ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB).getData(ICC_Profile.icSigHead);
 }
예제 #10
0
 private static class GRAY {
   private static final byte[] header =
       ICC_Profile.getInstance(ColorSpace.CS_GRAY).getData(ICC_Profile.icSigHead);
 }