Commits

Sergey Astanin committed 0900f0f

checks on order and ranges of pixel coordinates

Comments (0)

Files changed (1)

     pts = []
     im = Image.open(file(imgfile))
     w, h = im.size
+    def check(var,maxval):
+        if not (0 <= var < maxval):
+            raise Exception("Coordinate %d is out of image dimension [0~%d]." % \
+                            (var, maxval-1))
+    for v,r in [(x1p,w), (x2p,w), (y1p,h), (y2p,h)]:
+        check(v,r)
+
     for i in xrange(x1p,x2p+1):
         js = xrange(y1p,y2p-1,-1)
         pixels = imap(lambda j: (j, im.getpixel((i,j))), js)
     x1, y1, x2, y2 = map(float, [x1, y1, x2, y2])
     x1p, y1p, x2p, y2p = map(int, [x1p, y1p, x2p, y2p])
 
+    if x2p < x1p:
+        raise Exception("The right corner was given first (should be the second).")
+    if y2p > y1p:
+        raise Exception("The top corner was given first (should be the second).")
+
     pts = unplot_file(imgfile, ((x1p,y1p), (x2p,y2p)), ((x1,y1), (x2,y2)), sensitivity, color)
     for x,y in pts:
         print x,y