You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2017/05/24 18:41:18 UTC
[30/50] [abbrv] commons-imaging git commit: XBM values can span
multiple pixels, but do not span multiple image rows.
XBM values can span multiple pixels, but do not span multiple image rows.
Patch by: me
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/imaging/trunk@1780709 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-imaging/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-imaging/commit/b33463dc
Tree: http://git-wip-us.apache.org/repos/asf/commons-imaging/tree/b33463dc
Diff: http://git-wip-us.apache.org/repos/asf/commons-imaging/diff/b33463dc
Branch: refs/heads/master
Commit: b33463dc694d6b33628af4a23c85afcbb6eb64b7
Parents: 960adeb
Author: Damjan Jovanovic <da...@apache.org>
Authored: Sat Jan 28 15:45:05 2017 +0000
Committer: Damjan Jovanovic <da...@apache.org>
Committed: Sat Jan 28 15:45:05 2017 +0000
----------------------------------------------------------------------
.../imaging/formats/xbm/XbmImageParser.java | 59 +++++++++++---------
1 file changed, 34 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-imaging/blob/b33463dc/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java b/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
index 1e1cae0..c9c9b1c 100644
--- a/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
@@ -244,32 +244,41 @@ public class XbmImageParser extends ImageParser {
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");
+ }
}
}