about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-11-02 02:45:55 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-11-02 02:45:55 +0000
commitc09c564c9a35558115bcc72663e2f6e3ef3f0734 (patch)
tree194dcb0410f3907d7ddb58e15728a4d079ceb770 /converter/ppm
parentc2b6d05b0a72ed21ab1bb06f8cc6374f68896239 (diff)
downloadnetpbm-mirror-c09c564c9a35558115bcc72663e2f6e3ef3f0734.tar.gz
netpbm-mirror-c09c564c9a35558115bcc72663e2f6e3ef3f0734.tar.xz
netpbm-mirror-c09c564c9a35558115bcc72663e2f6e3ef3f0734.zip
accept rectangle specifications in input that have the corners in any order
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3411 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/picttoppm.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c
index 0a2f896c..b8fb8642 100644
--- a/converter/ppm/picttoppm.c
+++ b/converter/ppm/picttoppm.c
@@ -794,19 +794,25 @@ dumpRect(const char * const label,
 static void
 readRect(struct Rect * const r) {
 
-    r->top    = readWord();
-    r->left   = readWord();
-    r->bottom = readWord();
-    r->right  = readWord();
-
-    if (r->top > r->bottom || r->right < r->left)
-        dumpRect("Invalid rectangle", *r);
-
-    if (r->top > r->bottom)
-        pm_error("Invalid PICT: a rectangle has a top below its bottom");
-    if (r->right < r->left)
-        pm_error("Invalid PICT: a rectangle has a right edge "
-                 "left of its left edge");
+    /* We don't have a formal specification for the Pict format, but we have
+       seen samples that have the rectangle corners either in top left, bottom
+       right order or bottom right, top left.  top left, bottom right is the
+       only one Picttoppm handled until October 2018, when we saw several
+       images in the bottom right, top left order and other Pict processing
+       programs considered that fine.
+
+       So now we accept all 4 possibilities.
+    */
+
+    Word const y1 = readWord();
+    Word const x1 = readWord();
+    Word const y2 = readWord();
+    Word const x2 = readWord();
+
+    r->top    = MIN(y1, y2);
+    r->left   = MIN(x1, x2);
+    r->bottom = MAX(y1, y2);
+    r->right  = MAX(x1, x2);
 }