Exemplo n.º 1
0
 def get_color(self, x, y):
     line = self.pixels[y]
     if self.pixelsize == 1:
         pixel = line[x]
         if self.palette:
             return Color.from_pixel(self.palette[pixel])
         else:
             return Color.from_pixel([pixel])
     else:
         start = x * self.pixelsize
         return Color.from_pixel(line[start:start+self.pixelsize])
Exemplo n.º 2
0
def get_pixel(pixels, pixelsize, x, y, palette):
    """
    Get the pixel in an image.
    This returns a list of values, which depend on your mode.
    """
    line = pixels[y]
    if pixelsize == 1:
        pixel = line[x]
        if palette:
            return Color.from_pixel(palette[pixel])
        else:
            return Color.from_pixel([pixel])
    else:
        start = x * pixelsize
        return Color.from_pixel(line[start:start+pixelsize])
Exemplo n.º 3
0
 def _fill_reverse_palette(self):
     self.reverse_palette = {}
     if not self.palette:
         return
     for index, color in enumerate(self.palette):
         color_obj = Color.from_pixel(color)
         color_obj.to_hexcode()
         self.reverse_palette[color_obj] = index
Exemplo n.º 4
0
 def _fill_reverse_palette(self):
     self.reverse_palette = {}
     if not self.palette:
         return
     for index, color in enumerate(self.palette):
         color_obj = Color.from_pixel(color)
         color_obj.to_hexcode()
         self.reverse_palette[color_obj] = index
Exemplo n.º 5
0
 def get_color(self, x, y):
     return Color.from_pixel(self.get_pixel(x, y))
Exemplo n.º 6
0
 def get_color(self, x, y):
     return Color.from_pixel(self.get_pixel(x, y))
Exemplo n.º 7
0
    def test_from_pixel(self):
        c = Color.from_pixel([10, 20, 30])
        self.assertEqual(ctuple(c), (10, 20, 30, 255))

        c = Color.from_pixel([10, 20, 30, 40])
        self.assertEqual(ctuple(c), (10, 20, 30, 40))
Exemplo n.º 8
0
    def test_from_pixel(self):
        c = Color.from_pixel([10, 20, 30])
        self.assertEqual(ctuple(c), (10, 20, 30, 255))

        c = Color.from_pixel([10, 20, 30, 40])
        self.assertEqual(ctuple(c), (10, 20, 30, 40))