001 /* 002 * 003 004 Licensed under the Apache License, Version 2.0 (the "License"); 005 you may not use this file except in compliance with the License. 006 You may obtain a copy of the License at 007 008 http://www.apache.org/licenses/LICENSE-2.0 009 010 Unless required by applicable law or agreed to in writing, software 011 distributed under the License is distributed on an "AS IS" BASIS, 012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 See the License for the specific language governing permissions and 014 limitations under the License. 015 */ 016 017 package railo.runtime.img.filter; 018 /** 019 * The interface for an image quantizer. The addColor method is called (repeatedly 020 * if necessary) with all the image pixels. A color table can then be returned by 021 * calling the buildColorTable method. 022 */ 023 public interface Quantizer { 024 /** 025 * Initialize the quantizer. This should be called before adding any pixels. 026 * @param numColors the number of colors we're quantizing to. 027 */ 028 public void setup(int numColors); 029 030 /** 031 * Add pixels to the quantizer. 032 * @param pixels the array of ARGB pixels 033 * @param offset the offset into the array 034 * @param count the count of pixels 035 */ 036 public void addPixels(int[] pixels, int offset, int count); 037 038 /** 039 * Build a color table from the added pixels. 040 * @return an array of ARGB pixels representing a color table 041 */ 042 public int[] buildColorTable(); 043 044 /** 045 * Using the previously-built color table, return the index into that table for a pixel. 046 * This is guaranteed to return a valid index - returning the index of a color closer 047 * to that requested if necessary. 048 * @param rgb the pixel to find 049 * @return the pixel's index in the color table 050 */ 051 public int getIndexForColor(int rgb); 052 }