Apply color mask to the image.

@param imageBuffer The image reference (must not be <code>null</code>).
@param maskColor The color mask (must not be <code>null</code>).
@return The masked image buffer.
@throws LionEngineException If invalid arguments.
426153
public static ImageBuffer applyMask(ImageBuffer imageBuffer, ColorRgba maskColor)
    {
        return factoryGraphic.applyMask(imageBuffer, maskColor);
    }
818427
function(image) {
        var maskWidth = this._getMaskX(image.width);
        var maskHeight = this._getMaskY(image.height);
        var buf = this._getResizedImageBuffer(image, maskWidth, maskHeight);
        var mask = new Array(maskWidth * maskHeight);
        for (var y = 0; y < maskHeight; y++) {
            for (var x = 0; x < maskWidth; x++) {
                var idx = (y * maskWidth + x);
                var filled = this._checkFilledPixel(buf, idx);
                mask[idx] = filled ? 1 : 0;
            }
        }
        return mask;
    }
43951
def drawMask(self,ax=None, mask=None, mtype='maglim'):
        
        if not ax: ax = plt.gca()
        if mask is None:
            mask = ugali.analysis.loglike.createMask(self.config,roi=self.roi)

        mask_map = hp.UNSEEN*np.ones(hp.nside2npix(self.nside))
        if mtype.lower() == 'maglim':
            mask_map[mask.roi.pixels] = mask.mask_1.mask_roi_sparse
        elif mtype.lower() == 'fracdet':
            mask_map[mask.roi.pixels] = mask.mask_1.frac_roi_sparse
        else:
            raise Exception("Unrecognized type: %s"%mtype)
        masked = (mask_map==hp.UNSEEN) | (mask_map==0)
        mask_map = np.ma.array(mask_map,mask=masked,fill_value=np.nan)

        im = drawHealpixMap(mask_map,self.lon,self.lat,self.radius,coord=self.coord)

        try: cbar = ax.cax.colorbar(im)
        except: cbar = plt.colorbar(im)
        cbar.ax.set_xticklabels(cbar.ax.get_xticklabels(),rotation=90)
        ax.annotate(mtype,**self.label_kwargs)
        return im
1323904
public static Bitmap processTintTransformationMap(Bitmap transformationMap, int tintColor) {
		// tint color
		int[] t = new int[] {
				Color.red(tintColor),
				Color.green(tintColor),
				Color.blue(tintColor) };
		
		int width = transformationMap.getWidth();
		int height = transformationMap.getHeight();
		int[] pixels = new int[width * height];
		transformationMap.getPixels(pixels, 0, width, 0, 0, width, height);
		
		float[] transformation = new float[2];
		
		for (int i=0; i<pixels.length; i++) {
			int color = pixels[i];
			int alpha = Color.alpha(color);
			transformation[0] = Color.red(color) / 255f;
			transformation[1] = Color.green(color) / 255f;
			pixels[i] = applyTransformation(t, alpha, transformation);
		}
		return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
	}
137313
@Override
    public AiColor wrapColor(ByteBuffer buffer, int offset) {
        AiColor color = new AiColor(buffer, offset);
        return color;
    }
950389
public static void drawMasked(Bitmap src, Drawable mask, Bitmap dest, int clearColor) {
        clearBitmap(dest, clearColor);
        Canvas canvas = new Canvas(dest);

        canvas.drawBitmap(src,
                new Rect(0, 0, src.getWidth(), src.getHeight()),
                new Rect(0, 0, dest.getWidth(), dest.getHeight()),
                new Paint(Paint.FILTER_BITMAP_FLAG));

        if (mask instanceof BitmapDrawable) {
            ((BitmapDrawable) mask).getPaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        } else if (mask instanceof NinePatchDrawable) {
            ((NinePatchDrawable) mask).getPaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        } else {
            throw new RuntimeException("Supported only BitmapDrawable or NinePatchDrawable");
        }
        mask.setBounds(0, 0, mask.getIntrinsicWidth(), mask.getIntrinsicHeight());
        mask.draw(canvas);
        canvas.setBitmap(null);
    }
350969
public final void setBackgroundColor(@ColorInt final int color) {
        this.background = new ColorDrawable(color);
        this.backgroundBitmap = null;
        this.backgroundId = -1;
        this.backgroundColor = color;
        adaptBackground();
    }
394910
public void setColorFilter(@ColorInt int color) {
        Drawable drawable = getIndeterminateDrawable();
        drawable = drawable.mutate();
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        setIndeterminateDrawable(drawable);
    }
88023
public static BufferedImage composeMaskedImage (
        ImageCreator isrc, BufferedImage mask, BufferedImage base)
    {
        int wid = base.getWidth();
        int hei = base.getHeight();

        Raster maskdata = mask.getData();
        Raster basedata = base.getData();

        // create a new image using the rasters if possible
        if (maskdata.getNumBands() == 4 && basedata.getNumBands() >= 3) {
            WritableRaster target = basedata.createCompatibleWritableRaster(wid, hei);

            // copy the alpha from the mask image
            int[] adata = maskdata.getSamples(0, 0, wid, hei, 3, (int[]) null);
            target.setSamples(0, 0, wid, hei, 3, adata);

            // copy the RGB from the base image
            for (int ii=0; ii < 3; ii++) {
                int[] cdata = basedata.getSamples(0, 0, wid, hei, ii, (int[]) null);
                target.setSamples(0, 0, wid, hei, ii, cdata);
            }

            return new BufferedImage(mask.getColorModel(), target, true, null);

        } else {
            // otherwise composite them by rendering them with an alpha
            // rule
            BufferedImage target = isrc.createImage(wid, hei, Transparency.TRANSLUCENT);
            Graphics2D g2 = target.createGraphics();
            try {
                g2.drawImage(mask, 0, 0, null);
                g2.setComposite(AlphaComposite.SrcIn);
                g2.drawImage(base, 0, 0, null);
            } finally {
                g2.dispose();
            }
            return target;
        }
    }
272975
public static <T extends ImageGray<T>, G extends GradientValue>
	SparseImageGradient<T,G> createSobel( Class<T> imageType , ImageBorder<T> border )
	{
		if( imageType == GrayF32.class) {
			return (SparseImageGradient)new GradientSparseSobel_F32((ImageBorder_F32)border);
		} else if( imageType == GrayU8.class ){
			return (SparseImageGradient)new GradientSparseSobel_U8((ImageBorder_S32)border);
		} else {
			throw new IllegalArgumentException("Unsupported image type "+imageType.getSimpleName());
		}
	}
1348989
protected BufferedImage create_BACKGROUND_Image(final int WIDTH, final int HEIGHT, BufferedImage image) {
        if (WIDTH <= 0 || HEIGHT <= 0) {
            return UTIL.createImage(1, 1, Transparency.TRANSLUCENT);
        }

        if (image == null) {
            image = UTIL.createImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
        }
        final Graphics2D G2 = image.createGraphics();
        G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

        final int IMAGE_WIDTH = image.getWidth();
        final int IMAGE_HEIGHT = image.getHeight();

        // Draw the background image
        BACKGROUND_FACTORY.createLinearBackground(WIDTH, HEIGHT, getBackgroundColor(), getModel().getCustomBackground(), getModel().getTextureColor(), image);

        // Draw the custom layer if selected
        if (isCustomLayerVisible()) {
            G2.drawImage(UTIL.getScaledInstance(getCustomLayer(), IMAGE_WIDTH, IMAGE_HEIGHT, RenderingHints.VALUE_INTERPOLATION_BICUBIC), 0, 0, null);
        }

        G2.dispose();

        return image;
    }
746011
public static <T extends ImageBase<T>>
	ComputeRegionMeanColor<T> regionMeanColor(ImageType<T> imageType) {
		if( imageType.getFamily() == ImageType.Family.GRAY) {
			switch( imageType.getDataType() ) {
				case U8:
					return (ComputeRegionMeanColor)new ComputeRegionMeanColor.U8();
				case F32:
					return (ComputeRegionMeanColor)new ComputeRegionMeanColor.F32();
			}
		} else if( imageType.getFamily() == ImageType.Family.PLANAR) {
			int N = imageType.getNumBands();
			switch( imageType.getDataType() ) {
				case U8:
					return (ComputeRegionMeanColor)new ComputeRegionMeanColor.PL_U8(N);
				case F32:
					return (ComputeRegionMeanColor)new ComputeRegionMeanColor.PL_F32(N);
			}
		}

		throw new IllegalArgumentException("Unknown imageType");
	}
337511
private BufferedImage create_BACKGROUND_Image(final int WIDTH, BufferedImage image) {
        if (WIDTH <= 0) {
            return null;
        }
        if (image == null) {
            image = UTIL.createImage(WIDTH, WIDTH, Transparency.TRANSLUCENT);
        }
        final Graphics2D G2 = image.createGraphics();
        G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        switch (getFrameType()) {
            case SQUARE:
                BACKGROUND_FACTORY.createLinearBackground(WIDTH, WIDTH, getBackgroundColor(), getCustomBackground(), getModel().getTextureColor(), image);
                break;
            case ROUND:

            default:
                BACKGROUND_FACTORY.createRadialBackground(WIDTH, getBackgroundColor(), getCustomBackground(), getModel().getTextureColor(), image);
                break;
        }
        G2.dispose();

        return image;
    }
849351
public static<T extends ImageGray<T>, D extends ImageGray<D>>
	void detectLineSegments( BufferedImage image ,
							 Class<T> imageType ,
							 Class<D> derivType )
	{
		// convert the line into a single band image
		T input = ConvertBufferedImage.convertFromSingle(image, null, imageType );

		// Comment/uncomment to try a different type of line detector
		DetectLineSegmentsGridRansac<T,D> detector = FactoryDetectLineAlgs.lineRansac(40, 30, 2.36, true, imageType, derivType);

		List<LineSegment2D_F32> found = detector.detect(input);

		// display the results
		ImageLinePanel gui = new ImageLinePanel();
		gui.setImage(image);
		gui.setLineSegments(found);
		gui.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));

		listPanel.addItem(gui, "Found Line Segments");
	}
1156421
private static Drawable getRippleMask(int color, int radius) {
        float[] outerRadius = new float[8];
        Arrays.fill(outerRadius, radius);
        RoundRectShape r = new RoundRectShape(outerRadius, null, null);
        ShapeDrawable shapeDrawable = new ShapeDrawable(r);
        shapeDrawable.getPaint().setColor(color);
        return shapeDrawable;
    }
773368
protected String textureFragmentShader() {
    StringBuilder str = new StringBuilder(FRAGMENT_PREAMBLE);

    str.append(textureUniforms());
    str.append(textureVaryings());

    str.append("void main(void) {\n");

    str.append(textureColor());
    str.append(textureTint());
    str.append(textureAlpha());

    str.append(
      "  gl_FragColor = textureColor;\n" +
      "}");

    return str.toString();
  }
1233343
public static BufferedImage ByteBufferImage( byte[] data, int width, int height ) {
        int[] bandoffsets = {0, 1, 2, 3};
        DataBufferByte dbb = new DataBufferByte(data, data.length);
        WritableRaster wr = Raster.createInterleavedRaster(dbb, width, height, width * 4, 4, bandoffsets, null);
        int[] bitfield = {8, 8, 8, 8};

        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        ColorModel cm = new ComponentColorModel(cs, bitfield, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);

        return new BufferedImage(cm, wr, false, null);
    }