TMI-DNG: Initial commit.

This commit is contained in:
Harald Kuhr 2014-10-15 12:22:55 +02:00
parent f69f706f60
commit 6ab0e64107
10 changed files with 1477 additions and 0 deletions

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2014, Harald Kuhr
~ All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~ * Redistributions of source code must retain the above copyright
~ notice, this list of conditions and the following disclaimer.
~ * Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ * Neither the name "TwelveMonkeys" nor the
~ names of its contributors may be used to endorse or promote products
~ derived from this software without specific prior written permission.
~
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
~ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
~ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
~ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
~ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
~ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
~ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
~ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
~ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
~ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>imageio</artifactId>
<groupId>com.twelvemonkeys.imageio</groupId>
<version>3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>imageio-dng</artifactId>
<name>TwelveMonkeys :: ImageIO :: DNG plugin</name>
<description>ImageIO plugin for Adobe Digital Negative and TIFF/EP (DNG).</description>
<dependencies>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-core</artifactId>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-core</artifactId>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-metadata</artifactId>
</dependency>
<dependency>
<version>${project.version}</version>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,127 @@
package com.twelvemonkeys.imageio.plugins.dng;
/**
* DNG
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: DNG.java,v 1.0 03.10.14 10:49 haraldk Exp$
*/
interface DNG {
// TODO: Some (all?) of these tags are defined by TIFF/EP, should we reflect that in package/class names?
/** CFA (Color Filter Array). */
int PHOTOMETRIC_CFA = 32803;
/** LinearRaw. */
int PHOTOMETRIC_LINEAR_RAW = 34892;
/**
* Lossy JPEG.
* <p/>
* Lossy JPEG (34892) is allowed for IFDs that use PhotometricInterpretation = 34892
* (LinearRaw) and 8-bit integer data. This new compression code is required to let the DNG
* reader know to use a lossy JPEG decoder rather than a lossless JPEG decoder for this
* combination of PhotometricInterpretation and BitsPerSample.
*/
int COMPRESSION_LOSSY_JPEG = 34892;
/**
* CFARepeatPatternDim
* <p/>
* This tag encodes the number of pixels horizontally and vertically that are needed to uniquely define the repeat
* pattern of the color filter array (CFA) pattern used in the color image sensor. It is mandatory when
* PhotometricInterpretation = 32803, and there are no defaults allowed. It is optional when
* PhotometricInterpretation = 2 or 6 and SensingMethod = 2, where it can be used to indicate the original sensor
* sampling positions.
*/
int TAG_CFA_REPEAT_PATTERN_DIM = 33421;
/**
* Indicates the color filter array (CFA) geometric pattern of the image sensor
* when a one-chip color area sensor is used.
* NOTE: This tag (defined in TIFF/EP) is different from the CFAPattern defined in normal TIFF.
*/
int TAG_CFA_PATTERN = 33422;
/** Indicates the image sensor type on the camera or input device. */
int TAG_SENSING_METHOD = 37399;
// From http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/cfapattern.html
byte CFA_PATTERN_RED = 0;
byte CFA_PATTERN_GREEN = 1;
byte CFA_PATTERN_BLUE = 2;
byte CFA_PATTERN_CYAN = 3;
byte CFA_PATTERN_MAGENTA = 4;
byte CFA_PATTERN_YELLOW = 5;
byte CFA_PATTERN_WHITE = 6; // ???? Should be KEY?
/**
* This tag encodes the DNG four-tier version number. For files compliant with this version of
* the DNG specification (1.4.0.0), this tag should contain the bytes: 1, 4, 0, 0.
*/
int TAG_DNG_VERSION = 50706;
int TAG_DNG_BACKWARD_VERSION = 50707;
/** UniqueCameraModel defines a unique, non-localized name for the camera model that created the image in the raw file. */
int TAG_UNIQUE_CAMERA_MODEL = 50708;
int TAG_LOCALIZED_CAMERA_MODEL = 50709;
/** CFA plane to RGB mapping (default: [0, 1, 2]). */
int TAG_CFA_PLANE_COLOR = 50710;
/** CFA spatial layout (default: 1). */
int TAG_CFA_LAYOUT = 50711;
/** 1 = Rectangular (or square) layout. */
int CFA_LAYOUT_RECTANGULAR = 1;
/** 2 = Staggered layout A: even columns are offset down by 1/2 row. */
int CFA_LAYOUT_STAGGERED_A = 2;
/** 3 = Staggered layout B: even columns are offset up by 1/2 row. */
int CFA_LAYOUT_STAGGERED_B = 3;
/** 4 = Staggered layout C: even rows are offset right by 1/2 column. */
int CFA_LAYOUT_STAGGERED_C = 4;
/** 5 = Staggered layout D: even rows are offset left by 1/2 column. */
int CFA_LAYOUT_STAGGERED_D = 5;
/** 6 = Staggered layout E: even rows are offset up by 1/2 row, even columns are offset left by 1/2 column. */
int CFA_LAYOUT_STAGGERED_E = 6;
/** 7 = Staggered layout F: even rows are offset up by 1/2 row, even columns are offset right by 1/2 column. */
int CFA_LAYOUT_STAGGERED_F = 7;
/** 8 = Staggered layout G: even rows are offset down by 1/2 row, even columns are offset left by 1/2 column. */
int CFA_LAYOUT_STAGGERED_G = 8;
/** 9 = Staggered layout H: even rows are offset down by 1/2 row, even columns are offset right by 1/2 column. */
int CFA_LAYOUT_STAGGERED_H = 9;
/** LinearizationTable describes a lookup table that maps stored values into linear values. */
int TAG_LINEARIZATION_TABLE = 50712;
/** This tag specifies repeat pattern size for the BlackLevel tag. Default: [1, 1]. */
int TAG_BLACK_LEVEL_REPEAT_DIM = 50713;
/**
* This tag specifies the zero light (a.k.a. thermal black or black current) encoding level,
* as a repeating pattern. Default: 0.
*/
int TAG_BLACK_LEVEL = 50714;
// TODO: Rest of DNG tags.
// ...
/**
* Horizontal Difference X2.
* Same as Horizontal Difference except the pixel two to the left is used rather than the pixel one to the left.
*/
int PREDICTOR_HORIZONTAL_X2 = 34892;
/**
* Horizontal Difference X4.
* Same as Horizontal Difference except the pixel four to the left is used rather than the pixel one to the left.
*/
int PREDICTOR_HORIZONTAL_X4 = 34893;
/**
* Floating Point X2.
* Same as Floating Point except the pixel two to the left is used rather than the pixel one to the left.
*/
int PREDICTOR_FLOATINGPOINT_X2 = 34894;
/**
* Floating Point X4.
* Same as Floating Point except the pixel four to the left is used rather than the pixel one to the left
*/
int PREDICTOR_FLOATINGPOINT_X4 = 34895;
}

View File

@ -0,0 +1,125 @@
/*
* Copyright (c) 2014, Harald Kuhr
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name "TwelveMonkeys" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.twelvemonkeys.imageio.plugins.dng;
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
import com.twelvemonkeys.imageio.spi.ProviderInfo;
import com.twelvemonkeys.imageio.util.IIOUtil;
import javax.imageio.ImageReader;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import java.io.IOException;
import java.nio.ByteOrder;
import java.util.Locale;
/**
* CR2ImageReaderSpi
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: CR2ImageReaderSpi.java,v 1.0 07.04.14 21:26 haraldk Exp$
*/
public final class DNGImageReaderSpi extends ImageReaderSpi {
public DNGImageReaderSpi() {
this(IIOUtil.getProviderInfo(DNGImageReaderSpi.class));
}
private DNGImageReaderSpi(final ProviderInfo pProviderInfo) {
super(
pProviderInfo.getVendorName(),
pProviderInfo.getVersion(),
new String[]{"dng", "NDG"},
new String[]{"dng"},
new String[]{
"image/x-adobe-dng", // TODO: Look up
},
"com.twelvemonkeys.imageio.plugins.dng.DNGImageReader",
new Class[] {ImageInputStream.class},
null,
true, null, null, null, null,
true,
null, null,
null, null
);
}
public boolean canDecodeInput(final Object pSource) throws IOException {
if (!(pSource instanceof ImageInputStream)) {
return false;
}
ImageInputStream stream = (ImageInputStream) pSource;
stream.mark();
try {
byte[] bom = new byte[2];
stream.readFully(bom);
ByteOrder originalOrder = stream.getByteOrder();
try {
if (bom[0] == 'I' && bom[1] == 'I') {
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
}
else if (bom[0] == 'M' && bom[1] == 'M') {
stream.setByteOrder(ByteOrder.BIG_ENDIAN);
}
else {
return false;
}
int tiffMagic = stream.readUnsignedShort();
if (tiffMagic != TIFF.TIFF_MAGIC) {
return false;
}
// TODO: This is not different from a normal TIFF...
return true;
}
finally {
stream.setByteOrder(originalOrder);
}
}
finally {
stream.reset();
}
}
@Override
public ImageReader createReaderInstance(Object extension) throws IOException {
return new DNGImageReader(this);
}
@Override
public String getDescription(Locale locale) {
return "Adobe Digital Negative (DNG) format Reader";
}
}

View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2014, Harald Kuhr
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name "TwelveMonkeys" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.twelvemonkeys.imageio.plugins.dng;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
import org.junit.Ignore;
import org.junit.Test;
import javax.imageio.ImageReader;
import javax.imageio.spi.ImageReaderSpi;
import java.awt.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
* CR2ImageReaderTest
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: CR2ImageReaderTest.java,v 1.0 07.04.14 21:52 haraldk Exp$
*/
public class DNGImageReaderTest extends ImageReaderAbstractTestCase {
@Override
protected List<TestData> getTestData() {
return Arrays.asList(
new TestData(getClassLoaderResource("/dng/L1004220.DNG"),
// Uncompressed RGB (thumbnail), Ucompressed CFA
// new Dimension(320, 216),
new Dimension(5216, 3472)),
new TestData(getClassLoaderResource("/dng/IMG_2224.dng"),
// Uncompressed RGB (thumbnail), JPEG Lossless CFA, JPEG DCT YCbCr
// new Dimension(256, 171),
new Dimension(3516, 2328),
new Dimension(1024, 683))
// new TestData(getClassLoaderResource("/dng/test.dng"), new Dimension(2, 2)) // Only JPEG Lossless CFA
);
}
@Override
protected ImageReaderSpi createProvider() {
return new DNGImageReaderSpi();
}
@Override
protected ImageReader createReader() {
return new com.twelvemonkeys.imageio.plugins.dng.DNGImageReader(createProvider());
}
@Override
protected Class getReaderClass() {
return com.twelvemonkeys.imageio.plugins.dng.DNGImageReader.class;
}
@Override
protected List<String> getFormatNames() {
return Arrays.asList("dng");
}
@Override
protected List<String> getSuffixes() {
return Arrays.asList("dng");
}
@Override
protected List<String> getMIMETypes() {
return Arrays.asList("image/x-dng");
}
@Test
@Ignore("Known issue: Subsampled reading not supported")
@Override
public void testReadWithSubsampleParamPixels() throws IOException {
super.testReadWithSubsampleParamPixels();
}
@Test
@Ignore("Known issue: Source region reading not supported")
@Override
public void testReadWithSourceRegionParamEqualImage() throws IOException {
super.testReadWithSourceRegionParamEqualImage();
}
}

Binary file not shown.

Binary file not shown.