001/**
002 *
003 * Copyright 2006 Jerry Huxtable
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api;
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    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    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    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    int getIndexForColor(int rgb);
053}