Damjan is working it today folks! :) Gary
On Wed, Sep 26, 2012 at 4:39 PM, <dam...@apache.org> wrote: > Author: damjan > Date: Wed Sep 26 20:39:16 2012 > New Revision: 1390721 > > URL: http://svn.apache.org/viewvc?rev=1390721&view=rev > Log: > Start adding braces everywhere. > > > Modified: > commons/proper/imaging/trunk/checkstyle.xml > > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java > > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java > > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageFormat.java > > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageParser.java > > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/Imaging.java > > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/color/ColorConversions.java > > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java > > Modified: commons/proper/imaging/trunk/checkstyle.xml > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/checkstyle.xml?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- commons/proper/imaging/trunk/checkstyle.xml (original) > +++ commons/proper/imaging/trunk/checkstyle.xml Wed Sep 26 20:39:16 2012 > @@ -35,6 +35,7 @@ limitations under the License. > <module name="AvoidStarImport"/> > <module name="RedundantImport"/> > <module name="UnusedImports"/> > + <module name="NeedBraces"/> > </module> > </module> > > > Modified: > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java > (original) > +++ > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java > Wed Sep 26 20:39:16 2012 > @@ -43,8 +43,9 @@ public class ColorTools { > public BufferedImage correctImage(BufferedImage src, File file) > throws ImageReadException, IOException { > ICC_Profile icc = Imaging.getICCProfile(file); > - if (icc == null) > + if (icc == null) { > return src; > + } > > ICC_ColorSpace cs = new ICC_ColorSpace(icc); > > @@ -104,13 +105,14 @@ public class ColorTools { > if (old_cm instanceof ComponentColorModel) { > ComponentColorModel ccm = (ComponentColorModel) old_cm; > // ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); > - if (force_no_alpha) > + if (force_no_alpha) { > return new ComponentColorModel(cs, false, false, > ComponentColorModel.OPAQUE, > ccm.getTransferType()); > - else > + } else { > return new ComponentColorModel(cs, ccm.hasAlpha(), > ccm.isAlphaPremultiplied(), ccm.getTransparency(), > ccm.getTransferType()); > + } > } else if (old_cm instanceof DirectColorModel) { > DirectColorModel dcm = (DirectColorModel) old_cm; > > > Modified: > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java > (original) > +++ > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java > Wed Sep 26 20:39:16 2012 > @@ -48,8 +48,9 @@ public class FormatCompliance { > > public void addComment(String s) throws ImageReadException { > comments.add(s); > - if (failOnError) > + if (failOnError) { > throw new ImageReadException(s); > + } > } > > public void addComment(String s, int value) throws ImageReadException > { > @@ -73,11 +74,12 @@ public class FormatCompliance { > public void dump(PrintWriter pw) { > pw.println("Format Compliance: " + description); > > - if (comments.size() == 0) > + if (comments.size() == 0) { > pw.println("\t" + "No comments."); > - else { > - for (int i = 0; i < comments.size(); i++) > + } else { > + for (int i = 0; i < comments.size(); i++) { > pw.println("\t" + (i + 1) + ": " + comments.get(i)); > + } > } > pw.println(""); > pw.flush(); > @@ -128,21 +130,26 @@ public class FormatCompliance { > > public boolean compare(String name, int valid[], int actual) > throws ImageReadException { > - for (int i = 0; i < valid.length; i++) > - if (actual == valid[i]) > + for (int i = 0; i < valid.length; i++) { > + if (actual == valid[i]) { > return true; > + } > + } > > StringBuilder result = new StringBuilder(); > result.append(name + ": " + "Unexpected value: (valid: "); > - if (valid.length > 1) > + if (valid.length > 1) { > result.append("{"); > + } > for (int i = 0; i < valid.length; i++) { > - if (i > 0) > + if (i > 0) { > result.append(", "); > + } > result.append(getValueDescription(valid[i])); > } > - if (valid.length > 1) > + if (valid.length > 1) { > result.append("}"); > + } > result.append(", actual: " + getValueDescription(actual) + ")"); > addComment(result.toString()); > return false; > > Modified: > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageFormat.java > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageFormat.java?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageFormat.java > (original) > +++ > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageFormat.java > Wed Sep 26 20:39:16 2012 > @@ -38,8 +38,9 @@ public class ImageFormat { > > @Override > public boolean equals(Object o) { > - if (!(o instanceof ImageFormat)) > + if (!(o instanceof ImageFormat)) { > return false; > + } > > ImageFormat other = (ImageFormat) o; > > > Modified: > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageParser.java > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageParser.java?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageParser.java > (original) > +++ > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ImageParser.java > Wed Sep 26 20:39:16 2012 > @@ -250,12 +250,14 @@ public abstract class ImageParser extend > */ > public final IImageMetadata getMetadata(File file, Map params) > throws ImageReadException, IOException { > - if (debug) > + if (debug) { > System.out.println(getName() + ".getMetadata" + ": " > + file.getName()); > + } > > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > return getMetadata(new ByteSourceFile(file), params); > } > @@ -364,8 +366,9 @@ public abstract class ImageParser extend > */ > public final ImageInfo getImageInfo(File file, Map params) > throws ImageReadException, IOException { > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > return getImageInfo(new ByteSourceFile(file), params); > } > @@ -414,8 +417,9 @@ public abstract class ImageParser extend > */ > public final FormatCompliance getFormatCompliance(File file) > throws ImageReadException, IOException { > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > return getFormatCompliance(new ByteSourceFile(file)); > } > @@ -471,8 +475,9 @@ public abstract class ImageParser extend > */ > public final List<BufferedImage> getAllBufferedImages(File file) > throws ImageReadException, IOException { > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > return getAllBufferedImages(new ByteSourceFile(file)); > } > @@ -533,8 +538,9 @@ public abstract class ImageParser extend > */ > public final BufferedImage getBufferedImage(File file, Map params) > throws ImageReadException, IOException { > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > return getBufferedImage(new ByteSourceFile(file), params); > } > @@ -635,8 +641,9 @@ public abstract class ImageParser extend > public final Dimension getImageSize(File file, Map params) > throws ImageReadException, IOException { > > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > return getImageSize(new ByteSourceFile(file), params); > } > @@ -748,11 +755,13 @@ public abstract class ImageParser extend > */ > public final byte[] getICCProfileBytes(File file, Map params) > throws ImageReadException, IOException { > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > - if (debug) > + if (debug) { > System.out.println(getName() + ": " + file.getName()); > + } > > return getICCProfileBytes(new ByteSourceFile(file), params); > } > @@ -806,11 +815,13 @@ public abstract class ImageParser extend > */ > public final String dumpImageFile(File file) throws > ImageReadException, > IOException { > - if (!canAcceptExtension(file)) > + if (!canAcceptExtension(file)) { > return null; > + } > > - if (debug) > + if (debug) { > System.out.println(getName() + ": " + file.getName()); > + } > > return dumpImageFile(new ByteSourceFile(file)); > } > @@ -903,9 +914,11 @@ public abstract class ImageParser extend > public boolean canAcceptType(ImageFormat type) { > ImageFormat types[] = getAcceptedTypes(); > > - for (int i = 0; i < types.length; i++) > - if (types[i].equals(type)) > + for (int i = 0; i < types.length; i++) { > + if (types[i].equals(type)) { > return true; > + } > + } > return false; > } > > @@ -927,17 +940,20 @@ public abstract class ImageParser extend > */ > protected final boolean canAcceptExtension(String filename) { > String exts[] = getAcceptedExtensions(); > - if (exts == null) > + if (exts == null) { > return true; > + } > > int index = filename.lastIndexOf('.'); > if (index >= 0) { > String ext = filename.substring(index); > ext = ext.toLowerCase(); > > - for (int i = 0; i < exts.length; i++) > - if (exts[i].toLowerCase().equals(ext)) > + for (int i = 0; i < exts.length; i++) { > + if (exts[i].toLowerCase().equals(ext)) { > return true; > + } > + } > } > return false; > } > @@ -952,14 +968,16 @@ public abstract class ImageParser extend > * IBufferedImageFactory. > */ > protected IBufferedImageFactory getBufferedImageFactory(Map params) { > - if (params == null) > + if (params == null) { > return new SimpleBufferedImageFactory(); > + } > > IBufferedImageFactory result = (IBufferedImageFactory) params > .get(ImagingConstants.BUFFERED_IMAGE_FACTORY); > > - if (null != result) > + if (null != result) { > return result; > + } > > return new SimpleBufferedImageFactory(); > } > @@ -974,8 +992,9 @@ public abstract class ImageParser extend > * otherwise, false. > */ > public static final boolean isStrict(Map params) { > - if (params == null || !params.containsKey(PARAM_KEY_STRICT)) > + if (params == null || !params.containsKey(PARAM_KEY_STRICT)) { > return false; > + } > return ((Boolean) params.get(PARAM_KEY_STRICT)).booleanValue(); > } > } > > Modified: > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/Imaging.java > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/Imaging.java?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/Imaging.java > (original) > +++ > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/Imaging.java > Wed Sep 26 20:39:16 2012 > @@ -96,8 +96,9 @@ public abstract class Imaging implements > * format file extension; otherwise, false. > */ > public static boolean hasImageFileExtension(File file) { > - if (file==null || !file.isFile()) > + if (file==null || !file.isFile()) { > return false; > + } > return hasImageFileExtension(file.getName()); > } > > @@ -111,8 +112,9 @@ public abstract class Imaging implements > * @return true if the filename has an image format file extension. > */ > public static boolean hasImageFileExtension(String filename) { > - if(filename==null) > + if(filename==null) { > return false; > + } > > filename = filename.toLowerCase(); > > @@ -123,8 +125,9 @@ public abstract class Imaging implements > > for (int j = 0; j < exts.length; j++) { > String ext = exts[j]; > - if (filename.endsWith(ext.toLowerCase())) > + if (filename.endsWith(ext.toLowerCase())) { > return true; > + } > } > } > > @@ -220,8 +223,9 @@ public abstract class Imaging implements > public static ImageFormat guessFormat(ByteSource byteSource) > throws ImageReadException, IOException { > > - if(byteSource==null) > + if (byteSource==null) { > return ImageFormat.IMAGE_FORMAT_UNKNOWN; > + } > > InputStream is = null; > > @@ -230,9 +234,10 @@ public abstract class Imaging implements > > int i1 = is.read(); > int i2 = is.read(); > - if ((i1 < 0) || (i2 < 0)) > + if ((i1 < 0) || (i2 < 0)) { > throw new ImageReadException( > "Couldn't read magic numbers to guess format."); > + } > > int b1 = i1 & 0xff; > int b2 = i2 & 0xff; > @@ -272,9 +277,10 @@ public abstract class Imaging implements > } else if (compareBytePair(MAGIC_NUMBERS_JBIG2_1, bytePair)) { > int i3 = is.read(); > int i4 = is.read(); > - if ((i3 < 0) || (i4 < 0)) > + if ((i3 < 0) || (i4 < 0)) { > throw new ImageReadException( > "Couldn't read magic numbers to guess > format."); > + } > > int b3 = i3 & 0xff; > int b4 = i4 & 0xff; > @@ -407,15 +413,18 @@ public abstract class Imaging implements > protected static ICC_Profile getICCProfile(ByteSource byteSource, Map > params) > throws ImageReadException, IOException { > byte bytes[] = getICCProfileBytes(byteSource, params); > - if (bytes == null) > + if (bytes == null) { > return null; > + } > > IccProfileParser parser = new IccProfileParser(); > IccProfileInfo info = parser.getICCProfileInfo(bytes); > - if (info == null) > + if (info == null) { > return null; > - if (info.issRGB()) > + } > + if (info.issRGB()) { > return null; > + } > > ICC_Profile icc = ICC_Profile.getInstance(bytes); > return icc; > @@ -695,8 +704,9 @@ public abstract class Imaging implements > for (int i = 0; i < imageParsers.length; i++) { > ImageParser imageParser = imageParsers[i]; > > - if (imageParser.canAcceptType(format)) > + if (imageParser.canAcceptType(format)) { > return imageParser; > + } > } > } > > @@ -707,8 +717,9 @@ public abstract class Imaging implements > for (int i = 0; i < imageParsers.length; i++) { > ImageParser imageParser = imageParsers[i]; > > - if (imageParser.canAcceptExtension(filename)) > + if (imageParser.canAcceptExtension(filename)) { > return imageParser; > + } > } > } > > @@ -1249,8 +1260,9 @@ public abstract class Imaging implements > public static BufferedImage getBufferedImage(InputStream is, Map > params) > throws ImageReadException, IOException { > String filename = null; > - if (params != null && params.containsKey(PARAM_KEY_FILENAME)) > + if (params != null && params.containsKey(PARAM_KEY_FILENAME)) { > filename = (String) params.get(PARAM_KEY_FILENAME); > + } > return getBufferedImage(new ByteSourceInputStream(is, filename), > params); > } > > @@ -1353,8 +1365,9 @@ public abstract class Imaging implements > private static BufferedImage getBufferedImage(ByteSource byteSource, > Map params) throws ImageReadException, IOException { > ImageParser imageParser = getImageParser(byteSource); > - if (null == params) > + if (null == params) { > params = new HashMap(); > + } > > return imageParser.getBufferedImage(byteSource, params); > } > @@ -1394,8 +1407,9 @@ public abstract class Imaging implements > writeImage(src, os, format, params); > } finally { > try { > - if (os != null) > + if (os != null) { > os.close(); > + } > } catch (Exception e) { > Debug.debug(e); > } > @@ -1466,16 +1480,18 @@ public abstract class Imaging implements > ImageParser imageParsers[] = ImageParser.getAllImageParsers(); > > // make sure params are non-null > - if (params == null) > + if (params == null) { > params = new HashMap(); > + } > > params.put(PARAM_KEY_FORMAT, format); > > for (int i = 0; i < imageParsers.length; i++) { > ImageParser imageParser = imageParsers[i]; > > - if (!imageParser.canAcceptType(format)) > + if (!imageParser.canAcceptType(format)) { > continue; > + } > > imageParser.writeImage(src, os, params); > return; > > Modified: > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/color/ColorConversions.java > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/color/ColorConversions.java?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/color/ColorConversions.java > (original) > +++ > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/color/ColorConversions.java > Wed Sep 26 20:39:16 2012 > @@ -34,18 +34,21 @@ public abstract class ColorConversions { > double var_Y = Y / ref_Y; // ref_Y = 100.000 > double var_Z = Z / ref_Z; // ref_Z = 108.883 > > - if (var_X > 0.008856) > + if (var_X > 0.008856) { > var_X = Math.pow(var_X, (1 / 3.0)); > - else > + } else { > var_X = (7.787 * var_X) + (16 / 116.0); > - if (var_Y > 0.008856) > + } > + if (var_Y > 0.008856) { > var_Y = Math.pow(var_Y, 1 / 3.0); > - else > + } else { > var_Y = (7.787 * var_Y) + (16 / 116.0); > - if (var_Z > 0.008856) > + } > + if (var_Z > 0.008856) { > var_Z = Math.pow(var_Z, 1 / 3.0); > - else > + } else { > var_Z = (7.787 * var_Z) + (16 / 116.0); > + } > > double L = (116 * var_Y) - 16; > double a = 500 * (var_X - var_Y); > @@ -62,18 +65,21 @@ public abstract class ColorConversions { > double var_X = a / 500 + var_Y; > double var_Z = var_Y - b / 200.0; > > - if (Math.pow(var_Y, 3) > 0.008856) > + if (Math.pow(var_Y, 3) > 0.008856) { > var_Y = Math.pow(var_Y, 3); > - else > + } else { > var_Y = (var_Y - 16 / 116.0) / 7.787; > - if (Math.pow(var_X, 3) > 0.008856) > + } > + if (Math.pow(var_X, 3) > 0.008856) { > var_X = Math.pow(var_X, 3); > - else > + } else { > var_X = (var_X - 16 / 116.0) / 7.787; > - if (Math.pow(var_Z, 3) > 0.008856) > + } > + if (Math.pow(var_Z, 3) > 0.008856) { > var_Z = Math.pow(var_Z, 3); > - else > + } else { > var_Z = (var_Z - 16 / 116.0) / 7.787; > + } > > double X = ref_X * var_X; // ref_X = 95.047 Observer= 2°, > Illuminant= > // D65 > @@ -127,18 +133,21 @@ public abstract class ColorConversions { > double var_G = var_X * -0.9689 + var_Y * 1.8758 + var_Z * 0.0415; > double var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * 1.0570; > > - if (var_R > 0.0031308) > + if (var_R > 0.0031308) { > var_R = 1.055 * Math.pow(var_R, (1 / 2.4)) - 0.055; > - else > + } else { > var_R = 12.92 * var_R; > - if (var_G > 0.0031308) > + } > + if (var_G > 0.0031308) { > var_G = 1.055 * Math.pow(var_G, (1 / 2.4)) - 0.055; > - else > + } else { > var_G = 12.92 * var_G; > - if (var_B > 0.0031308) > + } > + if (var_B > 0.0031308) { > var_B = 1.055 * Math.pow(var_B, (1 / 2.4)) - 0.055; > - else > + } else { > var_B = 12.92 * var_B; > + } > > double R = (var_R * 255); > double G = (var_G * 255); > @@ -156,18 +165,21 @@ public abstract class ColorConversions { > double var_G = g / 255.0; // Where G = 0 ÷ 255 > double var_B = b / 255.0; // Where B = 0 ÷ 255 > > - if (var_R > 0.04045) > + if (var_R > 0.04045) { > var_R = Math.pow((var_R + 0.055) / 1.055, 2.4); > - else > + } else { > var_R = var_R / 12.92; > - if (var_G > 0.04045) > + } > + if (var_G > 0.04045) { > var_G = Math.pow((var_G + 0.055) / 1.055, 2.4); > - else > + } else { > var_G = var_G / 12.92; > - if (var_B > 0.04045) > + } > + if (var_B > 0.04045) { > var_B = Math.pow((var_B + 0.055) / 1.055, 2.4); > - else > + } else { > var_B = var_B / 12.92; > + } > > var_R = var_R * 100; > var_G = var_G * 100; > @@ -222,12 +234,15 @@ public abstract class ColorConversions { > > double var_K = 1.0; > > - if (C < var_K) > + if (C < var_K) { > var_K = C; > - if (M < var_K) > + } > + if (M < var_K) { > var_K = M; > - if (Y < var_K) > + } > + if (Y < var_K) { > var_K = Y; > + } > if (var_K == 1) { // Black > C = 0; > M = 0; > @@ -296,19 +311,21 @@ public abstract class ColorConversions { > > double H, S; > // Debug.debug("del_Max", del_Max); > - if (del_Max == 0) // This is a gray, no chroma... > - { > + if (del_Max == 0) { > + // This is a gray, no chroma... > + > H = 0; // HSL results = 0 ÷ 1 > S = 0; > - } else > + } else { > // Chromatic data... > - { > + > // Debug.debug("L", L); > > - if (L < 0.5) > + if (L < 0.5) { > S = del_Max / (var_Max + var_Min); > - else > + } else { > S = del_Max / (2 - var_Max - var_Min); > + } > > // Debug.debug("S", S); > > @@ -316,19 +333,22 @@ public abstract class ColorConversions { > double del_G = (((var_Max - var_G) / 6) + (del_Max / 2)) / > del_Max; > double del_B = (((var_Max - var_B) / 6) + (del_Max / 2)) / > del_Max; > > - if (maxIsR) > + if (maxIsR) { > H = del_B - del_G; > - else if (maxIsG) > + } else if (maxIsG) { > H = (1 / 3.0) + del_R - del_B; > - else > + } else { > H = (2 / 3.0) + del_G - del_R; > + } > > // Debug.debug("H1", H); > > - if (H < 0) > + if (H < 0) { > H += 1; > - if (H > 1) > + } > + if (H > 1) { > H -= 1; > + } > > // Debug.debug("H2", H); > } > @@ -343,18 +363,19 @@ public abstract class ColorConversions { > public static int convertHSLtoRGB(double H, double S, double L) { > double R, G, B; > > - if (S == 0) // HSL values = 0 ÷ 1 > - { > + if (S == 0) { > + // HSL values = 0 ÷ 1 > R = L * 255; // RGB results = 0 ÷ 255 > G = L * 255; > B = L * 255; > } else { > double var_2; > > - if (L < 0.5) > + if (L < 0.5) { > var_2 = L * (1 + S); > - else > + } else { > var_2 = (L + S) - (S * L); > + } > > double var_1 = 2 * L - var_2; > > @@ -366,19 +387,22 @@ public abstract class ColorConversions { > return convertRGBtoRGB(R, G, B); > } > > - private static double convertHuetoRGB(double v1, double v2, double > vH) // Function > - > // Hue_2_RGB > - { > - if (vH < 0) > + private static double convertHuetoRGB(double v1, double v2, double > vH) { > + if (vH < 0) { > vH += 1; > - if (vH > 1) > + } > + if (vH > 1) { > vH -= 1; > - if ((6 * vH) < 1) > + } > + if ((6 * vH) < 1) { > return (v1 + (v2 - v1) * 6 * vH); > - if ((2 * vH) < 1) > + } > + if ((2 * vH) < 1) { > return (v2); > - if ((3 * vH) < 2) > + } > + if ((3 * vH) < 2) { > return (v1 + (v2 - v1) * ((2 / 3.0) - vH) * 6); > + } > return (v1); > } > > @@ -410,30 +434,32 @@ public abstract class ColorConversions { > double V = var_Max; > > double H, S; > - if (del_Max == 0) // This is a gray, no chroma... > - { > + if (del_Max == 0) { > + // This is a gray, no chroma... > H = 0; // HSV results = 0 ÷ 1 > S = 0; > - } else > + } else { > // Chromatic data... > - { > S = del_Max / var_Max; > > double del_R = (((var_Max - var_R) / 6) + (del_Max / 2)) / > del_Max; > double del_G = (((var_Max - var_G) / 6) + (del_Max / 2)) / > del_Max; > double del_B = (((var_Max - var_B) / 6) + (del_Max / 2)) / > del_Max; > > - if (maxIsR) > + if (maxIsR) { > H = del_B - del_G; > - else if (maxIsG) > + } else if (maxIsG) { > H = (1 / 3.0) + del_R - del_B; > - else > + } else { > H = (2 / 3.0) + del_G - del_R; > + } > > - if (H < 0) > + if (H < 0) { > H += 1; > - if (H > 1) > + } > + if (H > 1) { > H -= 1; > + } > } > > return new ColorHsv(H, S, V); > @@ -446,15 +472,16 @@ public abstract class ColorConversions { > public static int convertHSVtoRGB(double H, double S, double V) { > double R, G, B; > > - if (S == 0) // HSV values = 0 ÷ 1 > - { > + if (S == 0) { > + // HSV values = 0 ÷ 1 > R = V * 255; > G = V * 255; > B = V * 255; > } else { > double var_h = H * 6; > - if (var_h == 6) > + if (var_h == 6) { > var_h = 0; // H must be < 1 > + } > double var_i = Math.floor(var_h); // Or ... var_i = floor( > var_h ) > double var_1 = V * (1 - S); > double var_2 = V * (1 - S * (var_h - var_i)); > @@ -497,9 +524,7 @@ public abstract class ColorConversions { > } > > public static final int convertCMYKtoRGB_Adobe(int sc, int sm, int sy, > - int sk) > - // throws ImageReadException, IOException > - { > + int sk) { > int red = 255 - (sc + sk); > int green = 255 - (sm + sk); > int blue = 255 - (sy + sk); > @@ -528,20 +553,23 @@ public abstract class ColorConversions { > double var_y_cube = cube(var_Y); > double var_z_cube = cube(var_Z); > > - if (var_y_cube > 0.008856) > + if (var_y_cube > 0.008856) { > var_Y = var_y_cube; > - else > + } else { > var_Y = (var_Y - 16 / 116.0) / 7.787; > + } > > - if (var_x_cube > 0.008856) > + if (var_x_cube > 0.008856) { > var_X = var_x_cube; > - else > + } else { > var_X = (var_X - 16 / 116.0) / 7.787; > + } > > - if (var_z_cube > 0.008856) > + if (var_z_cube > 0.008856) { > var_Z = var_z_cube; > - else > + } else { > var_Z = (var_Z - 16 / 116.0) / 7.787; > + } > > // double ref_X = 95.047; > // double ref_Y = 100.000; > @@ -563,19 +591,22 @@ public abstract class ColorConversions { > double var_G = var_X * -0.9689 + var_Y * 1.8758 + var_Z * > 0.0415; > double var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * > 1.0570; > > - if (var_R > 0.0031308) > + if (var_R > 0.0031308) { > var_R = 1.055 * Math.pow(var_R, (1 / 2.4)) - 0.055; > - else > + } else { > var_R = 12.92 * var_R; > - if (var_G > 0.0031308) > + } > + if (var_G > 0.0031308) { > var_G = 1.055 * Math.pow(var_G, (1 / 2.4)) - 0.055; > - else > + } else { > var_G = 12.92 * var_G; > + } > > - if (var_B > 0.0031308) > + if (var_B > 0.0031308) { > var_B = 1.055 * Math.pow(var_B, (1 / 2.4)) - 0.055; > - else > + } else { > var_B = 12.92 * var_B; > + } > > R = (var_R * 255); > G = (var_G * 255); > @@ -618,10 +649,11 @@ public abstract class ColorConversions { > public static ColorCieLch convertCIELabtoCIELCH(double L, double a, > double b) { > double var_H = Math.atan2(b, a); // Quadrant by signs > > - if (var_H > 0) > + if (var_H > 0) { > var_H = (var_H / Math.PI) * 180.0; > - else > + } else { > var_H = 360 - radian_2_degree(Math.abs(var_H)); > + } > > // L = L; > double C = Math.sqrt(square(a) + square(b)); > @@ -668,10 +700,11 @@ public abstract class ColorConversions { > double var_Y = Y / 100.0; > // Debug.debug("var_Y", var_Y); > > - if (var_Y > 0.008856) > + if (var_Y > 0.008856) { > var_Y = Math.pow(var_Y, (1 / 3.0)); > - else > + } else { > var_Y = (7.787 * var_Y) + (16 / 116.0); > + } > > double ref_X = 95.047; // Observer= 2°, Illuminant= D65 > double ref_Y = 100.000; > @@ -700,10 +733,11 @@ public abstract class ColorConversions { > // problems here with div by zero > > double var_Y = (L + 16) / 116; > - if (Math.pow(var_Y, 3) > 0.008856) > + if (Math.pow(var_Y, 3) > 0.008856) { > var_Y = Math.pow(var_Y, 3); > - else > + } else { > var_Y = (var_Y - 16 / 116) / 7.787; > + } > > double ref_X = 95.047; // Observer= 2°, Illuminant= D65 > double ref_Y = 100.000; > > Modified: > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java > URL: > http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java?rev=1390721&r1=1390720&r2=1390721&view=diff > > ============================================================================== > --- > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java > (original) > +++ > commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java > Wed Sep 26 20:39:16 2012 > @@ -46,20 +46,21 @@ public class BasicCParser { > hadBackSlash = !hadBackSlash; > } else if (c == '"') { > token.append('"'); > - if (!hadBackSlash) > + if (!hadBackSlash) { > return token.toString(); > + } > hadBackSlash = false; > - } else if (c == '\r' || c == '\n') > + } else if (c == '\r' || c == '\n') { > throw new ImageReadException( > "Unterminated string in XPM file"); > - else { > + } else { > token.append((char) c); > hadBackSlash = false; > } > } else if (inIdentifier) { > - if (Character.isLetterOrDigit(c) || c == '_') > + if (Character.isLetterOrDigit(c) || c == '_') { > token.append((char) c); > - else { > + } else { > is.unread(c); > return token.toString(); > } > @@ -76,17 +77,20 @@ public class BasicCParser { > return token.toString(); > } else if (c == ' ' || c == '\t' || c == '\r' || c == > '\n') { > // ignore > - } else > + } else { > throw new ImageReadException( > "Unhandled/invalid character '" + ((char) c) > + "' found in XPM file"); > + } > } > } > > - if (inIdentifier) > + if (inIdentifier) { > return token.toString(); > - if (inString) > + } > + if (inString) { > throw new ImageReadException("Unterminated string ends XMP > file"); > + } > return null; > } > > @@ -105,38 +109,44 @@ public class BasicCParser { > for (int c = is.read(); c != -1; c = is.read()) { > if (inComment) { > if (c == '*') { > - if (hadStar && !seenFirstComment) > + if (hadStar && !seenFirstComment) { > firstComment.append('*'); > + } > hadStar = true; > } else if (c == '/') { > if (hadStar) { > hadStar = false; > inComment = false; > seenFirstComment = true; > - } else > + } else { > out.write(c); > + } > } else { > - if (hadStar && !seenFirstComment) > + if (hadStar && !seenFirstComment) { > firstComment.append('*'); > + } > hadStar = false; > - if (!seenFirstComment) > + if (!seenFirstComment) { > firstComment.append((char) c); > + } > } > } else if (inString) { > if (c == '\\') { > - if (hadBackSlash) > + if (hadBackSlash) { > out.write('\\'); > + } > hadBackSlash = true; > } else if (c == '"') { > if (hadBackSlash) { > out.write('\\'); > hadBackSlash = false; > - } else > + } else { > inString = false; > + } > out.write('"'); > - } else if (c == '\r' || c == '\n') > + } else if (c == '\r' || c == '\n') { > throw new ImageReadException("Unterminated string in > file"); > - else { > + } else { > if (hadBackSlash) { > out.write('\\'); > hadBackSlash = false; > @@ -147,60 +157,73 @@ public class BasicCParser { > if (c == '\r' || c == '\n') { > inDirective = false; > String[] tokens = > tokenizeRow(directiveBuffer.toString()); > - if (tokens.length < 2 || tokens.length > 3) > + if (tokens.length < 2 || tokens.length > 3) { > throw new ImageReadException( > "Bad preprocessor directive"); > - if (!tokens[0].equals("define")) > + } > + if (!tokens[0].equals("define")) { > throw new ImageReadException("Invalid/unsupported > " > + "preprocessor directive '" + tokens[0] > + "'"); > + } > defines.put(tokens[1], (tokens.length == 3) ? > tokens[2] > : null); > directiveBuffer.setLength(0); > - } else > + } else { > directiveBuffer.append((char) c); > + } > } else { > if (c == '/') { > - if (hadSlash) > + if (hadSlash) { > out.write('/'); > + } > hadSlash = true; > } else if (c == '*') { > if (hadSlash) { > inComment = true; > hadSlash = false; > - } else > + } else { > out.write(c); > + } > } else if (c == '"') { > - if (hadSlash) > + if (hadSlash) { > out.write('/'); > + } > hadSlash = false; > out.write(c); > inString = true; > } else if (c == '#') { > - if (defines == null) > + if (defines == null) { > throw new ImageReadException( > "Unexpected preprocessor directive"); > + } > inDirective = true; > } else { > - if (hadSlash) > + if (hadSlash) { > out.write('/'); > + } > hadSlash = false; > out.write(c); > // Only whitespace allowed before first comment: > - if (c != ' ' && c != '\t' && c != '\r' && c != '\n') > + if (c != ' ' && c != '\t' && c != '\r' && c != '\n') { > seenFirstComment = true; > + } > } > } > } > - if (hadSlash) > + if (hadSlash) { > out.write('/'); > - if (hadStar) > + } > + if (hadStar) { > out.write('*'); > - if (inString) > + } > + if (inString) { > throw new ImageReadException( > "Unterminated string at the end of file"); > - if (inComment) > + } > + if (inComment) { > throw new ImageReadException( > "Unterminated comment at the end of file"); > + } > return out; > } > > @@ -208,42 +231,47 @@ public class BasicCParser { > String[] tokens = row.split("[ \t]"); > int numLiveTokens = 0; > for (int i = 0; i < tokens.length; i++) { > - if (tokens[i] != null && tokens[i].length() > 0) > + if (tokens[i] != null && tokens[i].length() > 0) { > ++numLiveTokens; > + } > } > String[] liveTokens = new String[numLiveTokens]; > int next = 0; > for (int i = 0; i < tokens.length; i++) { > - if (tokens[i] != null && tokens[i].length() > 0) > + if (tokens[i] != null && tokens[i].length() > 0) { > liveTokens[next++] = tokens[i]; > + } > } > return liveTokens; > } > > public static void unescapeString(StringBuilder stringBuilder, String > string) > throws ImageReadException { > - if (string.length() < 2) > + if (string.length() < 2) { > throw new ImageReadException("Parsing XPM file failed, " > + "string is too short"); > + } > if (string.charAt(0) != '"' > - || string.charAt(string.length() - 1) != '"') > + || string.charAt(string.length() - 1) != '"') { > throw new ImageReadException("Parsing XPM file failed, " > + "string not surrounded by '\"'"); > + } > boolean hadBackSlash = false; > for (int i = 1; i < (string.length() - 1); i++) { > char c = string.charAt(i); > if (hadBackSlash) { > - if (c == '\\') > + if (c == '\\') { > stringBuilder.append('\\'); > - else if (c == '"') > + } else if (c == '"') { > stringBuilder.append('"'); > - else if (c == '\'') > + } else if (c == '\'') { > stringBuilder.append('\''); > - else if (c == 'x') { > - if (i + 2 >= string.length()) > + } else if (c == 'x') { > + if (i + 2 >= string.length()) { > throw new ImageReadException( > "Parsing XPM file failed, " > + "hex constant in string too > short"); > + } > char hex1 = string.charAt(i + 1); > char hex2 = string.charAt(i + 2); > i += 2; > @@ -260,11 +288,13 @@ public class BasicCParser { > || c == '4' || c == '5' || c == '6' || c == '7') { > int length = 1; > if (i + 1 < string.length() && '0' <= string.charAt(i > + 1) > - && string.charAt(i + 1) <= '7') > + && string.charAt(i + 1) <= '7') { > ++length; > + } > if (i + 2 < string.length() && '0' <= string.charAt(i > + 2) > - && string.charAt(i + 2) <= '7') > + && string.charAt(i + 2) <= '7') { > ++length; > + } > int constant = 0; > for (int j = 0; j < length; j++) { > constant *= 8; > @@ -272,36 +302,39 @@ public class BasicCParser { > } > i += length - 1; > stringBuilder.append((char) constant); > - } else if (c == 'a') > + } else if (c == 'a') { > stringBuilder.append((char) 0x07); > - else if (c == 'b') > + } else if (c == 'b') { > stringBuilder.append((char) 0x08); > - else if (c == 'f') > + } else if (c == 'f') { > stringBuilder.append((char) 0x0c); > - else if (c == 'n') > + } else if (c == 'n') { > stringBuilder.append((char) 0x0a); > - else if (c == 'r') > + } else if (c == 'r') { > stringBuilder.append((char) 0x0d); > - else if (c == 't') > + } else if (c == 't') { > stringBuilder.append((char) 0x09); > - else if (c == 'v') > + } else if (c == 'v') { > stringBuilder.append((char) 0x0b); > - else > + } else { > throw new ImageReadException("Parsing XPM file > failed, " > + "invalid escape sequence"); > + } > hadBackSlash = false; > } else { > - if (c == '\\') > + if (c == '\\') { > hadBackSlash = true; > - else if (c == '"') > + } else if (c == '"') { > throw new ImageReadException("Parsing XPM file > failed, " > + "extra '\"' found in string"); > - else > + } else { > stringBuilder.append(c); > + } > } > } > - if (hadBackSlash) > + if (hadBackSlash) { > throw new ImageReadException("Parsing XPM file failed, " > + "unterminated escape sequence found in string"); > + } > } > } > > > -- E-Mail: garydgreg...@gmail.com | ggreg...@apache.org JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0 Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory