Java BufferedImage Operation depalettize(BufferedImage img, int maxBytes)

Here you can find the source of depalettize(BufferedImage img, int maxBytes)

Description

Convert an image to a direct color map

License

Apache License

Declaration

public static BufferedImage depalettize(BufferedImage img, int maxBytes) 

Method Source Code

//package com.java2s;
/*/*from  w  ww. j a  v a 2 s  . c  o m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;

import java.awt.image.IndexColorModel;

public class Main {
    /**
     * Convert an image to a direct color map
     */
    public static BufferedImage depalettize(BufferedImage img, int maxBytes) {
        // Even is we use an RGB buffer instead of RGBA it still uses 4 bytes in memory
        if (img.getWidth() * img.getHeight() * 4 > maxBytes) {
            // Image is too large to depalettize
            return null;
        }
        ColorModel colorModel = img.getColorModel();
        if (colorModel instanceof IndexColorModel) {
            IndexColorModel indexModel = (IndexColorModel) colorModel;
            return indexModel.convertToIntDiscrete(img.getData(), false);
        }
        return null;
    }
}

Related

  1. cutToSquare(BufferedImage src)
  2. cylindricalMapping(BufferedImage img, double f)
  3. darkenImage(final BufferedImage image, final float darken)
  4. declareNewBufferedImage(int x, int y)
  5. declareNewBufferedImageAndCopy(BufferedImage img)
  6. determineBackgroundColor(BufferedImage bim)
  7. doInGraphics(final BufferedImage image, final Consumer consumer)
  8. duplicate(BufferedImage image)
  9. DuplicateBufferedImage(BufferedImage bi)