当前位置: 首页>>代码示例>>Java>>正文


Java JpegSegmentType类代码示例

本文整理汇总了Java中com.drew.imaging.jpeg.JpegSegmentType的典型用法代码示例。如果您正苦于以下问题:Java JpegSegmentType类的具体用法?Java JpegSegmentType怎么用?Java JpegSegmentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JpegSegmentType类属于com.drew.imaging.jpeg包,在下文中一共展示了JpegSegmentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readJpegSegments

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
public void readJpegSegments(@NotNull Iterable<byte[]> segments, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
{
    for (byte[] segmentBytes : segments) {
        JpegCommentDirectory directory = new JpegCommentDirectory();
        metadata.addDirectory(directory);

        // The entire contents of the directory are the comment
        directory.setStringValue(JpegCommentDirectory.TAG_COMMENT, new StringValue(segmentBytes, null));
    }
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:11,代码来源:JpegCommentReader.java

示例2: extract

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
public void extract(byte[] segmentBytes, Metadata metadata, JpegSegmentType segmentType)
{
    JpegDirectory directory = new JpegDirectory();
    metadata.addDirectory(directory);

    // The value of TAG_COMPRESSION_TYPE is determined by the segment type found
    directory.setInt(JpegDirectory.TAG_COMPRESSION_TYPE, segmentType.byteValue - JpegSegmentType.SOF0.byteValue);

    SequentialReader reader = new SequentialByteArrayReader(segmentBytes);

    try {
        directory.setInt(JpegDirectory.TAG_DATA_PRECISION, reader.getUInt8());
        directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16());
        directory.setInt(JpegDirectory.TAG_IMAGE_WIDTH, reader.getUInt16());
        short componentCount = reader.getUInt8();
        directory.setInt(JpegDirectory.TAG_NUMBER_OF_COMPONENTS, componentCount);

        // 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
        for (int i = 0; i < (int)componentCount; i++) {
            final int componentId = reader.getUInt8();
            final int samplingFactorByte = reader.getUInt8();
            final int quantizationTableNumber = reader.getUInt8();
            final JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
            directory.setObject(JpegDirectory.TAG_COMPONENT_DATA_1 + i, component);
        }
    } catch (IOException ex) {
        directory.addError(ex.getMessage());
    }
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:33,代码来源:JpegReader.java

示例3: processBytes

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
@NotNull
public static HuffmanTablesDirectory processBytes(String filePath) throws Exception
{
    Metadata metadata = new Metadata();
    JpegSegmentData segmentData = JpegSegmentReader.readSegments(
        new File(filePath),
        Collections.singletonList(JpegSegmentType.DHT));

    Iterable<byte[]> segments = segmentData.getSegments(JpegSegmentType.DHT);
    for (byte[] segment : segments) {
        new JpegDhtReader().extract(new SequentialByteArrayReader(segment), metadata);
    }


    HuffmanTablesDirectory directory = metadata.getFirstDirectoryOfType(HuffmanTablesDirectory.class);
    assertNotNull(directory);
    assertEquals(1, metadata.getDirectoriesOfType(HuffmanTablesDirectory.class).size());
    return directory;
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:20,代码来源:JpegDhtReaderTest.java

示例4: setUp

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
@Before
public void setUp() throws Exception
{
    Metadata metadata = new Metadata();
    List<byte[]> jpegSegments = new ArrayList<byte[]>();
    jpegSegments.add(FileUtil.readBytes("Tests/Data/withXmpAndIptc.jpg.app1.1"));
    new XmpReader().readJpegSegments(jpegSegments, metadata, JpegSegmentType.APP1);

    Collection<XmpDirectory> xmpDirectories = metadata.getDirectoriesOfType(XmpDirectory.class);

    assertNotNull(xmpDirectories);
    assertEquals(1, xmpDirectories.size());

    _directory = xmpDirectories.iterator().next();

    assertFalse(_directory.hasErrors());
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:18,代码来源:XmpReaderTest.java

示例5: getSegmentTypes

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
@NotNull
    public Iterable<JpegSegmentType> getSegmentTypes()
    {
        // NOTE that some SOFn values do not exist
        return Arrays.asList(
            JpegSegmentType.SOF0,
            JpegSegmentType.SOF1,
            JpegSegmentType.SOF2,
            JpegSegmentType.SOF3,
//            JpegSegmentType.SOF4,
            JpegSegmentType.SOF5,
            JpegSegmentType.SOF6,
            JpegSegmentType.SOF7,
            JpegSegmentType.SOF8,
            JpegSegmentType.SOF9,
            JpegSegmentType.SOF10,
            JpegSegmentType.SOF11,
//            JpegSegmentType.SOF12,
            JpegSegmentType.SOF13,
            JpegSegmentType.SOF14,
            JpegSegmentType.SOF15
        );
    }
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:24,代码来源:JpegReader.java

示例6: extract

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
/**
 * Version specifically for dealing with XMP found in JPEG segments. This form of XMP has a peculiar preamble, which
 * must be removed before parsing the XML.
 *
 * @param segmentBytes The byte array from which the metadata should be extracted.
 * @param metadata The {@link Metadata} object into which extracted values should be merged.
 * @param segmentType The {@link JpegSegmentType} being read.
 */
public void extract(@NotNull byte[] segmentBytes, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
{
    XmpDirectory directory = metadata.getOrCreateDirectory(XmpDirectory.class);

    // XMP in a JPEG file has a 29 byte preamble which is not valid XML.
    final int preambleLength = 29;

    // check for the header length
    if (segmentBytes.length <= preambleLength + 1) {
        directory.addError(String.format("Xmp data segment must contain at least %d bytes", preambleLength + 1));
        return;
    }

    ByteArrayReader reader = new ByteArrayReader(segmentBytes);

    String preamble = new String(segmentBytes, 0, preambleLength);
    if (!"http://ns.adobe.com/xap/1.0/\0".equals(preamble)) {
        directory.addError("XMP data segment doesn't begin with 'http://ns.adobe.com/xap/1.0/'");
        return;
    }

    byte[] xmlBytes = new byte[segmentBytes.length - preambleLength];
    System.arraycopy(segmentBytes, 29, xmlBytes, 0, xmlBytes.length);
    extract(xmlBytes, metadata);
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:34,代码来源:XmpReader.java

示例7: processApp1Bytes

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
public static XmpDirectory processApp1Bytes(String filePath) throws IOException
{
    Metadata metadata = new Metadata();
    new XmpReader().extract(FileUtil.readBytes(filePath), metadata, JpegSegmentType.APP1);
    XmpDirectory directory = metadata.getDirectory(XmpDirectory.class);
    assertNotNull(directory);
    return directory;
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:9,代码来源:XmpReaderTest.java

示例8: readJpegSegments

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
public void readJpegSegments(@NotNull Iterable<byte[]> segments, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
{
    final int preambleLength = JPEG_SEGMENT_PREAMBLE.length();

    // ICC data can be spread across multiple JPEG segments.
    // We concat them together in this buffer for later processing.
    byte[] buffer = null;

    for (byte[] segmentBytes : segments) {
        // Skip any segments that do not contain the required preamble
        if (segmentBytes.length < preambleLength || !JPEG_SEGMENT_PREAMBLE.equalsIgnoreCase(new String(segmentBytes, 0, preambleLength)))
            continue;

        // NOTE we ignore three bytes here -- are they useful for anything?

        // Grow the buffer
        if (buffer == null) {
            buffer = new byte[segmentBytes.length - 14];
            // skip the first 14 bytes
            System.arraycopy(segmentBytes, 14, buffer, 0, segmentBytes.length - 14);
        } else {
            byte[] newBuffer = new byte[buffer.length + segmentBytes.length - 14];
            System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
            System.arraycopy(segmentBytes, 14, newBuffer, buffer.length, segmentBytes.length - 14);
            buffer = newBuffer;
        }
    }

    if (buffer != null)
        extract(new ByteArrayReader(buffer), metadata);
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:32,代码来源:IccReader.java

示例9: getBytes

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
private byte[] getBytes(@NotNull final SequentialReader reader, int count) throws IOException {
    byte[] bytes = new byte[count];
    for (int i = 0; i < count; i++) {
        byte b = reader.getByte();
        if ((b & 0xFF) == 0xFF) {
            byte stuffing = reader.getByte();
            if (stuffing != 0x00) {
                throw new IOException("Marker " + JpegSegmentType.fromByte(stuffing) + " found inside DHT segment");
            }
        }
        bytes[i] = b;
    }
    return bytes;
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:15,代码来源:JpegDhtReader.java

示例10: testExtractWithNullDataThrows

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
@Test
public void testExtractWithNullDataThrows() throws Exception
{
    try{
        new ExifReader().extract(null, new Metadata(), JpegSegmentType.APP1);
        Assert.fail("Exception expected");
    } catch (NullPointerException npe) {
        // passed
    }
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:11,代码来源:ExifReaderTest.java

示例11: testLoadJpegWithNoExifData

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
@Test
public void testLoadJpegWithNoExifData() throws Exception
{
    byte[] badExifData = new byte[]{ 1,2,3,4,5,6,7,8,9,10 };
    Metadata metadata = new Metadata();
    new ExifReader().extract(badExifData, metadata, JpegSegmentType.APP1);
    assertEquals(0, metadata.getDirectoryCount());
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:9,代码来源:ExifReaderTest.java

示例12: extract

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
public void extract(byte[] segmentBytes, Metadata metadata, JpegSegmentType segmentType)
{
    JpegDirectory directory = metadata.getFirstDirectoryOfType(JpegDirectory.class);
    if (directory == null) {
        ErrorDirectory errorDirectory = new ErrorDirectory();
        metadata.addDirectory(errorDirectory);
        errorDirectory.addError("DNL segment found without SOFx - illegal JPEG format");
        return;
    }

    SequentialReader reader = new SequentialByteArrayReader(segmentBytes);

    try {
        // Only set height from DNL if it's not already defined
        Integer i = directory.getInteger(JpegDirectory.TAG_IMAGE_HEIGHT);
        if (i == null || i == 0) {
            directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16());
        }
    } catch (IOException ex) {
        directory.addError(ex.getMessage());
    }
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:23,代码来源:JpegDnlReader.java

示例13: readJpegSegments

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
/**
 * Version specifically for dealing with XMP found in JPEG segments. This form of XMP has a peculiar preamble, which
 * must be removed before parsing the XML.
 *
 * @param segments The byte array from which the metadata should be extracted.
 * @param metadata The {@link Metadata} object into which extracted values should be merged.
 * @param segmentType The {@link JpegSegmentType} being read.
 */
public void readJpegSegments(@NotNull Iterable<byte[]> segments, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
{
    final int preambleLength = XMP_JPEG_PREAMBLE.length();
    final int extensionPreambleLength = XMP_EXTENSION_JPEG_PREAMBLE.length();
    String extendedXMPGUID = null;
    byte[] extendedXMPBuffer = null;

    for (byte[] segmentBytes : segments) {
        // XMP in a JPEG file has an identifying preamble which is not valid XML
        if (segmentBytes.length >= preambleLength) {
            // NOTE we expect the full preamble here, but some images (such as that reported on GitHub #102)
            // start with "XMP\0://ns.adobe.com/xap/1.0/" which appears to be an error but is easily recovered
            // from. In such cases, the actual XMP data begins at the same offset.
            if (XMP_JPEG_PREAMBLE.equalsIgnoreCase(new String(segmentBytes, 0, preambleLength)) ||
                "XMP".equalsIgnoreCase(new String(segmentBytes, 0, 3))) {

                byte[] xmlBytes = new byte[segmentBytes.length - preambleLength];
                System.arraycopy(segmentBytes, preambleLength, xmlBytes, 0, xmlBytes.length);
                extract(xmlBytes, metadata);
                // Check in the Standard XMP if there should be a Extended XMP part in other chunks.
                extendedXMPGUID = getExtendedXMPGUID(metadata);
                continue;
            }
        }

        // If we know that there's Extended XMP chunks, look for them.
        if (extendedXMPGUID != null &&
            segmentBytes.length >= extensionPreambleLength &&
            XMP_EXTENSION_JPEG_PREAMBLE.equalsIgnoreCase(new String(segmentBytes, 0, extensionPreambleLength))) {

            extendedXMPBuffer = processExtendedXMPChunk(metadata, segmentBytes, extendedXMPGUID, extendedXMPBuffer);
        }
    }

    // Now that the Extended XMP chunks have been concatenated, let's parse and merge with the Standard XMP.
    if (extendedXMPBuffer != null) {
        extract(extendedXMPBuffer, metadata);
    }
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:48,代码来源:XmpReader.java

示例14: readJpegSegments

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
public void readJpegSegments(@NotNull final Iterable<byte[]> segments, @NotNull final Metadata metadata, @NotNull final JpegSegmentType segmentType)
{
    assert(segmentType == JpegSegmentType.APP1);

    for (byte[] segmentBytes : segments) {
        // Filter any segments containing unexpected preambles
        if (segmentBytes.length < JPEG_SEGMENT_PREAMBLE.length() || !new String(segmentBytes, 0, JPEG_SEGMENT_PREAMBLE.length()).equals(JPEG_SEGMENT_PREAMBLE))
            continue;
        extract(new ByteArrayReader(segmentBytes), metadata, JPEG_SEGMENT_PREAMBLE.length());
    }
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:12,代码来源:ExifReader.java

示例15: printUsage

import com.drew.imaging.jpeg.JpegSegmentType; //导入依赖的package包/类
private static void printUsage()
{
    System.out.println("USAGE:\n");
    System.out.println("\tjava com.drew.tools.ExtractJpegSegmentTool <filename> (*|<segment> [<segment> ...])\n");

    System.out.print("Where segment is one or more of:");
    for (JpegSegmentType segmentType : JpegSegmentType.class.getEnumConstants()) {
        if (segmentType.canContainMetadata) {
            System.out.print(" " + segmentType.toString());
        }
    }
    System.out.println();
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:14,代码来源:ExtractJpegSegmentTool.java


注:本文中的com.drew.imaging.jpeg.JpegSegmentType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。