X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Ftterminal%2FSixel.java;h=a4c00fc67f1da1ca38847b9bb5dad63daac5e006;hb=12b90437b5f22c2ae6e9b9b14c3b62b60f6143e5;hp=8e363ef125c6830f2ad759aefff42a4a56179db2;hpb=8dd530ffad462c13126f82465c6fd2928e310b78;p=fanfix.git diff --git a/src/jexer/tterminal/Sixel.java b/src/jexer/tterminal/Sixel.java index 8e363ef..a4c00fc 100644 --- a/src/jexer/tterminal/Sixel.java +++ b/src/jexer/tterminal/Sixel.java @@ -72,6 +72,16 @@ public class Sixel { */ private static int HEIGHT_INCREASE = 400; + /** + * Maximum width in pixels. + */ + private static int MAX_WIDTH = 1000; + + /** + * Maximum height in pixels. + */ + private static int MAX_HEIGHT = 1000; + /** * Current scanning state. */ @@ -142,6 +152,11 @@ public class Sixel { */ private Color color = Color.BLACK; + /** + * If set, abort processing this image. + */ + private boolean abort = false; + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -150,12 +165,14 @@ public class Sixel { * Public constructor. * * @param buffer the sixel data to parse + * @param palette palette to use, or null for a private palette */ - public Sixel(final String buffer) { + public Sixel(final String buffer, final HashMap palette) { this.buffer = buffer; - palette = new HashMap(); - for (int i = 0; i < buffer.length(); i++) { - consume(buffer.charAt(i)); + if (palette == null) { + this.palette = new HashMap(); + } else { + this.palette = palette; } } @@ -169,6 +186,16 @@ public class Sixel { * @return the sixel data as an image. */ public BufferedImage getImage() { + if (buffer != null) { + for (int i = 0; (i < buffer.length()) && (abort == false); i++) { + consume(buffer.charAt(i)); + } + buffer = null; + } + if (abort == true) { + return null; + } + if ((width > 0) && (height > 0) && (image != null)) { /* System.err.println(String.format("%d %d %d %d", width, y + 1, @@ -300,6 +327,9 @@ public class Sixel { if (x > width) { width = x; } + if (width > MAX_WIDTH) { + abort = true; + } return; } @@ -337,6 +367,12 @@ public class Sixel { if (x > width) { width = x; } + if (width > MAX_WIDTH) { + abort = true; + } + if (y + 1 > MAX_HEIGHT) { + abort = true; + } } /** @@ -393,7 +429,13 @@ public class Sixel { if ((pan == pad) && (pah > 0) && (pav > 0)) { rasterWidth = pah; rasterHeight = pav; - resizeImage(rasterWidth, rasterHeight); + if ((rasterWidth <= MAX_WIDTH) && (rasterHeight <= MAX_HEIGHT)) { + resizeImage(rasterWidth, rasterHeight); + } else { + abort = true; + } + } else { + abort = true; } }