source: josm/trunk/src/com/drew/metadata/jpeg/JpegReader.java@ 7828

Last change on this file since 7828 was 6127, checked in by bastiK, 12 years ago

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

File size: 3.3 KB
RevLine 
[4231]1/*
[6127]2 * Copyright 2002-2012 Drew Noakes
[4231]3 *
[6127]4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
[4231]7 *
[6127]8 * http://www.apache.org/licenses/LICENSE-2.0
[4231]9 *
[6127]10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * http://drewnoakes.com/code/exif/
19 * http://code.google.com/p/metadata-extractor/
[4231]20 */
21package com.drew.metadata.jpeg;
22
[6127]23import com.drew.lang.BufferBoundsException;
24import com.drew.lang.BufferReader;
25import com.drew.lang.annotations.NotNull;
[4231]26import com.drew.metadata.Metadata;
27import com.drew.metadata.MetadataReader;
28
29/**
[6127]30 * Decodes Jpeg SOF0 data, populating a <code>Metadata</code> object with tag values in a <code>JpegDirectory</code>.
[4231]31 *
[6127]32 * @author Darrell Silver http://www.darrellsilver.com and Drew Noakes http://drewnoakes.com
[4231]33 */
34public class JpegReader implements MetadataReader
35{
36 /**
37 * Performs the Jpeg data extraction, adding found values to the specified
38 * instance of <code>Metadata</code>.
39 */
[6127]40 public void extract(@NotNull final BufferReader reader, @NotNull Metadata metadata)
[4231]41 {
[6127]42 JpegDirectory directory = metadata.getOrCreateDirectory(JpegDirectory.class);
[4231]43
44 try {
45 // data precision
[6127]46 int dataPrecision = reader.getUInt8(JpegDirectory.TAG_JPEG_DATA_PRECISION);
[4231]47 directory.setInt(JpegDirectory.TAG_JPEG_DATA_PRECISION, dataPrecision);
48
49 // process height
[6127]50 int height = reader.getUInt16(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
[4231]51 directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT, height);
52
53 // process width
[6127]54 int width = reader.getUInt16(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
[4231]55 directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH, width);
56
57 // number of components
[6127]58 int numberOfComponents = reader.getUInt8(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS);
[4231]59 directory.setInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS, numberOfComponents);
60
61 // for each component, there are three bytes of data:
62 // 1 - Component ID: 1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q
63 // 2 - Sampling factors: bit 0-3 vertical, 4-7 horizontal
64 // 3 - Quantization table number
65 int offset = 6;
[6127]66 for (int i = 0; i < numberOfComponents; i++) {
67 int componentId = reader.getUInt8(offset++);
68 int samplingFactorByte = reader.getUInt8(offset++);
69 int quantizationTableNumber = reader.getUInt8(offset++);
[4231]70 JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
71 directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + i, component);
72 }
73
[6127]74 } catch (BufferBoundsException ex) {
75 directory.addError(ex.getMessage());
[4231]76 }
77 }
78}
Note: See TracBrowser for help on using the repository browser.