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 20:22:40 UTC
svn commit: r1391156 [4/4] - in
/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging:
formats/pcx/ formats/png/ formats/png/chunks/ formats/png/scanlinefilters/
formats/pnm/ formats/psd/ formats/psd/dataparsers/ formats/psd/datareader...
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java Thu Sep 27 18:22:37 2012
@@ -34,22 +34,25 @@ public class IccProfileParser extends Bi
}
public IccProfileInfo getICCProfileInfo(ICC_Profile icc_profile) {
- if (icc_profile == null)
+ if (icc_profile == null) {
return null;
+ }
return getICCProfileInfo(new ByteSourceArray(icc_profile.getData()));
}
public IccProfileInfo getICCProfileInfo(byte bytes[]) {
- if (bytes == null)
+ if (bytes == null) {
return null;
+ }
return getICCProfileInfo(new ByteSourceArray(bytes));
}
public IccProfileInfo getICCProfileInfo(File file) {
- if (file == null)
+ if (file == null) {
return null;
+ }
return getICCProfileInfo(new ByteSourceFile(file));
}
@@ -61,14 +64,13 @@ public class IccProfileParser extends Bi
try {
IccProfileInfo result;
- {
- is = byteSource.getInputStream();
+ is = byteSource.getInputStream();
- result = readICCProfileInfo(is);
- }
+ result = readICCProfileInfo(is);
- if (result == null)
+ if (result == null) {
return null;
+ }
is.close();
is = null;
@@ -88,16 +90,18 @@ public class IccProfileParser extends Bi
Debug.debug(e);
} finally {
try {
- if (is != null)
+ if (is != null) {
is.close();
+ }
} catch (Exception e) {
Debug.debug(e);
}
}
- if (debug)
+ if (debug) {
Debug.debug();
+ }
return null;
}
@@ -106,8 +110,9 @@ public class IccProfileParser extends Bi
CachingInputStream cis = new CachingInputStream(is);
is = cis;
- if (debug)
+ if (debug) {
Debug.debug();
+ }
// setDebug(true);
@@ -131,8 +136,9 @@ public class IccProfileParser extends Bi
int CMMTypeSignature = read4Bytes("Signature", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("CMMTypeSignature", CMMTypeSignature);
+ }
int ProfileVersion = read4Bytes("ProfileVersion", is,
"Not a Valid ICC Profile");
@@ -140,62 +146,72 @@ public class IccProfileParser extends Bi
int ProfileDeviceClassSignature = read4Bytes(
"ProfileDeviceClassSignature", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("ProfileDeviceClassSignature",
ProfileDeviceClassSignature);
+ }
int ColorSpace = read4Bytes("ColorSpace", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("ColorSpace", ColorSpace);
+ }
int ProfileConnectionSpace = read4Bytes("ProfileConnectionSpace",
is, "Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("ProfileConnectionSpace", ProfileConnectionSpace);
+ }
skipBytes(is, 12, "Not a Valid ICC Profile");
int ProfileFileSignature = read4Bytes("ProfileFileSignature", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("ProfileFileSignature", ProfileFileSignature);
+ }
int PrimaryPlatformSignature = read4Bytes(
"PrimaryPlatformSignature", is, "Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("PrimaryPlatformSignature",
PrimaryPlatformSignature);
+ }
int VariousFlags = read4Bytes("ProfileFileSignature", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("ProfileFileSignature", ProfileFileSignature);
+ }
int DeviceManufacturer = read4Bytes("ProfileFileSignature", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("DeviceManufacturer", DeviceManufacturer);
+ }
int DeviceModel = read4Bytes("DeviceModel", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("DeviceModel", DeviceModel);
+ }
skipBytes(is, 8, "Not a Valid ICC Profile");
int RenderingIntent = read4Bytes("RenderingIntent", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("RenderingIntent", RenderingIntent);
+ }
skipBytes(is, 12, "Not a Valid ICC Profile");
int ProfileCreatorSignature = read4Bytes("ProfileCreatorSignature",
is, "Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("ProfileCreatorSignature",
ProfileCreatorSignature);
+ }
byte ProfileID[] = null;
skipBytes(is, 16, "Not a Valid ICC Profile");
@@ -254,8 +270,9 @@ public class IccProfileParser extends Bi
byte data[] = cis.getCache();
- if (data.length < ProfileSize)
+ if (data.length < ProfileSize) {
throw new IOException("Couldn't read ICC Profile.");
+ }
IccProfileInfo result = new IccProfileInfo(data, ProfileSize,
CMMTypeSignature, ProfileVersion,
@@ -265,8 +282,9 @@ public class IccProfileParser extends Bi
DeviceModel, RenderingIntent, ProfileCreatorSignature,
ProfileID, tags);
- if (debug)
+ if (debug) {
Debug.debug("issRGB: " + result.issRGB());
+ }
return result;
} catch (Exception e) {
@@ -287,30 +305,34 @@ public class IccProfileParser extends Bi
}
public Boolean issRGB(ICC_Profile icc_profile) {
- if (icc_profile == null)
+ if (icc_profile == null) {
return null;
+ }
return issRGB(new ByteSourceArray(icc_profile.getData()));
}
public Boolean issRGB(byte bytes[]) {
- if (bytes == null)
+ if (bytes == null) {
return null;
+ }
return issRGB(new ByteSourceArray(bytes));
}
public Boolean issRGB(File file) {
- if (file == null)
+ if (file == null) {
return null;
+ }
return issRGB(new ByteSourceFile(file));
}
public Boolean issRGB(ByteSource byteSource) {
try {
- if (debug)
+ if (debug) {
Debug.debug();
+ }
// setDebug(true);
@@ -336,13 +358,15 @@ public class IccProfileParser extends Bi
int DeviceManufacturer = read4Bytes("ProfileFileSignature", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("DeviceManufacturer", DeviceManufacturer);
+ }
int DeviceModel = read4Bytes("DeviceModel", is,
"Not a Valid ICC Profile");
- if (debug)
+ if (debug) {
printCharQuad("DeviceModel", DeviceModel);
+ }
boolean result = ((DeviceManufacturer == IEC) && (DeviceModel == sRGB));
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java Thu Sep 27 18:22:37 2012
@@ -92,9 +92,9 @@ public class IccTag implements BinaryCon
(byte) (0xff & (signature >> 0)), }, "US-ASCII")
+ ")");
- if (data == null)
+ if (data == null) {
pw.println(prefix + "data: " + Arrays.toString(data));
- else {
+ } else {
pw.println(prefix + "data: " + data.length);
pw.println(prefix
@@ -108,9 +108,9 @@ public class IccTag implements BinaryCon
(byte) (0xff & (data_type_signature >> 0)), }, "US-ASCII")
+ ")");
- if (itdt == null)
+ if (itdt == null) {
pw.println(prefix + "IccTagType : " + "unknown");
- else {
+ } else {
pw.println(prefix + "IccTagType : " + itdt.getName());
itdt.dump(prefix, data);
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java Thu Sep 27 18:22:37 2012
@@ -54,22 +54,28 @@ class ColorSpaceSubset {
public final boolean contains(int red, int green, int blue) {
red >>= (8 - precision);
- if (mins[0] > red)
+ if (mins[0] > red) {
return false;
- if (maxs[0] < red)
+ }
+ if (maxs[0] < red) {
return false;
+ }
green >>= (8 - precision);
- if (mins[1] > green)
+ if (mins[1] > green) {
return false;
- if (maxs[1] < green)
+ }
+ if (maxs[1] < green) {
return false;
+ }
blue >>= (8 - precision);
- if (mins[2] > blue)
+ if (mins[2] > blue) {
return false;
- if (maxs[2] < blue)
+ }
+ if (maxs[2] < blue) {
return false;
+ }
return true;
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java Thu Sep 27 18:22:37 2012
@@ -94,8 +94,9 @@ public class MedianCutQuantizer {
throws ImageWriteException {
this.color_counts = color_counts;
- if (color_counts.size() < 1)
+ if (color_counts.size() < 1) {
throw new ImageWriteException("empty color_group");
+ }
for (int i = 0; i < color_counts.size(); i++) {
ColorCount color = color_counts.get(i);
@@ -128,14 +129,18 @@ public class MedianCutQuantizer {
int green = 0xff & (argb >> 8);
int blue = 0xff & (argb >> 0);
- if (!ignoreAlpha && (alpha < min_alpha || alpha > max_alpha))
+ if (!ignoreAlpha && (alpha < min_alpha || alpha > max_alpha)) {
return false;
- if (red < min_red || red > max_red)
+ }
+ if (red < min_red || red > max_red) {
return false;
- if (green < min_green || green > max_green)
+ }
+ if (green < min_green || green > max_green) {
return false;
- if (blue < min_blue || blue > max_blue)
+ }
+ if (blue < min_blue || blue > max_blue) {
return false;
+ }
return true;
}
@@ -191,16 +196,18 @@ public class MedianCutQuantizer {
for (int x = 0; x < width; x++) {
int argb = row[x];
- if (ignoreAlpha)
+ if (ignoreAlpha) {
argb &= 0xffffff;
+ }
argb &= mask;
ColorCount color = color_map.get(argb);
if (color == null) {
color = new ColorCount(argb);
color_map.put(argb, color);
- if (color_map.keySet().size() > max)
+ if (color_map.keySet().size() > max) {
return null;
+ }
}
color.count++;
}
@@ -221,8 +228,9 @@ public class MedianCutQuantizer {
mask + " (" + Integer.toHexString(mask) + ")");
Map<Integer, ColorCount> result = groupColors1(image, max, mask);
- if (result != null)
+ if (result != null) {
return result;
+ }
}
throw new Error("");
}
@@ -233,8 +241,9 @@ public class MedianCutQuantizer {
int discrete_colors = color_map.keySet().size();
if (discrete_colors <= max_colors) {
- if (verbose)
+ if (verbose) {
Debug.debug("lossless palette: " + discrete_colors);
+ }
int palette[] = new int[discrete_colors];
List<ColorCount> color_counts = new ArrayList<ColorCount>(
@@ -243,15 +252,17 @@ public class MedianCutQuantizer {
for (int i = 0; i < color_counts.size(); i++) {
ColorCount color_count = color_counts.get(i);
palette[i] = color_count.argb;
- if (ignoreAlpha)
+ if (ignoreAlpha) {
palette[i] |= 0xff000000;
+ }
}
return new SimplePalette(palette);
}
- if (verbose)
+ if (verbose) {
Debug.debug("discrete colors: " + discrete_colors);
+ }
List<ColorGroup> color_groups = new ArrayList<ColorGroup>();
ColorGroup root = new ColorGroup(new ArrayList<ColorCount>(
@@ -260,8 +271,9 @@ public class MedianCutQuantizer {
final Comparator<ColorGroup> comparator = new Comparator<ColorGroup>() {
public int compare(ColorGroup cg1, ColorGroup cg2) {
- if (cg1.max_diff == cg2.max_diff)
+ if (cg1.max_diff == cg2.max_diff) {
return cg2.diff_total - cg1.diff_total;
+ }
return cg2.max_diff - cg1.max_diff;
}
};
@@ -271,8 +283,9 @@ public class MedianCutQuantizer {
ColorGroup color_group = color_groups.get(0);
- if (color_group.max_diff == 0)
+ if (color_group.max_diff == 0) {
break;
+ }
if (!ignoreAlpha
&& color_group.alpha_diff > color_group.red_diff
&& color_group.alpha_diff > color_group.green_diff
@@ -289,8 +302,9 @@ public class MedianCutQuantizer {
}
int palette_size = color_groups.size();
- if (verbose)
+ if (verbose) {
Debug.debug("palette size: " + palette_size);
+ }
int palette[] = new int[palette_size];
@@ -301,13 +315,15 @@ public class MedianCutQuantizer {
color_group.palette_index = i;
- if (color_group.color_counts.size() < 1)
+ if (color_group.color_counts.size() < 1) {
throw new ImageWriteException("empty color_group: "
+ color_group);
+ }
}
- if (palette_size > discrete_colors)
+ if (palette_size > discrete_colors) {
throw new ImageWriteException("palette_size>discrete_colors");
+ }
return new MedianCutPalette(root, palette);
}
@@ -358,13 +374,14 @@ public class MedianCutQuantizer {
break;
}
- if (median_index == color_group.color_counts.size() - 1)
+ if (median_index == color_group.color_counts.size() - 1) {
median_index--;
- else if (median_index > 0) {
+ } else if (median_index > 0) {
int new_diff = Math.abs(new_count - count_half);
int old_diff = Math.abs(count_half - old_count);
- if (old_diff < new_diff)
+ if (old_diff < new_diff) {
median_index--;
+ }
}
color_groups.remove(color_group);
@@ -432,8 +449,9 @@ public class MedianCutQuantizer {
default:
throw new Error("bad mode.");
}
- if (value <= limit)
+ if (value <= limit) {
return less;
+ }
return more;
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java Thu Sep 27 18:22:37 2012
@@ -65,8 +65,9 @@ public class PaletteFactory {
count += Integer.bitCount(eight);
}
- if (debug)
+ if (debug) {
System.out.println("Used colors: " + count);
+ }
int colormap[] = new int[count];
int mapsize = 0;
@@ -126,8 +127,9 @@ public class PaletteFactory {
private DivisionCandidate finishDivision(int table[],
ColorSpaceSubset subset, int component, int precision, int sum,
int slice) {
- if (debug)
+ if (debug) {
subset.dump("trying (" + component + "): ");
+ }
int total = subset.total;
@@ -174,8 +176,9 @@ public class PaletteFactory {
private List<DivisionCandidate> divideSubset2(int table[],
ColorSpaceSubset subset, int component, int precision) {
- if (debug)
+ if (debug) {
subset.dump("trying (" + component + "): ");
+ }
int total = subset.total;
@@ -198,8 +201,9 @@ public class PaletteFactory {
sum1 += last;
- if (sum1 >= (total / 2))
+ if (sum1 >= (total / 2)) {
break;
+ }
}
sum2 = sum1 - last;
@@ -212,10 +216,12 @@ public class PaletteFactory {
List<DivisionCandidate> result = new ArrayList<DivisionCandidate>();
- if (dc1 != null)
+ if (dc1 != null) {
result.add(dc1);
- if (dc2 != null)
+ }
+ if (dc2 != null) {
result.add(dc2);
+ }
return result;
}
@@ -277,17 +283,19 @@ public class PaletteFactory {
while (true) {
count++;
- if (debug)
+ if (debug) {
System.out.println("cycle(" + count + "): " + v.size()
+ " done");
+ }
int max_area = -1;
ColorSpaceSubset max_subset = null;
for (int i = 0; i < v.size(); i++) {
ColorSpaceSubset subset = v.get(i);
- if (ignore.contains(subset))
+ if (ignore.contains(subset)) {
continue;
+ }
int area = subset.total;
if (max_subset == null) {
@@ -302,8 +310,9 @@ public class PaletteFactory {
if (max_subset == null) {
return v;
}
- if (debug)
+ if (debug) {
System.out.println("\t" + "area: " + max_area);
+ }
DivisionCandidate dc = divideSubset2(table, max_subset,
precision);
@@ -311,11 +320,13 @@ public class PaletteFactory {
v.remove(max_subset);
v.add(dc.dst_a);
v.add(dc.dst_b);
- } else
+ } else {
ignore.add(max_subset);
+ }
- if (v.size() == desired_count)
+ if (v.size() == desired_count) {
return v;
+ }
}
}
@@ -376,8 +387,9 @@ public class PaletteFactory {
subset.setAverageRGB(table);
- if (debug)
+ if (debug) {
subset.dump(i + ": ");
+ }
}
Collections.sort(subsets, ColorSpaceSubset.rgbComparator);
@@ -439,10 +451,11 @@ public class PaletteFactory {
int height = src.getHeight();
if (ColorSpace.TYPE_GRAY == src.getColorModel().getColorSpace()
- .getType())
+ .getType()) {
return true;
+ }
- for (int y = 0; y < height; y++)
+ for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int argb = src.getRGB(x, y);
@@ -450,10 +463,11 @@ public class PaletteFactory {
int green = 0xff & (argb >> 8);
int blue = 0xff & (argb >> 0);
- if (red != green || red != blue)
+ if (red != green || red != blue) {
return false;
+ }
}
-
+ }
return true;
}
@@ -465,17 +479,19 @@ public class PaletteFactory {
int width = src.getWidth();
int height = src.getHeight();
- if (!src.getColorModel().hasAlpha())
+ if (!src.getColorModel().hasAlpha()) {
return false;
+ }
- for (int y = 0; y < height; y++)
+ for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int argb = src.getRGB(x, y);
int alpha = 0xff & (argb >> 24);
- if (alpha < threshold)
+ if (alpha < threshold) {
return true;
+ }
}
-
+ }
return false;
}
@@ -488,40 +504,46 @@ public class PaletteFactory {
if (alpha < 0xff) {
if (first < 0) {
first = rgb;
- } else if (rgb != first)
+ } else if (rgb != first) {
return 2; // more than one transparent color;
+ }
}
}
- if (first < 0)
+ if (first < 0) {
return 0;
+ }
return 1;
}
public int countTransparentColors(BufferedImage src) {
ColorModel cm = src.getColorModel();
- if (!cm.hasAlpha())
+ if (!cm.hasAlpha()) {
return 0;
+ }
int width = src.getWidth();
int height = src.getHeight();
int first = -1;
- for (int y = 0; y < height; y++)
+ for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int rgb = src.getRGB(x, y);
int alpha = 0xff & (rgb >> 24);
if (alpha < 0xff) {
if (first < 0) {
first = rgb;
- } else if (rgb != first)
+ } else if (rgb != first) {
return 2; // more than one transparent color;
+ }
}
}
+ }
- if (first < 0)
+ if (first < 0) {
return 0;
+ }
return 1;
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java Thu Sep 27 18:22:37 2012
@@ -29,24 +29,23 @@ public class QuantizedPalette extends Pa
this.subsets = subsets;
this.precision = precision;
- {
- straight = new ColorSpaceSubset[1 << (precision * 3)];
+ straight = new ColorSpaceSubset[1 << (precision * 3)];
- for (int i = 0; i < subsets.size(); i++) {
- ColorSpaceSubset subset = subsets.get(i);
- subset.setIndex(i);
-
- for (int u = subset.mins[0]; u <= subset.maxs[0]; u++)
- for (int j = subset.mins[1]; j <= subset.maxs[1]; j++)
- for (int k = subset.mins[2]; k <= subset.maxs[2]; k++) {
- int index = (u << (precision * 2))
- | (j << (precision * 1))
- | (k << (precision * 0));
- straight[index] = subset;
- }
+ for (int i = 0; i < subsets.size(); i++) {
+ ColorSpaceSubset subset = subsets.get(i);
+ subset.setIndex(i);
+
+ for (int u = subset.mins[0]; u <= subset.maxs[0]; u++) {
+ for (int j = subset.mins[1]; j <= subset.maxs[1]; j++) {
+ for (int k = subset.mins[2]; k <= subset.maxs[2]; k++) {
+ int index = (u << (precision * 2))
+ | (j << (precision * 1))
+ | (k << (precision * 0));
+ straight[index] = subset;
+ }
+ }
}
}
-
}
@Override
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/SimplePalette.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/SimplePalette.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/SimplePalette.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/SimplePalette.java Thu Sep 27 18:22:37 2012
@@ -37,8 +37,9 @@ public class SimplePalette extends Palet
private int getPaletteIndex(int palette[], int argb) {
for (int i = 0; i < palette.length; i++) {
- if (palette[i] == argb)
+ if (palette[i] == argb) {
return i;
+ }
}
return -1;
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/Debug.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/Debug.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/Debug.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/Debug.java Thu Sep 27 18:22:37 2012
@@ -79,12 +79,13 @@ public final class Debug {
public static String getDebug(String message, int v[]) {
StringBuilder result = new StringBuilder();
- if (v == null)
+ if (v == null) {
result.append(message + " (" + null + ")" + newline);
- else {
+ } else {
result.append(message + " (" + v.length + ")" + newline);
- for (int i = 0; i < v.length; i++)
+ for (int i = 0; i < v.length; i++) {
result.append("\t" + v[i] + newline);
+ }
result.append(newline);
}
return result.toString();
@@ -99,24 +100,26 @@ public final class Debug {
StringBuilder result = new StringBuilder();
- if (v == null)
+ if (v == null) {
result.append(message + " (" + null + ")" + newline);
- else {
+ } else {
result.append(message + " (" + v.length + ")" + newline);
for (int i = 0; i < max && i < v.length; i++) {
int b = 0xff & v[i];
char c;
- if (b == 0 || b == 10 || b == 11 || b == 13)
+ if (b == 0 || b == 10 || b == 11 || b == 13) {
c = ' ';
- else
+ } else {
c = (char) b;
+ }
result.append("\t" + i + ": " + b + " (" + c + ", 0x"
+ Integer.toHexString(b) + ")" + newline);
}
- if (v.length > max)
+ if (v.length > max) {
result.append("\t" + "..." + newline);
+ }
result.append(newline);
}
@@ -126,13 +129,14 @@ public final class Debug {
public static String getDebug(String message, char v[]) {
StringBuilder result = new StringBuilder();
- if (v == null)
+ if (v == null) {
result.append(getDebug(message + " (" + null + ")") + newline);
- else {
+ } else {
result.append(getDebug(message + " (" + v.length + ")") + newline);
- for (int i = 0; i < v.length; i++)
+ for (int i = 0; i < v.length; i++) {
result.append(getDebug("\t" + v[i] + " (" + (0xff & v[i]))
+ ")" + newline);
+ }
result.append(newline);
}
return result.toString();
@@ -147,9 +151,10 @@ public final class Debug {
result.append(getDebug(message + " (" + v.size() + ")" + suffix)
+ newline);
- for (int i = 0; i < v.size(); i++)
+ for (int i = 0; i < v.size(); i++) {
result.append(getDebug("\t" + v.get(i).toString() + suffix)
+ newline);
+ }
result.append(newline);
return result.toString();
@@ -162,8 +167,9 @@ public final class Debug {
public static String getDebug(String message, Map<?,?> map) {
StringBuilder result = new StringBuilder();
- if (map == null)
+ if (map == null) {
return getDebug(message + " map: " + null);
+ }
List<Object> keys = new ArrayList<Object>(map.keySet());
result.append(getDebug(message + " map: " + keys.size()) + newline);
@@ -189,8 +195,9 @@ public final class Debug {
private static void log(StringBuilder buffer, String s) {
Debug.debug(s);
- if (buffer != null)
+ if (buffer != null) {
buffer.append(s + newline);
+ }
}
public static boolean compare(String prefix, Map<?, ?> a, Map<?, ?> b, List<?> ignore,
@@ -241,8 +248,9 @@ public final class Debug {
result = false;
}
- if (result)
+ if (result) {
log(buffer, prefix + "a is the same as b");
+ }
return result;
}
@@ -313,32 +321,33 @@ public final class Debug {
}
public static void debug(String message, Object value) {
- if (value == null)
+ if (value == null) {
debug(message, "null");
- else if (value instanceof char[])
+ } else if (value instanceof char[]) {
debug(message, (char[]) value);
- else if (value instanceof byte[])
+ } else if (value instanceof byte[]) {
debug(message, (byte[]) value);
- else if (value instanceof int[])
+ } else if (value instanceof int[]) {
debug(message, (int[]) value);
- else if (value instanceof String)
+ } else if (value instanceof String) {
debug(message, (String) value);
- else if (value instanceof java.util.List)
+ } else if (value instanceof java.util.List) {
debug(message, (java.util.List<?>) value);
- else if (value instanceof Map)
+ } else if (value instanceof Map) {
debug(message, (Map<?, ?>) value);
- // else if (value instanceof Object)
- // debug(message, (Object) value);
- else if (value instanceof ICC_Profile)
+ // } else if (value instanceof Object) {
+ // debug(message, (Object) value);
+ } else if (value instanceof ICC_Profile) {
debug(message, (ICC_Profile) value);
- else if (value instanceof File)
+ } else if (value instanceof File) {
debug(message, (File) value);
- else if (value instanceof Date)
+ } else if (value instanceof Date) {
debug(message, (Date) value);
- else if (value instanceof Calendar)
+ } else if (value instanceof Calendar) {
debug(message, (Calendar) value);
- else
+ } else {
debug(message, value.toString());
+ }
}
public static void debug(String message, Object value[]) {
@@ -358,84 +367,87 @@ public final class Debug {
}
public static String getDebug(String message, Object value) {
- if (value == null)
+ if (value == null) {
return getDebug(message, "null");
- else if (value instanceof Calendar)
+ } else if (value instanceof Calendar) {
return getDebug(message, (Calendar) value);
- else if (value instanceof Date)
+ } else if (value instanceof Date) {
return getDebug(message, (Date) value);
- else if (value instanceof File)
+ } else if (value instanceof File) {
return getDebug(message, (File) value);
- else if (value instanceof ICC_Profile)
+ } else if (value instanceof ICC_Profile) {
return getDebug(message, (ICC_Profile) value);
- else if (value instanceof Map)
+ } else if (value instanceof Map) {
return getDebug(message, (Map<?,?>) value);
- else if (value instanceof Map)
+ } else if (value instanceof Map) {
return getDebug(message, (Map<?,?>) value); //
// else if (value instanceof Object) // getDebug(message, (Object)
// value);
- else if (value instanceof String)
+ } else if (value instanceof String) {
return getDebug(message, (String) value);
- else if (value instanceof byte[])
+ } else if (value instanceof byte[]) {
return getDebug(message, (byte[]) value);
- else if (value instanceof char[])
+ } else if (value instanceof char[]) {
return getDebug(message, (char[]) value);
- else if (value instanceof int[])
+ } else if (value instanceof int[]) {
return getDebug(message, (int[]) value);
- else if (value instanceof java.util.List)
+ } else if (value instanceof java.util.List) {
return getDebug(message, (java.util.List<?>) value);
- else
+ } else {
return getDebug(message, value.toString());
+ }
}
public static String getType(Object value) {
- if (value == null)
+ if (value == null) {
return "null";
- else if (value instanceof Object[])
+ } else if (value instanceof Object[]) {
return "[Object[]: " + ((Object[]) value).length + "]";
- else if (value instanceof char[])
+ } else if (value instanceof char[]) {
return "[char[]: " + ((char[]) value).length + "]";
- else if (value instanceof byte[])
+ } else if (value instanceof byte[]) {
return "[byte[]: " + ((byte[]) value).length + "]";
- else if (value instanceof short[])
+ } else if (value instanceof short[]) {
return "[short[]: " + ((short[]) value).length + "]";
- else if (value instanceof int[])
+ } else if (value instanceof int[]) {
return "[int[]: " + ((int[]) value).length + "]";
- else if (value instanceof long[])
+ } else if (value instanceof long[]) {
return "[long[]: " + ((long[]) value).length + "]";
- else if (value instanceof float[])
+ } else if (value instanceof float[]) {
return "[float[]: " + ((float[]) value).length + "]";
- else if (value instanceof double[])
+ } else if (value instanceof double[]) {
return "[double[]: " + ((double[]) value).length + "]";
- else if (value instanceof boolean[])
+ } else if (value instanceof boolean[]) {
return "[boolean[]: " + ((boolean[]) value).length + "]";
- else
+ } else {
return value.getClass().getName();
+ }
}
public static boolean isArray(Object value) {
- if (value == null)
+ if (value == null) {
return false;
- else if (value instanceof Object[])
+ } else if (value instanceof Object[]) {
return true;
- else if (value instanceof char[])
+ } else if (value instanceof char[]) {
return true;
- else if (value instanceof byte[])
+ } else if (value instanceof byte[]) {
return true;
- else if (value instanceof short[])
+ } else if (value instanceof short[]) {
return true;
- else if (value instanceof int[])
+ } else if (value instanceof int[]) {
return true;
- else if (value instanceof long[])
+ } else if (value instanceof long[]) {
return true;
- else if (value instanceof float[])
+ } else if (value instanceof float[]) {
return true;
- else if (value instanceof double[])
+ } else if (value instanceof double[]) {
return true;
- else if (value instanceof boolean[])
+ } else if (value instanceof boolean[]) {
return true;
- else
+ } else {
return false;
+ }
}
public static String getDebug(String message, Object value[]) {
@@ -530,8 +542,9 @@ public final class Debug {
String suffix = " [" + counter++ + "]";
debug(message + " (" + v.size() + ")" + suffix);
- for (int i = 0; i < v.size(); i++)
+ for (int i = 0; i < v.size(); i++) {
debug("\t" + v.get(i).toString() + suffix);
+ }
debug();
}
@@ -625,8 +638,9 @@ public final class Debug {
+ ste.getMethodName() + "(" + ste.getFileName()
+ ":" + ste.getLineNumber() + ")" + newline);
}
- if (limit >= 0 && stes.length > limit)
+ if (limit >= 0 && stes.length > limit) {
result.append("\t..." + newline);
+ }
}
// e.printStackTrace(System.out);
@@ -658,12 +672,13 @@ public final class Debug {
public static void debugIPQuad(String message, byte bytes[]) {
System.out.print(message + ": ");
- if (bytes == null)
+ if (bytes == null) {
System.out.print("null");
- else {
+ } else {
for (int i = 0; i < bytes.length; i++) {
- if (i > 0)
+ if (i > 0) {
System.out.print(".");
+ }
System.out.print(0xff & bytes[i]);
}
}
@@ -681,10 +696,12 @@ public final class Debug {
s_ar1 = "" + aspect_ratio;
s_ar2 = "" + aspect_ratio2;
- if (s_ar1.length() > 7)
+ if (s_ar1.length() > 7) {
s_ar1 = s_ar1.substring(0, 7);
- if (s_ar2.length() > 7)
+ }
+ if (s_ar2.length() > 7) {
s_ar2 = s_ar2.substring(0, 7);
+ }
}
return (prefix + ": "
@@ -707,10 +724,12 @@ public final class Debug {
s_ar1 = "" + aspect_ratio;
s_ar2 = "" + aspect_ratio2;
- if (s_ar1.length() > 7)
+ if (s_ar1.length() > 7) {
s_ar1 = s_ar1.substring(0, 7);
- if (s_ar2.length() > 7)
+ }
+ if (s_ar2.length() > 7) {
s_ar2 = s_ar2.substring(0, 7);
+ }
}
return (prefix
@@ -725,51 +744,59 @@ public final class Debug {
}
public static void dump(String prefix, Object value) {
- if (value == null)
+ if (value == null) {
debug(prefix, "null");
- else if (value instanceof Object[]) {
+ } else if (value instanceof Object[]) {
Object[] array = (Object[]) value;
debug(prefix, array);
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
dump(prefix + "\t" + i + ": ", array[i]);
+ }
} else if (value instanceof int[]) {
int[] array = (int[]) value;
debug(prefix, array);
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
debug(prefix + "\t" + i + ": ", array[i]);
+ }
} else if (value instanceof char[]) {
char[] array = (char[]) value;
debug(prefix, "[" + new String(array) + "]");
} else if (value instanceof long[]) {
long[] array = (long[]) value;
debug(prefix, array);
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
debug(prefix + "\t" + i + ": ", array[i]);
+ }
} else if (value instanceof boolean[]) {
boolean[] array = (boolean[]) value;
debug(prefix, array);
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
debug(prefix + "\t" + i + ": ", array[i]);
+ }
} else if (value instanceof byte[]) {
byte[] array = (byte[]) value;
debug(prefix, array);
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
debug(prefix + "\t" + i + ": ", array[i]);
+ }
} else if (value instanceof float[]) {
float[] array = (float[]) value;
debug(prefix, array);
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
debug(prefix + "\t" + i + ": ", array[i]);
+ }
} else if (value instanceof double[]) {
double[] array = (double[]) value;
debug(prefix, array);
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
debug(prefix + "\t" + i + ": ", array[i]);
+ }
} else if (value instanceof java.util.List) {
java.util.List<?> list = (java.util.List<?>) value;
debug(prefix, "list");
- for (int i = 0; i < list.size(); i++)
+ for (int i = 0; i < list.size(); i++) {
dump(prefix + "\t" + "list: " + i + ": ", list.get(i));
+ }
} else if (value instanceof Map) {
java.util.Map map = (java.util.Map) value;
debug(prefix, "map");
@@ -779,10 +806,9 @@ public final class Debug {
Object key = keys.get(i);
dump(prefix + "\t" + "map: " + key + " -> ", map.get(key));
}
- }
- // else if (value instanceof String)
- // debug(prefix, value);
- else {
+ // } else if (value instanceof String) {
+ // debug(prefix, value);
+ } else {
debug(prefix, value.toString());
debug(prefix + "\t", value.getClass().getName());
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/IoUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/IoUtils.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/IoUtils.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/IoUtils.java Thu Sep 27 18:22:37 2012
@@ -65,8 +65,9 @@ public class IoUtils implements ImagingC
return os.toByteArray();
} finally {
try {
- if (os != null)
+ if (os != null) {
os.close();
+ }
} catch (IOException e) {
Debug.debug(e);
}
@@ -91,8 +92,9 @@ public class IoUtils implements ImagingC
return getInputStreamBytes(is);
} finally {
try {
- if (is != null)
+ if (is != null) {
is.close();
+ }
} catch (IOException e) {
Debug.debug(e);
}
@@ -108,8 +110,9 @@ public class IoUtils implements ImagingC
putInputStreamToFile(stream, file);
} finally {
try {
- if (stream != null)
+ if (stream != null) {
stream.close();
+ }
} catch (Exception e) {
Debug.debug(e);
@@ -132,8 +135,9 @@ public class IoUtils implements ImagingC
copyStreamToStream(src, stream);
} finally {
try {
- if (stream != null)
+ if (stream != null) {
stream.close();
+ }
} catch (Exception e) {
Debug.debug(e);
}
@@ -156,21 +160,23 @@ public class IoUtils implements ImagingC
int count;
byte[] buffer = new byte[4096];
- while ((count = bis.read(buffer, 0, buffer.length)) > 0)
+ while ((count = bis.read(buffer, 0, buffer.length)) > 0) {
dst.write(buffer, 0, count);
-
+ }
bos.flush();
} finally {
if (close_streams) {
try {
- if (bis != null)
+ if (bis != null) {
bis.close();
+ }
} catch (IOException e) {
Debug.debug(e);
}
try {
- if (bos != null)
+ if (bos != null) {
bos.close();
+ }
} catch (IOException e) {
Debug.debug(e);
}
@@ -212,18 +218,19 @@ public class IoUtils implements ImagingC
return true;
} finally {
try {
- if (srcChannel != null)
+ if (srcChannel != null) {
srcChannel.close();
+ }
} catch (IOException e) {
Debug.debug(e);
}
try {
- if (dstChannel != null)
+ if (dstChannel != null) {
dstChannel.close();
+ }
} catch (IOException e) {
Debug.debug(e);
-
}
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/ParamMap.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/ParamMap.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/ParamMap.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/ParamMap.java Thu Sep 27 18:22:37 2012
@@ -24,10 +24,9 @@ public class ParamMap {
public static boolean getParamBoolean(Map params, Object key,
boolean default_value) {
boolean result = default_value;
- {
- Object o = params == null ? null : params.get(key);
- if (o != null && o instanceof Boolean)
- result = ((Boolean) o).booleanValue();
+ Object o = params == null ? null : params.get(key);
+ if (o != null && o instanceof Boolean) {
+ result = ((Boolean) o).booleanValue();
}
return result;
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/UnicodeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/UnicodeUtils.java?rev=1391156&r1=1391155&r2=1391156&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/UnicodeUtils.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/util/UnicodeUtils.java Thu Sep 27 18:22:37 2012
@@ -174,8 +174,9 @@ public abstract class UnicodeUtils imple
for (int i = index; i < bytes.length - 1; i += 2) {
int c1 = 0xff & bytes[index];
int c2 = 0xff & bytes[index + 1];
- if (c1 == 0 && c2 == 0)
+ if (c1 == 0 && c2 == 0) {
return i;
+ }
}
return -1;
}
@@ -220,8 +221,9 @@ public abstract class UnicodeUtils imple
public int findEnd(byte bytes[], int index, boolean includeTerminator)
throws UnicodeException {
for (int i = index; i < bytes.length; i++) {
- if (bytes[i] == 0)
+ if (bytes[i] == 0) {
return includeTerminator ? i + 1 : i;
+ }
}
return bytes.length;
// throw new UnicodeException("Terminator not found.");
@@ -251,48 +253,57 @@ public abstract class UnicodeUtils imple
// http://en.wikipedia.org/wiki/UTF-8
while (true) {
- if (index == bytes.length)
+ if (index == bytes.length) {
return bytes.length;
- if (index > bytes.length)
+ }
+ if (index > bytes.length) {
throw new UnicodeException("Terminator not found.");
+ }
int c1 = 0xff & bytes[index++];
- if (c1 == 0)
+ if (c1 == 0) {
return includeTerminator ? index : index - 1;
- else if (c1 <= 0x7f)
+ } else if (c1 <= 0x7f) {
continue;
- else if (c1 <= 0xDF) {
- if (index >= bytes.length)
+ } else if (c1 <= 0xDF) {
+ if (index >= bytes.length) {
throw new UnicodeException("Invalid unicode.");
-
+ }
int c2 = 0xff & bytes[index++];
- if (c2 < 0x80 || c2 > 0xBF)
+ if (c2 < 0x80 || c2 > 0xBF) {
throw new UnicodeException("Invalid code point.");
+ }
} else if (c1 <= 0xEF) {
- if (index >= bytes.length - 1)
+ if (index >= bytes.length - 1) {
throw new UnicodeException("Invalid unicode.");
-
+ }
int c2 = 0xff & bytes[index++];
- if (c2 < 0x80 || c2 > 0xBF)
+ if (c2 < 0x80 || c2 > 0xBF) {
throw new UnicodeException("Invalid code point.");
+ }
int c3 = 0xff & bytes[index++];
- if (c3 < 0x80 || c3 > 0xBF)
+ if (c3 < 0x80 || c3 > 0xBF) {
throw new UnicodeException("Invalid code point.");
+ }
} else if (c1 <= 0xF4) {
- if (index >= bytes.length - 2)
+ if (index >= bytes.length - 2) {
throw new UnicodeException("Invalid unicode.");
-
+ }
int c2 = 0xff & bytes[index++];
- if (c2 < 0x80 || c2 > 0xBF)
+ if (c2 < 0x80 || c2 > 0xBF) {
throw new UnicodeException("Invalid code point.");
+ }
int c3 = 0xff & bytes[index++];
- if (c3 < 0x80 || c3 > 0xBF)
+ if (c3 < 0x80 || c3 > 0xBF) {
throw new UnicodeException("Invalid code point.");
+ }
int c4 = 0xff & bytes[index++];
- if (c4 < 0x80 || c4 > 0xBF)
+ if (c4 < 0x80 || c4 > 0xBF) {
throw new UnicodeException("Invalid code point.");
- } else
+ }
+ } else {
throw new UnicodeException("Invalid code point.");
+ }
}
}
}
@@ -359,10 +370,12 @@ public abstract class UnicodeUtils imple
// http://en.wikipedia.org/wiki/UTF-16/UCS-2
while (true) {
- if (index == bytes.length)
+ if (index == bytes.length) {
return bytes.length;
- if (index > bytes.length - 1)
+ }
+ if (index > bytes.length - 1) {
throw new UnicodeException("Terminator not found.");
+ }
int c1 = 0xff & bytes[index++];
int c2 = 0xff & bytes[index++];
@@ -371,15 +384,16 @@ public abstract class UnicodeUtils imple
if (c1 == 0 && c2 == 0) {
return includeTerminator ? index : index - 2;
} else if (msb1 >= 0xD8) {
- if (index > bytes.length - 1)
+ if (index > bytes.length - 1) {
throw new UnicodeException("Terminator not found.");
-
+ }
// second word.
int c3 = 0xff & bytes[index++];
int c4 = 0xff & bytes[index++];
int msb2 = byteOrder == BYTE_ORDER_BIG_ENDIAN ? c3 : c4;
- if (msb2 < 0xDC)
+ if (msb2 < 0xDC) {
throw new UnicodeException("Invalid code point.");
+ }
}
}
}
@@ -404,17 +418,19 @@ public abstract class UnicodeUtils imple
throws UnicodeException {
// http://en.wikipedia.org/wiki/UTF-16/UCS-2
- if (index >= bytes.length - 1)
+ if (index >= bytes.length - 1) {
throw new UnicodeException("Missing BOM.");
+ }
int c1 = 0xff & bytes[index++];
int c2 = 0xff & bytes[index++];
- if (c1 == 0xFF && c2 == 0xFE)
+ if (c1 == 0xFF && c2 == 0xFE) {
byteOrder = BYTE_ORDER_LITTLE_ENDIAN;
- else if (c1 == 0xFE && c2 == 0xFF)
+ } else if (c1 == 0xFE && c2 == 0xFF) {
byteOrder = BYTE_ORDER_BIG_ENDIAN;
- else
+ } else {
throw new UnicodeException("Invalid byte order mark.");
+ }
return super.findEnd(bytes, index, includeTerminator);
}