public class Quantize extends Object
RenderingHints is supposed to provide a way to block dithering, but I have not been able to get that to work. It always dithers, so we use this class instead.
The following modifications were added to the original code: - Made it work with image data with transparent pixels. - Clarified documentation of the main method. - Changed the 'QUICK' constant to false for better quantization. - Fixed an integer overflow that caused a bug quantizing large images.
Original headers follow: An efficient color quantization algorithm, adapted from the C++ implementation quantize.c in ImageMagick. The pixels for an image are placed into an oct tree. The oct tree is reduced in size, and the pixels from the original image are reassigned to the nodes in the reduced tree.
Here is the copyright notice from ImageMagick:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Permission is hereby granted, free of charge, to any person obtaining a %
% copy of this software and associated documentation files ("ImageMagick"), %
% to deal in ImageMagick without restriction, including without limitation %
% the rights to use, copy, modify, merge, publish, distribute, sublicense, %
% and/or sell copies of ImageMagick, and to permit persons to whom the %
% ImageMagick is furnished to do so, subject to the following conditions: %
% %
% The above copyright notice and this permission notice shall be included in %
% all copies or substantial portions of ImageMagick. %
% %
% The software is provided "as is", without warranty of any kind, express or %
% implied, including but not limited to the warranties of merchantability, %
% fitness for a particular purpose and noninfringement. In no event shall %
% E. I. du Pont de Nemours and Company be liable for any claim, damages or %
% other liability, whether in an action of contract, tort or otherwise, %
% arising from, out of or in connection with ImageMagick or the use or other %
% dealings in ImageMagick. %
% %
% Except as contained in this notice, the name of the E. I. du Pont de %
% Nemours and Company shall not be used in advertising or otherwise to %
% promote the sale, use or other dealings in ImageMagick without prior %
% written authorization from the E. I. du Pont de Nemours and Company. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
| Constructor and Description |
|---|
Quantize() |
| Modifier and Type | Method and Description |
|---|---|
static int[] |
quantizeImage(int[][] pixels,
int max_colors)
Reduce the image to the given number of colors.
|
public static int[] quantizeImage(int[][] pixels,
int max_colors)
pixels - an in/out parameter that should initially contain
[A]RGB values but that will contain color palette indicies upon return.Copyright © 2015. All rights reserved.