|
|
@ -6,6 +6,12 @@ class Pixel(namedtuple('Pixel', ['r', 'g', 'b'])):
|
|
|
|
raise ValueError('Some component too bright.')
|
|
|
|
raise ValueError('Some component too bright.')
|
|
|
|
if min(self.r, self.g, self.b) < 0:
|
|
|
|
if min(self.r, self.g, self.b) < 0:
|
|
|
|
raise ValueError('Some component negative.')
|
|
|
|
raise ValueError('Some component negative.')
|
|
|
|
|
|
|
|
def _to_valid(self):
|
|
|
|
|
|
|
|
return Pixel(
|
|
|
|
|
|
|
|
int(max(0, min(255, self.r))),
|
|
|
|
|
|
|
|
int(max(0, min(255, self.g))),
|
|
|
|
|
|
|
|
int(max(0, min(255, self.b))),
|
|
|
|
|
|
|
|
)
|
|
|
|
def __add__(self, other):
|
|
|
|
def __add__(self, other):
|
|
|
|
return Pixel(
|
|
|
|
return Pixel(
|
|
|
|
self.r + other.r,
|
|
|
|
self.r + other.r,
|
|
|
@ -58,7 +64,7 @@ class Picture:
|
|
|
|
seq = []
|
|
|
|
seq = []
|
|
|
|
for line in self.pixels:
|
|
|
|
for line in self.pixels:
|
|
|
|
for pix in line:
|
|
|
|
for pix in line:
|
|
|
|
seq.extend(pix)
|
|
|
|
seq.extend(pix._to_valid())
|
|
|
|
|
|
|
|
|
|
|
|
# bytes…
|
|
|
|
# bytes…
|
|
|
|
b = bytes(seq)
|
|
|
|
b = bytes(seq)
|
|
|
|