Exemple #1
0
 /* (non-Javadoc)
  * @see org.ejs.gui.images.IPaletteMapper#getPixelForGreyscaleMode(int)
  */
 @Override
 public int getPixelForGreyscaleMode(int pixel) {
   byte[] rgb = {0, 0, 0};
   ColorMapUtils.pixelToRGB(pixel, rgb);
   rgb = getRgbToGreyForGreyscaleMode(rgb);
   return ColorMapUtils.rgb8ToPixel(rgb);
 }
  public IndexColorModel transformMap(IndexColorModel icm) {
    if (!icm.hasAlpha())
      throw new IllegalArgumentException("Must have alpha channel in order to scale alpha!");

    byte[][] table = ColorMapUtils.extractTable(icm);
    table[3] = linearScale(table[3]);

    icm = new IndexColorModel(8, icm.getMapSize(), table[0], table[1], table[2], table[3]);
    return icm;
  }
  public RenderedImage transformImage(RenderedImage img) {

    if (!(img.getColorModel() instanceof IndexColorModel))
      throw new IllegalArgumentException(
          "Cannot transform this operations: doesn'three have IndexColorModel");

    IndexColorModel icm = (IndexColorModel) img.getColorModel();
    icm = transformMap(icm);
    RenderedImage retImg = ColorMapUtils.insertColorMap(img, icm);

    return retImg;
  }
Exemple #4
0
  /**
   * Get RGB pixel for each palette entry. The pixels are calculated lazily in case the palette
   * changes (this is called only after the mapping is complete).
   *
   * @return
   */
  protected int[] getPalettePixels() {
    if (palettePixels == null) {

      palettePixels = new int[numColors];

      for (int x = 0; x < numColors; x++) {
        byte[] nrgb = palette[x];
        if (isColorMappedGreyscale) nrgb = getRgbToGreyForGreyscaleMode(nrgb);
        palettePixels[x] = ColorMapUtils.rgb8ToPixel(nrgb);
      }
    }
    return palettePixels;
  }
Exemple #5
0
  /* (non-Javadoc)
   * @see org.ejs.gui.images.IPaletteMapper#getRgbToGreyForGreyscaleMode(byte[])
   */
  @Override
  public byte[] getRgbToGreyForGreyscaleMode(byte[] rgb) {
    int lum = ColorMapUtils.getRGBLum(rgb);

    TreeMap<Integer, byte[]> map = getGreyToRgbMap();
    Entry<Integer, byte[]> entry = map.ceilingEntry(lum);
    if (entry == null) {
      entry = map.floorEntry(lum);
      if (entry == null) {
        throw new AssertionError();
      }
    }

    return entry.getValue();
  }