# -*- coding: utf-8 -*-
#Python script to calculate useful information about displays
#from data typically provided by manufacturer/retailer/specsheet
#You have permission to redistribute and modify this script, on the condition that this line is present and unmodified, and that you credit the author(s) below.
#CEDStone - origninal script - 2013
#CEDStone - added list of abbreviations, metric conversions - 2013
import fractions
import math
x=0
y=0
d=0
acrodict={
          "(7680, 4800)":  "WHUXGA",
          "(6400, 4800)":   "HUXGA",
          "(7680, 4320)": "UHD, 8k",
          "(6400, 4096)":  "WHSXGA",
          "(5120, 4096)":   "HSXGA",
          "(5120, 3200)":   "WHXGA",
          "(4096, 3072)":    "HXGA",
          "(3840, 2400)":  "WQUXGA",
          "(3200, 2400)":   "QUXGA",
          "(3840, 2160)":"QFHD or 4k",
          "(3200, 2048)":  "WQSXGA",
          "(2560, 2048)":   "QSXGA",
          "(3200, 1800)":    "QHD+",
          "(2880, 1800)":  "WQXGA+",
          "(2560, 1600)":   "WQXGA",
          "(2048, 1536)":    "QXGA",
          "(2560, 1440)":     "QHD",
          "(1920, 1200)":   "WUXGA",
          "(1600, 1200)":    "UXGA",
          "(2048, 1152)":   "QWXGA",
          "(1920, 1080)":  "fullHD",
          "(1680, 1050)":  "WSXGA+",
          "(1400, 1050)":    "SXGA",
          "(1280, 1024)":    "SXGA",
          "(1440, 960) ":       "?",
          "(1280, 960)" :   "SXGA-",
          "(1600, 900)" :     "HD+",
          "(1440, 900)" :   "WXGA+",
          "(1280, 864)" :       "?",
          "(1152, 864)" :    "XGA+",
          "(1280, 800)" :    "WXGA",
          "(1366, 768)" :    "WXGA",
          "(1280, 768)" :    "WXGA",
          "(1152, 768)" :       "?",
          "(1024, 768)" :     "XGA",
          "(1280, 720)" :"HD or WXGA",
          "(1152, 720)" :       "?",
          "(1136, 640)" :       "?",
          "(1024, 640)" :       "?",
          "(960, 640)"  :    "DVGA",
          "(1024, 600)" :   "WSVGA",
          "(800, 600)"  :    "SVGA",
          "(1024, 576)" :   "WSVGA",
          "(960, 540)"  :     "qHD",
          "(854, 480)"  :   "FWVGA",
          "(800, 480)"  :    "WVGA",
          "(640, 480)"  :     "VGA",
          "(640, 360)"  :     "nHD",
          "(480, 320)"  :    "HVGA",
          "(432, 240)"  :  "FWQVGA",
          "(400, 240)"  :   "WQVGA",
          "(384, 240)"  :   "WQVGA",
          "(320, 240)"  :    "QVGA",
          "(240, 160)"  :   "HQVGA",
          "(160, 120)"  :   "QQVGA",
          "(1, 1)"      :  "an LED",
          }
print "------------------------------------------"
x = int(   raw_input("  Columns:               ") )
y = int(   raw_input("  Rows:                  ") )
d = float( raw_input("  Diagonal length (in)   ") )
if x*y*d==0:                                        # Avoid division by zero
    print "Exiting (invalid input)"
    exit()
if str((x,y)) in acrodict :                         # Is the given resolution known?
    acro=str(acrodict[str((x,y))]) 
elif str((y,x)) in acrodict :
    acro=str(acrodict[str((y,x))])                  # perhaps if backwards?
else:
    acro="non-standard"
dp = math.sqrt(pow(x, 2) + pow(y, 2))               # How many px fit anlong the diagonal
gcd = (fractions.gcd(x, y))
xin = x/(dp/d)                                      # Width in inches
yin = y/(dp/d)                                      # Hieght in inches
xcm = xin*2.54
ycm = yin*2.54
print "  Pixel density         ", round(dp/d, 1), "ppi"
print "  Megapixels            ", round((x*y)/1000000, 1), "MP"
print "  Area                  ", round((xin*yin), 1), "in^2  = ", round((xcm*ycm), 1), "cm^2"
print "  Width                 ", round(xin, 1), "in    = ", round(xcm, 1), "cm"
print "  Height                ", round(yin, 1), "in    = ", round(ycm, 1), "cm"
print "  Orientation:          ",
if x>y :
    print "Landscape"
if x<y :
    print "Portrait"
if x==y :
    print "N/A (Square)"
print "  Aspect ratio:         ", (x/gcd), ":", (y/gcd)
print "  Sometimes known as    ", acro 
print "------------------------------------------"