Encodes the color as an Integer in RGBA encoding

        Returns None if any of red, green or blue are None.
        If alpha is None we use 255 by default.

        :return:    Integer
        :rtype:     int
486792
def rgba_to_int(cls, red, green, blue, alpha):
        
        red = unwrap(red)
        green = unwrap(green)
        blue = unwrap(blue)
        alpha = unwrap(alpha)
        if red is None or green is None or blue is None:
            return None
        if alpha is None:
            alpha = 255
        r = red << 24
        g = green << 16
        b = blue << 8
        a = alpha << 0
        rgba_int = r+g+b+a
        if (rgba_int > (2**31-1)):       # convert to signed 32-bit int
            rgba_int = rgba_int - 2**32
        return rgba_int
1048524
def parse_color(self, color):
        '''
        
        '''
        if color == 'none':
            return None
        return (
            int(color[1:3], 16),
            int(color[3:5], 16),
            int(color[5:7], 16))
409447
def _rgba(r, g, b, a, **kwargs):
    
    return ColorValue((float(r), float(g), float(b), float(a)))
252073
def _alpha_color color
      return nil unless trns

      # For color type 0 (grayscale), the tRNS chunk contains a single gray level value, stored in the format:
      #
      #   Gray:  2 bytes, range 0 .. (2^bitdepth)-1
      #
      # For color type 2 (truecolor), the tRNS chunk contains a single RGB color value, stored in the format:
      #
      #   Red:   2 bytes, range 0 .. (2^bitdepth)-1
      #   Green: 2 bytes, range 0 .. (2^bitdepth)-1
      #   Blue:  2 bytes, range 0 .. (2^bitdepth)-1
      #
      # (If the image bit depth is less than 16, the least significant bits are used and the others are 0)
      # Pixels of the specified gray level are to be treated as transparent (equivalent to alpha value 0);
      # all other pixels are to be treated as fully opaque ( alpha = (2^bitdepth)-1 )

      @alpha_color ||=
        case hdr.color
        when COLOR_GRAYSCALE
          v = trns.data.unpack('n')[0] & (2**hdr.depth-1)
          Color.from_grayscale(v, :depth => hdr.depth)
        when COLOR_RGB
          a = trns.data.unpack('n3').map{ |v| v & (2**hdr.depth-1) }
          Color.new(*a, :depth => hdr.depth)
        else
          raise Exception, "color2alpha only intended for GRAYSCALE & RGB color modes"
        end

      color == @alpha_color ? 0 : (2**hdr.depth-1)
    end
519695
def to_truecolor_alpha_bytes(color)
      [r(color), g(color), b(color), a(color)]
    end
157951
def rgba_bytes_tuple(self, x):
        
        return tuple(int(u*255.9999) for u in self.rgba_floats_tuple(x))
1032698
def to_ansi_24bit(self):
        
        text = self.text.replace('\x1b', '')
        if self.color and self.bg_color:
            c = self.color.scale(255)
            bg_c = self.bg_color.scale(255)
            return ansicolor(text,
                             fg=(c.r, c.g, c.b),
                             bg=(bg_c.r, bg_c.g, bg_c.b))
        elif self.color:
            c = self.color.scale(255)
            return ansicolor(text,
                             fg=(c.r, c.g, c.b))
        elif self.bg_color:
            bg_c = self.bg_color.scale(255)
            return ansicolor(text,
                             bg=(bg_c.r, bg_c.g, bg_c.b))
        else:
            return text
1169532
def normalize_rgb(r, g, b, a):
    
    r = int(r, 10)
    g = int(g, 10)
    b = int(b, 10)
    if a:
        a = float(a) * 256
    if r > 255 or g > 255 or b > 255 or (a and a > 255):
        return None
    color = '#%02x%02x%02x' % (r, g, b)
    if a:
        color += '%02x' % int(a)
    return color
592607
def hex_to_rgb(h):
    
    h = h.lstrip('#')
    return tuple(int(h[i:i+2], 16)/255. for i in (0, 2 ,4))
264523
def swapColors(self):
		
		rgba = self.color.get_0_255()
		self.color = self.secondColor
		self.secondColor = Color(rgba, '0-255')
1236090
def from_rgb(cls, r: int, g: int, b: int) -> 'ColorCode':
        
        c = cls()
        c._init_rgb(r, g, b)
        return c
1015798
def as_rgb(self):
        
        rgb = [mpl.colors.colorConverter.to_rgb(hex) for hex in self]
        return ColorPalette(rgb)
137263
def hls(self):
        
        r, g, b = self.color
        hls = colorsys.rgb_to_hls(r, g, b)
        hls = (int(round(hls[0] * 360)), hls[1], hls[2])
        return self._append_alpha_if_necessary(hls)
758399
def to_color(self):
        
        color_data = np.zeros([self.height, self.width, 3])
        color_data[:, :, 0] = self.data
        color_data[:, :, 1] = self.data
        color_data[:, :, 2] = self.data
        return ColorImage(color_data.astype(np.uint8), self._frame)
750825
def hex_to_rgb(color):
    
    color = normalize(color)
    color = color[1:]
    # return 'rgb'+str(tuple(ord(c) for c in color.decode('hex')))
    return 'rgb' + str((int(color[0:2], base=16), int(color[2:4], base=16), int(color[4:6], base=16)))
326956
def color(self):
        
        return ColorImage(self.raw_data[:, :, :3].astype(
            np.uint8), frame=self.frame)
726842
def uint32_to_rgb(uint32)
      return [0, 0, 0] unless uint32.is_a?(Integer)

      r = (uint32 & 0xff000000) >> 24
      g = (uint32 & 0x00ff0000) >> 16
      b = (uint32 & 0x0000ff00) >> 8

      [r, g, b]
    end