commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1545998 [5/5] - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/ main/java/org/apache/commons/imaging/common/ main/java/org/apache/commons/imaging/common/mylzw/ main/java/org/apache/commons/imaging/formats/bmp/ m...
Date Wed, 27 Nov 2013 11:21:16 GMT
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutMostPopulatedBoxesImplementation.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutMostPopulatedBoxesImplementation.java?rev=1545998&r1=1545997&r2=1545998&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutMostPopulatedBoxesImplementation.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutMostPopulatedBoxesImplementation.java
Wed Nov 27 11:21:14 2013
@@ -31,7 +31,7 @@ public class MedianCutMostPopulatedBoxes
         int maxPoints = 0;
         ColorGroup colorGroup = null;
         for (ColorGroup group : colorGroups) {
-            if (group.max_diff > 0) {
+            if (group.maxDiff > 0) {
                 if (group.totalPoints > maxPoints) {
                     colorGroup = group;
                     maxPoints = group.totalPoints;
@@ -51,36 +51,36 @@ public class MedianCutMostPopulatedBoxes
             if (ignoreAlpha && colorComponent == ColorComponent.ALPHA) {
                 continue;
             }
-            Collections.sort(colorGroup.color_counts, new ColorComparer(colorComponent));
-            final int count_half = (int) Math.round((double) colorGroup.totalPoints / 2);
-            int old_count = 0, new_count = 0;
-            int median_index;
-            for (median_index = 0; median_index < colorGroup.color_counts.size(); median_index++)
{
-                final ColorCount color_count = colorGroup.color_counts.get(median_index);
+            Collections.sort(colorGroup.colorCounts, new ColorComparer(colorComponent));
+            final int countHalf = (int) Math.round((double) colorGroup.totalPoints / 2);
+            int oldCount = 0, newCount = 0;
+            int medianIndex;
+            for (medianIndex = 0; medianIndex < colorGroup.colorCounts.size(); medianIndex++)
{
+                final ColorCount colorCount = colorGroup.colorCounts.get(medianIndex);
     
-                new_count += color_count.count;
+                newCount += colorCount.count;
     
-                if (new_count < count_half) {
-                    old_count = new_count;
+                if (newCount < countHalf) {
+                    oldCount = newCount;
                 } else {
                     break;
                 }
             }
-            if (median_index == colorGroup.color_counts.size() - 1) {
-                median_index--;
-            } else if (median_index > 0) {
-                final int new_diff = Math.abs(new_count - count_half);
-                final int old_diff = Math.abs(count_half - old_count);
-                if (old_diff < new_diff) {
-                    median_index--;
+            if (medianIndex == colorGroup.colorCounts.size() - 1) {
+                medianIndex--;
+            } else if (medianIndex > 0) {
+                final int newDiff = Math.abs(newCount - countHalf);
+                final int oldDiff = Math.abs(countHalf - oldCount);
+                if (oldDiff < newDiff) {
+                    medianIndex--;
                 }
             }
 
             final List<ColorCount> lowerColors = new ArrayList<ColorCount>(
-                    colorGroup.color_counts.subList(0, median_index + 1));
+                    colorGroup.colorCounts.subList(0, medianIndex + 1));
             final List<ColorCount> upperColors = new ArrayList<ColorCount>(
-                    colorGroup.color_counts.subList(median_index + 1,
-                            colorGroup.color_counts.size()));
+                    colorGroup.colorCounts.subList(medianIndex + 1,
+                            colorGroup.colorCounts.size()));
             if (lowerColors.isEmpty() || upperColors.isEmpty()) {
                 continue;
             }
@@ -91,7 +91,7 @@ public class MedianCutMostPopulatedBoxes
             if (score < bestScore) {
                 bestScore = score;
                 bestColorComponent = colorComponent;
-                bestMedianIndex = median_index;
+                bestMedianIndex = medianIndex;
             }
         }
 
@@ -99,33 +99,33 @@ public class MedianCutMostPopulatedBoxes
             return false;
         }
         
-        Collections.sort(colorGroup.color_counts, new ColorComparer(bestColorComponent));
+        Collections.sort(colorGroup.colorCounts, new ColorComparer(bestColorComponent));
         final List<ColorCount> lowerColors = new ArrayList<ColorCount>(
-                colorGroup.color_counts.subList(0, bestMedianIndex + 1));
+                colorGroup.colorCounts.subList(0, bestMedianIndex + 1));
         final List<ColorCount> upperColors = new ArrayList<ColorCount>(
-                colorGroup.color_counts.subList(bestMedianIndex + 1,
-                        colorGroup.color_counts.size()));
+                colorGroup.colorCounts.subList(bestMedianIndex + 1,
+                        colorGroup.colorCounts.size()));
         final ColorGroup lowerGroup = new ColorGroup(lowerColors, ignoreAlpha);
         final ColorGroup upperGroup = new ColorGroup(upperColors, ignoreAlpha);
         colorGroups.remove(colorGroup);
         colorGroups.add(lowerGroup);
         colorGroups.add(upperGroup);
         
-        final ColorCount median_value = colorGroup.color_counts
+        final ColorCount medianValue = colorGroup.colorCounts
                 .get(bestMedianIndex);
         int limit;
         switch (bestColorComponent) {
         case ALPHA:
-            limit = median_value.alpha;
+            limit = medianValue.alpha;
             break;
         case RED:
-            limit = median_value.red;
+            limit = medianValue.red;
             break;
         case GREEN:
-            limit = median_value.green;
+            limit = medianValue.green;
             break;
         case BLUE:
-            limit = median_value.blue;
+            limit = medianValue.blue;
             break;
         default:
             throw new Error("Bad mode.");

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutPalette.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutPalette.java?rev=1545998&r1=1545997&r2=1545998&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutPalette.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutPalette.java
Wed Nov 27 11:21:14 2013
@@ -32,6 +32,6 @@ class MedianCutPalette extends SimplePal
             cg = cg.cut.getColorGroup(rgb);
         }
 
-        return cg.palette_index;
+        return cg.paletteIndex;
     }
 }

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=1545998&r1=1545997&r2=1545998&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
Wed Nov 27 11:21:14 2013
@@ -28,13 +28,13 @@ import org.apache.commons.imaging.util.D
 public class MedianCutQuantizer {
     private final boolean ignoreAlpha;
 
-    public MedianCutQuantizer(final boolean ignore_alpha) {
-        this.ignoreAlpha = ignore_alpha;
+    public MedianCutQuantizer(final boolean ignoreAlpha) {
+        this.ignoreAlpha = ignoreAlpha;
     }
 
     private Map<Integer, ColorCount> groupColors1(final BufferedImage image, final
int max,
             final int mask) {
-        final Map<Integer, ColorCount> color_map = new HashMap<Integer, ColorCount>();
+        final Map<Integer, ColorCount> colorMap = new HashMap<Integer, ColorCount>();
 
         final int width = image.getWidth();
         final int height = image.getHeight();
@@ -50,11 +50,11 @@ public class MedianCutQuantizer {
                 }
                 argb &= mask;
 
-                ColorCount color = color_map.get(argb);
+                ColorCount color = colorMap.get(argb);
                 if (color == null) {
                     color = new ColorCount(argb);
-                    color_map.put(argb, color);
-                    if (color_map.keySet().size() > max) {
+                    colorMap.put(argb, color);
+                    if (colorMap.keySet().size() > max) {
                         return null;
                     }
                 }
@@ -62,11 +62,10 @@ public class MedianCutQuantizer {
             }
         }
 
-        return color_map;
+        return colorMap;
     }
 
-    public Map<Integer, ColorCount> groupColors(final BufferedImage image,
-            final int max_colors) {
+    public Map<Integer, ColorCount> groupColors(final BufferedImage image, final int
maxColors) {
         final int max = Integer.MAX_VALUE;
 
         for (int i = 0; i < 8; i++) {
@@ -83,24 +82,24 @@ public class MedianCutQuantizer {
         throw new Error("");
     }
     
-    public Palette process(final BufferedImage image, final int max_colors,
+    public Palette process(final BufferedImage image, final int maxColors,
             final MedianCutImplementation medianCutImplementation, final boolean verbose)
             throws ImageWriteException {
-        final Map<Integer, ColorCount> color_map = groupColors(image, max_colors);
+        final Map<Integer, ColorCount> colorMap = groupColors(image, maxColors);
 
-        final int discrete_colors = color_map.keySet().size();
-        if (discrete_colors <= max_colors) {
+        final int discreteColors = colorMap.keySet().size();
+        if (discreteColors <= maxColors) {
             if (verbose) {
-                Debug.debug("lossless palette: " + discrete_colors);
+                Debug.debug("lossless palette: " + discreteColors);
             }
 
-            final int[] palette = new int[discrete_colors];
-            final List<ColorCount> color_counts = new ArrayList<ColorCount>(
-                    color_map.values());
+            final int[] palette = new int[discreteColors];
+            final List<ColorCount> colorCounts = new ArrayList<ColorCount>(
+                    colorMap.values());
 
-            for (int i = 0; i < color_counts.size(); i++) {
-                final ColorCount color_count = color_counts.get(i);
-                palette[i] = color_count.argb;
+            for (int i = 0; i < colorCounts.size(); i++) {
+                final ColorCount colorCount = colorCounts.get(i);
+                palette[i] = colorCount.argb;
                 if (ignoreAlpha) {
                     palette[i] |= 0xff000000;
                 }
@@ -110,42 +109,41 @@ public class MedianCutQuantizer {
         }
 
         if (verbose) {
-            Debug.debug("discrete colors: " + discrete_colors);
+            Debug.debug("discrete colors: " + discreteColors);
         }
 
-        final List<ColorGroup> color_groups = new ArrayList<ColorGroup>();
-        final ColorGroup root = new ColorGroup(new ArrayList<ColorCount>(
-                color_map.values()), ignoreAlpha);
-        color_groups.add(root);
+        final List<ColorGroup> colorGroups = new ArrayList<ColorGroup>();
+        final ColorGroup root = new ColorGroup(new ArrayList<ColorCount>(colorMap.values()),
ignoreAlpha);
+        colorGroups.add(root);
 
-        while (color_groups.size() < max_colors) {
-            if (!medianCutImplementation.performNextMedianCut(color_groups, ignoreAlpha))
{
+        while (colorGroups.size() < maxColors) {
+            if (!medianCutImplementation.performNextMedianCut(colorGroups, ignoreAlpha))
{
                 break;
             }
         }
 
-        final int palette_size = color_groups.size();
+        final int paletteSize = colorGroups.size();
         if (verbose) {
-            Debug.debug("palette size: " + palette_size);
+            Debug.debug("palette size: " + paletteSize);
         }
 
-        final int[] palette = new int[palette_size];
+        final int[] palette = new int[paletteSize];
 
-        for (int i = 0; i < color_groups.size(); i++) {
-            final ColorGroup color_group = color_groups.get(i);
+        for (int i = 0; i < colorGroups.size(); i++) {
+            final ColorGroup colorGroup = colorGroups.get(i);
 
-            palette[i] = color_group.getMedianValue();
+            palette[i] = colorGroup.getMedianValue();
 
-            color_group.palette_index = i;
+            colorGroup.paletteIndex = i;
 
-            if (color_group.color_counts.size() < 1) {
+            if (colorGroup.colorCounts.size() < 1) {
                 throw new ImageWriteException("empty color_group: "
-                        + color_group);
+                        + colorGroup);
             }
         }
 
-        if (palette_size > discrete_colors) {
-            throw new ImageWriteException("palette_size>discrete_colors");
+        if (paletteSize > discreteColors) {
+            throw new ImageWriteException("palette_size > discrete_colors");
         }
 
         return new MedianCutPalette(root, palette);

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=1545998&r1=1545997&r2=1545998&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
Wed Nov 27 11:21:14 2013
@@ -93,14 +93,14 @@ public class PaletteFactory {
 
     private int pixelToQuantizationTableIndex(int argb, final int precision) {
         int result = 0;
-        final int precision_mask = (1 << precision) - 1;
+        final int precisionMask = (1 << precision) - 1;
 
         for (int i = 0; i < COMPONENTS; i++) {
             int sample = argb & 0xff;
             argb >>= 8;
 
             sample >>= (8 - precision);
-            result = (result << precision) | (sample & precision_mask);
+            result = (result << precision) | (sample & precisionMask);
         }
 
         return result;
@@ -147,13 +147,13 @@ public class PaletteFactory {
             return null;
         }
 
-        final int[] slice_mins = new int[subset.mins.length];
-        System.arraycopy(subset.mins, 0, slice_mins, 0, subset.mins.length);
-        final int[] slice_maxs = new int[subset.maxs.length];
-        System.arraycopy(subset.maxs, 0, slice_maxs, 0, subset.maxs.length);
+        final int[] sliceMins = new int[subset.mins.length];
+        System.arraycopy(subset.mins, 0, sliceMins, 0, subset.mins.length);
+        final int[] sliceMaxs = new int[subset.maxs.length];
+        System.arraycopy(subset.maxs, 0, sliceMaxs, 0, subset.maxs.length);
 
-        slice_maxs[component] = slice;
-        slice_mins[component] = slice + 1;
+        sliceMaxs[component] = slice;
+        sliceMins[component] = slice + 1;
 
         if (DEBUG) {
             System.out.println("total: " + total);
@@ -165,10 +165,8 @@ public class PaletteFactory {
 
         }
 
-        final ColorSpaceSubset first = new ColorSpaceSubset(sum, precision,
-                subset.mins, slice_maxs);
-        final ColorSpaceSubset second = new ColorSpaceSubset(total - sum, precision,
-                slice_mins, subset.maxs);
+        final ColorSpaceSubset first = new ColorSpaceSubset(sum, precision, subset.mins,
sliceMaxs);
+        final ColorSpaceSubset second = new ColorSpaceSubset(total - sum, precision, sliceMins,
subset.maxs);
 
         return new DivisionCandidate(first, second);
 
@@ -182,10 +180,10 @@ public class PaletteFactory {
 
         final int total = subset.total;
 
-        final int[] slice_mins = new int[subset.mins.length];
-        System.arraycopy(subset.mins, 0, slice_mins, 0, subset.mins.length);
-        final int[] slice_maxs = new int[subset.maxs.length];
-        System.arraycopy(subset.maxs, 0, slice_maxs, 0, subset.maxs.length);
+        final int[] sliceMins = new int[subset.mins.length];
+        System.arraycopy(subset.mins, 0, sliceMins, 0, subset.mins.length);
+        final int[] sliceMaxs = new int[subset.maxs.length];
+        System.arraycopy(subset.maxs, 0, sliceMaxs, 0, subset.maxs.length);
 
         int sum1 = 0, sum2;
         int slice1, slice2;
@@ -193,10 +191,10 @@ public class PaletteFactory {
 
         for (slice1 = subset.mins[component]; slice1 != subset.maxs[component] + 1; slice1++)
{
 
-            slice_mins[component] = slice1;
-            slice_maxs[component] = slice1;
+            sliceMins[component] = slice1;
+            sliceMaxs[component] = slice1;
 
-            last = getFrequencyTotal(table, slice_mins, slice_maxs,
+            last = getFrequencyTotal(table, sliceMins, sliceMaxs,
                     precision);
 
             sum1 += last;
@@ -234,8 +232,8 @@ public class PaletteFactory {
         dcs.addAll(divideSubset2(table, subset, 1, precision));
         dcs.addAll(divideSubset2(table, subset, 2, precision));
 
-        DivisionCandidate best_v = null;
-        double best_score = Double.MAX_VALUE;
+        DivisionCandidate bestV = null;
+        double bestScore = Double.MAX_VALUE;
 
         for (DivisionCandidate dc : dcs) {
             final ColorSpaceSubset first = dc.dst_a;
@@ -246,17 +244,17 @@ public class PaletteFactory {
             final int diff = Math.abs(area1 - area2);
             final double score = ((double) diff) / ((double) Math.max(area1, area2));
 
-            if (best_v == null) {
-                best_v = dc;
-                best_score = score;
-            } else if (score < best_score) {
-                best_v = dc;
-                best_score = score;
+            if (bestV == null) {
+                bestV = dc;
+                bestScore = score;
+            } else if (score < bestScore) {
+                bestV = dc;
+                bestScore = score;
             }
 
         }
 
-        return best_v;
+        return bestV;
     }
 
     private static class DivisionCandidate {
@@ -271,12 +269,12 @@ public class PaletteFactory {
     }
 
     private List<ColorSpaceSubset> divide(final List<ColorSpaceSubset> v,
-            final int desired_count, final int[] table, final int precision) {
+            final int desiredCount, final int[] table, final int precision) {
         final List<ColorSpaceSubset> ignore = new ArrayList<ColorSpaceSubset>();
 
         while (true) {
-            int max_area = -1;
-            ColorSpaceSubset max_subset = null;
+            int maxArea = -1;
+            ColorSpaceSubset maxSubset = null;
 
             for (ColorSpaceSubset subset : v) {
                 if (ignore.contains(subset)) {
@@ -284,33 +282,33 @@ public class PaletteFactory {
                 }
                 final int area = subset.total;
 
-                if (max_subset == null) {
-                    max_subset = subset;
-                    max_area = area;
-                } else if (area > max_area) {
-                    max_subset = subset;
-                    max_area = area;
+                if (maxSubset == null) {
+                    maxSubset = subset;
+                    maxArea = area;
+                } else if (area > maxArea) {
+                    maxSubset = subset;
+                    maxArea = area;
                 }
             }
 
-            if (max_subset == null) {
+            if (maxSubset == null) {
                 return v;
             }
             if (DEBUG) {
-                System.out.println("\t" + "area: " + max_area);
+                System.out.println("\t" + "area: " + maxArea);
             }
 
-            final DivisionCandidate dc = divideSubset2(table, max_subset,
+            final DivisionCandidate dc = divideSubset2(table, maxSubset,
                     precision);
             if (dc != null) {
-                v.remove(max_subset);
+                v.remove(maxSubset);
                 v.add(dc.dst_a);
                 v.add(dc.dst_b);
             } else {
-                ignore.add(max_subset);
+                ignore.add(maxSubset);
             }
 
-            if (v.size() == desired_count) {
+            if (v.size() == desiredCount) {
                 return v;
             }
         }
@@ -328,9 +326,9 @@ public class PaletteFactory {
     public Palette makeQuantizedRgbPalette(final BufferedImage src, final int max) {
         final int precision = 6; // in bits
 
-        final int table_scale = precision * COMPONENTS;
-        final int table_size = 1 << table_scale;
-        final int[] table = new int[table_size];
+        final int tableScale = precision * COMPONENTS;
+        final int tableSize = 1 << tableScale;
+        final int[] table = new int[tableSize];
 
         final int width = src.getWidth();
         final int height = src.getHeight();
@@ -340,8 +338,8 @@ public class PaletteFactory {
         subsets.add(all);
 
         if (DEBUG) {
-            final int pre_total = getFrequencyTotal(table, all.mins, all.maxs, precision);
-            System.out.println("pre total: " + pre_total);
+            final int preTotal = getFrequencyTotal(table, all.mins, all.maxs, precision);
+            System.out.println("pre total: " + preTotal);
         }
 
         // step 1: count frequency of colors
@@ -356,8 +354,8 @@ public class PaletteFactory {
         }
 
         if (DEBUG) {
-            final int all_total = getFrequencyTotal(table, all.mins, all.maxs, precision);
-            System.out.println("all total: " + all_total);
+            final int allTotal = getFrequencyTotal(table, all.mins, all.maxs, precision);
+            System.out.println("all total: " + allTotal);
             System.out.println("width * height: " + (width * height));
         }
 
@@ -378,7 +376,7 @@ public class PaletteFactory {
             }
         }
 
-        Collections.sort(subsets, ColorSpaceSubset.rgbComparator);
+        Collections.sort(subsets, ColorSpaceSubset.RGB_COMPARATOR);
 
         return new QuantizedPalette(subsets, precision);
     }

Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java?rev=1545998&r1=1545997&r2=1545998&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java
(original)
+++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java
Wed Nov 27 11:21:14 2013
@@ -66,11 +66,11 @@ public class SampleUsage {
             final BufferedImage image = someImage;
             final File dst = someFile;
             final ImageFormat format = ImageFormats.PNG;
-            final Map<String, Object> optional_params = new HashMap<String, Object>();
-            Imaging.writeImage(image, dst, format, optional_params);
+            final Map<String, Object> optionalParams = new HashMap<String, Object>();
+            Imaging.writeImage(image, dst, format, optionalParams);
 
             final OutputStream os = someOutputStream;
-            Imaging.writeImage(image, os, format, optional_params);
+            Imaging.writeImage(image, os, format, optionalParams);
 
             // <b>get the image's embedded ICC Profile, if it has one. </b>
             final byte iccProfileBytes[] = Imaging.getICCProfileBytes(imageBytes);
@@ -92,8 +92,8 @@ public class SampleUsage {
             }
 
             // <b>try to guess the image's format. </b>
-            final ImageFormat image_format = Imaging.guessFormat(imageBytes);
-            image_format.equals(ImageFormats.PNG);
+            final ImageFormat imageFormat = Imaging.guessFormat(imageBytes);
+            imageFormat.equals(ImageFormats.PNG);
 
             // <b>get all metadata stored in EXIF format (ie. from JPEG or
             // TIFF). </b>



Mime
View raw message