You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by da...@apache.org on 2012/09/27 07:42:26 UTC
svn commit: r1390849 [2/3] - in
/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats:
bmp/ bmp/pixelparsers/ bmp/writers/ dcx/ gif/ icns/ ico/ jpeg/
jpeg/decoder/ jpeg/exif/ jpeg/iptc/ jpeg/segments/ jpeg/xmp/
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java Thu Sep 27 05:42:25 2012
@@ -134,12 +134,14 @@ public class IcoImageParser extends Imag
int IconType = read2Bytes("IconType", is, "Not a Valid ICO File");
int IconCount = read2Bytes("IconCount", is, "Not a Valid ICO File");
- if (Reserved != 0)
+ if (Reserved != 0) {
throw new ImageReadException("Not a Valid ICO File: reserved is "
+ Reserved);
- if (IconType != 1 && IconType != 2)
+ }
+ if (IconType != 1 && IconType != 2) {
throw new ImageReadException("Not a Valid ICO File: icon type is "
+ IconType);
+ }
return new FileHeader(Reserved, IconType, IconCount);
@@ -183,100 +185,26 @@ public class IcoImageParser extends Imag
private IconInfo readIconInfo(InputStream is) throws ImageReadException,
IOException {
- byte Width = readByte("Width", is, "Not a Valid ICO File"); // Width (1
- // byte),
- // Width of
- // Icon (1
- // to 255)
- byte Height = readByte("Height", is, "Not a Valid ICO File"); // Height
- // (1
- // byte),
- // Height
- // of Icon
- // (1 to
- // 255)
- byte ColorCount = readByte("ColorCount", is, "Not a Valid ICO File"); // ColorCount
- // (1
- // byte),
- // Number
- // of
- // colors,
- // either
- // 0
- // for
- // 24
- // bit
- // or
- // higher,
- // 2
- // for
- // monochrome
- // or
- // 16
- // for
- // 16
- // color
- // images.
- byte Reserved = readByte("Reserved", is, "Not a Valid ICO File"); // Reserved
- // (1
- // byte),
- // Not
- // used
- // (always
- // 0)
- int Planes = read2Bytes("Planes", is, "Not a Valid ICO File"); // Planes
- // (2
- // bytes),
- // always
- // 1
- int BitCount = read2Bytes("BitCount", is, "Not a Valid ICO File"); // BitCount
- // (2
- // bytes),
- // number
- // of
- // bits
- // per
- // pixel
- // (1
- // for
- // monochrome,
- // 4
- // for
- // 16
- // colors,
- // 8
- // for
- // 256
- // colors,
- // 24
- // for
- // true
- // colors,
- // 32
- // for
- // true
- // colors
- // +
- // alpha
- // channel)
- int ImageSize = read4Bytes("ImageSize", is, "Not a Valid ICO File"); // ImageSize
- // (4
- // bytes),
- // Length
- // of
- // resource
- // in
- // bytes
- int ImageOffset = read4Bytes("ImageOffset", is, "Not a Valid ICO File"); // ImageOffset
- // (4
- // bytes),
- // start
- // of
- // the
- // image
- // in
- // the
- // file.
+ // Width (1 byte), Width of Icon (1 to 255)
+ byte Width = readByte("Width", is, "Not a Valid ICO File");
+ // Height (1 byte), Height of Icon (1 to 255)
+ byte Height = readByte("Height", is, "Not a Valid ICO File");
+ // ColorCount (1 byte), Number of colors, either
+ // 0 for 24 bit or higher,
+ // 2 for monochrome or 16 for 16 color images.
+ byte ColorCount = readByte("ColorCount", is, "Not a Valid ICO File");
+ // Reserved (1 byte), Not used (always 0)
+ byte Reserved = readByte("Reserved", is, "Not a Valid ICO File");
+ // Planes (2 bytes), always 1
+ int Planes = read2Bytes("Planes", is, "Not a Valid ICO File");
+ // BitCount (2 bytes), number of bits per pixel (1 for monchrome,
+ // 4 for 16 colors, 8 for 256 colors, 24 for true colors,
+ // 32 for true colors + alpha channel)
+ int BitCount = read2Bytes("BitCount", is, "Not a Valid ICO File");
+ // ImageSize (4 bytes), Length of resource in bytes
+ int ImageSize = read4Bytes("ImageSize", is, "Not a Valid ICO File");
+ // ImageOffset (4 bytes), start of the image in the file
+ int ImageOffset = read4Bytes("ImageOffset", is, "Not a Valid ICO File");
return new IconInfo(Width, Height, ColorCount, Reserved, Planes,
BitCount, ImageSize, ImageOffset);
@@ -479,12 +407,14 @@ public class IcoImageParser extends Imag
}
byte[] RestOfFile = readByteArray("RestOfFile", is.available(), is);
- if (Size != 40)
+ if (Size != 40) {
throw new ImageReadException(
"Not a Valid ICO File: Wrong bitmap header size " + Size);
- if (Planes != 1)
+ }
+ if (Planes != 1) {
throw new ImageReadException(
"Not a Valid ICO File: Planes can't be " + Planes);
+ }
if (Compression == 0 && BitCount == 32) {
// 32 BPP RGB icons need an alpha channel, but BMP files don't have
@@ -545,9 +475,10 @@ public class IcoImageParser extends Imag
// alpha
// if the image would be completely transparent with alpha...
int t_scanline_size = (Width + 7) / 8;
- if ((t_scanline_size % 4) != 0)
+ if ((t_scanline_size % 4) != 0) {
t_scanline_size += 4 - (t_scanline_size % 4); // pad scanline to 4
// byte size.
+ }
int tcolor_map_size_bytes = t_scanline_size * (Height / 2);
byte[] transparency_map = null;
try {
@@ -555,8 +486,9 @@ public class IcoImageParser extends Imag
tcolor_map_size_bytes, bmpInputStream,
"Not a Valid ICO File");
} catch (IOException ioEx) {
- if (BitCount != 32)
+ if (BitCount != 32) {
throw ioEx;
+ }
}
boolean allAlphasZero = true;
@@ -587,8 +519,9 @@ public class IcoImageParser extends Imag
| (0xffffff & bmpImage.getRGB(x, y)));
}
}
- } else
+ } else {
resultImage = bmpImage;
+ }
return new BitmapIconData(fIconInfo, header, resultImage);
}
@@ -653,8 +586,9 @@ public class IcoImageParser extends Imag
throws ImageReadException, IOException {
ImageContents contents = readImage(byteSource);
contents.fileHeader.dump(pw);
- for (int i = 0; i < contents.iconDatas.length; i++)
+ for (int i = 0; i < contents.iconDatas.length; i++) {
contents.iconDatas[i].dump(pw);
+ }
return true;
}
@@ -663,10 +597,11 @@ public class IcoImageParser extends Imag
Map params) throws ImageReadException, IOException {
ImageContents contents = readImage(byteSource);
FileHeader fileHeader = contents.fileHeader;
- if (fileHeader.iconCount > 0)
+ if (fileHeader.iconCount > 0) {
return contents.iconDatas[0].readBufferedImage();
- else
+ } else {
throw new ImageReadException("No icons in ICO file");
+ }
}
@Override
@@ -718,8 +653,9 @@ public class IcoImageParser extends Imag
params = (params == null) ? new HashMap() : new HashMap(params);
// clear format key.
- if (params.containsKey(PARAM_KEY_FORMAT))
+ if (params.containsKey(PARAM_KEY_FORMAT)) {
params.remove(PARAM_KEY_FORMAT);
+ }
PixelDensity pixelDensity = (PixelDensity) params.remove(PARAM_KEY_PIXEL_DENSITY);
@@ -734,27 +670,31 @@ public class IcoImageParser extends Imag
final int bitCount;
final boolean hasTransparency = paletteFactory.hasTransparency(src);
if (palette == null) {
- if (hasTransparency)
+ if (hasTransparency) {
bitCount = 32;
- else
+ } else {
bitCount = 24;
- } else if (palette.length() <= 2)
+ }
+ } else if (palette.length() <= 2) {
bitCount = 1;
- else if (palette.length() <= 16)
+ } else if (palette.length() <= 16) {
bitCount = 4;
- else
+ } else {
bitCount = 8;
+ }
BinaryOutputStream bos = new BinaryOutputStream(os, BYTE_ORDER_INTEL);
int scanline_size = (bitCount * src.getWidth() + 7) / 8;
- if ((scanline_size % 4) != 0)
+ if ((scanline_size % 4) != 0) {
scanline_size += 4 - (scanline_size % 4); // pad scanline to 4 byte
// size.
+ }
int t_scanline_size = (src.getWidth() + 7) / 8;
- if ((t_scanline_size % 4) != 0)
+ if ((t_scanline_size % 4) != 0) {
t_scanline_size += 4 - (t_scanline_size % 4); // pad scanline to 4
// byte size.
+ }
int imageSize = 40 + 4 * (bitCount <= 8 ? (1 << bitCount) : 0)
+ src.getHeight() * scanline_size + src.getHeight()
* t_scanline_size;
@@ -850,8 +790,9 @@ public class IcoImageParser extends Imag
bits_in_cache = 0;
}
- for (int x = 0; x < row_padding; x++)
+ for (int x = 0; x < row_padding; x++) {
bos.write(0);
+ }
}
int t_row_padding = t_scanline_size - (src.getWidth() + 7) / 8;
@@ -860,8 +801,9 @@ public class IcoImageParser extends Imag
int argb = src.getRGB(x, y);
int alpha = 0xff & (argb >> 24);
bit_cache <<= 1;
- if (alpha == 0)
+ if (alpha == 0) {
bit_cache |= 1;
+ }
bits_in_cache++;
if (bits_in_cache >= 8) {
bos.write(0xff & bit_cache);
@@ -877,8 +819,9 @@ public class IcoImageParser extends Imag
bits_in_cache = 0;
}
- for (int x = 0; x < t_row_padding; x++)
+ for (int x = 0; x < t_row_padding; x++) {
bos.write(0);
+ }
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java Thu Sep 27 05:42:25 2012
@@ -173,8 +173,9 @@ public class JpegImageMetadata implement
.get(i);
// Debug.debug("dir", dir);
TiffImageData rawImageData = dir.getTiffImageData();
- if (null != rawImageData)
+ if (null != rawImageData) {
return rawImageData;
+ }
}
return null;
@@ -183,11 +184,13 @@ public class JpegImageMetadata implement
public List<IImageMetadataItem> getItems() {
List<IImageMetadataItem> result = new ArrayList<IImageMetadataItem>();
- if (null != exif)
+ if (null != exif) {
result.addAll(exif.getItems());
+ }
- if (null != photoshop)
+ if (null != photoshop) {
result.addAll(photoshop.getItems());
+ }
return result;
}
@@ -200,15 +203,16 @@ public class JpegImageMetadata implement
}
public String toString(String prefix) {
- if (prefix == null)
+ if (prefix == null) {
prefix = "";
+ }
StringBuilder result = new StringBuilder();
result.append(prefix);
- if (null == exif)
+ if (null == exif) {
result.append("No Exif metadata.");
- else {
+ } else {
result.append("Exif metadata:");
result.append(newline);
result.append(exif.toString("\t"));
@@ -218,9 +222,9 @@ public class JpegImageMetadata implement
result.append(newline);
result.append(prefix);
- if (null == photoshop)
+ if (null == photoshop) {
result.append("No Photoshop (IPTC) metadata.");
- else {
+ } else {
result.append("Photoshop (IPTC) metadata:");
result.append(newline);
result.append(photoshop.toString("\t"));
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java Thu Sep 27 05:42:25 2012
@@ -95,12 +95,14 @@ public class JpegImageParser extends Ima
}
private boolean keepMarker(int marker, int markers[]) {
- if (markers == null)
+ if (markers == null) {
return true;
+ }
for (int i = 0; i < markers.length; i++) {
- if (markers[i] == marker)
+ if (markers[i] == marker) {
return true;
+ }
}
return false;
@@ -133,8 +135,9 @@ public class JpegImageParser extends Ima
public boolean visitSegment(int marker, byte markerBytes[],
int markerLength, byte markerLengthBytes[],
byte segmentData[]) throws ImageReadException, IOException {
- if (marker == EOIMarker)
+ if (marker == EOIMarker) {
return false;
+ }
// Debug.debug("visitSegment marker", marker);
// // Debug.debug("visitSegment keepMarker(marker, markers)",
@@ -142,8 +145,9 @@ public class JpegImageParser extends Ima
// Debug.debug("visitSegment keepMarker(marker, markers)",
// keepMarker(marker, markers));
- if (!keepMarker(marker, markers))
+ if (!keepMarker(marker, markers)) {
return true;
+ }
if (marker == JPEG_APP13_Marker) {
// Debug.debug("app 13 segment data", segmentData.length);
@@ -165,8 +169,9 @@ public class JpegImageParser extends Ima
result.add(new ComSegment(marker, segmentData));
}
- if (returnAfterFirst)
+ if (returnAfterFirst) {
return false;
+ }
return true;
}
@@ -190,17 +195,19 @@ public class JpegImageParser extends Ima
private byte[] assembleSegments(List<App2Segment> v, boolean start_with_zero)
throws ImageReadException {
- if (v.size() < 1)
+ if (v.size() < 1) {
throw new ImageReadException("No App2 Segments Found.");
+ }
int markerCount = v.get(0).num_markers;
// if (permissive && (markerCount == 0))
// markerCount = v.size();
- if (v.size() != markerCount)
+ if (v.size() != markerCount) {
throw new ImageReadException("App2 Segments Missing. Found: "
+ v.size() + ", Expected: " + markerCount + ".");
+ }
Collections.sort(v);
@@ -272,21 +279,25 @@ public class JpegImageParser extends Ima
// throw away non-icc profile app2 segments.
for (int i = 0; i < segments.size(); i++) {
App2Segment segment = (App2Segment) segments.get(i);
- if (segment.icc_bytes != null)
+ if (segment.icc_bytes != null) {
filtered.add(segment);
+ }
}
}
- if ((filtered == null) || (filtered.size() < 1))
+ if ((filtered == null) || (filtered.size() < 1)) {
return null;
+ }
byte bytes[] = assembleSegments(filtered);
- if (debug)
+ if (debug) {
System.out.println("bytes" + ": " + bytes.length);
+ }
- if (debug)
+ if (debug) {
System.out.println("");
+ }
return (bytes);
}
@@ -299,8 +310,9 @@ public class JpegImageParser extends Ima
JpegPhotoshopMetadata photoshop = getPhotoshopMetadata(byteSource,
params);
- if (null == exif && null == photoshop)
+ if (null == exif && null == photoshop) {
return null;
+ }
JpegImageMetadata result = new JpegImageMetadata(photoshop, exif);
@@ -316,8 +328,9 @@ public class JpegImageParser extends Ima
for (int i = 0; i < v.size(); i++) {
GenericSegment segment = (GenericSegment) v.get(i);
- if (isExifAPP1Segment(segment))
+ if (isExifAPP1Segment(segment)) {
result.add(segment);
+ }
}
return result;
@@ -326,13 +339,16 @@ public class JpegImageParser extends Ima
public TiffImageMetadata getExifMetadata(ByteSource byteSource, Map params)
throws ImageReadException, IOException {
byte bytes[] = getExifRawData(byteSource);
- if (null == bytes)
+ if (null == bytes) {
return null;
+ }
- if (params == null)
+ if (params == null) {
params = new HashMap();
- if (!params.containsKey(PARAM_KEY_READ_THUMBNAILS))
+ }
+ if (!params.containsKey(PARAM_KEY_READ_THUMBNAILS)) {
params.put(PARAM_KEY_READ_THUMBNAILS, Boolean.TRUE);
+ }
return (TiffImageMetadata) new TiffImageParser().getMetadata(bytes,
params);
@@ -343,24 +359,28 @@ public class JpegImageParser extends Ima
List<Segment> segments = readSegments(byteSource,
new int[] { JPEG_APP1_Marker, }, false);
- if ((segments == null) || (segments.size() < 1))
+ if ((segments == null) || (segments.size() < 1)) {
return null;
+ }
List<Segment> exifSegments = filterAPP1Segments(segments);
- if (debug)
+ if (debug) {
System.out.println("exif_segments.size" + ": "
+ exifSegments.size());
+ }
// Debug.debug("segments", segments);
// Debug.debug("exifSegments", exifSegments);
// TODO: concatenate if multiple segments, need example.
- if (exifSegments.size() < 1)
+ if (exifSegments.size() < 1) {
return null;
- if (exifSegments.size() > 1)
+ }
+ if (exifSegments.size() > 1) {
throw new ImageReadException(
"Sanselan currently can't parse EXIF metadata split across multiple APP1 segments. "
+ "Please send this image to the Sanselan project.");
+ }
GenericSegment segment = (GenericSegment) exifSegments.get(0);
byte bytes[] = segment.bytes;
@@ -390,8 +410,9 @@ public class JpegImageParser extends Ima
public boolean visitSegment(int marker, byte markerBytes[],
int markerLength, byte markerLengthBytes[],
byte segmentData[]) throws ImageReadException, IOException {
- if (marker == 0xffd9)
+ if (marker == 0xffd9) {
return false;
+ }
if (marker == JPEG_APP1_Marker) {
if (byteArrayHasPrefix(segmentData, EXIF_IDENTIFIER_CODE)) {
@@ -427,8 +448,9 @@ public class JpegImageParser extends Ima
public boolean visitSegment(int marker, byte markerBytes[],
int markerLength, byte markerLengthBytes[],
byte segmentData[]) throws ImageReadException, IOException {
- if (marker == 0xffd9)
+ if (marker == 0xffd9) {
return false;
+ }
if (marker == JPEG_APP13_Marker) {
if (new IptcParser().isPhotoshopJpegSegment(segmentData)) {
@@ -464,8 +486,9 @@ public class JpegImageParser extends Ima
public boolean visitSegment(int marker, byte markerBytes[],
int markerLength, byte markerLengthBytes[],
byte segmentData[]) throws ImageReadException, IOException {
- if (marker == 0xffd9)
+ if (marker == 0xffd9) {
return false;
+ }
if (marker == JPEG_APP1_Marker) {
if (new JpegXmpParser().isXmpJpegSegment(segmentData)) {
@@ -512,8 +535,9 @@ public class JpegImageParser extends Ima
public boolean visitSegment(int marker, byte markerBytes[],
int markerLength, byte markerLengthBytes[],
byte segmentData[]) throws ImageReadException, IOException {
- if (marker == 0xffd9)
+ if (marker == 0xffd9) {
return false;
+ }
if (marker == JPEG_APP1_Marker) {
if (new JpegXmpParser().isXmpJpegSegment(segmentData)) {
@@ -528,11 +552,13 @@ public class JpegImageParser extends Ima
};
new JpegUtils().traverseJFIF(byteSource, visitor);
- if (result.size() < 1)
+ if (result.size() < 1) {
return null;
- if (result.size() > 1)
+ }
+ if (result.size() > 1) {
throw new ImageReadException(
"Jpeg file contains more than one XMP segment.");
+ }
return result.get(0);
}
@@ -541,8 +567,9 @@ public class JpegImageParser extends Ima
List<Segment> segments = readSegments(byteSource,
new int[] { JPEG_APP13_Marker, }, false);
- if ((segments == null) || (segments.size() < 1))
+ if ((segments == null) || (segments.size() < 1)) {
return null;
+ }
PhotoshopApp13Data photoshopApp13Data = null;
@@ -550,15 +577,17 @@ public class JpegImageParser extends Ima
App13Segment segment = (App13Segment) segments.get(i);
PhotoshopApp13Data data = segment.parsePhotoshopSegment(params);
- if (data != null && photoshopApp13Data != null)
+ if (data != null && photoshopApp13Data != null) {
throw new ImageReadException(
"Jpeg contains more than one Photoshop App13 segment.");
+ }
photoshopApp13Data = data;
}
- if (null == photoshopApp13Data)
+ if (null == photoshopApp13Data) {
return null;
+ }
return new JpegPhotoshopMetadata(photoshopApp13Data);
}
@@ -575,11 +604,13 @@ public class JpegImageParser extends Ima
}, true);
- if ((segments == null) || (segments.size() < 1))
+ if ((segments == null) || (segments.size() < 1)) {
throw new ImageReadException("No JFIF Data Found.");
+ }
- if (segments.size() > 1)
+ if (segments.size() > 1) {
throw new ImageReadException("Redundant JFIF Data Found.");
+ }
SofnSegment fSOFNSegment = (SofnSegment) segments.get(0);
@@ -609,8 +640,9 @@ public class JpegImageParser extends Ima
}, false);
- if (SOF_segments == null)
+ if (SOF_segments == null) {
throw new ImageReadException("No SOFN Data Found.");
+ }
// if (SOF_segments.size() != 1)
// System.out.println("Incoherent SOFN Data Found: "
@@ -623,21 +655,24 @@ public class JpegImageParser extends Ima
// SofnSegment fSOFNSegment = (SofnSegment) findSegment(segments,
// SOFNmarkers);
- if (fSOFNSegment == null)
+ if (fSOFNSegment == null) {
throw new ImageReadException("No SOFN Data Found.");
+ }
int Width = fSOFNSegment.width;
int Height = fSOFNSegment.height;
JfifSegment jfifSegment = null;
- if ((jfifSegments != null) && (jfifSegments.size() > 0))
+ if ((jfifSegments != null) && (jfifSegments.size() > 0)) {
jfifSegment = (JfifSegment) jfifSegments.get(0);
+ }
List<Segment> app14Segments = readSegments(byteSource, new int[] { JPEG_APP14_Marker }, true);
App14Segment app14Segment = null;
- if (app14Segments != null && !app14Segments.isEmpty())
+ if (app14Segments != null && !app14Segments.isEmpty()) {
app14Segment = (App14Segment) app14Segments.get(0);
+ }
// JfifSegment fTheJFIFSegment = (JfifSegment) findSegment(segments,
// kJFIFMarker);
@@ -679,14 +714,16 @@ public class JpegImageParser extends Ima
{
TiffField field = metadata
.findEXIFValue(TiffTagConstants.TIFF_TAG_XRESOLUTION);
- if (field != null)
+ if (field != null) {
x_density = ((Number) field.getValue()).doubleValue();
+ }
}
{
TiffField field = metadata
.findEXIFValue(TiffTagConstants.TIFF_TAG_YRESOLUTION);
- if (field != null)
+ if (field != null) {
y_density = ((Number) field.getValue()).doubleValue();
+ }
}
{
TiffField field = metadata
@@ -774,10 +811,11 @@ public class JpegImageParser extends Ima
colorType = ImageInfo.COLOR_TYPE_YCCK;
}
} else if (jfifSegment != null) {
- if (Number_of_components == 1)
+ if (Number_of_components == 1) {
colorType = ImageInfo.COLOR_TYPE_GRAYSCALE;
- else if (Number_of_components == 3)
+ } else if (Number_of_components == 3) {
colorType = ImageInfo.COLOR_TYPE_YCbCr;
+ }
} else {
if (Number_of_components == 1) {
colorType = ImageInfo.COLOR_TYPE_GRAYSCALE;
@@ -792,16 +830,17 @@ public class JpegImageParser extends Ima
boolean haveOther = false;
for (SofnSegment.Component component : fSOFNSegment.components) {
final int id = component.componentIdentifier;
- if (id == 1)
+ if (id == 1) {
have1 = true;
- else if (id == 2)
+ } else if (id == 2) {
have2 = true;
- else if (id == 3)
+ } else if (id == 3) {
have3 = true;
- else if (id == 4)
+ } else if (id == 4) {
have4 = true;
- else
+ } else {
haveOther = true;
+ }
}
if (Number_of_components == 3 && have1 && have2 && have3 && !have4 && !haveOther) {
colorType = ImageInfo.COLOR_TYPE_YCbCr;
@@ -818,20 +857,21 @@ public class JpegImageParser extends Ima
boolean haveY = false;
for (SofnSegment.Component component : fSOFNSegment.components) {
final int id = component.componentIdentifier;
- if (id == 'R')
+ if (id == 'R') {
haveR = true;
- else if (id == 'G')
+ } else if (id == 'G') {
haveG = true;
- else if (id == 'B')
+ } else if (id == 'B') {
haveB = true;
- else if (id == 'A')
+ } else if (id == 'A') {
haveA = true;
- else if (id == 'C')
+ } else if (id == 'C') {
haveC = true;
- else if (id == 'c')
+ } else if (id == 'c') {
havec = true;
- else if (id == 'Y')
+ } else if (id == 'Y') {
haveY = true;
+ }
}
if (haveR && haveG && haveB && !haveA && !haveC && !havec && !haveY) {
colorType = ImageInfo.COLOR_TYPE_RGB;
@@ -849,27 +889,33 @@ public class JpegImageParser extends Ima
int minVerticalSamplingFactor = Integer.MAX_VALUE;
int maxVerticalSamplingFactor = Integer.MIN_VALUE;
for (SofnSegment.Component component : fSOFNSegment.components) {
- if (minHorizontalSamplingFactor > component.horizontalSamplingFactor)
+ if (minHorizontalSamplingFactor > component.horizontalSamplingFactor) {
minHorizontalSamplingFactor = component.horizontalSamplingFactor;
- if (maxHorizontalSmaplingFactor < component.horizontalSamplingFactor)
+ }
+ if (maxHorizontalSmaplingFactor < component.horizontalSamplingFactor) {
maxHorizontalSmaplingFactor = component.horizontalSamplingFactor;
- if (minVerticalSamplingFactor > component.verticalSamplingFactor)
+ }
+ if (minVerticalSamplingFactor > component.verticalSamplingFactor) {
minVerticalSamplingFactor = component.verticalSamplingFactor;
- if (maxVerticalSamplingFactor < component.verticalSamplingFactor)
+ }
+ if (maxVerticalSamplingFactor < component.verticalSamplingFactor) {
maxVerticalSamplingFactor = component.verticalSamplingFactor;
+ }
}
boolean isSubsampled = (minHorizontalSamplingFactor != maxHorizontalSmaplingFactor) ||
(minVerticalSamplingFactor != maxVerticalSamplingFactor);
if (Number_of_components == 3) {
- if (isSubsampled)
+ if (isSubsampled) {
colorType = ImageInfo.COLOR_TYPE_YCbCr;
- else
+ } else {
colorType = ImageInfo.COLOR_TYPE_RGB;
+ }
} else if (Number_of_components == 4) {
- if (isSubsampled)
+ if (isSubsampled) {
colorType = ImageInfo.COLOR_TYPE_YCCK;
- else
+ } else {
colorType = ImageInfo.COLOR_TYPE_CMYK;
+ }
}
}
}
@@ -1063,8 +1109,9 @@ public class JpegImageParser extends Ima
{
ImageInfo imageInfo = getImageInfo(byteSource);
- if (imageInfo == null)
+ if (imageInfo == null) {
return false;
+ }
imageInfo.toString(pw, "");
}
@@ -1074,8 +1121,9 @@ public class JpegImageParser extends Ima
{
List<Segment> segments = readSegments(byteSource, null, false);
- if (segments == null)
+ if (segments == null) {
throw new ImageReadException("No Segments Found.");
+ }
for (int d = 0; d < segments.size(); d++) {
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegPhotoshopMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegPhotoshopMetadata.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegPhotoshopMetadata.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegPhotoshopMetadata.java Thu Sep 27 05:42:25 2012
@@ -38,8 +38,9 @@ public class JpegPhotoshopMetadata exten
Collections.sort(records, IptcRecord.COMPARATOR);
for (int j = 0; j < records.size(); j++) {
IptcRecord element = records.get(j);
- if (element.iptcType != IptcTypes.RECORD_VERSION)
+ if (element.iptcType != IptcTypes.RECORD_VERSION) {
add(element.getIptcTypeName(), element.getValue());
+ }
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java Thu Sep 27 05:42:25 2012
@@ -73,8 +73,9 @@ public class JpegUtils extends BinaryFil
// Debug.debug("markerBytes", markerBytes);
if (marker == EOIMarker || marker == SOS_Marker) {
- if (!visitor.beginSOS())
+ if (!visitor.beginSOS()) {
return;
+ }
byte imageData[] = getStreamBytes(is);
visitor.visitSOS(marker, markerBytes, imageData);
@@ -97,8 +98,9 @@ public class JpegUtils extends BinaryFil
// Debug.debug("segmentLength", segmentLength);
if (!visitor.visitSegment(marker, markerBytes, segmentLength,
- segmentLengthBytes, segmentData))
+ segmentLengthBytes, segmentData)) {
return;
+ }
}
} finally {
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java Thu Sep 27 05:42:25 2012
@@ -87,8 +87,9 @@ public class JpegDecoder extends BinaryF
int yMCUs = (sofnSegment.height + vSize - 1) / vSize;
Block[] mcu = allocateMCUMemory();
Block[] scaledMCU = new Block[mcu.length];
- for (int i = 0; i < scaledMCU.length; i++)
+ for (int i = 0; i < scaledMCU.length; i++) {
scaledMCU[i] = new Block(hSize, vSize);
+ }
int[] preds = new int[sofnSegment.numberOfComponents];
ColorModel colorModel;
WritableRaster raster;
@@ -110,9 +111,10 @@ public class JpegDecoder extends BinaryF
// Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
// raster = colorModel.createCompatibleWritableRaster(
// sofnSegment.width, sofnSegment.height);
- } else
+ } else {
throw new ImageReadException(sofnSegment.numberOfComponents
+ " components are invalid or unsupported");
+ }
DataBuffer dataBuffer = raster.getDataBuffer();
for (int y1 = 0; y1 < vSize * yMCUs; y1 += vSize) {
@@ -135,10 +137,11 @@ public class JpegDecoder extends BinaryF
int Y = scaledMCU[0].samples[srcRowOffset + x2];
dataBuffer.setElem(dstRowOffset + x2, (Y << 16)
| (Y << 8) | Y);
- } else
+ } else {
throw new ImageReadException(
"Unsupported JPEG with " + mcu.length
+ " components");
+ }
}
srcRowOffset += hSize;
dstRowOffset += sofnSegment.width;
@@ -173,9 +176,10 @@ public class JpegDecoder extends BinaryF
SOF15Marker, };
if (Arrays.binarySearch(sofnSegments, marker) >= 0) {
- if (marker != SOF0Marker)
+ if (marker != SOF0Marker) {
throw new ImageReadException("Only sequential, baseline JPEGs "
+ "are supported at the moment");
+ }
sofnSegment = new SofnSegment(marker, segmentData);
} else if (marker == DQTMarker) {
DqtSegment dqtSegment = new DqtSegment(marker, segmentData);
@@ -183,16 +187,18 @@ public class JpegDecoder extends BinaryF
DqtSegment.QuantizationTable table = dqtSegment.quantizationTables
.get(i);
if (0 > table.destinationIdentifier
- || table.destinationIdentifier >= quantizationTables.length)
+ || table.destinationIdentifier >= quantizationTables.length) {
throw new ImageReadException(
"Invalid quantization table identifier "
+ table.destinationIdentifier);
+ }
quantizationTables[table.destinationIdentifier] = table;
int[] quantizationMatrixInt = new int[64];
ZigZag.zigZagToBlock(table.elements, quantizationMatrixInt);
float[] quantizationMatrixFloat = new float[64];
- for (int j = 0; j < 64; j++)
+ for (int j = 0; j < 64; j++) {
quantizationMatrixFloat[j] = quantizationMatrixInt[j];
+ }
Dct.scaleDequantizationMatrix(quantizationMatrixFloat);
scaledQuantizationTables[table.destinationIdentifier] = quantizationMatrixFloat;
}
@@ -201,18 +207,20 @@ public class JpegDecoder extends BinaryF
for (int i = 0; i < dhtSegment.huffmanTables.size(); i++) {
DhtSegment.HuffmanTable table = dhtSegment.huffmanTables.get(i);
DhtSegment.HuffmanTable[] tables;
- if (table.tableClass == 0)
+ if (table.tableClass == 0) {
tables = huffmanDCTables;
- else if (table.tableClass == 1)
+ } else if (table.tableClass == 1) {
tables = huffmanACTables;
- else
+ } else {
throw new ImageReadException("Invalid huffman table class "
+ table.tableClass);
+ }
if (0 > table.destinationIdentifier
- || table.destinationIdentifier >= tables.length)
+ || table.destinationIdentifier >= tables.length) {
throw new ImageReadException(
"Invalid huffman table identifier "
+ table.destinationIdentifier);
+ }
tables[table.destinationIdentifier] = table;
}
}
@@ -222,10 +230,10 @@ public class JpegDecoder extends BinaryF
private void rescaleMCU(Block[] dataUnits, int hSize, int vSize, Block[] ret) {
for (int i = 0; i < dataUnits.length; i++) {
Block block = dataUnits[i];
- if (block.width == hSize && block.height == vSize)
+ if (block.width == hSize && block.height == vSize) {
System.arraycopy(block.samples, 0, ret[i].samples, 0, hSize
* vSize);
- else {
+ } else {
int hScale = hSize / block.width;
int vScale = vSize / block.height;
if (hScale == 2 && vScale == 2) {
@@ -266,8 +274,9 @@ public class JpegDecoder extends BinaryF
break;
}
}
- if (frameComponent == null)
+ if (frameComponent == null) {
throw new ImageReadException("Invalid component");
+ }
Block fullBlock = new Block(
8 * frameComponent.horizontalSamplingFactor,
8 * frameComponent.verticalSamplingFactor);
@@ -291,8 +300,9 @@ public class JpegDecoder extends BinaryF
break;
}
}
- if (frameComponent == null)
+ if (frameComponent == null) {
throw new ImageReadException("Invalid component");
+ }
Block fullBlock = mcu[i];
for (int y = 0; y < frameComponent.verticalSamplingFactor; y++) {
for (int x = 0; x < frameComponent.horizontalSamplingFactor; x++) {
@@ -317,10 +327,11 @@ public class JpegDecoder extends BinaryF
int r = rrrr;
if (ssss == 0) {
- if (r == 15)
+ if (r == 15) {
k += 16;
- else
+ } else {
break;
+ }
} else {
k += r;
@@ -328,10 +339,11 @@ public class JpegDecoder extends BinaryF
zz[k] = receive(ssss, is);
zz[k] = extend(zz[k], ssss);
- if (k == 63)
+ if (k == 63) {
break;
- else
+ } else {
k++;
+ }
}
}
@@ -340,8 +352,9 @@ public class JpegDecoder extends BinaryF
float[] scaledQuantizationTable = scaledQuantizationTables[frameComponent.quantTabDestSelector];
ZigZag.zigZagToBlock(zz, blockInt);
- for (int j = 0; j < 64; j++)
+ for (int j = 0; j < 64; j++) {
block[j] = blockInt[j] * scaledQuantizationTable[j];
+ }
Dct.inverseDCT8x8(block);
int dstRowOffset = 8 * y * 8
@@ -352,12 +365,13 @@ public class JpegDecoder extends BinaryF
float sample = block[srcNext++];
sample += shift;
int result;
- if (sample < 0)
+ if (sample < 0) {
result = 0;
- else if (sample > max)
+ } else if (sample > max) {
result = max;
- else
+ } else {
result = fastRound(sample);
+ }
fullBlock.samples[dstRowOffset + xx] = result;
}
dstRowOffset += 8 * frameComponent.horizontalSamplingFactor;
@@ -412,10 +426,12 @@ public class JpegDecoder extends BinaryF
ImageReadException {
JpegUtils jpegUtils = new JpegUtils();
jpegUtils.traverseJFIF(byteSource, this);
- if (imageReadException != null)
+ if (imageReadException != null) {
throw imageReadException;
- if (ioException != null)
+ }
+ if (ioException != null) {
throw ioException;
+ }
return image;
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegInputStream.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegInputStream.java Thu Sep 27 05:42:25 2012
@@ -34,19 +34,22 @@ public class JpegInputStream {
public int nextBit() throws IOException, ImageReadException {
if (cnt == 0) {
b = is.read();
- if (b < 0)
+ if (b < 0) {
throw new ImageReadException("Premature End of File");
+ }
cnt = 8;
if (b == 0xff) {
int b2 = is.read();
- if (b2 < 0)
+ if (b2 < 0) {
throw new ImageReadException("Premature End of File");
+ }
if (b2 != 0) {
- if (b2 == (0xff & JpegConstants.DNLMarker))
+ if (b2 == (0xff & JpegConstants.DNLMarker)) {
throw new ImageReadException("DNL not yet supported");
- else
+ } else {
throw new ImageReadException("Invalid marker found "
+ "in entropy data");
+ }
}
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/YCbCrConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/YCbCrConverter.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/YCbCrConverter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/YCbCrConverter.java Thu Sep 27 05:42:25 2012
@@ -31,20 +31,24 @@ public class YCbCrConverter {
for (int Y = 0; Y < 256; Y++) {
for (int Cr = 0; Cr < 256; Cr++) {
int r = Y + fastRound(1.402f * (Cr - 128));
- if (r < 0)
+ if (r < 0) {
r = 0;
- if (r > 255)
+ }
+ if (r > 255) {
r = 255;
+ }
reds[(Cr << 8) | Y] = r << 16;
}
}
for (int Y = 0; Y < 256; Y++) {
for (int Cb = 0; Cb < 256; Cb++) {
int b = Y + fastRound(1.772f * (Cb - 128));
- if (b < 0)
+ if (b < 0) {
b = 0;
- if (b > 255)
+ }
+ if (b > 255) {
b = 255;
+ }
blues[(Cb << 8) | Y] = b;
}
}
@@ -85,10 +89,11 @@ public class YCbCrConverter {
for (int Y = 0; Y < 256; Y++) {
for (int value = 0; value < 270; value++) {
int green = Y - (value - 135);
- if (green < 0)
+ if (green < 0) {
green = 0;
- else if (green > 255)
+ } else if (green > 255) {
green = 255;
+ }
greens2[(value << 8) | Y] = green << 8;
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java Thu Sep 27 05:42:25 2012
@@ -166,14 +166,11 @@ public class ExifRewriter extends Binary
EXIF_IDENTIFIER_CODE)) {
pieces.add(new JFIFPieceSegment(marker, markerBytes,
markerLengthBytes, segmentData));
- }
- // else if (exifSegmentArray[0] != null)
- // {
+ // } else if (exifSegmentArray[0] != null) {
// // TODO: add support for multiple segments
// throw new ImageReadException(
// "More than one APP1 EXIF segment.");
- // }
- else {
+ } else {
JFIFPiece piece = new JFIFPieceSegmentExif(marker,
markerBytes, markerLengthBytes, segmentData);
pieces.add(piece);
@@ -388,8 +385,9 @@ public class ExifRewriter extends Binary
writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes);
- } else
+ } else {
writer = new TiffImageWriterLossy(outputSet.byteOrder);
+ }
boolean includeEXIFPrefix = true;
byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
@@ -509,16 +507,18 @@ public class ExifRewriter extends Binary
for (int i = 0; i < segments.size(); i++) {
JFIFPiece piece = segments.get(i);
- if (piece instanceof JFIFPieceSegmentExif)
+ if (piece instanceof JFIFPieceSegmentExif) {
hasExif = true;
+ }
}
if (!hasExif && newBytes != null) {
byte markerBytes[] = convertShortToByteArray(JPEG_APP1_Marker,
byteOrder);
- if (newBytes.length > 0xffff)
+ if (newBytes.length > 0xffff) {
throw new ExifOverflowException(
"APP1 Segment is too long: " + newBytes.length);
+ }
int markerLength = newBytes.length + 2;
byte markerLengthBytes[] = convertShortToByteArray(
markerLength, byteOrder);
@@ -526,8 +526,9 @@ public class ExifRewriter extends Binary
int index = 0;
JFIFPieceSegment firstSegment = (JFIFPieceSegment) segments
.get(index);
- if (firstSegment.marker == JFIFMarker)
+ if (firstSegment.marker == JFIFMarker) {
index = 1;
+ }
segments.add(0, new JFIFPieceSegmentExif(JPEG_APP1_Marker,
markerBytes, markerLengthBytes, newBytes));
}
@@ -538,18 +539,21 @@ public class ExifRewriter extends Binary
JFIFPiece piece = segments.get(i);
if (piece instanceof JFIFPieceSegmentExif) {
// only replace first APP1 segment; skips others.
- if (APP1Written)
+ if (APP1Written) {
continue;
+ }
APP1Written = true;
- if (newBytes == null)
+ if (newBytes == null) {
continue;
+ }
byte markerBytes[] = convertShortToByteArray(
JPEG_APP1_Marker, byteOrder);
- if (newBytes.length > 0xffff)
+ if (newBytes.length > 0xffff) {
throw new ExifOverflowException(
"APP1 Segment is too long: " + newBytes.length);
+ }
int markerLength = newBytes.length + 2;
byte markerLengthBytes[] = convertShortToByteArray(
markerLength, byteOrder);
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java Thu Sep 27 05:42:25 2012
@@ -43,15 +43,18 @@ public class IptcParser extends BinaryFi
public boolean isPhotoshopJpegSegment(byte segmentData[]) {
if (!BinaryFileParser.byteArrayHasPrefix(segmentData,
- PHOTOSHOP_IDENTIFICATION_STRING))
+ PHOTOSHOP_IDENTIFICATION_STRING)) {
return false;
+ }
int index = PHOTOSHOP_IDENTIFICATION_STRING.size();
- if (index + CONST_8BIM.size() > segmentData.length)
+ if (index + CONST_8BIM.size() > segmentData.length) {
return false;
+ }
- if (!CONST_8BIM.equals(segmentData, index, CONST_8BIM.size()))
+ if (!CONST_8BIM.equals(segmentData, index, CONST_8BIM.size())) {
return false;
+ }
return true;
}
@@ -114,8 +117,9 @@ public class IptcParser extends BinaryFi
IptcBlock block = allBlocks.get(i);
// Ignore everything but IPTC data.
- if (!block.isIPTCBlock())
+ if (!block.isIPTCBlock()) {
continue;
+ }
records.addAll(parseIPTCBlock(block.blockData, verbose));
}
@@ -131,24 +135,26 @@ public class IptcParser extends BinaryFi
// Integer recordVersion = null;
while (index + 1 < bytes.length) {
int tagMarker = 0xff & bytes[index++];
- if (verbose)
+ if (verbose) {
Debug.debug("tagMarker",
tagMarker + " (0x" + Integer.toHexString(tagMarker)
+ ")");
+ }
if (tagMarker != IPTC_RECORD_TAG_MARKER) {
- if (verbose)
- System.out
- .println("Unexpected record tag marker in IPTC data.");
+ if (verbose) {
+ System.out.println("Unexpected record tag marker in IPTC data.");
+ }
return elements;
}
int recordNumber = 0xff & bytes[index++];
- if (verbose)
+ if (verbose) {
Debug.debug(
"recordNumber",
recordNumber + " (0x"
+ Integer.toHexString(recordNumber) + ")");
+ }
// int recordPrefix = convertByteArrayToShort("recordPrefix", index,
// bytes);
@@ -169,10 +175,11 @@ public class IptcParser extends BinaryFi
// "Unexpected record prefix in IPTC data.");
int recordType = 0xff & bytes[index];
- if (verbose)
+ if (verbose) {
Debug.debug("recordType",
recordType + " (0x" + Integer.toHexString(recordType)
+ ")");
+ }
index++;
int recordSize = convertByteArrayToShort("recordSize", index, bytes);
@@ -180,12 +187,14 @@ public class IptcParser extends BinaryFi
boolean extendedDataset = recordSize > IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE;
int dataFieldCountLength = recordSize & 0x7fff;
- if (extendedDataset && verbose)
+ if (extendedDataset && verbose) {
Debug.debug("extendedDataset. dataFieldCountLength: "
+ dataFieldCountLength);
- if (extendedDataset) // ignore extended dataset and everything
- // after.
+ }
+ if (extendedDataset) {
+ // ignore extended dataset and everything after.
return elements;
+ }
byte recordData[] = readBytearray("recordData", bytes, index,
recordSize);
@@ -194,13 +203,15 @@ public class IptcParser extends BinaryFi
// Debug.debug("recordSize", recordSize + " (0x"
// + Integer.toHexString(recordSize) + ")");
- if (recordNumber != IPTC_APPLICATION_2_RECORD_NUMBER)
+ if (recordNumber != IPTC_APPLICATION_2_RECORD_NUMBER) {
continue;
+ }
if (recordType == 0) {
- if (verbose)
+ if (verbose) {
System.out.println("ignore record version record! "
+ elements.size());
+ }
// ignore "record version" record;
continue;
}
@@ -264,8 +275,9 @@ public class IptcParser extends BinaryFi
byte[] idString = bis.readByteArray(
PHOTOSHOP_IDENTIFICATION_STRING.size(),
"App13 Segment missing identification string");
- if (!PHOTOSHOP_IDENTIFICATION_STRING.equals(idString))
+ if (!PHOTOSHOP_IDENTIFICATION_STRING.equals(idString)) {
throw new ImageReadException("Not a Photoshop App13 Segment");
+ }
// int index = PHOTOSHOP_IDENTIFICATION_STRING.length;
@@ -274,24 +286,28 @@ public class IptcParser extends BinaryFi
.readByteArray(CONST_8BIM.size(),
"App13 Segment missing identification string",
false, false);
- if (null == imageResourceBlockSignature)
+ if (null == imageResourceBlockSignature) {
break;
- if (!CONST_8BIM.equals(imageResourceBlockSignature))
+ }
+ if (!CONST_8BIM.equals(imageResourceBlockSignature)) {
throw new ImageReadException(
"Invalid Image Resource Block Signature");
+ }
int blockType = bis
.read2ByteInteger("Image Resource Block missing type");
- if (verbose)
+ if (verbose) {
Debug.debug("blockType",
blockType + " (0x" + Integer.toHexString(blockType)
+ ")");
+ }
int blockNameLength = bis
.read1ByteInteger("Image Resource Block missing name length");
- if (verbose && blockNameLength > 0)
+ if (verbose && blockNameLength > 0) {
Debug.debug("blockNameLength", blockNameLength + " (0x"
+ Integer.toHexString(blockNameLength) + ")");
+ }
byte[] blockNameBytes;
if (blockNameLength == 0) {
bis.read1ByteInteger("Image Resource Block has invalid name");
@@ -299,19 +315,22 @@ public class IptcParser extends BinaryFi
} else {
blockNameBytes = bis.readByteArray(blockNameLength,
"Invalid Image Resource Block name", verbose, strict);
- if (null == blockNameBytes)
+ if (null == blockNameBytes) {
break;
+ }
- if (blockNameLength % 2 == 0)
+ if (blockNameLength % 2 == 0) {
bis.read1ByteInteger("Image Resource Block missing padding byte");
+ }
}
int blockSize = bis
.read4ByteInteger("Image Resource Block missing size");
- if (verbose)
+ if (verbose) {
Debug.debug("blockSize",
blockSize + " (0x" + Integer.toHexString(blockSize)
+ ")");
+ }
/*
* doesn't catch cases where blocksize is invalid but is still less
@@ -324,13 +343,15 @@ public class IptcParser extends BinaryFi
byte[] blockData = bis.readByteArray(blockSize,
"Invalid Image Resource Block data", verbose, strict);
- if (null == blockData)
+ if (null == blockData) {
break;
+ }
blocks.add(new IptcBlock(blockType, blockNameBytes, blockData));
- if ((blockSize % 2) != 0)
+ if ((blockSize % 2) != 0) {
bis.read1ByteInteger("Image Resource Block missing padding byte");
+ }
}
return blocks;
@@ -356,25 +377,30 @@ public class IptcParser extends BinaryFi
CONST_8BIM.writeTo(bos);
- if (block.blockType < 0 || block.blockType > 0xffff)
+ if (block.blockType < 0 || block.blockType > 0xffff) {
throw new ImageWriteException("Invalid IPTC block type.");
+ }
bos.write2ByteInteger(block.blockType);
- if (block.blockNameBytes.length > 255)
+ if (block.blockNameBytes.length > 255) {
throw new ImageWriteException("IPTC block name is too long: "
+ block.blockNameBytes.length);
+ }
bos.write(block.blockNameBytes.length);
bos.write(block.blockNameBytes);
- if (block.blockNameBytes.length % 2 == 0)
+ if (block.blockNameBytes.length % 2 == 0) {
bos.write(0); // pad to even size, including length byte.
+ }
- if (block.blockData.length > IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE)
+ if (block.blockData.length > IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE) {
throw new ImageWriteException("IPTC block data is too long: "
+ block.blockData.length);
+ }
bos.write4ByteInteger(block.blockData.length);
bos.write(block.blockData);
- if (block.blockData.length % 2 == 1)
+ if (block.blockData.length % 2 == 1) {
bos.write(0); // pad to even size
+ }
}
@@ -414,21 +440,24 @@ public class IptcParser extends BinaryFi
for (int i = 0; i < elements.size(); i++) {
IptcRecord element = elements.get(i);
- if (element.iptcType == IptcTypes.RECORD_VERSION)
+ if (element.iptcType == IptcTypes.RECORD_VERSION) {
continue; // ignore
+ }
bos.write(IPTC_RECORD_TAG_MARKER);
bos.write(IPTC_APPLICATION_2_RECORD_NUMBER);
if (element.iptcType.getType() < 0
- || element.iptcType.getType() > 0xff)
+ || element.iptcType.getType() > 0xff) {
throw new ImageWriteException("Invalid record type: "
+ element.iptcType.getType());
+ }
bos.write(element.iptcType.getType());
byte recordData[] = element.value.getBytes("ISO-8859-1");
- if (!new String(recordData, "ISO-8859-1").equals(element.value))
+ if (!new String(recordData, "ISO-8859-1").equals(element.value)) {
throw new ImageWriteException(
"Invalid record value, not ISO-8859-1");
+ }
bos.write2Bytes(recordData.length);
bos.write(recordData);
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java Thu Sep 27 05:42:25 2012
@@ -29,8 +29,9 @@ public abstract class IptcTypeLookup imp
}
public static final IptcType getIptcType(int type) {
- if (!IPTC_TYPE_MAP.containsKey(type))
+ if (!IPTC_TYPE_MAP.containsKey(type)) {
return IptcTypes.getUnknown(type);
+ }
return IPTC_TYPE_MAP.get(type);
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java Thu Sep 27 05:42:25 2012
@@ -110,9 +110,10 @@ public class JpegIptcRewriter extends Jp
List<JFIFPiece> oldPieces = jfifPieces.pieces;
List<JFIFPiece> photoshopApp13Segments = findPhotoshopApp13Segments(oldPieces);
- if (photoshopApp13Segments.size() > 1)
+ if (photoshopApp13Segments.size() > 1) {
throw new ImageReadException(
"Image contains more than one Photoshop App13 segment.");
+ }
List<JFIFPiece> newPieces = removePhotoshopApp13Segments(oldPieces);
if (photoshopApp13Segments.size() == 1) {
JFIFPieceSegment oldSegment = (JFIFPieceSegment) photoshopApp13Segments
@@ -208,9 +209,10 @@ public class JpegIptcRewriter extends Jp
List<JFIFPiece> oldPieces = jfifPieces.pieces;
List<JFIFPiece> photoshopApp13Segments = findPhotoshopApp13Segments(oldPieces);
- if (photoshopApp13Segments.size() > 1)
+ if (photoshopApp13Segments.size() > 1) {
throw new ImageReadException(
"Image contains more than one Photoshop App13 segment.");
+ }
List<JFIFPiece> newPieces = removePhotoshopApp13Segments(oldPieces);
{
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java Thu Sep 27 05:42:25 2012
@@ -42,8 +42,9 @@ public class PhotoshopApp13Data implemen
List<IptcBlock> result = new ArrayList<IptcBlock>();
for (int i = 0; i < rawBlocks.size(); i++) {
IptcBlock block = rawBlocks.get(i);
- if (!block.isIPTCBlock())
+ if (!block.isIPTCBlock()) {
result.add(block);
+ }
}
return result;
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java Thu Sep 27 05:42:25 2012
@@ -69,8 +69,9 @@ public class App13Segment extends AppnSe
* metadata. However, we should not treat App13 signatures without
* Photoshop's signature as Photoshop/IPTC segments.
*/
- if (!isPhotoshopJpegSegment())
+ if (!isPhotoshopJpegSegment()) {
return null;
+ }
return new IptcParser().parsePhotoshopSegment(bytes, params);
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java Thu Sep 27 05:42:25 2012
@@ -32,14 +32,16 @@ public class ComSegment extends Segment
throws IOException {
super(marker, marker_length);
- if (getDebug())
+ if (getDebug()) {
System.out.println("ComSegment marker_length: " + marker_length);
+ }
comment = readByteArray("Comment", marker_length, is,
"Error reading JPEG comment");
- if (getDebug())
+ if (getDebug()) {
System.out.println("");
+ }
}
@Override
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java Thu Sep 27 05:42:25 2012
@@ -79,10 +79,12 @@ public class DhtSegment extends Segment
code++;
k++;
- if (huffSize[k] == si)
+ if (huffSize[k] == si) {
continue;
- if (huffSize[k] == 0)
+ }
+ if (huffSize[k] == 0) {
break;
+ }
do {
code <<= 1;
si++;
@@ -94,11 +96,12 @@ public class DhtSegment extends Segment
j = 0;
while (true) {
i++;
- if (i > 16)
+ if (i > 16) {
break;
- if (bits[i] == 0)
+ }
+ if (bits[i] == 0) {
maxCode[i] = -1;
- else {
+ } else {
valPtr[i] = j;
minCode[i] = huffCode[j];
j += bits[i] - 1;
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java Thu Sep 27 05:42:25 2012
@@ -50,9 +50,10 @@ public class JfifSegment extends Segment
byte signature[] = readBytes(is, JFIF0_SIGNATURE.size());
if (!JFIF0_SIGNATURE.equals(signature)
- && !JFIF0_SIGNATURE_ALTERNATIVE.equals(signature))
+ && !JFIF0_SIGNATURE_ALTERNATIVE.equals(signature)) {
throw new ImageReadException(
"Not a Valid JPEG File: missing JFIF string");
+ }
jfifMajorVersion = readByte("JFIF_major_version", is,
"Not a Valid JPEG File");
@@ -71,8 +72,9 @@ public class JfifSegment extends Segment
}
- if (getDebug())
+ if (getDebug()) {
System.out.println("");
+ }
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java Thu Sep 27 05:42:25 2012
@@ -128,12 +128,15 @@ public abstract class Segment extends Bi
default:
}
- if ((marker >= 0xff02) && (marker <= 0xffbf))
+ if ((marker >= 0xff02) && (marker <= 0xffbf)) {
return "Reserved";
- if ((marker >= 0xffe0) && (marker <= 0xffef))
+ }
+ if ((marker >= 0xffe0) && (marker <= 0xffef)) {
return "APP" + (marker - 0xffe0);
- if ((marker >= 0xfff0) && (marker <= 0xfffd))
+ }
+ if ((marker >= 0xfff0) && (marker <= 0xfffd)) {
return "JPG" + (marker - 0xffe0);
+ }
return "Unknown";
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java Thu Sep 27 05:42:25 2012
@@ -53,8 +53,9 @@ public class SofnSegment extends Segment
throws ImageReadException, IOException {
super(marker, marker_length);
- if (getDebug())
+ if (getDebug()) {
System.out.println("SOF0Segment marker_length: " + marker_length);
+ }
precision = readByte("Data_precision", is, "Not a Valid JPEG File");
height = read2Bytes("Image_height", is, "Not a Valid JPEG File");
@@ -77,8 +78,9 @@ public class SofnSegment extends Segment
quantTabDestSelector);
}
- if (getDebug())
+ if (getDebug()) {
System.out.println("");
+ }
}
@Override
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java?rev=1390849&r1=1390848&r2=1390849&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java Thu Sep 27 05:42:25 2012
@@ -49,8 +49,9 @@ public class SosSegment extends Segment
throws IOException {
super(marker, marker_length);
- if (getDebug())
+ if (getDebug()) {
System.out.println("SosSegment marker_length: " + marker_length);
+ }
// Debug.debug("SOS", marker_length);
@@ -91,8 +92,9 @@ public class SosSegment extends Segment
successiveApproximationBitHigh = (successive_approximation_bit_position >> 4) & 0xf;
successiveApproximationBitLow = successive_approximation_bit_position & 0xf;
- if (getDebug())
+ if (getDebug()) {
System.out.println("");
+ }
}
@Override