/*!
Changes the colors of the image based on threshold values. The luminance will be calculated and if it is
in a threshold range it will use the specified color for the range.
556844
static function setImageColorThreshold( $imageObject, $filterData, $sourceMimeData, $destinationMimeData,
                                            $thresholdList )
    {
        foreach ( array_keys( $thresholdList ) as $thresholdKey )
        {
            $thresholdList[$thresholdKey]['color'] = ImageColorAllocate( $imageObject, $thresholdItem['rgb'][0], $thresholdItem['rgb'][1], $thresholdItem['rgb'][2] );
        }
        $defaultColor = $thresholdList[count( $thresholdList ) - 1]['color'];

        $width = ImageSX( $imageObject );
        $height = ImageSY( $imageObject );
        for ( $y = 0; $y < $height; ++$y )
        {
            for ( $x = 0; $x < $width; ++$x )
            {
                $rgb = ImageColorAt( $imageObject, $x, $y );

                $r = ( $rgb >> 16 ) & 0xff;
                $g = ( $rgb >> 8 ) & 0x0ff;
                $b = ( $rgb ) & 0x0ff;

                $luminance = ( $r * 0.3 ) + ( $g * 0.59 ) + ( $b * 0.11 );

                $color = false;
                foreach ( $thresholdList as $thresholdItem )
                {
                    if ( $luminance <= $thresholdItem['threshold'] )
                    {
                        $color = $thresholdItem['color'];
                        break;
                    }
                }
                if ( $color === false )
                    $color = $defaultColor;

                ImageSetPixel( $imageObject, $x, $y, $color );
            }
        }
        return $imageObject;
    }
906002
public function execute($image)
    {
        $red = $this->argument(0)->between(-100, 100)->required()->value();
        $green = $this->argument(1)->between(-100, 100)->required()->value();
        $blue = $this->argument(2)->between(-100, 100)->required()->value();

        // normalize colorize levels
        $red = $this->normalizeLevel($red);
        $green = $this->normalizeLevel($green);
        $blue = $this->normalizeLevel($blue);

        $qrange = $image->getCore()->getQuantumRange();

        // apply
        $image->getCore()->levelImage(0, $red, $qrange['quantumRangeLong'], \Imagick::CHANNEL_RED);
        $image->getCore()->levelImage(0, $green, $qrange['quantumRangeLong'], \Imagick::CHANNEL_GREEN);
        $image->getCore()->levelImage(0, $blue, $qrange['quantumRangeLong'], \Imagick::CHANNEL_BLUE);

        return true;
    }
917497
function setBackground()
  {
    $dat = @getimagesize($this->bgimg);
    if($dat == false) { return; }

    switch($dat[2]) {
      case 1:  $newim = @imagecreatefromgif($this->bgimg); break;
      case 2:  $newim = @imagecreatefromjpeg($this->bgimg); break;
      case 3:  $newim = @imagecreatefrompng($this->bgimg); break;
      case 15: $newim = @imagecreatefromwbmp($this->bgimg); break;
      case 16: $newim = @imagecreatefromxbm($this->bgimg); break;
      default: return;
    }

    if(!$newim) return;

    imagecopy($this->im, $newim, 0, 0, 0, 0, $this->image_width, $this->image_height);
  }
1174985
protected function convertToTrueColor()
    {
        if (!imageistruecolor($this->resource)) {
            if (function_exists('imagepalettetotruecolor')) {
                // Available in PHP 5.5
                imagepalettetotruecolor($this->resource);
            } else {
                $transparentIndex = imagecolortransparent($this->resource);

                $w = $this->width();
                $h = $this->height();

                $img = imagecreatetruecolor($w, $h);
                imagecopy($img, $this->resource, 0, 0, 0, 0, $w, $h);

                if ($transparentIndex != -1) {
                    $width = $this->width();
                    $height = $this->height();

                    imagealphablending($img, false);
                    imagesavealpha($img, true);

                    for ($x = 0; $x < $width; ++$x) {
                        for ($y = 0; $y < $height; ++$y) {
                            if (imagecolorat($this->resource, $x, $y) == $transparentIndex) {
                                imagesetpixel($img, $x, $y, 127 << 24);
                            }
                        }
                    }
                }

                $this->resource = $img;
            }
        }

        imagesavealpha($this->resource, true);
    }
31786
private int[] changeColor() {
        int[] changedPixels = new int[pixels.length];
        double frequenz = 2 * Math.PI / 1020;

        for (int i = 0; i < pixels.length; i++) {
            int argb = pixels[i];
            int a = (argb >> 24) & 0xff;
            int r = (argb >> 16) & 0xff;
            int g = (argb >> 8) & 0xff;
            int b = argb & 0xff;

            r = (int) (255 * Math.sin(frequenz * r));
            b = (int) (-255 * Math.cos(frequenz * b) + 255);

            changedPixels[i] = (a << 24) | (r << 16) | (g << 8) | b;
        }

        return changedPixels;
    }
729307
public function blackAndWhite()
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Make image black and white
		# Param in:   n/a
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ($this->imageResized)
		{

			imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
			imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -1000);
		}

	}
255936
function setStrokeColor($color, $force = false)
    {
        $new_color = array($color[0], $color[1], $color[2], isset($color[3]) ? $color[3] : null);

        if (!$force && $this->currentStrokeColor == $new_color) {
            return;
        }

        if (isset($new_color[3])) {
            $this->currentStrokeColor = $new_color;
            $this->addContent(vsprintf("\n%.3F %.3F %.3F %.3F K", $this->currentStrokeColor));
        } else {
            if (isset($new_color[2])) {
                $this->currentStrokeColor = $new_color;
                $this->addContent(vsprintf("\n%.3F %.3F %.3F RG", $this->currentStrokeColor));
            }
        }
    }
1032890
function(color) {
		var l = color[2];

		if (color[1] == 0) {
			l = Math.round(l*255);
			return [l, l, l];
		} else {
			function hue2rgb(p, q, t) {
				if (t < 0) t += 1;
				if (t > 1) t -= 1;
				if (t < 1/6) return p + (q - p) * 6 * t;
				if (t < 1/2) return q;
				if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
				return p;
			}

			var s = color[1];
			var q = (l < 0.5 ? l * (1 + s) : l + s - l * s);
			var p = 2 * l - q;
			var r = hue2rgb(p, q, color[0] + 1/3);
			var g = hue2rgb(p, q, color[0]);
			var b = hue2rgb(p, q, color[0] - 1/3);
			return [Math.round(r*255), Math.round(g*255), Math.round(b*255)];
		}
	}
209044
public void setThresholdColor(final Color COLOR) {
        if (null == thresholdColor) {
            _thresholdColor = COLOR;
            fireTileEvent(REDRAW_EVENT);
        } else {
            thresholdColor.set(COLOR);
        }
    }
994744
function luminosity(color){
  utils.assertColor(color);
  color = color.rgba;
  function processChannel(channel) {
    channel = channel / 255;
    return (0.03928 > channel)
      ? channel / 12.92
      : Math.pow(((channel + 0.055) / 1.055), 2.4);
  }
  return new nodes.Unit(
    0.2126 * processChannel(color.r)
    + 0.7152 * processChannel(color.g)
    + 0.0722 * processChannel(color.b)
  );
}
221056
function _imageBlend($mode, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent)
    {
        if ($mode == IMAGE_TOOLBOX_BLEND_COPY)
        {
            if ($percent == 100)
            {
                imagecopy($this->_img['main']['resource'], $this->_img['operator']['resource'], $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
            }
            else
            {
                imagecopymerge($this->_img['main']['resource'], $this->_img['operator']['resource'], $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);
            }
        }
        else
        {
            $functionname = $this->_imagecreatefunction;
            $dummy = $functionname($src_w, $src_h);
            for ($y = 0; $y < $src_h; $y++)
            {
                for ($x = 0; $x < $src_w; $x++)
                {
                    $colorindex = imagecolorat($this->_img['main']['resource'], $dst_x + $x, $dst_y + $y);
                    $colorrgb1 = imagecolorsforindex($this->_img['main']['resource'], $colorindex);
                    $colorindex = imagecolorat($this->_img['operator']['resource'], $src_x + $x, $src_y + $y);
                    $colorrgb2 = imagecolorsforindex($this->_img['operator']['resource'], $colorindex);
                    $colorblend = $this->_calculateBlendvalue($mode, $colorrgb1, $colorrgb2);
                    $newcolor = imagecolorallocate($dummy, $colorblend['red'], $colorblend['green'], $colorblend['blue']);
                    imagesetpixel($dummy, $x, $y, $newcolor);
                }
            }

            $this->_img['target']['resource'] = $functionname($this->_img['main']['width'], $this->_img['main']['height']);
            imagecopy($this->_img['target']['resource'], $this->_img['main']['resource'], 0, 0, 0, 0, $this->_img['main']['width'], $this->_img['main']['height']);
            imagecopymerge($this->_img['target']['resource'], $dummy, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);

            $this->_img['main']['resource'] = $this->_img['target']['resource'];
            unset($this->_img['target']);
        }
    }
1332751
function (data, colorFunc, state) {
        var gradientPixels = this._gradientPixels;
        var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
        var color = [0, 0, 0, 0];
        var off = 0;
        for (var i = 0; i < 256; i++) {
            colorFunc[state](i / 255, true, color);
            pixelsSingleState[off++] = color[0];
            pixelsSingleState[off++] = color[1];
            pixelsSingleState[off++] = color[2];
            pixelsSingleState[off++] = color[3];
        }
        return pixelsSingleState;
    }
1238347
function updateCustomColor() {
                    switch (scope.val) {
                        case scope.ngTrueVal:
                            if (angular.isDefined(attrs.ngTrueColor)) {
                                scope.styleSwitch['background-color'] = attrs.ngTrueColor;
                            }
                            break;
                        case scope.ngFalseVal:
                            if (angular.isDefined(attrs.ngFalseColor)) {
                                scope.styleSwitch['background-color'] = attrs.ngFalseColor;
                            }
                            break;
                        default:
                            if (scope.triToggle) {
                                if (angular.isDefined(attrs.ngNullColor)) {
                                    scope.styleSwitch['background-color'] = attrs.ngNullColor;
                                }
                            }
                            break;
                    }
                }
480595
public void setColorRange(int firstIndex, int lastIndex, int color1, int color2) {
		for (int i = firstIndex; i <= lastIndex; i++)
			map[i] = ImageMath.mixColors((float)(i-firstIndex)/(lastIndex-firstIndex), color1, color2);
	}
1163454
function setBgColor($color)
    {
        $value = $this->_getColor($color);
        $this->_bg_color = $value;
        if ($this->_pattern == 0) { // force color to be seen
            $this->_pattern = 1;
        }
    }
86842
def palettize(self, colormap):
        

        if self.mode not in ("L", "LA"):
            raise ValueError("Image should be grayscale to colorize")
        self.channels[0], self.palette = colormap.palettize(self.channels[0])
        if self.mode == "L":
            self.mode = "P"
        else:
            self.mode = "PA"
574125
function adjustLuminance(rgb, lum) {
  var newRgb = {};
  newRgb.red = calculateLuminance(rgb.red, lum);
  newRgb.green = calculateLuminance(rgb.green, lum);
  newRgb.blue = calculateLuminance(rgb.blue, lum);

  return newRgb;
}