java类java.awt.image.IndexColorModel的实例源码

JFIFMarkerSegment.java 文件源码 项目:jdk8u-jdk 阅读 25 收藏 0 点赞 0 评论 0
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
ShortHistogramTest.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
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;
}
RleEncodingTest.java 文件源码 项目:openjdk-jdk10 阅读 16 收藏 0 点赞 0 评论 0
private static void encodeRLE4Test() throws IOException {
    // create 4bpp image
    byte[] r = new byte[16];
    r[0] = (byte)0xff;
    byte[] g = new byte[16];
    g[1] = (byte)0xff;
    byte[] b = new byte[16];
    b[2] = (byte)0xff;
    IndexColorModel icm = new IndexColorModel(4, 16, r, g, b);

    BufferedImage bimg = new BufferedImage(100, 100,
                                           BufferedImage.TYPE_BYTE_BINARY,
                                           icm);

    Graphics gr = bimg.getGraphics();
    gr.setColor(Color.green);
    gr.fillRect(0, 0, 100, 100);

    doTest(bimg, "BI_RLE4", ImageWriteParam.MODE_EXPLICIT);
}
FloatColorMap.java 文件源码 项目:jtk 阅读 16 收藏 0 点赞 0 评论 0
/**
 * Constructs a color map with more than one color components.
 * @param f arrays of floats, one array for each color component.
 * @param ic array index of the component for the index color model.
 * @param icm the index color model corresponding to one component.
 */
public FloatColorMap(float[][][] f, int ic, IndexColorModel icm) {
  super(icm);
  Check.argument(
    f.length==1 || f.length==3 || f.length==4,
    "number of arrays (color components) equals 1, 3, or 4");
  int nc = f.length;
  FloatByteMap[] fbm = new FloatByteMap[nc];
  for (int jc=0; jc<nc; ++jc)
    fbm[jc] = new FloatByteMap(f[jc]);
  _fbmi0 = fbm[0];
  _fbmi1 = (nc>1)?fbm[1]:fbm[0];
  _fbmi2 = (nc>1)?fbm[2]:fbm[0];
  _fbmi3 = (nc>3)?fbm[3]:null;
  _fbmic = fbm[ic];
}
BMPSubsamplingTest.java 文件源码 项目:openjdk-jdk10 阅读 16 收藏 0 点赞 0 评论 0
private BufferedImage createIndexImage(int bpp) {
    // calculate palette size
    int psize = (1 << bpp);

    // prepare palette;
    byte[] r = new byte[psize];
    byte[] g = new byte[psize];
    byte[] b = new byte[psize];

    for (int i = 0; i < colors.length; i++) {
        r[i] = (byte)(0xff & colors[i].getRed());
        g[i] = (byte)(0xff & colors[i].getGreen());
        b[i] = (byte)(0xff & colors[i].getBlue());
    }

    // now prepare appropriate index clor model
    IndexColorModel icm = new IndexColorModel(bpp, psize, r, g, b);

    return new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
}
XYZApp.java 文件源码 项目:openjdk-jdk10 阅读 34 收藏 0 点赞 0 评论 0
private void Setup() {
    balls = new Image[nBalls];
    byte red[] = new byte[256];
    red[0] = (byte) bgGrey;
    byte green[] = new byte[256];
    green[0] = (byte) bgGrey;
    byte blue[] = new byte[256];
    blue[0] = (byte) bgGrey;
    for (int r = 0; r < nBalls; r++) {
        float b = (float) (r + 1) / nBalls;
        for (int i = maxr; i >= 1; --i) {
            float d = (float) i / maxr;
            red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b);
            green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b);
            blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b);
        }
        IndexColorModel model = new IndexColorModel(8, maxr + 1,
                red, green, blue, 0);
        balls[r] = applet.createImage(
                new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2));
    }
}
TransparencyTest.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
protected  static IndexColorModel createIndexedBitmaskColorModel() {
    int paletteSize = 8;
    byte[] red = new byte[paletteSize];
    byte[] green = new byte[paletteSize];
    byte[] blue = new byte[paletteSize];

    red[0] = (byte)0xff; green[0] = (byte)0x00; blue[0] = (byte)0x00;
    red[1] = (byte)0x00; green[1] = (byte)0xff; blue[1] = (byte)0x00;
    red[2] = (byte)0x00; green[2] = (byte)0x00; blue[2] = (byte)0xff;
    red[3] = (byte)0xff; green[3] = (byte)0xff; blue[3] = (byte)0xff;
    red[4] = (byte)0x00; green[4] = (byte)0x00; blue[4] = (byte)0x00;
    red[5] = (byte)0x80; green[5] = (byte)0x80; blue[5] = (byte)0x80;
    red[6] = (byte)0xff; green[6] = (byte)0xff; blue[6] = (byte)0x00;
    red[7] = (byte)0x00; green[7] = (byte)0xff; blue[7] = (byte)0xff;

    int numBits = 3;

    IndexColorModel icm = new IndexColorModel(numBits, paletteSize,
                                              red, green, blue, 5);

    return icm;
}
ColorMap.java 文件源码 项目:jtk 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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);
}
ColorMap.java 文件源码 项目:jtk 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Returns an index color model with specified opacities (alphas).
 * @param icm an index color model from which to copy RGBs.
 * @param alpha array of opacities in the range [0.0,1.0].
 * @return the index color model with alphas.
 */
public static IndexColorModel setAlpha(IndexColorModel icm, float[] 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);
  int n = min(size,alpha.length);
  for (int i=0; i<n; ++i)
    a[i] = (byte)(255.0f*alpha[i]+0.5f);
  return new IndexColorModel(bits,size,r,g,b,a);
}
IndexColorModelEqualsTest.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
private static void verifyEquals(IndexColorModel m1,
                                 IndexColorModel m2) {
    if (m1.equals(null)) {
        throw new RuntimeException("equals(null) returns true");
    }
    if (!(m1.equals(m2))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (!(m2.equals(m1))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (m1.hashCode() != m2.hashCode()) {
        throw new RuntimeException("HashCode is not same for same"
                + " IndexColorModels");
    }
}
BufImgSurfaceData.java 文件源码 项目:openjdk-jdk10 阅读 28 收藏 0 点赞 0 评论 0
public static SurfaceData createDataBC(BufferedImage bImg,
                                       SurfaceType sType,
                                       int primaryBank,
                                       double scaleX, double scaleY)
{
    ByteComponentRaster bcRaster =
        (ByteComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType,
                              scaleX, scaleY);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bcRaster.getDataStorage(),
                    bcRaster.getDataOffset(primaryBank), 0,
                    bcRaster.getWidth(),
                    bcRaster.getHeight(),
                    bcRaster.getPixelStride(),
                    bcRaster.getScanlineStride(),
                    icm);
    return bisd;
}
GIFImageReader.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
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;
}
IDLColorModelFactory.java 文件源码 项目:ramus 阅读 125 收藏 0 点赞 0 评论 0
public static IndexColorModel createColorModel() {
    // Create a 6x6x6 color cube
    int[] cmap = new int[256];
    int i = 0;
    for (int r = 0; r < 256; r += 51) {
        for (int g = 0; g < 256; g += 51) {
            for (int b = 0; b < 256; b += 51) {
                cmap[i++] = (r << 16) | (g << 8) | b;
            }
        }
    }
    // And populate the rest of the cmap with gray values
    int grayIncr = 256 / (256 - i);

    // The gray ramp will be between 18 and 252
    int gray = grayIncr * 3;
    for (; i < 256; i++) {
        cmap[i] = (gray << 16) | (gray << 8) | gray;
        gray += grayIncr;
    }

    return new IndexColorModel(8, 256, cmap, 0, false, -1,
            DataBuffer.TYPE_BYTE);
}
XYZApp.java 文件源码 项目:OpenJSharp 阅读 18 收藏 0 点赞 0 评论 0
private void Setup() {
    balls = new Image[nBalls];
    byte red[] = new byte[256];
    red[0] = (byte) bgGrey;
    byte green[] = new byte[256];
    green[0] = (byte) bgGrey;
    byte blue[] = new byte[256];
    blue[0] = (byte) bgGrey;
    for (int r = 0; r < nBalls; r++) {
        float b = (float) (r + 1) / nBalls;
        for (int i = maxr; i >= 1; --i) {
            float d = (float) i / maxr;
            red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b);
            green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b);
            blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b);
        }
        IndexColorModel model = new IndexColorModel(8, maxr + 1,
                red, green, blue, 0);
        balls[r] = applet.createImage(
                new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2));
    }
}
BufImgSurfaceData.java 文件源码 项目:OpenJSharp 阅读 30 收藏 0 点赞 0 评论 0
public static SurfaceData createDataSC(BufferedImage bImg,
                                       SurfaceType sType,
                                       IndexColorModel icm) {
    ShortComponentRaster scRaster =
        (ShortComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(scRaster.getDataBuffer(), bImg, sType);
    bisd.initRaster(scRaster.getDataStorage(),
                    scRaster.getDataOffset(0) * 2, 0,
                    scRaster.getWidth(),
                    scRaster.getHeight(),
                    scRaster.getPixelStride() * 2,
                    scRaster.getScanlineStride() * 2,
                    icm);
    return bisd;
}
BufImgSurfaceData.java 文件源码 项目:OpenJSharp 阅读 27 收藏 0 点赞 0 评论 0
public static SurfaceData createDataBC(BufferedImage bImg,
                                       SurfaceType sType,
                                       int primaryBank) {
    ByteComponentRaster bcRaster =
        (ByteComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bcRaster.getDataStorage(),
                    bcRaster.getDataOffset(primaryBank), 0,
                    bcRaster.getWidth(),
                    bcRaster.getHeight(),
                    bcRaster.getPixelStride(),
                    bcRaster.getScanlineStride(),
                    icm);
    return bisd;
}
BufImgSurfaceData.java 文件源码 项目:OpenJSharp 阅读 35 收藏 0 点赞 0 评论 0
public static SurfaceData createDataBP(BufferedImage bImg,
                                       SurfaceType sType) {
    BytePackedRaster bpRaster =
        (BytePackedRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bpRaster.getDataStorage(),
                    bpRaster.getDataBitOffset() / 8,
                    bpRaster.getDataBitOffset() & 7,
                    bpRaster.getWidth(),
                    bpRaster.getHeight(),
                    0,
                    bpRaster.getScanlineStride(),
                    icm);
    return bisd;
}
JFIFMarkerSegment.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
JFIFMarkerSegment.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
JFIFMarkerSegment.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
GIFImageReader.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
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;
}
IndexColorModelEqualsTest.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
private static void testConstructor7() {
    /*
     * verify equality with constructor
     * IndexColorModel(int bits, int size, int[] cmap, int start,
     * int transferType, BigInteger validBits)
     */
    /*
     * In setRGBs() function of IndexColorModel we override
     * transparent_index value to map to pixel value if alpha is 0x00
     * so we should have atleast minimum alpha value to keep
     * both model1 and model2 same.
     */
    int color = 16777216;
    IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
    IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
    verifyEquals(model1, model2);
}
TransparencyTest.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
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;
}
LookupTables.java 文件源码 项目:imagingbook-common 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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));
}
mxPngEncodeParam.java 文件源码 项目:Tarski 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Returns an instance of <code>PNGEncodeParam.Palette</code>,
 * <code>PNGEncodeParam.Gray</code>, or
 * <code>PNGEncodeParam.RGB</code> appropriate for encoding
 * the given image.
 *
 * <p> If the image has an <code>IndexColorModel</code>, an
 * instance of <code>PNGEncodeParam.Palette</code> is returned.
 * Otherwise, if the image has 1 or 2 bands an instance of
 * <code>PNGEncodeParam.Gray</code> is returned.  In all other
 * cases an instance of <code>PNGEncodeParam.RGB</code> is
 * returned.
 *
 * <p> Note that this method does not provide any guarantee that
 * the given image will be successfully encoded by the PNG
 * encoder, as it only performs a very superficial analysis of
 * the image structure.
 */
public static mxPngEncodeParam getDefaultEncodeParam(RenderedImage im)
{
    ColorModel colorModel = im.getColorModel();
    if (colorModel instanceof IndexColorModel)
    {
        return new mxPngEncodeParam.Palette();
    }

    SampleModel sampleModel = im.getSampleModel();
    int numBands = sampleModel.getNumBands();

    if (numBands == 1 || numBands == 2)
    {
        return new mxPngEncodeParam.Gray();
    }
    else
    {
        return new mxPngEncodeParam.RGB();
    }
}
BMPSubsamplingTest.java 文件源码 项目:jdk8u-jdk 阅读 17 收藏 0 点赞 0 评论 0
private BufferedImage createIndexImage(int bpp) {
    // calculate palette size
    int psize = (1 << bpp);

    // prepare palette;
    byte[] r = new byte[psize];
    byte[] g = new byte[psize];
    byte[] b = new byte[psize];

    for (int i = 0; i < colors.length; i++) {
        r[i] = (byte)(0xff & colors[i].getRed());
        g[i] = (byte)(0xff & colors[i].getGreen());
        b[i] = (byte)(0xff & colors[i].getBlue());
    }

    // now prepare appropriate index clor model
    IndexColorModel icm = new IndexColorModel(bpp, psize, r, g, b);

    return new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
}
ShortHistogramTest.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
protected BufferedImage createTestImage(int numColors) {

        IndexColorModel icm = createTestICM(numColors);
        int w = numColors * 10;
        int h = 20;

        BufferedImage img = new BufferedImage(w, h,
                BufferedImage.TYPE_BYTE_INDEXED, icm);

        Graphics2D g = img.createGraphics();
        for (int i = 0; i < numColors; i++) {
            int rgb = icm.getRGB(i);
            //System.out.printf("pixel %d, rgb %x\n", i, rgb);
            g.setColor(new Color(rgb));
            g.fillRect(i * 10, 0, w - i * 10, h);
        }
        g.dispose();

       return img;
    }
JFIFMarkerSegment.java 文件源码 项目:jdk8u-jdk 阅读 28 收藏 0 点赞 0 评论 0
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
GIFImageReader.java 文件源码 项目:jdk8u-jdk 阅读 22 收藏 0 点赞 0 评论 0
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;
}
PaletteBuilder.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
protected RenderedImage getIndexedImage() {
    IndexColorModel icm = getIndexColorModel();

    BufferedImage dst =
        new BufferedImage(src.getWidth(), src.getHeight(),
                          BufferedImage.TYPE_BYTE_INDEXED, icm);

    WritableRaster wr = dst.getRaster();
    for (int y =0; y < dst.getHeight(); y++) {
        for (int x = 0; x < dst.getWidth(); x++) {
            Color aColor = getSrcColor(x,y);
            wr.setSample(x, y, 0, findColorIndex(root, aColor));
        }
    }

    return dst;
}


问题


面经


文章

微信
公众号

扫码关注公众号