commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1390611 - in /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging: formats/bmp/ formats/gif/ formats/ico/ formats/pcx/ formats/xpm/ palette/
Date Wed, 26 Sep 2012 17:08:59 GMT
Author: damjan
Date: Wed Sep 26 17:08:58 2012
New Revision: 1390611

URL: http://svn.apache.org/viewvc?rev=1390611&view=rev
Log:
Refactor and document palettes.


Added:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/package-info.java
  (with props)
Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/Palette.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java?rev=1390611&r1=1390610&r2=1390611&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
Wed Sep 26 17:08:58 2012
@@ -772,7 +772,7 @@ public class BmpImageParser extends Imag
             throw new ImageWriteException("Unknown parameter: " + firstKey);
         }
 
-        final SimplePalette palette = new PaletteFactory().makeSimpleRgbPalette(
+        final SimplePalette palette = new PaletteFactory().makeExactRgbPaletteSimple(
                 src, 256);
 
         BmpWriter writer = null;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java?rev=1390611&r1=1390610&r2=1390611&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
Wed Sep 26 17:08:58 2012
@@ -812,7 +812,7 @@ public class GifImageParser extends Imag
 
         int max_colors = hasAlpha ? 255 : 256;
 
-        Palette palette2 = new PaletteFactory().makeSimpleRgbPalette(src,
+        Palette palette2 = new PaletteFactory().makeExactRgbPaletteSimple(src,
                 max_colors);
         // int palette[] = new PaletteFactory().makePaletteSimple(src, 256);
         // Map palette_map = paletteToMap(palette);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java?rev=1390611&r1=1390610&r2=1390611&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
Wed Sep 26 17:08:58 2012
@@ -730,7 +730,7 @@ public class IcoImageParser extends Imag
 
         final PaletteFactory paletteFactory = new PaletteFactory();
         final SimplePalette palette = paletteFactory
-                .makeSimpleRgbPalette(src, 256);
+                .makeExactRgbPaletteSimple(src, 256);
         final int bitCount;
         final boolean hasTransparency = paletteFactory.hasTransparency(src);
         if (palette == null) {

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java?rev=1390611&r1=1390610&r2=1390611&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
Wed Sep 26 17:08:58 2012
@@ -130,7 +130,7 @@ public class PcxWriter implements PcxCon
             throws ImageWriteException, IOException {
         final PaletteFactory paletteFactory = new PaletteFactory();
         final SimplePalette palette = paletteFactory
-                .makeSimpleRgbPalette(src, 256);
+                .makeExactRgbPaletteSimple(src, 256);
         BinaryOutputStream bos = new BinaryOutputStream(os,
                 BinaryOutputStream.BYTE_ORDER_INTEL);
         if (palette == null || bitDepth == 24 || bitDepth == 32) {

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java?rev=1390611&r1=1390610&r2=1390611&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
Wed Sep 26 17:08:58 2012
@@ -661,7 +661,7 @@ public class XpmImageParser extends Imag
         int maxColors = writePalette.length;
         int charsPerPixel = 1;
         for (; palette == null;) {
-            palette = paletteFactory.makeSimpleRgbPalette(src,
+            palette = paletteFactory.makeExactRgbPaletteSimple(src,
                     hasTransparency ? maxColors - 1 : maxColors);
             if (palette == null) {
                 maxColors *= writePalette.length;

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=1390611&r1=1390610&r2=1390611&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
Wed Sep 26 17:08:58 2012
@@ -146,7 +146,12 @@ class ColorSpaceSubset {
         rgb = (int) (((redsum & 0xff) << 16) | ((greensum & 0xff) <<
8) | ((bluesum & 0xff) << 0));
     }
 
-    public int index;
+    // the index in the palette.
+    private int index;
+    
+    public final int getIndex() {
+        return index;
+    }
 
     public final void setIndex(int i) {
         index = i;

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=1390611&r1=1390610&r2=1390611&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 Sep 26 17:08:58 2012
@@ -304,11 +304,6 @@ public class MedianCutQuantizer {
             if (color_group.color_counts.size() < 1)
                 throw new ImageWriteException("empty color_group: "
                         + color_group);
-
-            // if(color_group.)
-            // Debug.debug("color_group", color_group);
-            // Debug.debug("palette[" + i + "]", palette[i] + " ("
-            // + Integer.toHexString(palette[i]) + ")");
         }
 
         if (palette_size > discrete_colors)
@@ -380,14 +375,10 @@ public class MedianCutQuantizer {
                         color_group.color_counts.size()));
 
         ColorGroup less, more;
-        {
-            less = new ColorGroup(new ArrayList<ColorCount>(color_counts1));
-            color_groups.add(less);
-        }
-        {
-            more = new ColorGroup(new ArrayList<ColorCount>(color_counts2));
-            color_groups.add(more);
-        }
+        less = new ColorGroup(new ArrayList<ColorCount>(color_counts1));
+        color_groups.add(less);
+        more = new ColorGroup(new ArrayList<ColorCount>(color_counts2));
+        color_groups.add(more);
 
         ColorCount median_value = color_group.color_counts
                 .get(median_index);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/Palette.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/Palette.java?rev=1390611&r1=1390610&r2=1390611&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/Palette.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/Palette.java
Wed Sep 26 17:08:58 2012
@@ -18,12 +18,30 @@ package org.apache.commons.imaging.palet
 
 import org.apache.commons.imaging.ImageWriteException;
 
+/**
+ * Color palette.
+ */
 public abstract class Palette {
 
+    /**
+     * Looks up the palette index for a given color.
+     * @param rgb the color to look up
+     * @return the palette index
+     * @throws ImageWriteException
+     */
     public abstract int getPaletteIndex(int rgb) throws ImageWriteException;
 
+    /**
+     * Looks up the color for a given palette index.
+     * @param index the palette index to look up
+     * @return the color in ARGB format
+     */
     public abstract int getEntry(int index);
 
+    /**
+     * The number of entries in the palette.
+     * @return the number of palette entries
+     */
     public abstract int length();
 
     public void dump() {

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=1390611&r1=1390610&r2=1390611&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 Sep 26 17:08:58 2012
@@ -28,12 +28,15 @@ import java.util.Set;
 
 import org.apache.commons.imaging.ImageWriteException;
 
+/**
+ * Factory for creating palettes.
+ */
 public class PaletteFactory {
     private static final boolean debug = false;
 
     /**
      * Builds an exact complete opaque palette containing all the colors in {@code src},
-     * using an algorithm that is faster than {@linkplain #makePaletteSimple} for large images
+     * using an algorithm that is faster than {@linkplain #makeExactRgbPaletteSimple} for
large images
      * but uses 2 mebibytes of working memory. Treats all the colors as opaque.
      * @param src the image whose palette to build
      * @return the palette
@@ -318,7 +321,9 @@ public class PaletteFactory {
 
     /**
      * Builds an inexact opaque palette of at most {@code max} colors in {@code src}
-     * using the Median Cut algorithm.
+     * using a variation of the Median Cut algorithm. Accurate to 6 bits per component,
+     * and works by splitting the color bounding box most heavily populated by colors
+     * along the component which splits the colors most evenly.
      * @param src the image whose palette to build
      * @param max the maximum number of colors the palette can contain
      * @return the palette of at most {@code max} colors
@@ -382,7 +387,9 @@ public class PaletteFactory {
     
     /**
      * Builds an inexact possibly translucent palette of at most {@code max} colors in {@code
src}
-     * using the Median Cut algorithm.
+     * using the traditional Median Cut algorithm. Color bounding boxes are split along the
+     * longest axis, with each step splitting the box. All bits in each component are used.
+     * The Algorithm is slower and seems exact than {@linkplain #makeQuantizedRgbPalette(BufferedImage,
int)}.
      * @param src the image whose palette to build
      * @param transparent whether to consider the alpha values
      * @param max the maximum number of colors the palette can contain
@@ -399,7 +406,7 @@ public class PaletteFactory {
      * @param max the maximum number of colors the palette can contain
      * @return the complete palette of {@code max} or less colors, or {@code null} if more
than {@code max} colors are necessary
      */
-    public SimplePalette makeSimpleRgbPalette(BufferedImage src, int max) {
+    public SimplePalette makeExactRgbPaletteSimple(BufferedImage src, int max) {
         // This is not efficient for large values of max, say, max > 256;
         Set<Integer> rgbs = new HashSet<Integer>();
 

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=1390611&r1=1390610&r2=1390611&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
Wed Sep 26 17:08:58 2012
@@ -57,7 +57,7 @@ public class QuantizedPalette extends Pa
                 | ((rgb >> (16 - 2 * precision)) & (precisionMask << precision))
                 | ((rgb >> (8 - precision)) & (precisionMask));
 
-        return straight[index].index;
+        return straight[index].getIndex();
     }
 
     @Override

Added: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/package-info.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/package-info.java?rev=1390611&view=auto
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/package-info.java
(added)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/package-info.java
Wed Sep 26 17:08:58 2012
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Color quantization and palette manipulation tools.
+ */
+package org.apache.commons.imaging.palette;
\ No newline at end of file

Propchange: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message