/*
* Copyright (c) 2014-2021 by Wen Yu
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License, v. 2.0 are satisfied: GNU General Public License, version 2
* or any later version.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
*
* Change History - most recent changes go on top of previous changes
*
* JPGMeta.java
*
* Who Date Description
* ==== ======= ===================================================
* WY 21Jun2019 Added code to return the removed metadata as a map
* WY 13Feb2017 Fixed bug with APP1 segment length too small
* WY 06Nov2016 Added support for Cardboard Camera image and audio
* WY 07Apr2016 Rewrite insertXMP() to leverage JpegXMP
* WY 30Mar2016 Rewrite writeComment() to leverage COMBuilder
* WY 06Jul2015 Added insertXMP(InputSream, OutputStream, XMP)
* WY 02Jul2015 Added support for APP14 segment reading
* WY 02Jul2015 Added support for APP12 segment reading
* WY 01Jul2015 Added support for non-standard XMP identifier
* WY 15Apr2015 Changed the argument type for insertIPTC() and insertIRB()
* WY 07Apr2015 Revised insertExif()
* WY 01Apr2015 Extract IPTC as stand-alone meta data from IRB if any
* WY 18Mar2015 Revised readAPP13(), insertIPTC() and insertIRB()
* to work with multiple APP13 segments
* WY 18Mar2015 Removed a few unused readAPPn methods
* WY 16Mar2015 Revised insertExif() to put EXIF in the position
* conforming to EXIF specification or the same place
* the original image EXIF exists
* WY 13Mar2015 initial creation
*/
package pixy.meta.jpeg;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import pixy.image.tiff.IFD;
import pixy.image.tiff.TiffTag;
import pixy.image.jpeg.COMBuilder;
import pixy.image.jpeg.Component;
import pixy.image.jpeg.DHTReader;
import pixy.image.jpeg.DQTReader;
import pixy.image.jpeg.HTable;
import pixy.image.jpeg.Marker;
import pixy.image.jpeg.QTable;
import pixy.image.jpeg.SOFReader;
import pixy.image.jpeg.SOSReader;
import pixy.image.jpeg.Segment;
import pixy.image.jpeg.UnknownSegment;
import pixy.io.FileCacheRandomAccessInputStream;
import pixy.io.IOUtils;
import pixy.io.RandomAccessInputStream;
import pixy.string.Base64;
import pixy.string.StringUtils;
import pixy.string.XMLUtils;
import pixy.util.ArrayUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import pixy.meta.Metadata;
import pixy.meta.MetadataType;
import pixy.meta.Thumbnail;
import pixy.meta.adobe.IRB;
import pixy.meta.adobe.ImageResourceID;
import pixy.meta.adobe._8BIM;
import pixy.meta.exif.Exif;
import pixy.meta.exif.ExifThumbnail;
import pixy.meta.adobe.ThumbnailResource;
import pixy.meta.icc.ICCProfile;
import pixy.meta.image.ImageMetadata;
import pixy.meta.image.Comments;
import pixy.meta.iptc.IPTC;
import pixy.meta.iptc.IPTCDataSet;
import pixy.meta.iptc.IPTCTag;
import pixy.meta.xmp.XMP;
import pixy.util.MetadataUtils;
import static pixy.image.jpeg.JPGConsts.*;
/**
* JPEG image tweaking tool
*
* @author Wen Yu, yuwen_66@yahoo.com
* @version 1.0 01/25/2013
*/
public class JPGMeta {
public static final EnumSet<Marker> APPnMarkers = EnumSet.range(Marker.APP0, Marker.APP15);
// Obtain a logger instance
private static final Logger LOGGER = LoggerFactory.getLogger(JPGMeta.class);
private static short copySegment(short marker, InputStream is, OutputStream os) throws IOException {
int length = IOUtils.readUnsignedShortMM(is);
byte[] buf = new byte[length - 2];
IOUtils.readFully(is, buf);
IOUtils.writeShortMM(os, marker);
IOUtils.writeShortMM(os, (short) length);
IOUtils.write(os, buf);
return (IOUtils.readShortMM(is));
}
/** Copy a single SOS segment */
@SuppressWarnings("unused")
private static short copySOS(InputStream is, OutputStream os) throws IOException {
// Need special treatment.
int nextByte = 0;
short marker = 0;
while((nextByte = IOUtils.read(is)) != -1) {
if(nextByte == 0xff) {
nextByte = IOUtils.read(is);
if (nextByte == -1) {
throw new IOException("Premature end of SOS segment!");
}
if (nextByte != 0x00) { // This is a marker
marker = (short)((0xff<<8)|nextByte);
switch (Marker.fromShort(marker)) {
case RST0:
case RST1:
case RST2:
case RST3:
case RST4:
case RST5:
case RST6:
case RST7:
IOUtils.writeShortMM(os, marker);
continue;
default:
}
break;
}
IOUtils.write(os, 0xff);
IOUtils.write(os, nextByte);
} else {
IOUtils.write(os, nextByte);
}
}
if (nextByte == -1) {
throw new IOException("Premature end of SOS segment!");
}
return marker;
}
private static void copyToEnd(InputStream is, OutputStream os) throws IOException {
byte[] buffer = new byte[10240]; // 10k buffer
int bytesRead = -1;
while((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
}
public static byte[] extractICCProfile(InputStream is) throws IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
// Flag when we are done
boolean finished = false;
int length = 0;
short marker;
Marker emarker;
// The very first marker should be the start_of_image marker!
if(Marker.fromShort(IOUtils.readShortMM(is)) != Marker.SOI)
throw new IOException("Invalid JPEG image, expected SOI marker not found!");
marker = IOUtils.readShortMM(is);
while (!finished) {
if (Marker.fromShort(marker) == Marker.EOI) {
finished = true;
} else { // Read markers
emarker = Marker.fromShort(marker);
switch (emarker) {
case JPG: // JPG and JPGn shouldn't appear in the image.
case JPG0:
case JPG13:
case TEM: // The only stand alone marker besides SOI, EOI, and RSTn.
marker = IOUtils.readShortMM(is);
break;
case PADDING:
int nextByte = 0;
while((nextByte = IOUtils.read(is)) == 0xff) {;}
marker = (short)((0xff<<8)|nextByte);
break;
case SOS:
//marker = skipSOS(is);
finished = true;
break;
case APP2:
readAPP2(is, bo);
marker = IOUtils.readShortMM(is);
break;
default:
length = IOUtils.readUnsignedShortMM(is);
byte[] buf = new byte[length - 2];
IOUtils.readFully(is, buf);
marker = IOUtils.readShortMM(is);
}
}
}
return bo.toByteArray();
}
public static void extractICCProfile(InputStream is, String pathToICCProfile) throws IOException {
byte[] icc_profile = extractICCProfile(is);
if(icc_profile != null && icc_profile.length > 0) {
String outpath = "";
if(pathToICCProfile.endsWith("\\") || pathToICCProfile.endsWith("/"))
outpath = pathToICCProfile + "icc_profile";
else
outpath = pathToICCProfile.replaceFirst("[.][^.]+$", "");
OutputStream os = new FileOutputStream(outpath + ".icc");
os.write(icc_profile);
os.close();
}
}
// Extract depth map from google phones and cardboard camera audio & stereo pair
public static
没有合适的资源?快使用搜索试试~ 我知道了~
适用于 Android 的 Java图像元数据操作工具_java_代码_下载
共1145个文件
class:655个
html:263个
java:171个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 131 浏览量
2022-06-15
01:10:27
上传
评论
收藏 44.32MB ZIP 举报
温馨提示
图像元数据操作: JPEG 和 TIFF EXIF 数据处理 将 EXIF 数据插入 JPEG。 从 JPEG 中提取 EXIF 数据。 从 JPEG 中删除 EXIF 数据和其他无关紧要的 APPn 段。 将 EXIF 数据插入 TIFF。 读取 TIFF 中嵌入的 EXIF 数据。 JPEG 和 TIFF ICC 配置文件支持 将 ICC 配置文件插入 JPEG 和 TIFF。 从 JPEG 和 TIFF 中提取 ICC 配置文件。 JPEG 和 TIFF IPTC 元数据支持 通过 RichTiffIPTC 标签将 IPTC 直接插入 TIFF。 通过 APP13 Photoshop IRB 将 IPTC 插入 JPEG 从 TIFF 和 JPEG 中提取 IPTC JPEG 和 TIFF Photoshop IRB 元数据支持 通过 APP13 段将 IRB 插入 JPEG 通过标签 PHOTOSHOP 将 IRB 插入 TIFF。 从 JPEG 和 TIFF 中提取 IRB 数据。 JPEG、GIF、PNG、TIFF XMP 元数据支持 将 XMP 元数据插入 JPEG、GI
资源推荐
资源详情
资源评论
收起资源包目录
适用于 Android 的 Java图像元数据操作工具_java_代码_下载 (1145个子文件)
niagra_falls.bmp 560KB
TIFFMeta.class 49KB
TIFFMeta.class 31KB
JPGMeta.class 30KB
ArrayUtils.class 23KB
TiffTag.class 18KB
StringUtils.class 18KB
TiffTag.class 17KB
ImageResourceID.class 15KB
ArrayUtils.class 15KB
ImageResourceID.class 14KB
Metadata.class 14KB
StringUtils.class 12KB
IRB.class 12KB
XMLUtils.class 12KB
ICCProfile.class 12KB
Exif.class 12KB
PNGMeta.class 12KB
TestPixyMetaAndroid.class 10KB
ExifTag.class 10KB
Metadata.class 10KB
IPTCApplicationTag.class 10KB
ICCProfile.class 9KB
ExifTag.class 9KB
Exif.class 9KB
IPTCApplicationTag.class 9KB
XMLUtils.class 8KB
PNGMeta.class 8KB
IOUtils.class 8KB
TestPixyMetaAndroid.class 8KB
LangUtils.class 8KB
GIFMeta.class 8KB
ProfileTag.class 7KB
IPTC.class 7KB
IPTCDataSet.class 7KB
XMP.class 7KB
ProfileTag.class 7KB
Marker.class 7KB
FieldType.class 6KB
JPGConsts.class 6KB
ExifThumbnail.class 6KB
ThumbnailResource.class 6KB
IFD.class 6KB
GPSTag.class 6KB
BMPMeta.class 6KB
SeekableStream.class 6KB
IRB.class 6KB
Marker.class 6KB
LangUtils.class 6KB
GIFMeta.class 6KB
GPSTag.class 5KB
DDB.class 5KB
IPTCNewsPhotoTag.class 5KB
IOUtils.class 5KB
BMPMeta.class 5KB
XMP.class 5KB
ExifThumbnail.class 5KB
TIMEChunk.class 5KB
ThumbnailResource.class 5KB
MetadataUtils.class 5KB
IPTCDataSet.class 5KB
IPTC.class 5KB
FieldType.class 5KB
TextualChunks.class 5KB
TextReader.class 5KB
MemoryCacheRandomAccessOutputStream.class 5KB
JFIF.class 4KB
IPTCNewsPhotoTag.class 4KB
IFD.class 4KB
VersionInfo.class 4KB
IPTC_NAA.class 4KB
IPTCEnvelopeTag.class 4KB
RandomAccessInputStream.class 4KB
WriteStrategyMM.class 4KB
WriteStrategyII.class 4KB
ChunkType.class 4KB
JPGQuality.class 4KB
CRC32.class 4KB
BlendModeKey.class 4KB
TextBuilder.class 4KB
FileUtils.class 4KB
Base64.class 4KB
RandomAccessOutputStream.class 4KB
ProfileTagTable.class 4KB
SeekableStream.class 4KB
DDB.class 4KB
EndianAwareInputStream.class 4KB
_8BIM.class 4KB
ImageMetadata.class 4KB
IntHashtable.class 4KB
TIMEChunk.class 4KB
InteropTag.class 4KB
Filter.class 4KB
ChunkType.class 4KB
IPTCEnvelopeTag.class 4KB
MetadataUtils.class 4KB
DuckyDataSet.class 4KB
BlendModeKey.class 4KB
TiffFieldEnum$PhotoMetric.class 4KB
TextualChunks.class 3KB
共 1145 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9149
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功