Create the frame individual 4-color palette for VobSub mode.

@index Index of caption
760281
private void determineFramePal(int index) {
		if ((inMode != InputMode.VOBSUB && inMode != InputMode.SUPIFO)
				|| configuration.getPaletteMode() != PaletteMode.KEEP_EXISTING) {
			// get the primary color from the source palette
			int rgbSrc[] = subtitleStream.getPalette().getRGB(
					subtitleStream.getPrimaryColorIndex());

			// match with primary color from 16 color target palette
			// note: skip index 0 , primary colors at even positions
			// special treatment for index 1: white
			Palette trgPallete = currentDVDPalette;
			int minDistance = 0xffffff; // init > 0xff*0xff*3 = 0x02fa03
			int colIdx = 0;
			for (int idx = 1; idx < trgPallete.getSize(); idx += 2) {
				int rgb[] = trgPallete.getRGB(idx);
				// distance vector (skip sqrt)
				int rd = rgbSrc[0] - rgb[0];
				int gd = rgbSrc[1] - rgb[1];
				int bd = rgbSrc[2] - rgb[2];
				int distance = rd * rd + gd * gd + bd * bd;
				// new minimum distance ?
				if (distance < minDistance) {
					colIdx = idx;
					minDistance = distance;
					if (minDistance == 0) {
						break;
					}
				}
				// special treatment for index 1 (white)
				if (idx == 1) {
					idx--; // -> continue with index = 2
				}
			}

			// set new frame palette
			int palFrame[] = new int[4];
			palFrame[0] = 0; // black - transparent color
			palFrame[1] = colIdx; // primary color
			if (colIdx == 1) {
				palFrame[2] = colIdx + 2; // special handling: white + dark grey
			} else {
				palFrame[2] = colIdx + 1; // darker version of primary color
			}
			palFrame[3] = 0; // black - opaque

			subVobTrg.setAlpha(DEFAULT_ALPHA);
			subVobTrg.setPal(palFrame);

			trgPal = SupDvdUtil.decodePalette(subVobTrg, trgPallete);
		}
	}
276938
def color_array_by_hue_mix(value, palette):
    
    if int(value, 2) > 0:

        # Convert bits to list and reverse order to avoid issues with
        # differing lengths
        int_list = [int(i) for i in list(value[2:])]
        int_list.reverse()

        # since this is a 1D array, we need the zeroth elements
        # of np.nonzero.
        locs = np.nonzero(int_list)[0]
        # print(locs)
        # print(palette)
        rgb_vals = [palette[i] for i in locs]

        rgb = [0]*len(rgb_vals[0])  # We don't know if it's rgb or rgba
        for val in rgb_vals:
            for index in range(len(val)):
                rgb[index] += val[index]

        for i in range(len(rgb)):
            rgb[i] /= len(locs)

        return tuple(rgb)

    if int(value, 2) == 0:
        return (1, 1, 1) if len(palette[0]) == 3 else (1, 1, 1, 1)

    return -1
1006860
def _build_color_variants(cls):
    
    # Get the basic frame types first.
    frametypes = cls.sets(registered=False)

    _colornames = [
        # 'black', disabled for now, it won't show on my terminal.
        'red',
        'green',
        'yellow',
        'blue',
        'magenta',
        'cyan',
        'white',
    ]
    _colornames.extend('light{}'.format(s) for s in _colornames[:])
    for colorname in _colornames:
        for framesobj in frametypes:
            framename = '{}_{}'.format(framesobj.name, colorname)
            cls.register(
                framesobj.as_colr(fore=colorname),
                name=framename,
            )
284522
def get_colour(index):
    
    colours = [
        'red', 'blue', 'green', 'pink',
        'yellow', 'magenta', 'orange', 'cyan',
    ]
    default_colour = 'purple'
    if index < len(colours):
        return colours[index]
    else:
        return default_colour
311313
def frame(params = nil)
      if params
        frame = params
        self
      else
        if selected.length == 1
          Rect.frame_for_view(selected.first)
        else
          selected.map{|s| Rect.frame_for_view(s)}
        end
      end
    end
1290427
def _read_color_and_depth_image(self):
        
        frames = self._pipe.wait_for_frames()
        if self._depth_align:
            frames = self._align.process(frames)

        depth_frame = frames.get_depth_frame()
        color_frame = frames.get_color_frame()

        if not depth_frame or not color_frame:
            logging.warning('Could not retrieve frames.')
            return None, None

        if self._filter_depth:
            depth_frame = self._filter_depth_frame(depth_frame)

        # convert to numpy arrays
        depth_image = self._to_numpy(depth_frame, np.float32)
        color_image = self._to_numpy(color_frame, np.uint8)

        # convert depth to meters
        depth_image *= self._depth_scale

        # bgr to rgb
        color_image = color_image[..., ::-1]

        depth = DepthImage(depth_image, frame=self._frame)
        color = ColorImage(color_image, frame=self._frame)
        return color, depth
1090579
public void paintFrame (Graphics2D g, int index, int x, int y) {
        _images[index].paint(g, x, y);
    }
263942
def save_palette_as_image(filename, palette):
    ""
    output_filename = '%s_palette.png' % filename[:filename.rfind('.')]
    size = (80 * len(palette.colors), 80)
    im = Image.new('RGB', size)
    draw = ImageDraw.Draw(im)
    for i, c in enumerate(palette.colors):
        v = colorsys.rgb_to_hsv(*norm_color(c.value))[2]
        (x1, y1) = (i * 80, 0)
        (x2, y2) = ((i + 1) * 80 - 1, 79)
        draw.rectangle([(x1, y1), (x2, y2)], fill=c.value)
        if v < 0.6:
            # white with shadow
            draw.text((x1 + 4, y1 + 4), rgb_to_hex(c.value), (90, 90, 90))
            draw.text((x1 + 3, y1 + 3), rgb_to_hex(c.value))
        else:
            # dark with bright "shadow"
            draw.text((x1 + 4, y1 + 4), rgb_to_hex(c.value), (230, 230, 230))
            draw.text((x1 + 3, y1 + 3), rgb_to_hex(c.value), (0, 0, 0))

    im.save(output_filename, "PNG")
150007
def _make_index(self):
        

        out = {}

        for layer in self._layers:
            cls = layer.__class__
            out[cls] = out.get(cls, []) + [layer]

        return out
114527
def scene_color(sequence_number, scene_id, color):
        """"""
        return MessageWriter().string("scene.color").uint64(sequence_number).uint32(scene_id) \
                              .uint8_3(int(color[0]*255), int(color[1]*255), int(color[2]*255)).get()
829364
def tbframes(tb):
  ''
  frames=[tb.tb_frame]
  while tb.tb_next: tb=tb.tb_next; frames.append(tb.tb_frame)
  return frames
467562
def getinnerframes(tb, context=1):
    """"""
    framelist = []
    while tb:
        framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
        tb = tb.tb_next
    return framelist
1350307
def _index_file(self):
        
        with self.filename.open() as fd:
            data = fd.read()

        ident = "Contour in frame"
        self._data = data.split(ident)[1:]
        self._initialized = True
1166961
def build_colormap(palette, info):
        """"""

        from trollimage.colormap import Colormap
        if 'palette_meanings' in palette.attrs:
            palette_indices = palette.attrs['palette_meanings']
        else:
            palette_indices = range(len(palette))

        sqpalette = np.asanyarray(palette).squeeze() / 255.0
        tups = [(val, tuple(tup))
                for (val, tup) in zip(palette_indices, sqpalette)]
        colormap = Colormap(*tups)
        if 'palette_meanings' not in palette.attrs:
            sf = info.get('scale_factor', np.array(1))
            colormap.set_range(
                *(np.array(info['valid_range']) * sf + info.get('add_offset', 0)))

        return colormap, sqpalette
1239416
private void updateTintFilter() {
        if (mTint == null) {
            mTintFilter = null;
            return;
        }
        // setMode, setColor of PorterDuffColorFilter are not public method in SDK v7. (Thanks @Google still not accessible in API v24)
        // Therefore we create a new one all the time here. Don't expect this is called often.
        int color = mTint.getColorForState(getState(), Color.TRANSPARENT);
        mTintFilter = new PorterDuffColorFilter(color, mTintMode);
    }
1272905
def makeVisualSong(self):
        
        self.files=os.listdir(self.basedir)
        self.stairs=[i for i in self.files if ("stair" in i) and ("R" in i)]
        self.sectors=[i for i in self.files if "sector" in i]
        self.stairs.sort()
        self.sectors.sort()
        filenames=[self.basedir+i for i in self.sectors[:4]]
        self.iS0=mpy.ImageSequenceClip(filenames,durations=[1.5,2.5,.5,1.5])
        self.iS1=mpy.ImageSequenceClip(
                          [self.basedir+self.sectors[2],
                           self.basedir+self.sectors[3],
                           self.basedir+self.sectors[2],
                           self.basedir+self.sectors[3],
                           self.basedir+self.sectors[2],
                           self.basedir+self.sectors[3],
                           self.basedir+self.sectors[2],
                           self.basedir+self.sectors[3]],
                durations=[0.25]*8)
        self.iS2=mpy.ImageSequenceClip(
                          [self.basedir+self.sectors[2],
                           self.basedir+self.sectors[3],
                           self.basedir+self.sectors[2],
                           self.basedir+self.sectors[3],
                           self.basedir+self.sectors[0]],
                durations=[0.75,0.25,0.75,0.25,2.]) # cai para sensível

        self.iS3=mpy.ImageSequenceClip(
                          [self.basedir+"BLANK.png",
                           self.basedir+self.sectors[0],
                           self.basedir+self.sectors[1],
                           self.basedir+self.sectors[1],
                           self.basedir+self.sectors[1],
                           self.basedir+self.sectors[0],
                           self.basedir+self.sectors[0]],
                durations=[1,0.5,2.,.25,.25,1.75, 0.25]) # [-1,8]

        self.iS4=mpy.ImageSequenceClip(
                          [self.basedir+self.sectors[2], # 1
                           self.basedir+self.sectors[3], # .5
                           self.basedir+self.sectors[5], # .5
                           self.basedir+self.sectors[2], # .75
                           self.basedir+self.sectors[0], #.25
                           self.basedir+self.sectors[2], # 1
                           self.basedir+self.sectors[0], # 2 8
                           self.basedir+self.sectors[3], # 2 7
                           self.basedir+self.sectors[0], # 2 -1
                          self.basedir+"BLANK.png",# 2
                           ],
                durations=[1,0.5,0.5,.75,
                              .25,1., 2.,2.,2.,2.]) # [0,7,11,0]

        self.iS=mpy.concatenate_videoclips((
            self.iS0,self.iS1,self.iS2,self.iS3,self.iS4))
1019929
def get_bgcolor(self, index):
        """"""
        if index.column() == 0:
            color = QColor(Qt.lightGray)
            color.setAlphaF(.05)
        elif index.column() < 3:
            color = QColor(Qt.lightGray)
            color.setAlphaF(.2)
        else:
            color = QColor(Qt.lightGray)
            color.setAlphaF(.3)
        return color