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