#!/usr/bin/env python """ simulate_display takes a screenshot, and produces a CRUDE simulation of what it might look like on the OLPC XO's unusual screen. This program is a quick hack. The output, very briefly compared, by eye, against a photograph of the actual screen under intermediate illuminiation, looks vaguely similar. My basic conclusion is that you don't have to worry color artifacts. """ import re, os, sys from tempfile import mkstemp import Image def simulate_display(i0,contribution_of_reflected_light): """ contribution_of_reflected_light (0.0-1.0) """ w,h = i0.size i1 = Image.new('RGB',i0.size) p0 = i0.load() p1 = i1.load() for x in range(0,w): for y in range(0,h): if x > 0 and x < (w-1) and y > 0 and y < (h-1): #XXX Assumes top left pixel is red, "0". But what is it really? channel = (0+x+y) % 3 lcd_value = p0[x,y][channel] reflected_light = lcd_value * contribution_of_reflected_light filtered_backlight = lcd_value * (1 - contribution_of_reflected_light) off_channel_value = reflected_light on_channel_value = reflected_light + filtered_backlight off = int(round(off_channel_value)) v = [off,off,off] v[channel] = int(round(on_channel_value)) p1[x,y] = tuple(v) else: #XXX Completely bogus 1 pixel border used for simplicity. p1[x,y] = p0[x,y] return i1 def print_usage_and_exit(): print """ Usage: simulate_display LIGHTING INFILE OUTFILE simulate_display takes a screenshot, and produces a crude simulation of what it might look like on the OLPC XO's unusual screen. LIGHTING 0-10 is the relative strength of the backlight and room illumination. 0 is backlight in dark room. 10 is direct sunlight. INFILE can be in any format PIL understands, or xwd. OUTFILE can be in any format PIL understands. The actual laptop looks better than the output of this program. The DCON does tweaking. So if your screenshot looks ok here, it's fine. And if your screenshot doesn't, it probably is still fine, but you might ask someone with actual hardware to check. Example: xwd > activity_snapshot.xwd simulate_display 5 activity_snapshot.xwd check_for_color_artifacts.png See also: http://wiki.laptop.org/go/GTK_for_OLPC . This program does _not_ use David Turner's swizzling algorithm. While useful for the interactive modified Xephyr for which it was intended, my understanding is it does not reflect the actual screen behavior. For our application, correctness is more important than sometimes dark simulated screen images BUGS: It assumes the top left pixel is a red one. It may not be? A one-pixel image border is copied from the original unmodified. I am just guessing at the handling of LIGHTING. """ sys.exit(-1) def main(argv): if len(argv) != 4: print_usage_and_exit() contribution_of_reflected_light = int(argv[1])/10.0 in_file = argv[2] out_file = argv[3] if re.compile('\.xwd$').search(in_file): ignore,tmp_file = mkstemp() os.system("xwdtopnm %s | pnmtopng > %s" % (in_file, tmp_file)) else: tmp_file = in_file i0 = Image.open(tmp_file) i1 = simulate_display(i0,contribution_of_reflected_light) i1.save(out_file) if __name__ == '__main__': main(sys.argv)