tuple: The color mask of the framebuffer.
540701
def color_mask(self) -> Tuple[bool, bool, bool, bool]:
        '''
            
        '''

        return self.mglo.color_mask
543407
def _segment_color(self, color_im, bounding_box, bgmodel, cfg, vis_segmentation=False):
        
        # read params
        foreground_mask_tolerance = cfg['foreground_mask_tolerance']
        color_seg_rgb_weight = cfg['color_seg_rgb_weight']
        color_seg_num_clusters = cfg['color_seg_num_clusters']
        color_seg_hsv_weight = cfg['color_seg_hsv_weight']
        color_seg_dist_pctile = cfg['color_seg_dist_pctile']
        color_seg_dist_thresh = cfg['color_seg_dist_thresh']
        color_seg_min_bg_dist = cfg['color_seg_min_bg_dist']
        min_contour_area= cfg['min_contour_area']
        contour_dist_thresh = cfg['contour_dist_thresh']

        # foreground masking
        binary_im = color_im.foreground_mask(foreground_mask_tolerance, bgmodel=bgmodel)
        binary_im = binary_im.prune_contours(area_thresh=min_contour_area, dist_thresh=contour_dist_thresh)
        if binary_im is None:
            return None, None, None

        color_im = color_im.mask_binary(binary_im)

        # kmeans segmentation
        segment_im = color_im.segment_kmeans(color_seg_rgb_weight,
                                             color_seg_num_clusters,
                                             hue_weight=color_seg_hsv_weight)
        
        # keep the segment that is farthest from the background
        bg_dists = []
        hsv_bgmodel = 255 * np.array(colorsys.rgb_to_hsv(float(bgmodel[0]) / 255,
                                                         float(bgmodel[1]) / 255,
                                                         float(bgmodel[2]) / 255))
        hsv_bgmodel = np.r_[color_seg_rgb_weight * np.array(bgmodel), color_seg_hsv_weight * hsv_bgmodel[:1]]

        for k in range(segment_im.num_segments-1):
            seg_mask = segment_im.segment_mask(k)
            color_im_segment = color_im.mask_binary(seg_mask)
            color_im_segment_data = color_im_segment.nonzero_data()
            color_im_segment_data = np.c_[color_seg_rgb_weight * color_im_segment_data, color_seg_hsv_weight * color_im_segment.nonzero_hsv_data()[:,:1]]

            # take the median distance from the background
            bg_dist = np.median(np.linalg.norm(color_im_segment_data - hsv_bgmodel, axis=1))
            if vis_segmentation:
                logging.info('BG Dist for segment %d: %.4f' %(k, bg_dist))
            bg_dists.append(bg_dist)

        # sort by distance
        dists_and_indices = zip(np.arange(len(bg_dists)), bg_dists)
        dists_and_indices.sort(key = lambda x: x[1], reverse=True)
        
        # mask out the segment in the binary image
        if color_seg_num_clusters > 1 and abs(dists_and_indices[0][1] - dists_and_indices[1][1]) > color_seg_dist_thresh and dists_and_indices[1][1] < color_seg_min_bg_dist:
            obj_segment = dists_and_indices[0][0]
            obj_seg_mask = segment_im.segment_mask(obj_segment)
            binary_im = binary_im.mask_binary(obj_seg_mask)
            binary_im, diff_px = binary_im.center_nonzero()
            bounding_box = Box(bounding_box.min_pt.astype(np.float32) - diff_px,
                               bounding_box.max_pt.astype(np.float32) - diff_px,
                               bounding_box.frame)

        if vis_segmentation:
            plt.figure()
            plt.subplot(1,3,1)
            plt.imshow(color_im.data)
            plt.axis('off')
            plt.subplot(1,3,2)
            plt.imshow(segment_im.data)
            plt.colorbar()
            plt.axis('off')
            plt.subplot(1,3,3)
            plt.imshow(binary_im.data, cmap=plt.cm.gray)
            plt.axis('off')
            plt.show()

        return binary_im, segment_im, bounding_box
785256
function paramThreeToGL ( p ) {

		if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
		if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
		if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;

		if ( p === THREE.NearestFilter ) return _gl.NEAREST;
		if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
		if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;

		if ( p === THREE.LinearFilter ) return _gl.LINEAR;
		if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
		if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;

		if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
		if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
		if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
		if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;

		if ( p === THREE.ByteType ) return _gl.BYTE;
		if ( p === THREE.ShortType ) return _gl.SHORT;
		if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
		if ( p === THREE.IntType ) return _gl.INT;
		if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
		if ( p === THREE.FloatType ) return _gl.FLOAT;

		if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
		if ( p === THREE.RGBFormat ) return _gl.RGB;
		if ( p === THREE.RGBAFormat ) return _gl.RGBA;
		if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
		if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;

		if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
		if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
		if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;

		if ( p === THREE.ZeroFactor ) return _gl.ZERO;
		if ( p === THREE.OneFactor ) return _gl.ONE;
		if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
		if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
		if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
		if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
		if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
		if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;

		if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
		if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
		if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;

		return 0;

	}
938959
function boxBlur(scl, tcl, w, h, r) {
    for (var i = 0, l = scl.length; i < l; i++) { tcl[i] = scl[i]; }
    boxBlurH(tcl, scl, w, h, r);
    boxBlurV(scl, tcl, w, h, r);
}
1034059
def mask(color1 = nil)
      color1 = color1 || Color.from_rgb(255,255,255)
      color2 = color1.dup
      color2.a = 0

      color_replace(color1,color2)
    end
890497
def contour_mask(self, contour):
        
        # fill in new data
        new_data = np.zeros(self.data.shape)
        num_boundary = contour.boundary_pixels.shape[0]
        boundary_px_ij_swapped = np.zeros([num_boundary, 1, 2])
        boundary_px_ij_swapped[:, 0, 0] = contour.boundary_pixels[:, 1]
        boundary_px_ij_swapped[:, 0, 1] = contour.boundary_pixels[:, 0]
        cv2.fillPoly(
            new_data, pts=[
                boundary_px_ij_swapped.astype(
                    np.int32)], color=(
                BINARY_IM_MAX_VAL, BINARY_IM_MAX_VAL, BINARY_IM_MAX_VAL))
        orig_zeros = np.where(self.data == 0)
        new_data[orig_zeros[0], orig_zeros[1]] = 0
        return BinaryImage(new_data.astype(np.uint8), frame=self._frame)
990135
function ImageBufferRendererWebgl(imageCanvas) {

	//////////////////////////////////////////////////////////////
	// ImageBufferRendererWebgl private constants

	// vertices representing entire viewport as two triangles which make up the whole
	// rectangle, in post-projection/clipspace coordinates
	var VIEWPORT_VERTICES = new Float32Array([
			-1.0, -1.0,
			1.0, -1.0,
			-1.0, 1.0,
			-1.0, 1.0,
			1.0, -1.0,
			1.0, 1.0]);
	var NUM_VIEWPORT_VERTICES = VIEWPORT_VERTICES.length / 2;

	// Texture coordinates corresponding to each viewport vertex
	var VERTEX_TEXTURE_COORDS = new Float32Array([
			0.0, 1.0,
			1.0, 1.0,
			0.0, 0.0,
			0.0, 0.0,
			1.0, 1.0,
			1.0, 0.0]);

	//////////////////////////////////////////////////////////////
	// ImageBufferRendererWebgl private properties
	var metadata = this;
	var contextAttributes = { premultipliedAlpha: true, depth: false };
	var glContext = imageCanvas.getContext('webgl', contextAttributes) || imageCanvas.getContext('experimental-webgl', contextAttributes);
	glContext.clearColor(0.0, 0.0, 0.0, 0.0);      // Set clear color to black, fully transparent

	var vertexShader = createShaderFromSource(glContext.VERTEX_SHADER,
			"\
			attribute vec2 aPosition;\
			attribute vec2 aTextureCoord;\
			\
			varying highp vec2 vTextureCoord;\
			\
			void main() {\
					gl_Position = vec4(aPosition, 0, 1);\
					vTextureCoord = aTextureCoord;\
			}");
	var fragmentShader = createShaderFromSource(glContext.FRAGMENT_SHADER,
			"\
			precision mediump float;\
			\
			varying highp vec2 vTextureCoord;\
			\
			uniform sampler2D uSampler;\
			\
			void main() {\
					gl_FragColor = texture2D(uSampler, vTextureCoord);\
			}");
	var program = createProgram([vertexShader, fragmentShader]);
	glContext.useProgram(program);

	var positionAttribute = glContext.getAttribLocation(program, "aPosition");
	glContext.enableVertexAttribArray(positionAttribute);

	var textureCoordAttribute = glContext.getAttribLocation(program, "aTextureCoord");
	glContext.enableVertexAttribArray(textureCoordAttribute);

	// Associate the uniform texture sampler with TEXTURE0 slot
	var textureSamplerUniform = glContext.getUniformLocation(program, "uSampler");
	glContext.uniform1i(textureSamplerUniform, 0);

	// Create a buffer used to represent whole set of viewport vertices
	var vertexBuffer = glContext.createBuffer();
	glContext.bindBuffer(glContext.ARRAY_BUFFER, vertexBuffer);
	glContext.bufferData(glContext.ARRAY_BUFFER, VIEWPORT_VERTICES, glContext.STATIC_DRAW);
	glContext.vertexAttribPointer(positionAttribute, 2, glContext.FLOAT, false, 0, 0);

	// Create a buffer used to represent whole set of vertex texture coordinates
	var textureCoordinateBuffer = glContext.createBuffer();
	glContext.bindBuffer(glContext.ARRAY_BUFFER, textureCoordinateBuffer);
	glContext.bufferData(glContext.ARRAY_BUFFER, VERTEX_TEXTURE_COORDS, glContext.STATIC_DRAW);
	glContext.vertexAttribPointer(textureCoordAttribute, 2, glContext.FLOAT, false, 0, 0);

	// Create a texture to contain images from Kinect server
	// Note: TEXTURE_MIN_FILTER, TEXTURE_WRAP_S and TEXTURE_WRAP_T parameters need to be set
	//       so we can handle textures whose width and height are not a power of 2.
	var texture = glContext.createTexture();
	glContext.bindTexture(glContext.TEXTURE_2D, texture);
	glContext.texParameteri(glContext.TEXTURE_2D, glContext.TEXTURE_MAG_FILTER, glContext.LINEAR);
	glContext.texParameteri(glContext.TEXTURE_2D, glContext.TEXTURE_MIN_FILTER, glContext.LINEAR);
	glContext.texParameteri(glContext.TEXTURE_2D, glContext.TEXTURE_WRAP_S, glContext.CLAMP_TO_EDGE);
	glContext.texParameteri(glContext.TEXTURE_2D, glContext.TEXTURE_WRAP_T, glContext.CLAMP_TO_EDGE);
	glContext.bindTexture(glContext.TEXTURE_2D, null);

	// Since we're only using one single texture, we just make TEXTURE0 the active one
	// at all times
	glContext.activeTexture(glContext.TEXTURE0);

	//////////////////////////////////////////////////////////////
	// ImageBufferRendererWebgl private methods

	// Create a shader of specified type, with the specified source, and compile it.
	//     .createShaderFromSource(shaderType, shaderSource)
	//
	// shaderType: Type of shader to create (fragment or vertex shader)
	// shaderSource: Source for shader to create (string)
	function createShaderFromSource(shaderType, shaderSource) {
			var shader = glContext.createShader(shaderType);
			glContext.shaderSource(shader, shaderSource);
			glContext.compileShader(shader);

			// Check for errors during compilation
			var status = glContext.getShaderParameter(shader, glContext.COMPILE_STATUS);
			if (!status) {
					var infoLog = glContext.getShaderInfoLog(shader);
					console.log("Unable to compile Kinect '" + shaderType + "' shader. Error:" + infoLog);
					glContext.deleteShader(shader);
					return null;
			}

			return shader;
	}

	// Create a WebGL program attached to the specified shaders.
	//     .createProgram(shaderArray)
	//
	// shaderArray: Array of shaders to attach to program
	function createProgram(shaderArray) {
			var newProgram = glContext.createProgram();

			for (var shaderIndex = 0; shaderIndex < shaderArray.length; ++shaderIndex) {
					glContext.attachShader(newProgram, shaderArray[shaderIndex]);
			}
			glContext.linkProgram(newProgram);

			// Check for errors during linking
			var status = glContext.getProgramParameter(newProgram, glContext.LINK_STATUS);
			if (!status) {
					var infoLog = glContext.getProgramInfoLog(newProgram);
					console.log("Unable to link Kinect WebGL program. Error:" + infoLog);
					glContext.deleteProgram(newProgram);
					return null;
			}

			return newProgram;
	}

	//////////////////////////////////////////////////////////////
	// ImageBufferRendererWebgl public properties
	this.isProcessing = false;
	this.canvas = imageCanvas;
	this.width = 0;
	this.height = 0;
	this.gl = glContext;

	//////////////////////////////////////////////////////////////
	// ImageBufferRendererWebgl public functions

	// Draw image data into WebGL canvas context
	//     .processImageData(imageBuffer, width, height)
	//
	// imageBuffer: ArrayBuffer containing image data
	// width: width of image corresponding to imageBuffer data
	// height: height of image corresponding to imageBuffer data
	this.processImageData = function(imageBuffer, width, height) {
			if ((width != metadata.width) || (height != metadata.height)) {
					// Whenever the image width or height changes, update tracked metadata and canvas
					// viewport dimensions.
					this.width = width;
					this.height = height;
					this.canvas.width = width;
					this.canvas.height = height;
					glContext.viewport(0, 0, width, height);
			}
			//Associate the specified image data with a WebGL texture so that shaders can use it
			glContext.bindTexture(glContext.TEXTURE_2D, texture);
			glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, width, height, 0, glContext.RGBA, glContext.UNSIGNED_BYTE, new Uint8Array(imageBuffer));

			//Draw vertices so that shaders get invoked and we can render the texture
			glContext.drawArrays(glContext.TRIANGLES, 0, NUM_VIEWPORT_VERTICES);
			glContext.bindTexture(glContext.TEXTURE_2D, null);
	};

	// Clear all image data from WebGL canvas
	//     .clear()
	this.clear = function() {
			glContext.clear(glContext.COLOR_BUFFER_BIT);
	};
}
7807
def draw_edge_visibility(gl, v, e, f, hidden_wireframe=True):
    """"""
    gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    ec = np.arange(1, len(e)+1)
    ec = np.tile(col(ec), (1, 3))
    ec[:, 0] = ec[:, 0] & 255
    ec[:, 1] = (ec[:, 1] >> 8 ) & 255
    ec[:, 2] = (ec[:, 2] >> 16 ) & 255
    ec = np.asarray(ec, dtype=np.uint8)
    
    draw_colored_primitives(gl, v, e, ec)
    
    if hidden_wireframe:
        gl.Enable(GL_POLYGON_OFFSET_FILL)
        gl.PolygonOffset(10.0, 1.0)
        draw_colored_primitives(gl, v, f, fc=np.zeros(f.shape))
        gl.Disable(GL_POLYGON_OFFSET_FILL)
    
    raw = np.asarray(gl.getImage(), np.uint32)
    raw = raw[:,:,0] + raw[:,:,1]*256 + raw[:,:,2]*256*256 - 1
    return raw
461797
function compositeRGB(foreground, background) {
  const [fr, fg, fb, fa] = chroma(foreground).rgba()
  const [br, bg, bb] = chroma(background).rgb()
  return chroma([(1 - fa) * br + fa * fr, (1 - fa) * bg + fa * fg, (1 - fa) * bb + fa * fb]).css()
}
18220
private static void calculateThresholdForBlock(byte[] luminances,
                                                 int subWidth,
                                                 int subHeight,
                                                 int width,
                                                 int height,
                                                 int[][] blackPoints,
                                                 BitMatrix matrix) {
    int maxYOffset = height - BLOCK_SIZE;
    int maxXOffset = width - BLOCK_SIZE;
    for (int y = 0; y < subHeight; y++) {
      int yoffset = y << BLOCK_SIZE_POWER;
      if (yoffset > maxYOffset) {
        yoffset = maxYOffset;
      }
      int top = cap(y, 2, subHeight - 3);
      for (int x = 0; x < subWidth; x++) {
        int xoffset = x << BLOCK_SIZE_POWER;
        if (xoffset > maxXOffset) {
          xoffset = maxXOffset;
        }
        int left = cap(x, 2, subWidth - 3);
        int sum = 0;
        for (int z = -2; z <= 2; z++) {
          int[] blackRow = blackPoints[top + z];
          sum += blackRow[left - 2] + blackRow[left - 1] + blackRow[left] + blackRow[left + 1] + blackRow[left + 2];
        }
        int average = sum / 25;
        thresholdBlock(luminances, xoffset, yoffset, average, width, matrix);
      }
    }
  }
1068598
def color_reducer(c1, c2):
    """"""
    return tuple(v1 + v2 for v1, v2 in itertools.izip(c1, c2))
111450
def latents_to_frames(z_top_interp, level_eps_interp, hparams):
  """"""
  # Decode [z^1_t, z^2_t .. z^l_t] to [X_t]
  images, _, _, _ = glow_ops.encoder_decoder(
      "codec", z_top_interp, hparams, eps=level_eps_interp, reverse=True)
  images = glow_ops.postprocess(images)
  return images
891791
def fill(framebuf, color):
        """"""
        if color:
            fill = 0xFF
        else:
            fill = 0x00
        for i in range(len(framebuf.buf)):
            framebuf.buf[i] = fill
188753
function getPixelSetter() {
    var offset = 0;
    return function(colors, c) {
        colors[offset] = c.r;
        colors[offset + 1] = c.g;
        colors[offset + 2] = c.b;
        colors[offset + 3] = c.a;
        offset += 4;
    };
}
1142382
def bk_red(cls):
        ""
        wAttributes = cls._get_text_attributes()
        wAttributes &= ~win32.BACKGROUND_MASK
        wAttributes |=  win32.BACKGROUND_RED
        cls._set_text_attributes(wAttributes)
1280877
def showcutoffs(self, redblue = False):
        
        
        highmask = self.numpyarray > self.z2
        lowmask = self.numpyarray < self.z1
        if redblue == False :
            if self.negative :
                self.drawmask(highmask, colour = 255)
                self.drawmask(lowmask, colour = 0)
            else :
                self.drawmask(highmask, colour = 0)
                self.drawmask(lowmask, colour = 255)
        else :
            
            self.drawmask(highmask, colour = (255, 0, 0))
            self.drawmask(lowmask, colour = (0, 0, 255))
178216
def rgba_floats_tuple(self, x):
        
        if x <= self.index[0]:
            return self.colors[0]
        if x >= self.index[-1]:
            return self.colors[-1]

        i = len([u for u in self.index if u < x])  # 0 < i < n.
        if self.index[i-1] < self.index[i]:
            p = (x - self.index[i-1])*1./(self.index[i]-self.index[i-1])
        elif self.index[i-1] == self.index[i]:
            p = 1.
        else:
            raise ValueError('Thresholds are not sorted.')

        return tuple((1.-p) * self.colors[i-1][j] + p*self.colors[i][j] for j
                     in range(4))