當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。