This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit 2a80bf9ea442984bad44d20aa756271e57498626 Author: Gary Gregory <[email protected]> AuthorDate: Sat Jan 3 12:11:55 2026 -0500 Javadoc --- .../commons/imaging/formats/gif/GifImageMetadata.java | 13 +++++++++++++ .../commons/imaging/palette/LongestAxisMedianCut.java | 3 +++ .../org/apache/commons/imaging/palette/MedianCut.java | 13 +++++++++++++ .../commons/imaging/palette/MedianCutQuantizer.java | 15 +++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/src/main/java/org/apache/commons/imaging/formats/gif/GifImageMetadata.java b/src/main/java/org/apache/commons/imaging/formats/gif/GifImageMetadata.java index 84017943..ab5abe45 100644 --- a/src/main/java/org/apache/commons/imaging/formats/gif/GifImageMetadata.java +++ b/src/main/java/org/apache/commons/imaging/formats/gif/GifImageMetadata.java @@ -22,6 +22,9 @@ import java.util.List; import org.apache.commons.imaging.common.ImageMetadata; +/** + * Metadata for GIF images. + */ public class GifImageMetadata implements ImageMetadata { private static final String NEWLINE = System.lineSeparator(); @@ -35,6 +38,11 @@ public class GifImageMetadata implements ImageMetadata { this.items = Collections.unmodifiableList(new ArrayList<>(items)); } + /** + * Gets the image height. + * + * @return the height in pixels. + */ public int getHeight() { return height; } @@ -44,6 +52,11 @@ public class GifImageMetadata implements ImageMetadata { return Collections.unmodifiableList(items); } + /** + * Gets the image width. + * + * @return the width in pixels. + */ public int getWidth() { return width; } diff --git a/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java b/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java index 89d94313..e3f9e48a 100644 --- a/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java +++ b/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java @@ -22,6 +22,9 @@ import java.util.List; import org.apache.commons.imaging.ImagingException; +/** + * Median cut implementation that cuts along the longest axis. + */ public class LongestAxisMedianCut implements MedianCut { private static final Comparator<ColorGroup> COMPARATOR = (cg1, cg2) -> { if (cg1.maxDiff == cg2.maxDiff) { diff --git a/src/main/java/org/apache/commons/imaging/palette/MedianCut.java b/src/main/java/org/apache/commons/imaging/palette/MedianCut.java index 97dcd645..05f6a36e 100644 --- a/src/main/java/org/apache/commons/imaging/palette/MedianCut.java +++ b/src/main/java/org/apache/commons/imaging/palette/MedianCut.java @@ -14,12 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.imaging.palette; import java.util.List; import org.apache.commons.imaging.ImagingException; +/** + * Performs median cut algorithms used in color quantization. + */ public interface MedianCut { + + /** + * Performs the next median cut operation. + * + * @param colorGroups the list of color groups. + * @param ignoreAlpha whether to ignore alpha channel. + * @return true if the cut was performed, false otherwise. + * @throws ImagingException if an imaging error occurs. + */ boolean performNextMedianCut(List<ColorGroup> colorGroups, boolean ignoreAlpha) throws ImagingException; } diff --git a/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java b/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java index 075bb93e..e89f9a9d 100644 --- a/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java +++ b/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java @@ -26,13 +26,28 @@ import org.apache.commons.imaging.ImagingException; import org.apache.commons.imaging.common.Allocator; import org.apache.commons.imaging.internal.Debug; +/** + * Implements median cut color quantization for reducing the number of colors in an image. + */ public class MedianCutQuantizer { private final boolean ignoreAlpha; + /** + * Constructs a new median cut quantizer. + * + * @param ignoreAlpha whether to ignore the alpha channel during quantization. + */ public MedianCutQuantizer(final boolean ignoreAlpha) { this.ignoreAlpha = ignoreAlpha; } + /** + * Groups colors in the image into a palette of at most maxColors colors. + * + * @param image the image to quantize. + * @param maxColors the maximum number of colors in the result. + * @return a map of colors to their counts. + */ public Map<Integer, ColorCount> groupColors(final BufferedImage image, final int maxColors) { final int max = Integer.MAX_VALUE;
