Пример #1
0
 protected Object clone() {
   JFIFExtensionMarkerSegment newGuy = (JFIFExtensionMarkerSegment) super.clone();
   if (thumb != null) {
     newGuy.thumb = (JFIFThumb) thumb.clone();
   }
   return newGuy;
 }
Пример #2
0
 /** Prints out the contents of this object to System.out for debugging. */
 void print() {
   printTag("JFIF");
   System.out.print("Version ");
   System.out.print(majorVersion);
   System.out.println(".0" + Integer.toString(minorVersion));
   System.out.print("Resolution units: ");
   System.out.println(resUnits);
   System.out.print("X density: ");
   System.out.println(Xdensity);
   System.out.print("Y density: ");
   System.out.println(Ydensity);
   System.out.print("Thumbnail Width: ");
   System.out.println(thumbWidth);
   System.out.print("Thumbnail Height: ");
   System.out.println(thumbHeight);
   if (!extSegments.isEmpty()) {
     for (Iterator iter = extSegments.iterator(); iter.hasNext(); ) {
       JFIFExtensionMarkerSegment extSegment = (JFIFExtensionMarkerSegment) iter.next();
       extSegment.print();
     }
   }
   if (iccSegment != null) {
     iccSegment.print();
   }
 }
Пример #3
0
 /** Writes out a new JFXX extension segment, without saving it. */
 private void writeJFXXSegment(
     int index, BufferedImage thumbnail, ImageOutputStream ios, JPEGImageWriter writer)
     throws IOException {
   JFIFExtensionMarkerSegment jfxx = null;
   try {
     jfxx = new JFIFExtensionMarkerSegment(thumbnail);
   } catch (IllegalThumbException e) {
     writer.warningOccurred(JPEGImageWriter.WARNING_ILLEGAL_THUMBNAIL);
     return;
   }
   writer.thumbnailStarted(index);
   jfxx.write(ios, writer);
   writer.thumbnailComplete();
 }
Пример #4
0
 /** Returns a deep-copy clone of this object. */
 protected Object clone() {
   JFIFMarkerSegment newGuy = (JFIFMarkerSegment) super.clone();
   if (!extSegments.isEmpty()) { // Clone the list with a deep copy
     newGuy.extSegments = new ArrayList();
     for (Iterator iter = extSegments.iterator(); iter.hasNext(); ) {
       JFIFExtensionMarkerSegment jfxx = (JFIFExtensionMarkerSegment) iter.next();
       newGuy.extSegments.add(jfxx.clone());
     }
   }
   if (iccSegment != null) {
     newGuy.iccSegment = (ICCMarkerSegment) iccSegment.clone();
   }
   return newGuy;
 }
Пример #5
0
  /**
   * Returns a tree of DOM nodes representing this object and any subordinate JFXX extension or ICC
   * Profile segments.
   */
  IIOMetadataNode getNativeNode() {
    IIOMetadataNode node = new IIOMetadataNode("app0JFIF");
    node.setAttribute("majorVersion", Integer.toString(majorVersion));
    node.setAttribute("minorVersion", Integer.toString(minorVersion));
    node.setAttribute("resUnits", Integer.toString(resUnits));
    node.setAttribute("Xdensity", Integer.toString(Xdensity));
    node.setAttribute("Ydensity", Integer.toString(Ydensity));
    node.setAttribute("thumbWidth", Integer.toString(thumbWidth));
    node.setAttribute("thumbHeight", Integer.toString(thumbHeight));
    if (!extSegments.isEmpty()) {
      IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX");
      node.appendChild(JFXXnode);
      for (Iterator iter = extSegments.iterator(); iter.hasNext(); ) {
        JFIFExtensionMarkerSegment seg = (JFIFExtensionMarkerSegment) iter.next();
        JFXXnode.appendChild(seg.getNativeNode());
      }
    }
    if (iccSegment != null) {
      node.appendChild(iccSegment.getNativeNode());
    }

    return node;
  }
Пример #6
0
  private void writeThumb(
      ImageOutputStream ios,
      BufferedImage thumb,
      JFIFExtensionMarkerSegment jfxx,
      int index,
      boolean onlyOne,
      JPEGImageWriter writer)
      throws IOException {
    ColorModel cm = thumb.getColorModel();
    ColorSpace cs = cm.getColorSpace();

    if (cm instanceof IndexColorModel) {
      // We never write a palette image into the header
      // So if it's the only one, we need to write the header first
      if (onlyOne) {
        write(ios, writer);
      }
      if ((jfxx == null) || (jfxx.code == THUMB_PALETTE)) {
        writeJFXXSegment(index, thumb, ios, writer); // default
      } else {
        // Expand to RGB
        BufferedImage thumbRGB =
            ((IndexColorModel) cm).convertToIntDiscrete(thumb.getRaster(), false);
        jfxx.setThumbnail(thumbRGB);
        writer.thumbnailStarted(index);
        jfxx.write(ios, writer); // Handles clipping if needed
        writer.thumbnailComplete();
      }
    } else if (cs.getType() == ColorSpace.TYPE_RGB) {
      if (jfxx == null) {
        if (onlyOne) {
          write(ios, thumb, writer); // As part of the header
        } else {
          writeJFXXSegment(index, thumb, ios, writer); // default
        }
      } else {
        // If this is the only one, write the header first
        if (onlyOne) {
          write(ios, writer);
        }
        if (jfxx.code == THUMB_PALETTE) {
          writeJFXXSegment(index, thumb, ios, writer); // default
          writer.warningOccurred(JPEGImageWriter.WARNING_NO_RGB_THUMB_AS_INDEXED);
        } else {
          jfxx.setThumbnail(thumb);
          writer.thumbnailStarted(index);
          jfxx.write(ios, writer); // Handles clipping if needed
          writer.thumbnailComplete();
        }
      }
    } else if (cs.getType() == ColorSpace.TYPE_GRAY) {
      if (jfxx == null) {
        if (onlyOne) {
          BufferedImage thumbRGB = expandGrayThumb(thumb);
          write(ios, thumbRGB, writer); // As part of the header
        } else {
          writeJFXXSegment(index, thumb, ios, writer); // default
        }
      } else {
        // If this is the only one, write the header first
        if (onlyOne) {
          write(ios, writer);
        }
        if (jfxx.code == THUMB_RGB) {
          BufferedImage thumbRGB = expandGrayThumb(thumb);
          writeJFXXSegment(index, thumbRGB, ios, writer);
        } else if (jfxx.code == THUMB_JPEG) {
          jfxx.setThumbnail(thumb);
          writer.thumbnailStarted(index);
          jfxx.write(ios, writer); // Handles clipping if needed
          writer.thumbnailComplete();
        } else if (jfxx.code == THUMB_PALETTE) {
          writeJFXXSegment(index, thumb, ios, writer); // default
          writer.warningOccurred(JPEGImageWriter.WARNING_NO_GRAY_THUMB_AS_INDEXED);
        }
      }
    } else {
      writer.warningOccurred(JPEGImageWriter.WARNING_ILLEGAL_THUMBNAIL);
    }
  }