Exemplo n.º 1
0
  public void writeToSequence(IIOImage img, ImageWriteParam param) throws IOException {
    ImageOutputStream out = (ImageOutputStream) getOutput();
    if (!(img.getRenderedImage() instanceof BufferedImage)) {
      throw new IOException(
          getClass().getName() + "writeToSequence:\n\tCan only write BufferedImage objects");
    }
    BufferedImage image = (BufferedImage) img.getRenderedImage();
    /*
        // Attempt to convert metadata, if present
        IIOMetadata  imd      = img.getMetadata();
        TIFFMetadata metadata = null;
        if(imd!=null){
          ImageTypeSpecifier type=ImageTypeSpecifier.createFromRenderedImage(image);
          metadata=(TIFFMetadata)convertImageMetadata(imd,type,null);
        }
        // Output metadata if present
        if(metadata != null){
          Iterator keywordIter = metadata.keywords.iterator();
          Iterator valueIter   = metadata.values.iterator();
          while(keywordIter.hasNext()){
            String keyword = (String)keywordIter.next();
            String value   = (String)valueIter.next();
            System.out.println("9\bKEYWORD: "+keyword);
            System.out.println("9\bVALUE: "+value);
          }
        }
    */
    IFD ifd;
    int pmi = RGB, comp = compNone, tiffComp = NOCOMPRESSION;

    TIFFImageWriteParam p = null;
    if ((param != null) && (param instanceof TIFFImageWriteParam)) {
      p = (TIFFImageWriteParam) param;
      pmi = p.getPhotometricInterpretation();
      if (p.getCompressionType().equals("none")) {
        comp = compNone;
        tiffComp = NOCOMPRESSION;
      } else if (p.getCompressionType().equals("mh")) {
        comp = compBaselineMH;
        tiffComp = CCITTGROUP3MODHUFFMAN;
      } else if (p.getCompressionType().equals("t4mh")) {
        comp = compT4MH;
        tiffComp = CCITTFAXT4;
      } else if (p.getCompressionType().equals("t4mr")) {
        comp = compT4MR;
        tiffComp = CCITTFAXT4;
      } else if (p.getCompressionType().equals("t6mmr")) {
        comp = compT6MMR;
        tiffComp = CCITTFAXT6;
      } else if (p.getCompressionType().equals("packbits")) {
        comp = compPackBits;
        tiffComp = PACKBITS;
      } else if (p.getCompressionType().equals("lzw")) {
        comp = compLZW;
        tiffComp = LZW;
      } else if (p.getCompressionType().equals("jpeg")) {
        comp = compJPEG;
        tiffComp = JPEG;
      }
      //      System.out.println("comp = "+p.getCompressionType()+" "+comp);
    }
    switch (pmi) {
      case WhiteIsZero:
        switch (comp) {
          case compBaselineMH:
            ifd = writeBModHufImage(out, image, p);
            break;
          case compT4MH:
          case compT4MR:
          case compT6MMR:
            ifd = TIFFClassFFactory.writeImage(out, image, comp, p);
            break;
          default:
            ifd = writeRGBImage(out, image, NOCOMPRESSION, p);
            break; // write image data as uncompressed rgb data.
        }
        break;
      case BlackIsZero:
        switch (comp) {
          default:
            ifd = writeGrayImage(out, image, tiffComp, p);
            break;
        }
        break;
      case RGB: // write image data as uncompressed rgb data.
        switch (comp) {
          default:
            ifd = writeRGBImage(out, image, tiffComp, p);
            break;
        }
        break;
      case CMYK:
        switch (comp) {
          default:
            ifd = writeCMYKImage(out, image, p);
            break;
        }
        break;
      case YCbCr:
        switch (comp) {
          default:
            ifd = writeYCbCrImage(out, image, tiffComp, p);
            break;
        }
        break;
      default:
        ifd = writeRGBImage(out, image, NOCOMPRESSION, p);
        break; // write image data as uncompressed rgb data.
    }
    ifdptr = ifd.write(out, ifdptr); // write ifd contents, entries and set ifd linked list pointer
  }