Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Python by yuv420p ( 14 years ago )
import Image
lena = Image.open('lena.png')
width, height = lena.size
numpixels = width * height
image = [0] * (numpixels * 3 / 2)
i = 0
ui = numpixels
vi = numpixels + numpixels / 4
#r, g, b, _ = lena.getpixel((128, 128))
#print r, g, b
print width, height
for y in range(height):
for x in range(width):
r, g, b, _ = lena.getpixel((x, y))
image[i] = (( (66*r + 129*g + 25*b + 128) >> 8) + 16) & 0xFF
if x % 2 == 0 and y % 2 == 0:
image[ui] = (((-38*r - 74*g + 112*b + 128) >> 8) + 128) & 0xFF
image[vi] = (((112*r - 94*g - 18*b + 128) >> 8) + 128) & 0xFF
ui += 1
vi += 1
i += 1
#
with open('lena.yuv420p', 'wb') as f:
f.write(''.join(chr(x) for x in image))
Revise this Paste