commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1780709 - /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
Date Sat, 28 Jan 2017 15:45:05 GMT
Author: damjan
Date: Sat Jan 28 15:45:05 2017
New Revision: 1780709

URL: http://svn.apache.org/viewvc?rev=1780709&view=rev
Log:
XBM values can span multiple pixels, but do not span multiple image rows.

Patch by: me

Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java?rev=1780709&r1=1780708&r2=1780709&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
Sat Jan 28 15:45:05 2017
@@ -244,32 +244,41 @@ public class XbmImageParser extends Imag
 
         final int rowLength = (xbmHeader.width + 7) / 8;
         final byte[] imageData = new byte[rowLength * xbmHeader.height];
-        for (int i = 0; i < imageData.length; ) {
-            token = cParser.nextToken();
-            if (token == null || !token.startsWith("0x")) {
-                throw new ImageReadException("Parsing XBM file failed, "
-                        + "hex value missing");
-            }
-            if (token.length() > hexWidth) {
-                throw new ImageReadException("Parsing XBM file failed, "
-                        + "hex value too long");
-            }
-            final int value = Integer.parseInt(token.substring(2), 16);
-            final int flipped = Integer.reverse(value) >>> (32 - inputWidth);
-            if (inputWidth == 16 && i < imageData.length) {
-                imageData[i++] = (byte) (flipped >>> 8);
-            }
-            imageData[i++] = (byte) flipped;
+        int i = 0;
+        for (int y = 0; y < xbmHeader.height; y++) {
+            for (int x = 0; x < xbmHeader.width; x += inputWidth) {
+                token = cParser.nextToken();
+                if (token == null || !token.startsWith("0x")) {
+                    throw new ImageReadException("Parsing XBM file failed, "
+                            + "hex value missing");
+                }
+                if (token.length() > hexWidth) {
+                    throw new ImageReadException("Parsing XBM file failed, "
+                            + "hex value too long");
+                }
+                final int value = Integer.parseInt(token.substring(2), 16);
+                final int flipped = Integer.reverse(value) >>> (32 - inputWidth);
+                if (inputWidth == 16) {
+                    if ((x + 8) < xbmHeader.width) {
+                        imageData[i++] = (byte) (flipped >>> 8);
+                        imageData[i++] = (byte) flipped;
+                    } else {
+                        imageData[i++] = (byte) flipped;
+                    }
+                } else {
+                    imageData[i++] = (byte) flipped;
+                }
 
-            token = cParser.nextToken();
-            if (token == null) {
-                throw new ImageReadException("Parsing XBM file failed, "
-                        + "premature end of file");
-            }
-            if (!",".equals(token)
-                    && ((i < imageData.length) || !"}".equals(token))) {
-                throw new ImageReadException("Parsing XBM file failed, "
-                        + "punctuation error");
+                token = cParser.nextToken();
+                if (token == null) {
+                    throw new ImageReadException("Parsing XBM file failed, "
+                            + "premature end of file");
+                }
+                if (!",".equals(token)
+                        && ((i < imageData.length) || !"}".equals(token))) {
+                    throw new ImageReadException("Parsing XBM file failed, "
+                            + "punctuation error");
+                }
             }
         }
 



Mime
View raw message