示例#1
0
文件: image.py 项目: dekkers/pymaging
 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])
示例#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])
 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
示例#4
0
文件: image.py 项目: wdv4758h/ZipPy
 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
 def get_color(self, x, y):
     return Color.from_pixel(self.get_pixel(x, y))
示例#6
0
文件: image.py 项目: wdv4758h/ZipPy
 def get_color(self, x, y):
     return Color.from_pixel(self.get_pixel(x, y))
示例#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))
示例#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))