當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexColorModel.getMapSize方法代碼示例

本文整理匯總了Java中java.awt.image.IndexColorModel.getMapSize方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexColorModel.getMapSize方法的具體用法?Java IndexColorModel.getMapSize怎麽用?Java IndexColorModel.getMapSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.image.IndexColorModel的用法示例。


在下文中一共展示了IndexColorModel.getMapSize方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setAlpha

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
/**
 * Returns an index color model with specified opacity (alpha).
 * @param icm an index color model from which to copy RGBs.
 * @param alpha opacity in the range [0.0,1.0].
 * @return the index color model with alpha.
 */
public static IndexColorModel setAlpha(IndexColorModel icm, double alpha) {
  int bits = icm.getPixelSize();
  int size = icm.getMapSize();
  byte[] r = new byte[size];
  byte[] g = new byte[size];
  byte[] b = new byte[size];
  byte[] a = new byte[size];
  icm.getReds(r);
  icm.getGreens(g);
  icm.getBlues(b);
  byte ia = (byte)(255.0*alpha+0.5);
  for (int i=0; i<size; ++i)
    a[i] = ia;
  return new IndexColorModel(bits,size,r,g,b,a);
}
 
開發者ID:MinesJTK,項目名稱:jtk,代碼行數:22,代碼來源:ColorMap.java

示例2: createIndexedImage

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
protected static BufferedImage createIndexedImage(int w, int h,
                                                  IndexColorModel icm)
{
    BufferedImage img = new BufferedImage(w, h,
                                          BufferedImage.TYPE_BYTE_INDEXED,
                                          icm);

    int mapSize = icm.getMapSize();
    int width = w / mapSize;

    WritableRaster wr = img.getRaster();
    for (int i = 0; i < mapSize; i++) {
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < width; x++) {
                wr.setSample(i * width + x, y, 0, i);
            }
        }
    }
    return img;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:TransparencyTest.java

示例3: getDefaultPalette

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:GIFImageReader.java

示例4: gethISTNode

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ShortHistogramTest.java

示例5: brightLut

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
/**
 * Modifies the lookup table to display a bright image with gray values
 * in the range minGray ... 255. Does nothing if ip is of type
 * ColorProcessor.
 * 
 * @param ip The target image.
 * @param minGray Minimum gray value.
 */
public static void brightLut(ImageProcessor ip, int minGray) {
	if (minGray < 0 || minGray >= 255)
		return;
	ColorModel cm = ip.getColorModel();
	if (!(cm instanceof IndexColorModel))
		return;
	IndexColorModel icm = (IndexColorModel) cm;
	int mapSize = icm.getMapSize();
	byte[] reds = new byte[mapSize];
	byte[] grns = new byte[mapSize];
	byte[] blus = new byte[mapSize];
	float scale = (255 - minGray) / 255f;
	for (int i = 0; i < mapSize; i++) {
		byte g = (byte) (Math.round(minGray + scale * i) & 0xFF);
		reds[i] = g;
		grns[i] = g;
		blus[i] = g;
	}
	ip.setColorModel(new IndexColorModel(8, mapSize, reds, grns, blus));
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:29,代碼來源:LookupTables.java

示例6: isMultiColor

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
/**
 * Determines if a specified color map has more than one color.
 * Note that we ignore any variation in alpha.
 */
private static boolean isMultiColor(ColorMapped cm) {
  ColorMap cmap = cm.getColorMap();
  IndexColorModel icm = cmap.getColorModel();
  int n = icm.getMapSize();
  int rgb = icm.getRGB(0)&0x00ffffff;
  for (int i=1; i<n; ++i) 
    if (rgb!=(icm.getRGB(i)&0x00ffffff))
      return true;
  return false;
}
 
開發者ID:MinesJTK,項目名稱:jtk,代碼行數:15,代碼來源:PlotPanel.java

示例7: isFilterableICM

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:TexturePaintContext.java

示例8: JFIFThumbPalette

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
JFIFThumbPalette(BufferedImage thumb) throws IllegalThumbException {
    super(thumb);
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    if (icm.getMapSize() > 256) {
        throw new IllegalThumbException();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:JFIFMarkerSegment.java

示例9: drawDIBImage

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
protected void drawDIBImage(byte[] image,
                            float destX, float destY,
                            float destWidth, float destHeight,
                            float srcX, float srcY,
                            float srcWidth, float srcHeight,
                            int sampleBitsPerPixel,
                            IndexColorModel icm) {
    int bitCount = 24;
    byte[] bmiColors = null;

    if (icm != null) {
        bitCount = sampleBitsPerPixel;
        bmiColors = new byte[(1<<icm.getPixelSize())*4];
        for (int i=0;i<icm.getMapSize(); i++) {
            bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
            bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
            bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
        }
    }

    drawDIBImage(getPrintDC(), image,
                 destX, destY,
                 destWidth, destHeight,
                 srcX, srcY,
                 srcWidth, srcHeight,
                 bitCount, bmiColors);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:WPrinterJob.java

示例10: listCurrentLut

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
/**
 * Lists the contents of the lookup-table currently associated
 * with the specified image.
 * 
 * @param ip The image.
 */
public static void listCurrentLut(ImageProcessor ip) {
	ColorModel cm = ip.getCurrentColorModel();
	IndexColorModel icm = (IndexColorModel) cm;
	int mapSize = icm.getMapSize();
	byte[] reds = new byte[mapSize];
	byte[] grns = new byte[mapSize];
	byte[] blus = new byte[mapSize];
	icm.getReds(reds);
	icm.getGreens(grns);
	icm.getBlues(blus);
	for (int i = 0; i < mapSize; i++) {
		IJ.log(String.format("%3d: %3d %3d %3d", i, reds[i] & 0xFF, grns[i] & 0xFF, blus[i] & 0xFF));
	}
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:21,代碼來源:LookupTables.java

示例11: setColorModel

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
public void setColorModel(ColorModel model) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    srcModel = model;

    // Check to see if model is INT_RGB
    if (model instanceof IndexColorModel) {
        if (model.getTransparency() == model.TRANSLUCENT) {
            // REMIND:
            // Probably need to composite anyway so force ARGB
            cmodel = ColorModel.getRGBdefault();
            srcLUT = null;
        }
        else {
            IndexColorModel icm = (IndexColorModel) model;
            numSrcLUT = icm.getMapSize();
            srcLUT = new int[Math.max(numSrcLUT, 256)];
            icm.getRGBs(srcLUT);
            srcLUTtransIndex = icm.getTransparentPixel();
            cmodel = model;
        }
    }
    else {
        if (cmodel == null) {
            cmodel = model;
            srcLUT   = null;
        }
        else if (model instanceof DirectColorModel) {
            // If it is INT_RGB or INT_ARGB, use the model
            DirectColorModel dcm = (DirectColorModel) model;
            if ((dcm.getRedMask() == 0xff0000) &&
                (dcm.getGreenMask() == 0xff00) &&
                (dcm.getBlueMask()  == 0x00ff)) {
                cmodel   = model;
                srcLUT   = null;
            }
        }
    }

    isSameCM = (cmodel == model);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:43,代碼來源:ImageRepresentation.java

示例12: createColorTable

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
/**
 * Create a color table from the image ColorModel and SampleModel.
 */
private static byte[] createColorTable(ColorModel colorModel,
                                       SampleModel sampleModel)
{
    byte[] colorTable;
    if (colorModel instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel)colorModel;
        int mapSize = icm.getMapSize();

        /**
         * The GIF image format assumes that size of image palette
         * is power of two. We will use closest larger power of two
         * as size of color table.
         */
        int ctSize = getGifPaletteSize(mapSize);

        byte[] reds = new byte[ctSize];
        byte[] greens = new byte[ctSize];
        byte[] blues = new byte[ctSize];
        icm.getReds(reds);
        icm.getGreens(greens);
        icm.getBlues(blues);

        /**
         * fill tail of color component arrays by replica of first color
         * in order to avoid appearance of extra colors in the color table
         */
        for (int i = mapSize; i < ctSize; i++) {
            reds[i] = reds[0];
            greens[i] = greens[0];
            blues[i] = blues[0];
        }

        colorTable = new byte[3*ctSize];
        int idx = 0;
        for (int i = 0; i < ctSize; i++) {
            colorTable[idx++] = reds[i];
            colorTable[idx++] = greens[i];
            colorTable[idx++] = blues[i];
        }
    } else if (sampleModel.getNumBands() == 1) {
        // create gray-scaled color table for single-banded images
        int numBits = sampleModel.getSampleSize()[0];
        if (numBits > 8) {
            numBits = 8;
        }
        int colorTableLength = 3*(1 << numBits);
        colorTable = new byte[colorTableLength];
        for (int i = 0; i < colorTableLength; i++) {
            colorTable[i] = (byte)(i/3);
        }
    } else {
        // We do not have enough information here
        // to create well-fit color table for RGB image.
        colorTable = null;
    }

    return colorTable;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:62,代碼來源:GIFImageWriter.java

示例13: setColorModel

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
public void setColorModel(ColorModel model) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    srcModel = model;

    // Check to see if model is INT_RGB
    if (model instanceof IndexColorModel) {
        if (model.getTransparency() == Transparency.TRANSLUCENT) {
            // REMIND:
            // Probably need to composite anyway so force ARGB
            cmodel = ColorModel.getRGBdefault();
            srcLUT = null;
        }
        else {
            IndexColorModel icm = (IndexColorModel) model;
            numSrcLUT = icm.getMapSize();
            srcLUT = new int[Math.max(numSrcLUT, 256)];
            icm.getRGBs(srcLUT);
            srcLUTtransIndex = icm.getTransparentPixel();
            cmodel = model;
        }
    }
    else {
        if (cmodel == null) {
            cmodel = model;
            srcLUT   = null;
        }
        else if (model instanceof DirectColorModel) {
            // If it is INT_RGB or INT_ARGB, use the model
            DirectColorModel dcm = (DirectColorModel) model;
            if ((dcm.getRedMask() == 0xff0000) &&
                (dcm.getGreenMask() == 0xff00) &&
                (dcm.getBlueMask()  == 0x00ff)) {
                cmodel   = model;
                srcLUT   = null;
            }
        }
    }

    isSameCM = (cmodel == model);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:43,代碼來源:ImageRepresentation.java


注:本文中的java.awt.image.IndexColorModel.getMapSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。