Get raster color.

@param i The color offset.
@param data The raster data (must not be <code>null</code>).
@return The rastered color.
@throws LionEngineException If invalid arguments.
541563
private static double getRasterFactor(int i, RasterData data)
    {
        Check.notNull(data);

        final double force = data.getForce();
        final double amplitude = data.getAmplitude();
        final int offset = data.getOffset();

        if (0 == data.getType())
        {
            return force * UtilMath.sin(i * amplitude + offset);
        }
        return force * UtilMath.cos(i * amplitude + offset);
    }
516011
public ClickableIconOverlay set(int id, IGeoPoint position, Drawable icon, DataType data) {
        set(position, icon);
        mId = id;
        mData = data;
        return this;
    }
392086
private static URI createRaster(
            final Dimension targetSize, final RasterReference rasterReference,
            final Double rotation, final Color backgroundColor,
            final File workingDir) throws IOException {
        final File path = File.createTempFile("north-arrow-", ".png", workingDir);

        final BufferedImage newImage =
                new BufferedImage(targetSize.width, targetSize.height, BufferedImage.TYPE_4BYTE_ABGR);
        final Graphics2D graphics2d = newImage.createGraphics();
        try {
            final BufferedImage originalImage = ImageIO.read(rasterReference.inputStream);
            if (originalImage == null) {
                LOGGER.warn("Unable to load NorthArrow graphic: {}, it is not an image format that can be " +
                                    "decoded",
                            rasterReference.uri);
                throw new IllegalArgumentException();
            }

            // set background color
            graphics2d.setColor(backgroundColor);
            graphics2d.fillRect(0, 0, targetSize.width, targetSize.height);

            // scale the original image to fit the new size
            int newWidth;
            int newHeight;
            if (originalImage.getWidth() > originalImage.getHeight()) {
                newWidth = targetSize.width;
                newHeight = Math.min(
                        targetSize.height,
                        (int) Math.ceil(newWidth / (originalImage.getWidth() /
                                (double) originalImage.getHeight())));
            } else {
                newHeight = targetSize.height;
                newWidth = Math.min(
                        targetSize.width,
                        (int) Math.ceil(newHeight / (originalImage.getHeight() /
                                (double) originalImage.getWidth())));
            }

            // position the original image in the center of the new
            int deltaX = (int) Math.floor((targetSize.width - newWidth) / 2.0);
            int deltaY = (int) Math.floor((targetSize.height - newHeight) / 2.0);

            if (!FloatingPointUtil.equals(rotation, 0.0)) {
                final AffineTransform rotate = AffineTransform.getRotateInstance(
                        rotation, targetSize.width / 2.0, targetSize.height / 2.0);
                graphics2d.setTransform(rotate);
            }

            graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                        RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            graphics2d.drawImage(originalImage, deltaX, deltaY, newWidth, newHeight, null);

            ImageUtils.writeImage(newImage, "png", path);
        } finally {
            graphics2d.dispose();
        }
        return path.toURI();
    }
716679
RenderedImage createSimpleIndexImage() {
        ColorModel srcCM = src.getColorModel();
        if(srcCM instanceof IndexColorModel) {
            return src;
        }
        
        Raster srcRaster = src.getData();
        boolean hasTransparent = srcCM.getTransparency() != Transparency.OPAQUE;
        int maxColorCount = 256;
        if(hasTransparent) {
            maxColorCount = 255;
        }
        
        int num = 0;
        Set<Integer> colorSet = new HashSet<Integer>();
        int[] colorArrays = new int[maxColorCount];
        for(int x = 0; x < src.getWidth(); x++) {
            for(int y = 0; y < src.getHeight(); y++) {
                int rgb = srcCM.getRGB(srcRaster.getDataElements(x, y, null)) & 0xFFFFFF;
                if(!colorSet.contains(rgb)) {
                    if(num == maxColorCount) {
                        return null;
                    }
                    
                    colorArrays[num++] = rgb;
                    colorSet.add(rgb);
                }
            }
        }
        if(num == 0) {
            throw new IllegalStateException("This image has no color");
        }
        
        int[] colors = null;
        if(hasTransparent) {
            colors = new int[num + 1];
            System.arraycopy(colorArrays, 0, colors, 1, num);
            colors[0] = 0;
        } else {
            colors = new int[num];
            System.arraycopy(colorArrays, 0, colors, 0, num);
        }
        
        Arrays.sort(colors);
        
        byte[] red = new byte[colors.length];
        byte[] green = new byte[colors.length];
        byte[] blue = new byte[colors.length];
        for(int i = 0; i < colors.length; i++) {
            red[i] = (byte)((colors[i] >> 16) & 0xFF);
            green[i] = (byte)((colors[i] >> 8) & 0xFF);
            blue[i] = (byte)((colors[i]) & 0xFF);
        }

        IndexColorModel destCM = null;
        if(hasTransparent) {
            destCM = new IndexColorModel(8, colors.length, red, green, blue, 0);
        } else {
            destCM = new IndexColorModel(8, colors.length, red, green, blue);
        }
        
        BufferedImage image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, destCM);
        WritableRaster raster = image.getRaster();
        for (int x = 0; x < src.getWidth(); x++) {
            for (int y = 0; y < src.getHeight(); y++) {
                int argb = srcCM.getRGB(srcRaster.getDataElements(x, y, null));
                if(hasTransparent && ((argb & 0xFF000000) != 0xFF000000)) {
                    raster.setSample(x, y, 0, 0);
                } else {
                    int index = Arrays.binarySearch(colors, (argb & 0x00FFFFFF));
                    if(index < 0) {
                        throw new IllegalStateException("Some colors not indexed");
                    }
                    raster.setSample(x, y, 0, index);
                }
            }
        }

        return image;
    }
253364
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
	public int getShadowColor (){
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
			return mInputView.getShadowColor();

		return 0;
	}
1006435
public static BufferedImage cloneImage(BufferedImage bi) {
        ColorModel cm = bi.getColorModel();
        boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
        WritableRaster raster = bi.copyData(null);
        return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
    }
734146
private void scatter(Graphics g, int i) {

    	int height = getHeight();
    	int width = getWidth();

    	int x = (int)(((this.variedParamValues[i] - this.lower_x_value) / (this.upper_x_value - this.lower_x_value)) * width); 
    	double value = this.measures[i].getLastValue(this.measureSelected);  

        if(Double.isNaN(value)){
        	// no result for this budget yet
            return;
        }

        int y = (int)(height - (value / this.upper_y_value) * height);

        g.setColor(this.colors[i]);

        if (this.isStandardDeviationPainted) {
            int len = (int) ((this.measureStds[i].getLastValue(this.measureSelected)/this.upper_y_value)*height);
            paintStandardDeviation(g, len, x, y);
        }

    	g.fillOval(x - DOT_SIZE/2, y - DOT_SIZE/2, DOT_SIZE, DOT_SIZE);

    }
367841
protected static ArrayList getSoilLayer(HashMap data) {
        if (data.containsKey("soil") || !data.containsKey("soilLayer")) {
            return MapUtil.getBucket(data, "soil").getDataList();
        } else {
            return new BucketEntry(data).getDataList();
        }
    }
22480
function (data) {
    this.attributes = this.initVariables(data, 'attribute');
    this.uniforms = this.initVariables(data, 'uniform');
    this.material = new (this.raw ? THREE.RawShaderMaterial : THREE.ShaderMaterial)({
      // attributes: this.attributes,
      uniforms: this.uniforms,
      vertexShader: this.vertexShader,
      fragmentShader: this.fragmentShader
    });
    return this.material;
  }
301259
public static int getColor(GraphicFactory graphicFactory, String colorString) {
        return getColor(graphicFactory, colorString, null, null);
    }
822008
public boolean write( RasterData rasterData ) throws RasterWritingFailureException {
        try {
            return writer.write(rasterData);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RasterWritingFailureException(e.getLocalizedMessage());
        }

    }
175014
public static byte[] getPixelsBGR(BufferedImage img, int y, int w, byte[] array, int[] temp) {
    final int x = 0;
    final int h = 1;

    assert array.length == temp.length * nrChannels(img);
    assert (temp.length == w);

    int imageType = img.getType();
    Raster raster;
    switch (imageType) {
      case BufferedImage.TYPE_3BYTE_BGR:
      case BufferedImage.TYPE_4BYTE_ABGR:
      case BufferedImage.TYPE_4BYTE_ABGR_PRE:
      case BufferedImage.TYPE_BYTE_GRAY:
        raster = img.getRaster();
        //int ttype= raster.getTransferType();
        raster.getDataElements(x, y, w, h, array);
        break;
      case BufferedImage.TYPE_INT_BGR:
        raster = img.getRaster();
        raster.getDataElements(x, y, w, h, temp);
        ints2bytes(temp, array, 0, 1, 2);  // bgr -->  bgr
        break;
      case BufferedImage.TYPE_INT_RGB:
        raster = img.getRaster();
        raster.getDataElements(x, y, w, h, temp);
        ints2bytes(temp, array, 2, 1, 0);  // rgb -->  bgr
        break;
      case BufferedImage.TYPE_INT_ARGB:
      case BufferedImage.TYPE_INT_ARGB_PRE:
        raster = img.getRaster();
        raster.getDataElements(x, y, w, h, temp);
        ints2bytes(temp, array, 2, 1, 0, 3);  // argb -->  abgr
        break;
      case BufferedImage.TYPE_CUSTOM: // TODO: works for my icon image loader, but else ???
        img.getRGB(x, y, w, h, temp, 0, w);
        ints2bytes(temp, array, 2, 1, 0, 3);  // argb -->  abgr
        break;
      default:
        img.getRGB(x, y, w, h, temp, 0, w);
        ints2bytes(temp, array, 2, 1, 0);  // rgb -->  bgr
        break;
    }

    return array;
  }
883489
@Override
    protected IIOMetadataNode getStandardChromaNode() {
        IIOMetadataNode chroma = new IIOMetadataNode("Chroma");

        // Handle ColorSpaceType (RGB/CMYK/YCbCr etc)...
        Entry photometricTag = ifd.getEntryById(TIFF.TAG_PHOTOMETRIC_INTERPRETATION);
        int photometricValue = getValueAsInt(photometricTag); // No default for this tag!
        int numChannelsValue = getSamplesPerPixelWithFallback();

        IIOMetadataNode colorSpaceType = new IIOMetadataNode("ColorSpaceType");
        chroma.appendChild(colorSpaceType);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_MASK: // It's really a transparency mask/alpha channel, but...
                colorSpaceType.setAttribute("name", "GRAY");
                break;
            case TIFFBaseline.PHOTOMETRIC_RGB:
            case TIFFBaseline.PHOTOMETRIC_PALETTE:
                colorSpaceType.setAttribute("name", "RGB");
                break;
            case TIFFExtension.PHOTOMETRIC_YCBCR:
                colorSpaceType.setAttribute("name", "YCbCr");
                break;
            case TIFFExtension.PHOTOMETRIC_CIELAB:
            case TIFFExtension.PHOTOMETRIC_ICCLAB:
            case TIFFExtension.PHOTOMETRIC_ITULAB:
                colorSpaceType.setAttribute("name", "Lab");
                break;
            case TIFFExtension.PHOTOMETRIC_SEPARATED:
                // TODO: May be CMYK, or something else... Consult InkSet and NumberOfInks!
                if (numChannelsValue == 3) {
                    colorSpaceType.setAttribute("name", "CMY");
                }
                else {
                    colorSpaceType.setAttribute("name", "CMYK");
                }
                break;
            case TIFFCustom.PHOTOMETRIC_LOGL: // ..?
            case TIFFCustom.PHOTOMETRIC_LOGLUV:
                colorSpaceType.setAttribute("name", "Luv");
                break;
            case TIFFCustom.PHOTOMETRIC_CFA:
            case TIFFCustom.PHOTOMETRIC_LINEAR_RAW: // ...or is this RGB?
                colorSpaceType.setAttribute("name", "3CLR");
                break;
            default:
                colorSpaceType.setAttribute("name", Integer.toHexString(numChannelsValue) + "CLR");
                break;
        }

        // NumChannels
        IIOMetadataNode numChannels = new IIOMetadataNode("NumChannels");
        chroma.appendChild(numChannels);
        if (photometricValue == TIFFBaseline.PHOTOMETRIC_PALETTE) {
            numChannels.setAttribute("value", "3");
        }
        else {
            numChannels.setAttribute("value", Integer.toString(numChannelsValue));
        }

        // BlackIsZero (defaults to TRUE)
        IIOMetadataNode blackIsZero = new IIOMetadataNode("BlackIsZero");
        chroma.appendChild(blackIsZero);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
                blackIsZero.setAttribute("value", "FALSE");
                break;
            default:
                break;
        }

        Entry colorMapTag = ifd.getEntryById(TIFF.TAG_COLOR_MAP);

        if (colorMapTag != null) {
            int[] colorMapValues = (int[]) colorMapTag.getValue();

            IIOMetadataNode palette = new IIOMetadataNode("Palette");
            chroma.appendChild(palette);

            int count = colorMapValues.length / 3;
            for (int i = 0; i < count; i++) {
                IIOMetadataNode paletteEntry = new IIOMetadataNode("PaletteEntry");
                paletteEntry.setAttribute("index", Integer.toString(i));

                // TODO: See TIFFImageReader createIndexColorModel, to detect 8 bit colorMap
                paletteEntry.setAttribute("red", Integer.toString((colorMapValues[i] >> 8) & 0xff));
                paletteEntry.setAttribute("green", Integer.toString((colorMapValues[i + count] >> 8) & 0xff));
                paletteEntry.setAttribute("blue", Integer.toString((colorMapValues[i + count * 2] >> 8) & 0xff));

                palette.appendChild(paletteEntry);
            }
        }

        return chroma;
    }
643934
private void paintFullCurve(Graphics g, int i){
            if (this.measures[i].getNumberOfValues(this.measureSelected) == 0) {
            	// no values of this measure available
            	return;
            }

            g.setColor(this.colors[i]);

            int height = getHeight();

//          // compute the relation of minimum PF and current PF
//          double processFrequencyFactor = pf / this.min_processFrequency;

            int n = this.measures[i].getNumberOfValues(this.measureSelected);

            int[] x = new int[n];
            int[] y = new int[n];

            for (int j = 0; j < n; j++) {
            	x[j] = (int) (j * x_resolution);
            	y[j] = (int)(height-(this.measures[i].getValue(this.measureSelected, j)/this.upper_y_value)*height);

            	if (this.isStandardDeviationPainted) {
            	    int len = (int) ((this.measureStds[i].getValue(this.measureSelected, j)/this.upper_y_value)*height);
            	    paintStandardDeviation(g, len, x[j], y[j]);
            	}
            }

            g.drawPolyline(x, y, n);
    }
866661
public Colorization getColorization (int classId, int colorId)
    {
        ColorRecord color = getColorRecord(classId, colorId);
        return (color == null) ? null : color.getColorization();
    }
602227
public final void setColors(Color[] colors) {
        int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                int idx = x + y * width;
                if (colors.length <= idx) break;
                int red   = (int)(colors[idx].getRed()   * 255.0);
                int green = (int)(colors[idx].getGreen() * 255.0);
                int blue  = (int)(colors[idx].getBlue()  * 255.0);
                int alpha = (int)(colors[idx].getAlpha() * 255.0);
                pixels[idx] = alpha << 24 |
                              red   << 16 |
                              green << 8  |
                              blue;
            }
        }
    }
368889
@Override
   public <E> E style(E element, Object data) throws VectorPrintException {
      if (getValue(DYNAMICDATA, Boolean.class)) {
         setData(convert(data));
      }
      return element;
   }