From: Kevin Lamonte Date: Mon, 5 Aug 2019 00:54:20 +0000 (-0500) Subject: refactor, sixel performance X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=03ae544a1639c127ebec9a46635f2ad465713908;p=fanfix.git refactor, sixel performance --- diff --git a/src/jexer/TImage.java b/src/jexer/TImage.java index c3e75be..3aaca2f 100644 --- a/src/jexer/TImage.java +++ b/src/jexer/TImage.java @@ -366,25 +366,8 @@ public class TImage extends TWidget { * @param always if true, always resize the cells */ private void sizeToImage(final boolean always) { - int textWidth = 16; - int textHeight = 20; - - if (getScreen() instanceof SwingTerminal) { - SwingTerminal terminal = (SwingTerminal) getScreen(); - - textWidth = terminal.getTextWidth(); - textHeight = terminal.getTextHeight(); - } if (getScreen() instanceof MultiScreen) { - MultiScreen terminal = (MultiScreen) getScreen(); - - textWidth = terminal.getTextWidth(); - textHeight = terminal.getTextHeight(); - } else if (getScreen() instanceof ECMA48Terminal) { - ECMA48Terminal terminal = (ECMA48Terminal) getScreen(); - - textWidth = terminal.getTextWidth(); - textHeight = terminal.getTextHeight(); - } + int textWidth = getScreen().getTextWidth(); + int textHeight = getScreen().getTextHeight(); if (image == null) { image = rotateImage(originalImage, clockwise); diff --git a/src/jexer/TTerminalWindow.java b/src/jexer/TTerminalWindow.java index 9780e29..d703b67 100644 --- a/src/jexer/TTerminalWindow.java +++ b/src/jexer/TTerminalWindow.java @@ -767,20 +767,8 @@ public class TTerminalWindow extends TScrollableWindow newStatusBar(i18n.getString("statusBarRunning")); // Pass the correct text cell width/height to the emulator - int textWidth = 16; - int textHeight = 20; - if (getScreen() instanceof SwingTerminal) { - SwingTerminal terminal = (SwingTerminal) getScreen(); - - textWidth = terminal.getTextWidth(); - textHeight = terminal.getTextHeight(); - } else if (getScreen() instanceof ECMA48Terminal) { - ECMA48Terminal terminal = (ECMA48Terminal) getScreen(); - textWidth = terminal.getTextWidth(); - textHeight = terminal.getTextHeight(); - } - emulator.setTextWidth(textWidth); - emulator.setTextHeight(textHeight); + emulator.setTextWidth(getScreen().getTextWidth()); + emulator.setTextHeight(getScreen().getTextHeight()); } /** @@ -961,15 +949,12 @@ public class TTerminalWindow extends TScrollableWindow private void putDoubleWidthCharXY(final DisplayLine line, final int x, final int y, final Cell cell) { - int textWidth = 16; - int textHeight = 20; + int textWidth = getScreen().getTextWidth(); + int textHeight = getScreen().getTextHeight(); boolean cursorBlinkVisible = true; if (getScreen() instanceof SwingTerminal) { SwingTerminal terminal = (SwingTerminal) getScreen(); - - textWidth = terminal.getTextWidth(); - textHeight = terminal.getTextHeight(); cursorBlinkVisible = terminal.getCursorBlinkVisible(); } else if (getScreen() instanceof ECMA48Terminal) { ECMA48Terminal terminal = (ECMA48Terminal) getScreen(); @@ -981,9 +966,6 @@ public class TTerminalWindow extends TScrollableWindow putCharXY(x + 1, y, ' ', cell); return; } - - textWidth = terminal.getTextWidth(); - textHeight = terminal.getTextHeight(); cursorBlinkVisible = blinkState; } else { // We don't know how to dray glyphs to this screen, draw them as diff --git a/src/jexer/backend/LogicalScreen.java b/src/jexer/backend/LogicalScreen.java index 24ba4af..513c599 100644 --- a/src/jexer/backend/LogicalScreen.java +++ b/src/jexer/backend/LogicalScreen.java @@ -134,6 +134,26 @@ public class LogicalScreen implements Screen { // Screen ----------------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Get the width of a character cell in pixels. + * + * @return the width in pixels of a character cell + */ + public int getTextWidth() { + // Default width is 16 pixels. + return 16; + } + + /** + * Get the height of a character cell in pixels. + * + * @return the height in pixels of a character cell + */ + public int getTextHeight() { + // Default height is 20 pixels. + return 20; + } + /** * Set drawing offset for x. * diff --git a/src/jexer/backend/MultiScreen.java b/src/jexer/backend/MultiScreen.java index b77872b..0c3a289 100644 --- a/src/jexer/backend/MultiScreen.java +++ b/src/jexer/backend/MultiScreen.java @@ -646,14 +646,7 @@ public class MultiScreen implements Screen { public int getTextWidth() { int textWidth = 16; for (Screen screen: screens) { - int newTextWidth = textWidth; - if (screen instanceof MultiScreen) { - newTextWidth = ((MultiScreen) screen).getTextWidth(); - } else if (screen instanceof ECMA48Terminal) { - newTextWidth = ((ECMA48Terminal) screen).getTextWidth(); - } else if (screen instanceof SwingTerminal) { - newTextWidth = ((SwingTerminal) screen).getTextWidth(); - } + int newTextWidth = screen.getTextWidth(); if (newTextWidth < textWidth) { textWidth = newTextWidth; } @@ -669,14 +662,7 @@ public class MultiScreen implements Screen { public int getTextHeight() { int textHeight = 20; for (Screen screen: screens) { - int newTextHeight = textHeight; - if (screen instanceof MultiScreen) { - newTextHeight = ((MultiScreen) screen).getTextHeight(); - } else if (screen instanceof ECMA48Terminal) { - newTextHeight = ((ECMA48Terminal) screen).getTextHeight(); - } else if (screen instanceof SwingTerminal) { - newTextHeight = ((SwingTerminal) screen).getTextHeight(); - } + int newTextHeight = screen.getTextHeight(); if (newTextHeight < textHeight) { textHeight = newTextHeight; } diff --git a/src/jexer/backend/Screen.java b/src/jexer/backend/Screen.java index 41c0756..2d9cd65 100644 --- a/src/jexer/backend/Screen.java +++ b/src/jexer/backend/Screen.java @@ -395,4 +395,18 @@ public interface Screen { */ public void setTitle(final String title); + /** + * Get the width of a character cell in pixels. + * + * @return the width in pixels of a character cell + */ + public int getTextWidth(); + + /** + * Get the height of a character cell in pixels. + * + * @return the height in pixels of a character cell + */ + public int getTextHeight(); + } diff --git a/src/jexer/backend/TWindowBackend.java b/src/jexer/backend/TWindowBackend.java index 3c1f832..f644b76 100644 --- a/src/jexer/backend/TWindowBackend.java +++ b/src/jexer/backend/TWindowBackend.java @@ -112,6 +112,26 @@ public class TWindowBackend extends TWindow implements Backend { window.setHeight(getHeight() + 2); } + /** + * Get the width of a character cell in pixels. + * + * @return the width in pixels of a character cell + */ + @Override + public int getTextWidth() { + return window.getScreen().getTextWidth(); + } + + /** + * Get the height of a character cell in pixels. + * + * @return the height in pixels of a character cell + */ + @Override + public int getTextHeight() { + return window.getScreen().getTextHeight(); + } + } diff --git a/src/jexer/tterminal/Sixel.java b/src/jexer/tterminal/Sixel.java index 1921f44..63e3c0f 100644 --- a/src/jexer/tterminal/Sixel.java +++ b/src/jexer/tterminal/Sixel.java @@ -172,6 +172,11 @@ public class Sixel { BufferedImage newImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); + if (DEBUG) { + System.err.println("resizeImage(); old " + image.getWidth() + "x" + + image.getHeight() + " new " + newWidth + "x" + newHeight); + } + Graphics2D gr = newImage.createGraphics(); gr.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); gr.dispose(); @@ -407,14 +412,15 @@ public class Sixel { toGround(); } - if (height + 6 < image.getHeight()) { + height += 6; + x = 0; + + if (height + 6 > image.getHeight()) { // Resize the image, give us another HEIGHT_INCREASE // pixels of vertical length. resizeImage(image.getWidth(), image.getHeight() + HEIGHT_INCREASE); } - height += 6; - x = 0; return; }