Ejemplo n.º 1
0
 /**
  * Updates the metadata information based on the parameters to this writer.
  *
  * @param meta the metadata
  * @param params the parameters
  * @return the updated metadata
  */
 protected IIOMetadata updateMetadata(IIOMetadata meta, ImageWriterParams params) {
   final String stdmeta = "javax_imageio_1.0";
   if (meta.isStandardMetadataFormatSupported()) {
     IIOMetadataNode root = (IIOMetadataNode) meta.getAsTree(stdmeta);
     IIOMetadataNode dim = getChildNode(root, "Dimension");
     IIOMetadataNode child;
     if (params.getResolution() != null) {
       child = getChildNode(dim, "HorizontalPixelSize");
       if (child == null) {
         child = new IIOMetadataNode("HorizontalPixelSize");
         dim.appendChild(child);
       }
       child.setAttribute("value", Double.toString(params.getResolution().doubleValue() / 25.4));
       child = getChildNode(dim, "VerticalPixelSize");
       if (child == null) {
         child = new IIOMetadataNode("VerticalPixelSize");
         dim.appendChild(child);
       }
       child.setAttribute("value", Double.toString(params.getResolution().doubleValue() / 25.4));
     }
     try {
       meta.mergeTree(stdmeta, root);
     } catch (IIOInvalidTreeException e) {
       throw new RuntimeException("Cannot update image metadata: " + e.getMessage());
     }
   }
   return meta;
 }
Ejemplo n.º 2
0
 IIOMetadataNode getNativeNode() {
   IIOMetadataNode node = new IIOMetadataNode("dqtable");
   node.setAttribute("elementPrecision", Integer.toString(elementPrecision));
   node.setAttribute("qtableId", Integer.toString(tableID));
   node.setUserObject(new JPEGQTable(data));
   return node;
 }
  private static byte[] convertChartToByteArray(
      Chart chartDetails, JFreeChart chart, int width, int height)
      throws IOException, IIOInvalidTreeException {
    BufferedImage buffImg =
        chart.createBufferedImage(
            width, height, BufferedImage.BITMASK | BufferedImage.SCALE_SMOOTH, null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();

    ImageWriteParam writeParam = writer.getDefaultWriteParam();
    ImageTypeSpecifier typeSpecifier =
        ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
    IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);

    if (chartDetails != null) {
      if (chartDetails.getId() == null) {
        chartDetails.setId("%ID%");
      }
      IIOMetadataNode textEntry = new IIOMetadataNode("tEXtEntry");
      textEntry.setAttribute("keyword", "chart-google-data");
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream objectOutputStream = new ObjectOutputStream(bout);
      objectOutputStream.writeObject(chartDetails);
      objectOutputStream.flush();
      textEntry.setAttribute(
          "value",
          (String)
              ChartRendererFactory.getRendererForOutput(ChartRendererGoogleTools.TYPE)
                  .renderChart(chartDetails));

      IIOMetadataNode text = new IIOMetadataNode("tEXt");
      text.appendChild(textEntry);

      IIOMetadataNode root = new IIOMetadataNode("javax_imageio_png_1.0");
      root.appendChild(text);

      metadata.mergeTree("javax_imageio_png_1.0", root);
    }
    // setDPI(metadata);

    final ImageOutputStream stream = ImageIO.createImageOutputStream(baos);
    try {
      writer.setOutput(stream);
      writer.write(metadata, new IIOImage(buffImg, null, metadata), writeParam);
    } finally {
      stream.close();
    }

    byte[] bytes = baos.toByteArray(); // ChartUtilities.encodeAsPNG(buffImg, true, 9);
    return bytes;
  }
Ejemplo n.º 4
0
  public IIOMetadataNode getStandardDocumentNode() {
    String versionString;
    switch (version) {
      case VERSION_2_5:
        versionString = "2.5";
        break;
      case VERSION_2_8_W_PALETTE:
        versionString = "2.8 with palette";
        break;
      case VERSION_2_8_WO_PALETTE:
        versionString = "2.8 without palette";
        break;
      case VERSION_PC_WINDOWS:
        versionString = "PC Paintbrush for Windows";
        break;
      case VERSION_3_0:
        versionString = "3.0";
        break;
      default:
        // unknown
        versionString = null;
    }

    IIOMetadataNode documentNode = null;
    if (versionString != null) {
      documentNode = new IIOMetadataNode("Document");
      IIOMetadataNode node = new IIOMetadataNode("FormatVersion");
      node.setAttribute("value", versionString);
      documentNode.appendChild(node);
    }

    return documentNode;
  }
Ejemplo n.º 5
0
 /*     */ IIOMetadataNode getNativeNode() {
   /* 132 */ IIOMetadataNode localIIOMetadataNode = new IIOMetadataNode("unknown");
   /* 133 */ localIIOMetadataNode.setAttribute("MarkerTag", Integer.toString(this.tag));
   /* 134 */ localIIOMetadataNode.setUserObject(this.data);
   /*     */
   /* 136 */ return localIIOMetadataNode;
   /*     */ }
  public IIOMetadataNode getStandardCompressionNode() {
    IIOMetadataNode compression_node = new IIOMetadataNode("Compression");
    IIOMetadataNode node = null; // scratch node

    node = new IIOMetadataNode("CompressionTypeName");
    node.setAttribute("value", "lzw");
    compression_node.appendChild(node);

    node = new IIOMetadataNode("Lossless");
    node.setAttribute("value", "true");
    compression_node.appendChild(node);

    // NumProgressiveScans not in stream
    // BitRate not in format

    return compression_node;
  }
  public IIOMetadataNode buildFiles(Settings settings) {
    IIOMetadataNode files = new IIOMetadataNode("files");

    // image directory
    IIOMetadataNode imageDir = new IIOMetadataNode("image_dir");
    imageDir.setAttribute("path", settings.getLastImageDir().getAbsolutePath());
    files.appendChild(imageDir);

    // ecu definition files
    Vector<File> defFiles = settings.getEcuDefinitionFiles();

    for (int i = 0; i < defFiles.size(); i++) {
      IIOMetadataNode ecuDef = new IIOMetadataNode("ecudefinitionfile");
      ecuDef.setAttribute("name", defFiles.get(i).getAbsolutePath());
      files.appendChild(ecuDef);
    }

    return files;
  }
  public IIOMetadataNode getStandardDimensionNode() {
    IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");
    IIOMetadataNode node = null; // scratch node

    node = new IIOMetadataNode("PixelAspectRatio");
    float aspectRatio = 1.0F;
    if (pixelAspectRatio != 0) {
      aspectRatio = (pixelAspectRatio + 15) / 64.0F;
    }
    node.setAttribute("value", Float.toString(aspectRatio));
    dimension_node.appendChild(node);

    node = new IIOMetadataNode("ImageOrientation");
    node.setAttribute("value", "Normal");
    dimension_node.appendChild(node);

    // HorizontalPixelSize not in format
    // VerticalPixelSize not in format
    // HorizontalPhysicalPixelSpacing not in format
    // VerticalPhysicalPixelSpacing not in format
    // HorizontalPosition not in format
    // VerticalPosition not in format
    // HorizontalPixelOffset not in stream
    // VerticalPixelOffset not in stream

    node = new IIOMetadataNode("HorizontalScreenSize");
    node.setAttribute(
        "value",
        logicalScreenWidth == UNDEFINED_INTEGER_VALUE ? "" : Integer.toString(logicalScreenWidth));
    dimension_node.appendChild(node);

    node = new IIOMetadataNode("VerticalScreenSize");
    node.setAttribute(
        "value",
        logicalScreenHeight == UNDEFINED_INTEGER_VALUE
            ? ""
            : Integer.toString(logicalScreenHeight));
    dimension_node.appendChild(node);

    return dimension_node;
  }
  @SuppressWarnings("unused")
  private static void setDPI(IIOMetadata metadata) throws IIOInvalidTreeException {

    // for PNG, it's dots per millimeter
    double dotsPerMilli = 1.0 * 600 / 10 / 2.54;

    IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
    horiz.setAttribute("value", Double.toString(dotsPerMilli));

    IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
    vert.setAttribute("value", Double.toString(dotsPerMilli));

    IIOMetadataNode dim = new IIOMetadataNode("Dimension");
    dim.appendChild(horiz);
    dim.appendChild(vert);

    IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
    root.appendChild(dim);

    metadata.mergeTree("javax_imageio_1.0", root);
  }
  public IIOMetadataNode getStandardDataNode() {
    IIOMetadataNode data_node = new IIOMetadataNode("Data");
    IIOMetadataNode node = null; // scratch node

    // PlanarConfiguration

    node = new IIOMetadataNode("SampleFormat");
    node.setAttribute("value", "Index");
    data_node.appendChild(node);

    node = new IIOMetadataNode("BitsPerSample");
    node.setAttribute(
        "value",
        colorResolution == UNDEFINED_INTEGER_VALUE ? "" : Integer.toString(colorResolution));
    data_node.appendChild(node);

    // SignificantBitsPerSample
    // SampleMSB

    return data_node;
  }
Ejemplo n.º 11
0
  public IIOMetadataNode getStandardDimensionNode() {
    IIOMetadataNode dimensionNode = new IIOMetadataNode("Dimension");
    IIOMetadataNode node = null; // scratch node

    node = new IIOMetadataNode("HorizontalPixelOffset");
    node.setAttribute("value", String.valueOf(xmin));
    dimensionNode.appendChild(node);

    node = new IIOMetadataNode("VerticalPixelOffset");
    node.setAttribute("value", String.valueOf(ymin));
    dimensionNode.appendChild(node);

    node = new IIOMetadataNode("HorizontalPixelSize");
    node.setAttribute("value", String.valueOf(254.0 / hdpi));
    dimensionNode.appendChild(node);

    node = new IIOMetadataNode("VerticalPixelSize");
    node.setAttribute("value", String.valueOf(254.0 / vdpi));
    dimensionNode.appendChild(node);

    if (hsize != 0) {
      node = new IIOMetadataNode("HorizontalScreenSize");
      node.setAttribute("value", String.valueOf(hsize));
      dimensionNode.appendChild(node);
    }

    if (vsize != 0) {
      node = new IIOMetadataNode("VerticalScreenSize");
      node.setAttribute("value", String.valueOf(vsize));
      dimensionNode.appendChild(node);
    }

    return dimensionNode;
  }
Ejemplo n.º 12
0
  public IIOMetadataNode buildWindow(Settings settings) {
    IIOMetadataNode windowSettings = new IIOMetadataNode("window");

    // window size
    IIOMetadataNode size = new IIOMetadataNode("size");
    size.setAttribute("x", ((int) settings.getWindowSize().getHeight()) + "");
    size.setAttribute("y", ((int) settings.getWindowSize().getWidth()) + "");
    windowSettings.appendChild(size);

    // window location
    IIOMetadataNode location = new IIOMetadataNode("location");
    location.setAttribute("x", ((int) settings.getWindowLocation().getX()) + "");
    location.setAttribute("y", ((int) settings.getWindowLocation().getY()) + "");
    windowSettings.appendChild(location);

    // splitpane location
    IIOMetadataNode splitpane = new IIOMetadataNode("splitpane");
    splitpane.setAttribute("location", settings.getSplitPaneLocation() + "");
    windowSettings.appendChild(splitpane);

    return windowSettings;
  }
Ejemplo n.º 13
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;
  }
  public IIOMetadataNode getStandardDocumentNode() {
    IIOMetadataNode document_node = new IIOMetadataNode("Document");
    IIOMetadataNode node = null; // scratch node

    node = new IIOMetadataNode("FormatVersion");
    node.setAttribute("value", version);
    document_node.appendChild(node);

    // SubimageInterpretation not in format
    // ImageCreationTime not in format
    // ImageModificationTime not in format

    return document_node;
  }
Ejemplo n.º 15
0
  public IIOMetadataNode buildOptions(Settings settings, String versionNumber) {
    IIOMetadataNode options = new IIOMetadataNode("options");

    // obsolete warning
    IIOMetadataNode obsoleteWarning = new IIOMetadataNode("obsoletewarning");
    obsoleteWarning.setAttribute("value", settings.isObsoleteWarning() + "");
    options.appendChild(obsoleteWarning);

    // calcultion conflicting warning
    IIOMetadataNode calcConflictWarning = new IIOMetadataNode("calcconflictwarning");
    calcConflictWarning.setAttribute("value", settings.isCalcConflictWarning() + "");
    options.appendChild(calcConflictWarning);

    // debug mode
    IIOMetadataNode debug = new IIOMetadataNode("debug");
    debug.setAttribute("value", settings.isDebug() + "");
    options.appendChild(debug);

    // userlevel
    IIOMetadataNode userLevel = new IIOMetadataNode("userlevel");
    userLevel.setAttribute("value", settings.getUserLevel() + "");
    options.appendChild(userLevel);

    // table click count
    IIOMetadataNode tableClickCount = new IIOMetadataNode("tableclickcount");
    tableClickCount.setAttribute("value", settings.getTableClickCount() + "");
    options.appendChild(tableClickCount);

    // last version used
    IIOMetadataNode version = new IIOMetadataNode("version");
    version.setAttribute("value", versionNumber);
    options.appendChild(version);

    // save debug level tables
    IIOMetadataNode saveDebugTables = new IIOMetadataNode("savedebugtables");
    saveDebugTables.setAttribute("value", settings.isSaveDebugTables() + "");
    options.appendChild(saveDebugTables);

    // display tables higher than userlevel
    IIOMetadataNode displayHighTables = new IIOMetadataNode("displayhightables");
    displayHighTables.setAttribute("value", settings.isDisplayHighTables() + "");
    options.appendChild(displayHighTables);

    return options;
  }
  public IIOMetadataNode getStandardChromaNode() {
    IIOMetadataNode chroma_node = new IIOMetadataNode("Chroma");
    IIOMetadataNode node = null; // scratch node

    node = new IIOMetadataNode("ColorSpaceType");
    node.setAttribute("name", "RGB");
    chroma_node.appendChild(node);

    node = new IIOMetadataNode("BlackIsZero");
    node.setAttribute("value", "TRUE");
    chroma_node.appendChild(node);

    // NumChannels not in stream
    // Gamma not in format

    if (globalColorTable != null) {
      node = new IIOMetadataNode("Palette");
      int numEntries = globalColorTable.length / 3;
      for (int i = 0; i < numEntries; i++) {
        IIOMetadataNode entry = new IIOMetadataNode("PaletteEntry");
        entry.setAttribute("index", Integer.toString(i));
        entry.setAttribute("red", Integer.toString(globalColorTable[3 * i] & 0xff));
        entry.setAttribute("green", Integer.toString(globalColorTable[3 * i + 1] & 0xff));
        entry.setAttribute("blue", Integer.toString(globalColorTable[3 * i + 2] & 0xff));
        node.appendChild(entry);
      }
      chroma_node.appendChild(node);

      // backgroundColorIndex is valid iff there is a color table
      node = new IIOMetadataNode("BackgroundIndex");
      node.setAttribute("value", Integer.toString(backgroundColorIndex));
      chroma_node.appendChild(node);
    }

    return chroma_node;
  }
Ejemplo n.º 17
0
 IIOMetadataNode getNativeNode() {
   IIOMetadataNode node = new IIOMetadataNode(name);
   node.setAttribute("thumbWidth", Integer.toString(thumbWidth));
   node.setAttribute("thumbHeight", Integer.toString(thumbHeight));
   return node;
 }
Ejemplo n.º 18
0
 IIOMetadataNode getNativeNode() {
   IIOMetadataNode node = new IIOMetadataNode("app0JFXX");
   node.setAttribute("extensionCode", Integer.toString(code));
   node.appendChild(thumb.getNativeNode());
   return node;
 }
  private Node getNativeTree() {
    IIOMetadataNode node; // scratch node
    IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName);

    node = new IIOMetadataNode("Version");
    node.setAttribute("value", version);
    root.appendChild(node);

    // Image descriptor
    node = new IIOMetadataNode("LogicalScreenDescriptor");
    /* NB: At the moment we use empty strings to support undefined
     * integer values in tree representation.
     * We need to add better support for undefined/default values later.
     */
    node.setAttribute(
        "logicalScreenWidth",
        logicalScreenWidth == UNDEFINED_INTEGER_VALUE ? "" : Integer.toString(logicalScreenWidth));
    node.setAttribute(
        "logicalScreenHeight",
        logicalScreenHeight == UNDEFINED_INTEGER_VALUE
            ? ""
            : Integer.toString(logicalScreenHeight));
    // Stored value plus one
    node.setAttribute(
        "colorResolution",
        colorResolution == UNDEFINED_INTEGER_VALUE ? "" : Integer.toString(colorResolution));
    node.setAttribute("pixelAspectRatio", Integer.toString(pixelAspectRatio));
    root.appendChild(node);

    if (globalColorTable != null) {
      node = new IIOMetadataNode("GlobalColorTable");
      int numEntries = globalColorTable.length / 3;
      node.setAttribute("sizeOfGlobalColorTable", Integer.toString(numEntries));
      node.setAttribute("backgroundColorIndex", Integer.toString(backgroundColorIndex));
      node.setAttribute("sortFlag", sortFlag ? "TRUE" : "FALSE");

      for (int i = 0; i < numEntries; i++) {
        IIOMetadataNode entry = new IIOMetadataNode("ColorTableEntry");
        entry.setAttribute("index", Integer.toString(i));
        int r = globalColorTable[3 * i] & 0xff;
        int g = globalColorTable[3 * i + 1] & 0xff;
        int b = globalColorTable[3 * i + 2] & 0xff;
        entry.setAttribute("red", Integer.toString(r));
        entry.setAttribute("green", Integer.toString(g));
        entry.setAttribute("blue", Integer.toString(b));
        node.appendChild(entry);
      }
      root.appendChild(node);
    }

    return root;
  }
Ejemplo n.º 20
0
  public IIOMetadataNode buildTableDisplay(Settings settings) {
    IIOMetadataNode tableDisplay = new IIOMetadataNode("tabledisplay");

    // font
    IIOMetadataNode font = new IIOMetadataNode("font");
    font.setAttribute("face", settings.getTableFont().getName());
    font.setAttribute("size", settings.getTableFont().getSize() + "");
    font.setAttribute("decoration", settings.getTableFont().getStyle() + "");
    tableDisplay.appendChild(font);

    // table cell size
    IIOMetadataNode cellSize = new IIOMetadataNode("cellsize");
    cellSize.setAttribute("height", ((int) settings.getCellSize().getHeight()) + "");
    cellSize.setAttribute("width", ((int) settings.getCellSize().getWidth()) + "");
    tableDisplay.appendChild(cellSize);

    // colors
    IIOMetadataNode colors = new IIOMetadataNode("colors");
    // max
    IIOMetadataNode max = new IIOMetadataNode("max");
    max.setAttribute("r", settings.getMaxColor().getRed() + "");
    max.setAttribute("g", settings.getMaxColor().getGreen() + "");
    max.setAttribute("b", settings.getMaxColor().getBlue() + "");
    colors.appendChild(max);
    // min
    IIOMetadataNode min = new IIOMetadataNode("min");
    min.setAttribute("r", settings.getMinColor().getRed() + "");
    min.setAttribute("g", settings.getMinColor().getGreen() + "");
    min.setAttribute("b", settings.getMinColor().getBlue() + "");
    colors.appendChild(min);
    // highlight
    IIOMetadataNode highlight = new IIOMetadataNode("highlight");
    highlight.setAttribute("r", settings.getHighlightColor().getRed() + "");
    highlight.setAttribute("g", settings.getHighlightColor().getGreen() + "");
    highlight.setAttribute("b", settings.getHighlightColor().getBlue() + "");
    colors.appendChild(highlight);
    // increased cell border
    IIOMetadataNode increaseBorder = new IIOMetadataNode("increaseborder");
    increaseBorder.setAttribute("r", settings.getIncreaseBorder().getRed() + "");
    increaseBorder.setAttribute("g", settings.getIncreaseBorder().getGreen() + "");
    increaseBorder.setAttribute("b", settings.getIncreaseBorder().getBlue() + "");
    colors.appendChild(increaseBorder);
    // decreased cell border
    IIOMetadataNode decreaseBorder = new IIOMetadataNode("decreaseborder");
    decreaseBorder.setAttribute("r", settings.getDecreaseBorder().getRed() + "");
    decreaseBorder.setAttribute("g", settings.getDecreaseBorder().getGreen() + "");
    decreaseBorder.setAttribute("b", settings.getDecreaseBorder().getBlue() + "");
    colors.appendChild(decreaseBorder);
    // axis cells
    IIOMetadataNode axis = new IIOMetadataNode("axis");
    axis.setAttribute("r", settings.getAxisColor().getRed() + "");
    axis.setAttribute("g", settings.getAxisColor().getGreen() + "");
    axis.setAttribute("b", settings.getAxisColor().getBlue() + "");
    colors.appendChild(axis);

    tableDisplay.appendChild(colors);

    return tableDisplay;
  }