Subversion Repositories general

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1267 → Rev 1268

/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/JpegComponent.java
0,0 → 1,81
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on Oct 9, 17:04:07 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg;
 
import com.drew.metadata.MetadataException;
 
import java.io.Serializable;
 
/**
* Created by IntelliJ IDEA.
* User: dnoakes
* Date: 09-Oct-2003
* Time: 17:04:07
* To change this template use Options | File Templates.
*/
public class JpegComponent implements Serializable
{
private final int _componentId;
private final int _samplingFactorByte;
private final int _quantizationTableNumber;
 
public JpegComponent(int componentId, int samplingFactorByte, int quantizationTableNumber)
{
_componentId = componentId;
_samplingFactorByte = samplingFactorByte;
_quantizationTableNumber = quantizationTableNumber;
}
 
public int getComponentId()
{
return _componentId;
}
 
public String getComponentName() throws MetadataException
{
switch (_componentId)
{
case 1:
return "Y";
case 2:
return "Cb";
case 3:
return "Cr";
case 4:
return "I";
case 5:
return "Q";
}
 
throw new MetadataException("Unsupported component id: " + _componentId);
}
 
public int getQuantizationTableNumber()
{
return _quantizationTableNumber;
}
 
public int getHorizontalSamplingFactor()
{
return _samplingFactorByte & 0x0F;
}
 
public int getVerticalSamplingFactor()
{
return (_samplingFactorByte>>4) & 0x0F;
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/JpegReader.java
0,0 → 1,146
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on Aug 2, 2003 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg;
 
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.imaging.jpeg.JpegSegmentReader;
import com.drew.metadata.Metadata;
import com.drew.metadata.MetadataException;
import com.drew.metadata.MetadataReader;
 
import java.io.File;
import java.io.InputStream;
 
/**
*
* @author Darrell Silver http://www.darrellsilver.com and Drew Noakes
*/
public class JpegReader implements MetadataReader
{
/**
* The SOF0 data segment.
*/
private final byte[] _data;
 
/**
* Creates a new JpegReader for the specified Jpeg jpegFile.
*/
public JpegReader(File jpegFile) throws JpegProcessingException
{
this(new JpegSegmentReader(jpegFile).readSegment(JpegSegmentReader.SEGMENT_SOF0));
}
 
/** Creates a JpegReader for a JPEG stream.
*
* @param is JPEG stream. Stream will be closed.
*/
public JpegReader(InputStream is) throws JpegProcessingException
{
this(new JpegSegmentReader(is).readSegment(JpegSegmentReader.SEGMENT_APPD));
}
 
public JpegReader(byte[] data)
{
_data = data;
}
 
/**
* Performs the Jpeg data extraction, returning a new instance of <code>Metadata</code>.
*/
public Metadata extract()
{
return extract(new Metadata());
}
 
/**
* Performs the Jpeg data extraction, adding found values to the specified
* instance of <code>Metadata</code>.
*/
public Metadata extract(Metadata metadata)
{
if (_data==null) {
return metadata;
}
 
JpegDirectory directory = (JpegDirectory)metadata.getDirectory(JpegDirectory.class);
 
try {
// data precision
int dataPrecision = get16Bits(JpegDirectory.TAG_JPEG_DATA_PRECISION);
directory.setInt(JpegDirectory.TAG_JPEG_DATA_PRECISION, dataPrecision);
 
// process height
int height = get32Bits(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT, height);
 
// process width
int width = get32Bits(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH, width);
 
// number of components
int numberOfComponents = get16Bits(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS);
directory.setInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS, numberOfComponents);
 
// for each component, there are three bytes of data:
// 1 - Component ID: 1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q
// 2 - Sampling factors: bit 0-3 vertical, 4-7 horizontal
// 3 - Quantization table number
int offset = 6;
for (int i=0; i<numberOfComponents; i++)
{
int componentId = get16Bits(offset++);
int samplingFactorByte = get16Bits(offset++);
int quantizationTableNumber = get16Bits(offset++);
JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + i, component);
}
 
} catch (MetadataException me) {
directory.addError("MetadataException: " + me);
}
 
return metadata;
}
 
/**
* Returns an int calculated from two bytes of data at the specified offset (MSB, LSB).
* @param offset position within the data buffer to read first byte
* @return the 32 bit int value, between 0x0000 and 0xFFFF
*/
private int get32Bits(int offset) throws MetadataException
{
if (offset+1>=_data.length) {
throw new MetadataException("Attempt to read bytes from outside Jpeg segment data buffer");
}
 
return ((_data[offset] & 255) << 8) | (_data[offset + 1] & 255);
}
 
/**
* Returns an int calculated from one byte of data at the specified offset.
* @param offset position within the data buffer to read byte
* @return the 16 bit int value, between 0x00 and 0xFF
*/
private int get16Bits(int offset) throws MetadataException
{
if (offset>=_data.length) {
throw new MetadataException("Attempt to read bytes from outside Jpeg segment data buffer");
}
 
return (_data[offset] & 255);
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/JpegDirectory.java
0,0 → 1,111
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created on Aug 2, 2003.
*/
package com.drew.metadata.jpeg;
 
import com.drew.metadata.Directory;
import com.drew.metadata.MetadataException;
 
import java.util.HashMap;
 
/**
* Directory of tags and values for the SOF0 Jpeg segment. This segment holds basic metadata about the image.
* @author Darrell Silver http://www.darrellsilver.com and Drew Noakes
*/
public class JpegDirectory extends Directory {
 
/** This is in bits/sample, usually 8 (12 and 16 not supported by most software). */
public static final int TAG_JPEG_DATA_PRECISION = 0;
/** The image's height. Necessary for decoding the image, so it should always be there. */
public static final int TAG_JPEG_IMAGE_HEIGHT = 1;
/** The image's width. Necessary for decoding the image, so it should always be there. */
public static final int TAG_JPEG_IMAGE_WIDTH = 3;
/** Usually 1 = grey scaled, 3 = color YcbCr or YIQ, 4 = color CMYK
* Each component TAG_COMPONENT_DATA_[1-4], has the following meaning:
* component Id(1byte)(1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q),
* sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.),
* quantization table number (1 byte).
* <p>
* This info is from http://www.funducode.com/freec/Fileformats/format3/format3b.htm
*/
public static final int TAG_JPEG_NUMBER_OF_COMPONENTS = 5;
 
// NOTE! Component tag type int values must increment in steps of 1
 
/** the first of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
public static final int TAG_JPEG_COMPONENT_DATA_1 = 6;
/** the second of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
public static final int TAG_JPEG_COMPONENT_DATA_2 = 7;
/** the third of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
public static final int TAG_JPEG_COMPONENT_DATA_3 = 8;
/** the fourth of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
public static final int TAG_JPEG_COMPONENT_DATA_4 = 9;
 
protected static final HashMap tagNameMap = new HashMap();
 
static {
tagNameMap.put(new Integer(TAG_JPEG_DATA_PRECISION), "Data Precision");
tagNameMap.put(new Integer(TAG_JPEG_IMAGE_WIDTH), "Image Width");
tagNameMap.put(new Integer(TAG_JPEG_IMAGE_HEIGHT), "Image Height");
tagNameMap.put(new Integer(TAG_JPEG_NUMBER_OF_COMPONENTS), "Number of Components");
tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_1), "Component 1");
tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_2), "Component 2");
tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_3), "Component 3");
tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_4), "Component 4");
}
 
public JpegDirectory() {
this.setDescriptor(new JpegDescriptor(this));
}
 
public String getName() {
return "Jpeg";
}
 
protected HashMap getTagNameMap() {
return tagNameMap;
}
 
/**
*
* @param componentNumber The zero-based index of the component. This number is normally between 0 and 3.
* Use getNumberOfComponents for bounds-checking.
* @return
*/
public JpegComponent getComponent(int componentNumber)
{
int tagType = JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + componentNumber;
 
JpegComponent component = (JpegComponent)getObject(tagType);
 
return component;
}
 
public int getImageWidth() throws MetadataException
{
return getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
}
 
public int getImageHeight() throws MetadataException
{
return getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
}
 
public int getNumberOfComponents() throws MetadataException
{
return getInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS);
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/JpegCommentReader.java
0,0 → 1,84
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on Oct 10, 2003 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg;
 
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.imaging.jpeg.JpegSegmentReader;
import com.drew.metadata.Metadata;
import com.drew.metadata.MetadataReader;
 
import java.io.File;
import java.io.InputStream;
 
/**
*
* @author Drew Noakes http://drewnoakes.com
*/
public class JpegCommentReader implements MetadataReader
{
/**
* The COM data segment.
*/
private final byte[] _data;
 
/**
* Creates a new JpegReader for the specified Jpeg jpegFile.
*/
public JpegCommentReader(File jpegFile) throws JpegProcessingException
{
this(new JpegSegmentReader(jpegFile).readSegment(JpegSegmentReader.SEGMENT_COM));
}
 
/** Creates a JpegCommentReader for a JPEG stream.
*
* @param is JPEG stream. Stream will be closed.
*/
public JpegCommentReader(InputStream is) throws JpegProcessingException
{
this(new JpegSegmentReader(is).readSegment(JpegSegmentReader.SEGMENT_APPD));
}
 
public JpegCommentReader(byte[] data)
{
_data = data;
}
 
/**
* Performs the Jpeg data extraction, returning a new instance of <code>Metadata</code>.
*/
public Metadata extract()
{
return extract(new Metadata());
}
 
/**
* Performs the Jpeg data extraction, adding found values to the specified
* instance of <code>Metadata</code>.
*/
public Metadata extract(Metadata metadata)
{
if (_data==null) {
return metadata;
}
 
JpegCommentDirectory directory = (JpegCommentDirectory)metadata.getDirectory(JpegCommentDirectory.class);
 
directory.setString(JpegCommentDirectory.TAG_JPEG_COMMENT, new String(_data));
 
return metadata;
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/JpegCommentDirectory.java
0,0 → 1,49
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on Oct 10, 2003 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg;
 
import com.drew.metadata.Directory;
 
import java.util.HashMap;
 
/**
*
* @author Drew Noakes http://drewnoakes.com
*/
public class JpegCommentDirectory extends Directory {
 
/** This is in bits/sample, usually 8 (12 and 16 not supported by most software). */
public static final int TAG_JPEG_COMMENT = 0;
 
protected static final HashMap tagNameMap = new HashMap();
 
static {
tagNameMap.put(new Integer(TAG_JPEG_COMMENT), "Jpeg Comment");
}
 
public JpegCommentDirectory() {
this.setDescriptor(new JpegCommentDescriptor(this));
}
 
public String getName() {
return "JpegComment";
}
 
protected HashMap getTagNameMap() {
return tagNameMap;
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/test/JpegDescriptorTest.java
0,0 → 1,82
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes 09-Oct-2003 15:22:23 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg.test;
 
import com.drew.metadata.MetadataException;
import com.drew.metadata.jpeg.JpegComponent;
import com.drew.metadata.jpeg.JpegDescriptor;
import com.drew.metadata.jpeg.JpegDirectory;
import junit.framework.TestCase;
 
/**
*
*/
public class JpegDescriptorTest extends TestCase
{
private JpegDirectory _directory;
private JpegDescriptor _descriptor;
 
public JpegDescriptorTest(String s)
{
super(s);
}
 
public void setUp() throws Exception
{
_directory = new JpegDirectory();
_descriptor = new JpegDescriptor(_directory);
}
 
public void testGetComponentDataDescription_InvalidComponentNumber() throws Exception
{
try {
_descriptor.getComponentDataDescription(1);
fail("Excepted exception");
} catch (MetadataException e) {
// expect exception
}
}
 
public void testGetImageWidthDescription() throws Exception
{
_directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH, 123);
assertEquals("123 pixels", _descriptor.getImageWidthDescription());
assertEquals("123 pixels", _directory.getDescription(JpegDirectory.TAG_JPEG_IMAGE_WIDTH));
}
 
public void testGetImageHeightDescription() throws Exception
{
_directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT, 123);
assertEquals("123 pixels", _descriptor.getImageHeightDescription());
assertEquals("123 pixels", _directory.getDescription(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT));
}
 
public void testGetDataPrecisionDescription() throws Exception
{
_directory.setInt(JpegDirectory.TAG_JPEG_DATA_PRECISION, 8);
assertEquals("8 bits", _descriptor.getDataPrecisionDescription());
assertEquals("8 bits", _directory.getDescription(JpegDirectory.TAG_JPEG_DATA_PRECISION));
}
 
public void testGetComponentDescription() throws MetadataException
{
JpegComponent component1 = new JpegComponent(1, 0x22, 0);
_directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_1, component1);
assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", _directory.getDescription(JpegDirectory.TAG_JPEG_COMPONENT_DATA_1));
assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", _descriptor.getComponentDataDescription(0));
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/test/JpegComponentTest.java
0,0 → 1,51
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on 09-Oct-2003 15:22:23 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg.test;
 
import com.drew.metadata.jpeg.JpegComponent;
import junit.framework.TestCase;
 
/**
*
*/
public class JpegComponentTest extends TestCase
{
public JpegComponentTest(String s)
{
super(s);
}
 
public void testGetComponentCharacter() throws Exception
{
JpegComponent component;
 
component = new JpegComponent(1,2,3);
assertEquals("Y", component.getComponentName());
 
component = new JpegComponent(2,2,3);
assertEquals("Cb", component.getComponentName());
 
component = new JpegComponent(3,2,3);
assertEquals("Cr", component.getComponentName());
 
component = new JpegComponent(4,2,3);
assertEquals("I", component.getComponentName());
 
component = new JpegComponent(5,2,3);
assertEquals("Q", component.getComponentName());
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/test/JpegReaderTest.java
0,0 → 1,150
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on 09-Oct-2003 15:22:23 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg.test;
 
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Metadata;
import com.drew.metadata.jpeg.JpegComponent;
import com.drew.metadata.jpeg.JpegDirectory;
import com.drew.metadata.jpeg.JpegReader;
import junit.framework.TestCase;
 
import java.io.File;
import java.io.FileNotFoundException;
 
/**
*
*/
public class JpegReaderTest extends TestCase
{
private JpegDirectory _directory;
 
public JpegReaderTest(String s)
{
super(s);
}
 
public void setUp() throws JpegProcessingException, FileNotFoundException
{
// use a known testing image
File jpegFile = new File("src/com/drew/metadata/jpeg/test/simple.jpg");
JpegReader reader = new JpegReader(jpegFile);
Metadata metadata = reader.extract();
assertTrue(metadata.containsDirectory(JpegDirectory.class));
_directory = (JpegDirectory)metadata.getDirectory(JpegDirectory.class);
}
 
public void testExtract_Width() throws Exception
{
assertEquals(800, _directory.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH));
}
 
public void testExtract_Height() throws Exception
{
assertEquals(600, _directory.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT));
}
 
public void testExtract_DataPrecision() throws Exception
{
assertEquals(8, _directory.getInt(JpegDirectory.TAG_JPEG_DATA_PRECISION));
}
 
public void testExtract_NumberOfComponents() throws Exception
{
assertEquals(3, _directory.getInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS));
}
 
public void testComponentData1() throws Exception
{
JpegComponent component = (JpegComponent)_directory.getObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_1);
assertEquals("Y", component.getComponentName());
assertEquals(1, component.getComponentId());
assertEquals(0, component.getQuantizationTableNumber());
assertEquals(2, component.getHorizontalSamplingFactor());
assertEquals(2, component.getVerticalSamplingFactor());
}
 
public void testComponentData2() throws Exception
{
JpegComponent component = (JpegComponent)_directory.getObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_2);
assertEquals("Cb", component.getComponentName());
assertEquals(2, component.getComponentId());
assertEquals(1, component.getQuantizationTableNumber());
assertEquals(1, component.getHorizontalSamplingFactor());
assertEquals(1, component.getVerticalSamplingFactor());
assertEquals("Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert", _directory.getDescription(JpegDirectory.TAG_JPEG_COMPONENT_DATA_2));
}
 
public void testComponentData3() throws Exception
{
JpegComponent component = (JpegComponent)_directory.getObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_3);
assertEquals("Cr", component.getComponentName());
assertEquals(3, component.getComponentId());
assertEquals(1, component.getQuantizationTableNumber());
assertEquals(1, component.getHorizontalSamplingFactor());
assertEquals(1, component.getVerticalSamplingFactor());
assertEquals("Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert", _directory.getDescription(JpegDirectory.TAG_JPEG_COMPONENT_DATA_3));
}
 
/*
// this test is part of an incomplete investigation into extracting audio from JPG files
public void testJpegWithAudio() throws Exception
{
// use a known testing image
File jpegFile = new File("src/com/drew/metadata/jpeg/test/audioPresent.jpg");
 
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(jpegFile);
byte[] segment1Bytes = jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP2);
System.out.println(segment1Bytes.length);
 
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP1));
System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP2).length);
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP3));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP4));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP5));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP6));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP7));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP8));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APP9));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APPA));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APPB));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APPC));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APPD));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APPE));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_APPF));
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_COM));
System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_DHT).length);
System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_DQT).length);
System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_SOF0).length);
// System.out.println(jpegSegmentReader.readSegment(JpegSegmentReader.SEGMENT_SOI));
 
// write the segment's data out to a wav file...
File audioFile = new File("src/com/drew/metadata/jpeg/test/audio.wav");
FileOutputStream os = null;
try
{
os = new FileOutputStream(audioFile);
os.write(segment1Bytes);
}
finally
{
if (os!=null)
os.close();
}
}
*/
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/test/simple.jpg
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/test/JpegDirectoryTest.java
0,0 → 1,91
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on 09-Oct-2003 15:22:23 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg.test;
 
import com.drew.metadata.jpeg.JpegComponent;
import com.drew.metadata.jpeg.JpegDirectory;
import junit.framework.TestCase;
 
/**
*
*/
public class JpegDirectoryTest extends TestCase
{
private JpegDirectory _directory;
 
public JpegDirectoryTest(String s)
{
super(s);
}
 
public void setUp()
{
_directory = new JpegDirectory();
}
 
public void testSetAndGetValue() throws Exception
{
_directory.setInt(123, 8);
assertEquals(8, _directory.getInt(123));
}
 
public void testGetComponent_NotAdded()
{
assertNull(_directory.getComponent(1));
}
 
// NOTE tests for individual tag values exist in JpegReaderTest.java
 
public void testGetImageWidth() throws Exception
{
_directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH, 123);
assertEquals(123, _directory.getImageWidth());
}
 
public void testGetImageHeight() throws Exception
{
_directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT, 123);
assertEquals(123, _directory.getImageHeight());
}
 
 
public void testGetNumberOfComponents() throws Exception
{
_directory.setInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS, 3);
assertEquals(3, _directory.getNumberOfComponents());
assertEquals("3", _directory.getDescription(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS));
}
 
public void testGetComponent() throws Exception
{
JpegComponent component1 = new JpegComponent(1, 2, 3);
JpegComponent component2 = new JpegComponent(1, 2, 3);
JpegComponent component3 = new JpegComponent(1, 2, 3);
JpegComponent component4 = new JpegComponent(1, 2, 3);
 
_directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_1, component1);
_directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_2, component2);
_directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_3, component3);
_directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_4, component4);
 
// component numbers are zero-indexed for this method
assertSame(component1, _directory.getComponent(0));
assertSame(component2, _directory.getComponent(1));
assertSame(component3, _directory.getComponent(2));
assertSame(component4, _directory.getComponent(3));
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/JpegDescriptor.java
0,0 → 1,88
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*/
package com.drew.metadata.jpeg;
 
import com.drew.metadata.Directory;
import com.drew.metadata.MetadataException;
import com.drew.metadata.TagDescriptor;
 
/**
* Provides human-readable string versions of the tags stored in a JpegDirectory.
* Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class.
*/
public class JpegDescriptor extends TagDescriptor
{
public JpegDescriptor(Directory directory)
{
super(directory);
}
 
public String getDescription(int tagType) throws MetadataException
{
switch (tagType)
{
case JpegDirectory.TAG_JPEG_COMPONENT_DATA_1:
return getComponentDataDescription(0);
case JpegDirectory.TAG_JPEG_COMPONENT_DATA_2:
return getComponentDataDescription(1);
case JpegDirectory.TAG_JPEG_COMPONENT_DATA_3:
return getComponentDataDescription(2);
case JpegDirectory.TAG_JPEG_COMPONENT_DATA_4:
return getComponentDataDescription(3);
case JpegDirectory.TAG_JPEG_DATA_PRECISION:
return getDataPrecisionDescription();
case JpegDirectory.TAG_JPEG_IMAGE_HEIGHT:
return getImageHeightDescription();
case JpegDirectory.TAG_JPEG_IMAGE_WIDTH:
return getImageWidthDescription();
}
 
return _directory.getString(tagType);
}
 
public String getImageWidthDescription()
{
return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH) + " pixels";
}
 
public String getImageHeightDescription()
{
return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT) + " pixels";
}
 
public String getDataPrecisionDescription()
{
return _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION) + " bits";
}
 
public String getComponentDataDescription(int componentNumber) throws MetadataException
{
JpegComponent component = ((JpegDirectory)_directory).getComponent(componentNumber);
 
if (component==null)
throw new MetadataException("No Jpeg component exists with number " + componentNumber);
 
StringBuffer sb = new StringBuffer();
sb.append(component.getComponentName());
sb.append(" component: Quantization table ");
sb.append(component.getQuantizationTableNumber());
sb.append(", Sampling factors ");
sb.append(component.getHorizontalSamplingFactor());
sb.append(" horiz/");
sb.append(component.getVerticalSamplingFactor());
sb.append(" vert");
return sb.toString();
}
}
/contrib/metadata-extractor/trunk/src/com/drew/metadata/jpeg/JpegCommentDescriptor.java
0,0 → 1,37
/*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on Oct 10, 2003 using IntelliJ IDEA.
*/
package com.drew.metadata.jpeg;
 
import com.drew.metadata.Directory;
import com.drew.metadata.TagDescriptor;
 
/**
*
* @author Drew Noakes http://drewnoakes.com
*/
public class JpegCommentDescriptor extends TagDescriptor
{
public JpegCommentDescriptor(Directory directory)
{
super(directory);
}
 
public String getDescription(int tagType)
{
return _directory.getString(tagType);
}
}