Java Examples for org.apache.sanselan.formats.tiff.write.TiffImageWriterLossless

The following java examples will help you to understand the usage of org.apache.sanselan.formats.tiff.write.TiffImageWriterLossless. These source code samples are taken from different open source projects.

Example 1
Project: deegree2-desktop-master  File: ExifModule.java View source code
/**
     * 
     */
public void linkImage() {
    if (appContainer.getViewPlatform().equalsIgnoreCase("application")) {
        String mmId = getInitParameter("assignedMapModel");
        MapModel mm = appContainer.getMapModel(new Identifier(mmId));
        SelectedFeaturesVisitor visitor = new SelectedFeaturesVisitor(2);
        try {
            mm.walkLayerTree(visitor);
            if (visitor.col.size() == 1) {
                Geometry g = visitor.col.getFeature(0).getDefaultGeometryPropertyValue();
                if (!(g instanceof Point)) {
                    return;
                }
                Point pt = (Point) g;
                if (!pt.getCoordinateSystem().equals(unrealWGS84)) {
                    GeoTransformer trans = new GeoTransformer(unrealWGS84);
                    pt = (Point) trans.transform(pt);
                }
                Preferences prefs = userNodeForPackage(ExifModule.class);
                String last = prefs.get("lastExifSaveDir" + getVersionNumber(), null);
                JFileChooser chooser = new JFileChooser(last);
                if (chooser.showOpenDialog(((IGeoDesktop) appContainer).getMainWndow()) == JFileChooser.APPROVE_OPTION) {
                    File file = chooser.getSelectedFile();
                    IImageMetadata metadata = Sanselan.getMetadata(file);
                    TiffOutputSet outputSet = null;
                    if (metadata instanceof JpegImageMetadata) {
                        TiffImageMetadata exif = ((JpegImageMetadata) metadata).getExif();
                        outputSet = exif.getOutputSet();
                    } else if (metadata instanceof TiffImageMetadata) {
                        outputSet = ((TiffImageMetadata) metadata).getOutputSet();
                    }
                    if (metadata == null) {
                        outputSet = new TiffOutputSet();
                    }
                    if (outputSet == null) {
                        DialogFactory.openErrorDialog(appContainer.getViewPlatform(), ((IGeoDesktop) appContainer).getMainWndow(), get("$MD10898"), get("$DI10017"));
                        return;
                    }
                    outputSet.setGPSInDegrees(pt.getX(), pt.getY());
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    FileInputStream in = new FileInputStream(file);
                    byte[] buf = new byte[65536];
                    int read;
                    while ((read = in.read(buf)) != -1) {
                        out.write(buf, 0, read);
                    }
                    in.close();
                    out.close();
                    byte[] bs = out.toByteArray();
                    FileOutputStream os = new FileOutputStream(file);
                    if (metadata == null || metadata instanceof JpegImageMetadata) {
                        new ExifRewriter().updateExifMetadataLossless(bs, os, outputSet);
                    } else {
                        new TiffImageWriterLossless(bs).write(os, outputSet);
                    }
                    prefs.put("lastExifSaveDir" + getVersionNumber(), file.getParent());
                    DialogFactory.openInformationDialog(appContainer.getViewPlatform(), ((IGeoDesktop) appContainer).getMainWndow(), get("$MD10900"), get("$DI10018"));
                }
            } else {
                DialogFactory.openErrorDialog(appContainer.getViewPlatform(), ((IGeoDesktop) appContainer).getMainWndow(), get("$MD10897"), get("$DI10017"));
            }
        } catch (IOException e) {
            DialogFactory.openErrorDialog(appContainer.getViewPlatform(), ((IGeoDesktop) appContainer).getMainWndow(), get("$MD10899", e), get("$DI10017"));
        } catch (Exception e) {
            LOG.logError("Unknown error", e);
        }
    }
}
Example 2
Project: sanselanandroid-master  File: ExifRewriter.java View source code
/** 
	 * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream.
	 * <p>
	 * Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF 
	 * segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting
	 * any part of the original segment that it couldn't parse.  This can cause the EXIF segment to 
	 * grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1
	 * segment of the Jpeg image.  
	 * <p>
	 * @param  byteSource  ByteSource containing Jpeg image data.
	 * @param  os  OutputStream to write the image to.
	 * @param  outputSet  TiffOutputSet containing the EXIF data to write.
	 */
public void updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, ImageWriteException {
    //		List outputDirectories = outputSet.getDirectories();
    JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    List pieces = jfifPieces.pieces;
    TiffImageWriterBase writer;
    // Multiple APP1 segments are rare and poorly supported.
    if (jfifPieces.exifPieces.size() > 0) {
        JFIFPieceSegment exifPiece = null;
        exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0);
        byte exifBytes[] = exifPiece.segmentData;
        exifBytes = getByteArrayTail("trimmed exif bytes", exifBytes, 6);
        writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes);
    } else
        writer = new TiffImageWriterLossy(outputSet.byteOrder);
    boolean includeEXIFPrefix = true;
    byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
    writeSegmentsReplacingExif(os, pieces, newBytes);
}
Example 3
Project: Latipics-master  File: ExifRewriter.java View source code
/** 
	 * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream.
	 * <p>
	 * Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF 
	 * segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting
	 * any part of the original segment that it couldn't parse.  This can cause the EXIF segment to 
	 * grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1
	 * segment of the Jpeg image.  
	 * <p>
	 * @param  byteSource  ByteSource containing Jpeg image data.
	 * @param  os  OutputStream to write the image to.
	 * @param  outputSet  TiffOutputSet containing the EXIF data to write.
	 */
public void updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, ImageWriteException {
    //		List outputDirectories = outputSet.getDirectories();
    JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    List pieces = jfifPieces.pieces;
    TiffImageWriterBase writer;
    // Multiple APP1 segments are rare and poorly supported.
    if (jfifPieces.exifPieces.size() > 0) {
        JFIFPieceSegment exifPiece = null;
        exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0);
        byte exifBytes[] = exifPiece.segmentData;
        exifBytes = getByteArrayTail("trimmed exif bytes", exifBytes, 6);
        writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes);
    } else
        writer = new TiffImageWriterLossy(outputSet.byteOrder);
    boolean includeEXIFPrefix = true;
    byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
    writeSegmentsReplacingExif(os, pieces, newBytes);
}
Example 4
Project: appengine-awt-master  File: ExifRewriter.java View source code
/**
     * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream.
     * <p>
     * Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF
     * segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting
     * any part of the original segment that it couldn't parse.  This can cause the EXIF segment to
     * grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1
     * segment of the Jpeg image.
     * <p>
     * @param  byteSource  ByteSource containing Jpeg image data.
     * @param  os  OutputStream to write the image to.
     * @param  outputSet  TiffOutputSet containing the EXIF data to write.
     */
public void updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, ImageWriteException {
    //        List outputDirectories = outputSet.getDirectories();
    JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    List pieces = jfifPieces.pieces;
    TiffImageWriterBase writer;
    // Multiple APP1 segments are rare and poorly supported.
    if (jfifPieces.exifPieces.size() > 0) {
        JFIFPieceSegment exifPiece = null;
        exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0);
        byte exifBytes[] = exifPiece.segmentData;
        exifBytes = getByteArrayTail("trimmed exif bytes", exifBytes, 6);
        writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes);
    } else
        writer = new TiffImageWriterLossy(outputSet.byteOrder);
    boolean includeEXIFPrefix = true;
    byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
    writeSegmentsReplacingExif(os, pieces, newBytes);
}
Example 5
Project: android_geotagger-master  File: ExifRewriter.java View source code
/** 
	 * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream.
	 * <p>
	 * Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF 
	 * segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting
	 * any part of the original segment that it couldn't parse.  This can cause the EXIF segment to 
	 * grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1
	 * segment of the Jpeg image.  
	 * <p>
	 * @param  byteSource  ByteSource containing Jpeg image data.
	 * @param  os  OutputStream to write the image to.
	 * @param  outputSet  TiffOutputSet containing the EXIF data to write.
	 */
public void updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, ImageWriteException {
    //		List outputDirectories = outputSet.getDirectories();
    JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    List pieces = jfifPieces.pieces;
    TiffImageWriterBase writer;
    // Multiple APP1 segments are rare and poorly supported.
    if (jfifPieces.exifPieces.size() > 0) {
        JFIFPieceSegment exifPiece = null;
        exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0);
        byte exifBytes[] = exifPiece.segmentData;
        exifBytes = getByteArrayTail("trimmed exif bytes", exifBytes, 6);
        writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes);
    } else
        writer = new TiffImageWriterLossy(outputSet.byteOrder);
    boolean includeEXIFPrefix = true;
    byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
    writeSegmentsReplacingExif(os, pieces, newBytes);
}
Example 6
Project: appengine-export-master  File: ExifRewriter.java View source code
/**
     * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream.
     * <p>
     * Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF
     * segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting
     * any part of the original segment that it couldn't parse.  This can cause the EXIF segment to
     * grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1
     * segment of the Jpeg image.
     * <p>
     * @param  byteSource  ByteSource containing Jpeg image data.
     * @param  os  OutputStream to write the image to.
     * @param  outputSet  TiffOutputSet containing the EXIF data to write.
     */
public void updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, ImageWriteException {
    //        List outputDirectories = outputSet.getDirectories();
    JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    List pieces = jfifPieces.pieces;
    TiffImageWriterBase writer;
    // Multiple APP1 segments are rare and poorly supported.
    if (jfifPieces.exifPieces.size() > 0) {
        JFIFPieceSegment exifPiece = null;
        exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0);
        byte exifBytes[] = exifPiece.segmentData;
        exifBytes = getByteArrayTail("trimmed exif bytes", exifBytes, 6);
        writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes);
    } else
        writer = new TiffImageWriterLossy(outputSet.byteOrder);
    boolean includeEXIFPrefix = true;
    byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
    writeSegmentsReplacingExif(os, pieces, newBytes);
}