diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-11-02 14:28:11 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-11-02 14:28:11 +0100 |
| commit | 0a7a249ae666dbb297dcdede4fbcdaf60045bf1b (patch) | |
| tree | d61290c58eb506ef8930633ad668ea05a4cbaf39 /src | |
| parent | work on porting the java code to python (diff) | |
| download | splashtool-0a7a249ae666dbb297dcdede4fbcdaf60045bf1b.tar.gz splashtool-0a7a249ae666dbb297dcdede4fbcdaf60045bf1b.tar.bz2 splashtool-0a7a249ae666dbb297dcdede4fbcdaf60045bf1b.tar.xz | |
more work on porting the java code to python
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
| -rw-r--r-- | src/Assemble.java | 73 | ||||
| -rwxr-xr-x | src/assemble | 72 |
2 files changed, 66 insertions, 79 deletions
diff --git a/src/Assemble.java b/src/Assemble.java deleted file mode 100644 index b8aee2f..0000000 --- a/src/Assemble.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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/>. - */ -import java.io.*; -import java.util.*; -import java.awt.*; -import java.awt.image.*; -import javax.imageio.*; - - -/** - * Assemble the splash - * - * @author Mattias Andrée <a href="mailto:maandree@member.fsf.org">maandree@member.fsf.org</a> - */ -public class Assemble -{ - public static void main(final String... args) throws IOException - { - 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(); - - if (args[1].toLowerCase().startsWith("-w") || args[1].toLowerCase().startsWith("--w")) - splash = widescreen(splash); - - ImageIO.write(splash, "png", new BufferedOutputStream(new FileOutputStream(new File(args[0])))); - } - - - private static BufferedImage widescreen(BufferedImage img) - { - BufferedImage rc = new BufferedImage(480 * 16 / 9, 480, BufferedImage.TYPE_INT_ARGB); - for (int y = 0; y < 480; y++) - for (int x = 0, e = 0; x < 640; x++) - { - rc.setRGB(x + e, y, img.getRGB(x, y)); - if (x % 3 == 2) - if (x == 639) - rc.setRGB(x + ++e, y, img.getRGB(x, y)); - else - { - int argb1 = img.getRGB(x, y); - int argb2 = img.getRGB(x + 1, y); - int a = (argb1 >>> 24) + (argb2 >>> 24); - int r = ((argb1 >> 16) & 255) + ((argb2 >> 16) & 255); - int g = ((argb1 >> 8) & 255) + ((argb2 >> 8) & 255); - int b = (argb1 & 255) + (argb2 & 255); - rc.setRGB(x + ++e, y, ((a >> 1) << 24) | ((r >> 1) << 16) | ((g >> 1) << 8) | (b >> 1)); - } - } - return rc; - } - -} - diff --git a/src/assemble b/src/assemble index 687f934..d82b44c 100755 --- a/src/assemble +++ b/src/assemble @@ -19,7 +19,10 @@ 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): +import sys + + +def join(fg, bg, alpha): t = alpha * linear(fg) + (255 - alpha) * linear(bg) t /= 255 if t <= 0.00304: @@ -33,6 +36,45 @@ def linear(c): return c / (255 * 12.92) return ((c + 14.025) / 269.025) ** 2.4 +def subpixels(p): + return ((p >> 24) & 255, (p >> 16) & 255, (p >> 8) & 255, (p >> 0) & 255) + +def buffer_join(layer, base, offx, offy): + for x in range(len(layer)): + if x + offx >= len(base): + break + layer_column = layer[x] + base_column = base[x + offx] + for y in range(len(column)): + if y + offy >= len(base_column): + break + (la, lr, lg, lb) = subpixels(layer_column[y]) + (ba, br, bg, bb) = subpixels(base_column[y + offy]) + r = join(lr, br, la) + g = join(lg, bg, la) + b = join(lb, bb, la) + base_column[y + offy] = (255 << 24) | (r << 16) | (g << 8) | b + +def widescreen(img): + rc = [[0] * (480 * 16 // 9) for i in range(480)] + for y in range(480): + e = 0 + for x in range(640): + rc[x + e][y] = img[x][y] + if x % 3 == 2: + argb = img[x][y] + if x < 639: + (a1, r1, g1, b1) = subpixels(argb) + (a2, r2, g2, b2) = subpixels(img[x + x1][y]) + a = ((a1 + a2) // 2) << 24 + r = ((r1 + r2) // 2) << 16 + g = ((g1 + g2) // 2) << 8 + b = ((b1 + b2) // 2) << 0 + argb = a | r | g | b + e += 1 + rc[x + e][y] = argb + return rc + # Read image data. splash = input() width = int(input()) @@ -98,15 +140,33 @@ for y in range(height): 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 + _a, r, g, b = subpixels(rgb) 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) + ca, cr, cg, cb = subpixels(c_) + r = join(cr, r, ca) + g = join(cg, g, ca) + b = join(cb, b, ca) rgb = (255 << 24) | (r << 16) | (g << 8) | b i_[x * charx + xi][y * chary + yi] = rgb x += 1 +# Apply layers. +buffer_join(background, splash, offx, offy) +buffer_join(shadow, splash, offx + 1, offy + 1) +buffer_join(foreground, splash, offx, offy) + +# Make widescreen preview. +if sys.argv[2].lower().startswith('-w') or sys.argv[2].lower().startswith('--w'): + splash = widescreen(splash) + +# Print image. +width, height = len(splash), len(splash[0]) +print('P3') +print('%i %i' % (width, height)) +print('255') +trans = ['%i' % i for i in range(256)] +for y in range(height): + for x in range(width): + print(trans[splash[x][y]]) |
