diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Assemble.java | 120 | ||||
| -rwxr-xr-x | src/parse.py | 21 |
2 files changed, 123 insertions, 18 deletions
diff --git a/src/Assemble.java b/src/Assemble.java index f1e9867..a1d9563 100644 --- a/src/Assemble.java +++ b/src/Assemble.java @@ -17,7 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.*; -import java.awt.Color; +import java.util.*; +import java.awt.*; import java.awt.image.*; import javax.imageio.*; @@ -31,31 +32,132 @@ public class Assemble { public static void main(final String... args) throws IOException { + ImageIO.scanForPlugins(); Scanner sc = new Scanner(System.in); - BufferedImage background = ImageIO.read(sc.nextLine()); - int chars = Integer.parseInt(sc.nextLine()); + BufferedImage splash = ImageIO.read(new BufferedInputStream(new FileInputStream(new File(sc.nextLine())))); int width = Integer.parseInt(sc.nextLine()); int height = Integer.parseInt(sc.nextLine()); - String[] rows = new String[30]; - for (int i = 0; i < 30; i++) + String[] rows = new String[height]; + for (int i = 0; i < height; i++) rows[i] = sc.nextLine(); int chars = Integer.parseInt(sc.nextLine()); int charx = Integer.parseInt(sc.nextLine()); int chary = Integer.parseInt(sc.nextLine()); int[][] charmap = new int[chars][chary]; - for (int i = 0, i < chars; i++) - for (int j = 0, j < chary; j++) + for (int i = 0; i < chars; i++) + for (int j = 0; j < chary; j++) { int r = 0; String line = sc.nextLine(); - for (int x = 0; x < 0; x++) + for (int x = 0; x < charx; x++) if (line.charAt(x) != ' ') - r |= 1 << (7 - x); + r |= 1 << x; charmap[i][j] = r; } + int offx = (640 - width * charx) / 2, offy = (480 - height * chary) / 2; + + BufferedImage background = new BufferedImage(width * charx, height * chary, BufferedImage.TYPE_INT_ARGB); BufferedImage foreground = new BufferedImage(width * charx, height * chary, BufferedImage.TYPE_INT_ARGB); + BufferedImage shadow = new BufferedImage(width * charx, height * chary, BufferedImage.TYPE_INT_ARGB); + + int fore = 0; + int back = 0; + long foreback = 0; + + for (int y = 0; y < height; y++) + { + int x = 0; + String row = rows[y]; + boolean escape = false; + for (int i = 0, n = row.length(); i < n; i++) + { + char c = row.charAt(i); + if (c == '\033') + { + fore = (int)(foreback >> 32); + back = (int)foreback; + escape ^= true; + foreback = 0; + } + else if (escape) + { + if (c == '#') + continue; + foreback = (foreback << 4) | ((c & 15) + (c <= '9' ? 0 : 9)); + } + else + { + int ci = c % chars; + if (c == '┌') ci = 218; + else if (c == '─') ci = 196; + else if (c == '┐') ci = 191; + else if (c == '│') ci = 179; + else if (c == '├') ci = 195; + else if (c == '┤') ci = 180; + else if (c == '└') ci = 192; + else if (c == '┘') ci = 217; + int[] chr = charmap[ci]; + int t; + for (int yi = 0; yi < chary; yi++) + for (int xi = 0; xi < charx; xi++) + { + int xo = (chr[yi] >>> xi) & 1; + int a, rgb = splash.getRGB((t = offx + x * charx + xi + xo) > 639 ? 639 : t, offy + y * chary + yi); + int r = (rgb >> 16) & 255; + int g = (rgb >> 8) & 255; + int b = rgb & 255; + if (xo == 1) + { + a = fore >>> 24; + shadow.setRGB(x * charx + xi, y * chary + yi, 128 << 24); + r = join((fore >> 16) & 255, r, a); + g = join((fore >> 8) & 255, g, a); + b = join((fore >> 0) & 255, b, a); + rgb = (255 << 24) | (r << 16) | (g << 8) | b; + foreground.setRGB(x * charx + xi, y * chary + yi, rgb); + } + else + { + a = back >>> 24; + r = join((back >> 16) & 255, r, a); + g = join((back >> 8) & 255, g, a); + b = join((back >> 0) & 255, b, a); + rgb = (255 << 24) | (r << 16) | (g << 8) | b; + background.setRGB(x * charx + xi, y * chary + yi, rgb); + } + } + x++; + } + } + } + Graphics g = splash.createGraphics(); + g.drawImage(background, offx, offy, null); + g.drawImage(shadow, offx + 1, offy + 1, null); + g.drawImage(foreground, offx, offy, null); + g.dispose(); + ImageIO.write(splash, "png", new BufferedOutputStream(new FileOutputStream(new File(args[0])))); + } + + + private static int join(int fg, int bg, int alpha) + { + double t = alpha * linear(fg) + (255 - alpha) * linear(bg); + t /= 255; + if (t <= 0.00304) + t *= 12.92; + else + t = 1.055 * Math.pow(t, 1 / 2.4) - 0.055; + return (int)(255 * t + 0.5); + } + + private static double linear(int c) + { + if (c <= 10) + return c / (255 * 12.92); + return Math.pow((c + 14.025) / 269.025, 2.4); } + } diff --git a/src/parse.py b/src/parse.py index a680d68..e02bd61 100755 --- a/src/parse.py +++ b/src/parse.py @@ -19,6 +19,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import os +import sys DEBUG = False @@ -120,24 +121,24 @@ if DEBUG: border = colour_border labels = (labels + '\n' * rows).split('\n')[:rows] -labels = [(' ' + x + ' ' * 58)[:58] + '\033\033' for x in labels] +labels = [(' ' + x + ' ' * 68)[:68] + '\033\033' for x in labels] labels = ['\033' + (colour_sel if x is labels[0] else colour_unsel) + '\033' + x for x in labels] -title = (' ' * ((58 - len(title)) // 2) + title + ' ' * 58)[:58] +title = (' ' * ((68 - len(title)) // 2) + title + ' ' * 68)[:68] title = '\033' + colour_title + '\033' + title + '\033\033' helpmsgendrow -= vshift -helptext = (helptext + '\n' * (helpmsgendrow - helpmsgrow)).split('\n')[: helpmsgendrow - helpmsgrow + 1] +helptext = (helptext + '\n' * (helpmsgendrow - helpmsgrow + 2)).split('\n')[: helpmsgendrow - helpmsgrow + 2] helptext = ['\033' + colour_help + '\033' + (' ' * margin + x + ' ' * width)[:width] + '\033\033' for x in helptext] helptext = '\n'.join(helptext) -menumargin = (width - 60) // 2 -text = '\n' * vshift + ' ' * menumargin + '\033' + border + '\033┌' + '─' * 58 + '┐\033\033\n' +menumargin = (width - 70) // 2 +text = '\n' * vshift + ' ' * menumargin + '\033' + border + '\033┌' + '─' * 68 + '┐\033\033\n' text += ' ' * menumargin + '\033' + border + '\033│\033\033' + title + '\033' + border + '\033│\033\033\n' -text += ' ' * menumargin + '\033' + border + '\033├' + '─' * 58 + '┤\033\033\n' +text += ' ' * menumargin + '\033' + border + '\033├' + '─' * 68 + '┤\033\033\n' for label in labels: text += ' ' * menumargin + '\033' + border + '\033│\033\033' + label + '\033' + border + '\033│\033\033\n' -text += ' ' * menumargin + '\033' + border + '\033└' + '─' * 58 + '┘\033\033\n' +text += ' ' * menumargin + '\033' + border + '\033└' + '─' * 68 + '┘\033\033\n' more = [] @@ -160,13 +161,15 @@ for seg in more: text += '\n' * (seg[0] - line) + seg[1] + '\n' line = seg[0] + len(seg[1].split('\n')) -text = background + '\n' + '\n'.join((text + '\n' * 30).split('\n')[:30]) +text = '\n'.join((text + '\n' * 30).split('\n')[:30]) +print(background) print(width) -print(30) +print(29) if DEBUG: text = text.replace('\033', '') print(text, end = '') +sys.stdout.flush() if not DEBUG: os.system('bash -c "psf2txt <(gunzip < \'%s\') /dev/stderr 2>&1 >/dev/null | grep -v ++"' % font.replace('\'', '\'\\\'\'')) |
