aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Assemble.java119
-rwxr-xr-xsrc/assemble112
-rwxr-xr-xsrc/splashtool12
3 files changed, 118 insertions, 125 deletions
diff --git a/src/Assemble.java b/src/Assemble.java
index a0b9969..b8aee2f 100644
--- a/src/Assemble.java
+++ b/src/Assemble.java
@@ -32,106 +32,6 @@ public class Assemble
{
public static void main(final String... args) throws IOException
{
- ImageIO.scanForPlugins();
- Scanner sc = new Scanner(System.in);
- 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[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++)
- {
- int r = 0;
- String line = sc.nextLine();
- for (int x = 0; x < charx; x++)
- if (line.charAt(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);
@@ -169,24 +69,5 @@ public class Assemble
return rc;
}
-
- 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/assemble b/src/assemble
new file mode 100755
index 0000000..687f934
--- /dev/null
+++ b/src/assemble
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+# -*- python -*-
+'''
+splashtool – A simple tool for creating SYSLINUX splashes without fuss
+
+Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+'''
+
+def join(fb, bg, alpha):
+ t = alpha * linear(fg) + (255 - alpha) * linear(bg)
+ t /= 255
+ if t <= 0.00304:
+ t *= 12.92
+ else:
+ t = 1.055 * t ** (1 / 2.4) - 0.055
+ return int(255 * t + 0.5)
+
+def linear(c):
+ if c <= 10:
+ return c / (255 * 12.92)
+ return ((c + 14.025) / 269.025) ** 2.4
+
+# Read image data.
+splash = input()
+width = int(input())
+height = int(input())
+rows = [input() for i in range(height)]
+
+# Read font data.
+chars = int(input())
+charx = int(input())
+chary = int(input())
+charmap = [[0] * chary for i in range(chars)]
+for i in range(chars):
+ for y in range(chary):
+ line = input()
+ charmap[i][y] = sum((0 if line[x] == ' ' else 1) << x for x in range(charx))
+
+# The overlay should be centered on the background.
+offx = (640 - width * charx) // 2
+offy = (480 - height * chary) // 2
+
+# Buffers for layers.
+# TODO splash = ... (splash)
+background = [[0] * (height * chary) for i in range(width * charx)]
+foreground = [[0] * (height * chary) for i in range(width * charx)]
+shadow = [[0] * (height * chary) for i in range(width * charx)]
+
+# Colours.
+fore = 0
+back = 0
+foreback = 0
+
+# Fill largers.
+for y in range(height):
+ x = 0
+ row = rows[y]
+ escape = False
+ for i in range(len(row)):
+ c = row[i]
+ if c == '\033':
+ fore = foreback >> 32
+ back = foreback & ((1 << 32) - 1)
+ escape = not escape
+ foreback = 0
+ elif escape:
+ if c == '#':
+ continue
+ foreback <<= 4
+ foreback |= (ord(c) & 15) + (0 if c <= '9' else 9)
+ foreback &= (1 << 64) - 1
+ else:
+ ci = ord(c) % chars
+ if c == '┌': ci = 218
+ elif c == '─': ci = 196
+ elif c == '┐': ci = 191
+ elif c == '│': ci = 179
+ elif c == '├': ci = 195
+ elif c == '┤': ci = 180
+ elif c == '└': ci = 192
+ elif c == '┘': ci = 217
+ char = charmap[ci]
+ for yi in range(chary):
+ for xi in range(charx):
+ xo = (char[yi] >> xi) & 1
+ t = offx + x * charx + xi + xo
+ rgb = splash[639 if t > 639 else t][offy + y * chary + yi]
+ r, g, b = (rgb >> 16) & 255, (rgb >> 8) & 255, (rgb >> 0) & 255
+ if xo == 1:
+ shadow[x * charx + xi][y * chary + yi] = 128 << 24
+ (c_, i_) = (fore, foreground) if xo == 1 else (back, background)
+ a = c_ >> 24
+ r = join((c_ >> 16) & 255, r, a)
+ g = join((c_ >> 8) & 255, g, a)
+ b = join((c_ >> 0) & 255, b, a)
+ rgb = (255 << 24) | (r << 16) | (g << 8) | b
+ i_[x * charx + xi][y * chary + yi] = rgb
+ x += 1
+
diff --git a/src/splashtool b/src/splashtool
index b88f4f5..fc36cbf 100755
--- a/src/splashtool
+++ b/src/splashtool
@@ -18,25 +18,25 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-in="$(realpath "$1")"
-out="$(realpath "$2")"
-d="$(dirname "$(realpath "$0")")"
+in="$(realpath "${1}")"
+out="$(realpath "${2}")"
+d="$(dirname "$(realpath "${0}")")"
-cd "$(dirname "$1")"
+cd "$(dirname "${1}")"
# Create an images from the generated data.
make_image ()
{
if [ -z "${debug}" ]; then
- java -cp "$d" Assemble "$out" "$3"
+ "${d}/assemble" "${out}" "${3}" | convert /dev/stdin "${out}"
else
cat
fi
}
-# Get the description text do display.
+# Get the description text to display.
get_text ()
{
awk 'BEGIN { text = 0; }