2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class implements the octree quantization method 0N/A * as it is described in the "Graphics Gems" 0N/A * (ISBN 0-12-286166-3, Chapter 4, pages 297-293) 0N/A * maximum of tree depth 0N/A * Creates an image representing given image 0N/A * <code>src</code> using <code>IndexColorModel</code>. 0N/A * Lossless conversion is not always possible (e.g. if number 0N/A * of colors in the given image exceeds maximum palette size). 0N/A * Result image then is an approximation constructed by octree 0N/A * quantization method. 0N/A * @exception IllegalArgumentException if <code>src</code> is 0N/A * <code>null</code>. 0N/A * @exception UnsupportedOperationException if implemented method 0N/A * is unable to create approximation of <code>src</code> 0N/A * and <code>canCreatePalette</code> returns <code>false</code>. 0N/A * @see createIndexColorModel 0N/A * @see canCreatePalette 0N/A * Creates an palette representing colors from given image 0N/A * <code>img</code>. If number of colors in the given image exceeds 0N/A * maximum palette size closest colors would be merged. 0N/A * @exception IllegalArgumentException if <code>img</code> is 0N/A * <code>null</code>. 0N/A * @exception UnsupportedOperationException if implemented method 0N/A * is unable to create approximation of <code>img</code> 0N/A * and <code>canCreatePalette</code> returns <code>false</code>. 0N/A * @see createIndexedImage 0N/A * @see canCreatePalette 0N/A * Returns <code>true</code> if PaletteBuilder is able to create 0N/A * palette for given image type. 0N/A * @param type an instance of <code>ImageTypeSpecifier</code> to be 0N/A * @return <code>true</code> if the <code>PaletteBuilder</code> 0N/A * is likely to be able to create palette for this image type. 0N/A * @exception IllegalArgumentException if <code>type</code> 0N/A * is <code>null</code>. 0N/A * Returns <code>true</code> if PaletteBuilder is able to create 0N/A * palette for given rendered image. 0N/A * @param image an instance of <code>RenderedImage</code> to be 0N/A * @return <code>true</code> if the <code>PaletteBuilder</code> 0N/A * is likely to be able to create palette for this image type. 0N/A * @exception IllegalArgumentException if <code>image</code> 0N/A * is <code>null</code>. 0N/A return 0;
// default transparnt pixel 0N/A for (
int y =
0; y < h; y++) {
0N/A for (
int x =
0; x < w; x++) {
0N/A * If transparency of given image is not opaque we assume all 0N/A * colors with alpha less than 1.0 as fully transparent. 0N/A size ++;
// we need place for transparent color; 0N/A for (
int i =
0; i <
8; i++) {
0N/A // nothing to reduce 0N/A // look for element with lower color count 0N/A // save pointer to first reducible node 0N/A // NB: current color count for node could be changed in future 0N/A for (
int i =
0; i <
8; i++) {
0N/A for (
int i =
0; i <
8; i++) {
0N/A * The node of color tree. 0N/A for (
int i =
0; i <
8; i++) {
0N/A int c =
0xff <<
24 | (
0xff&r) <<
16 | (
0xff&g) <<
8 | (
0xff&b);