summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satserver
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-27 21:22:27 +0200
committerSimon Rettberg2014-06-27 21:22:27 +0200
commite323c3767bc6351549bfed6cec907006ea42d1ef (patch)
tree8e14c423159a1a62bf54e5458e41b4cefb9b8c92 /src/main/java/org/openslx/satserver
parentBetter error handling for ldadp launching (diff)
downloadtmlite-bwlp-e323c3767bc6351549bfed6cec907006ea42d1ef.tar.gz
tmlite-bwlp-e323c3767bc6351549bfed6cec907006ea42d1ef.tar.xz
tmlite-bwlp-e323c3767bc6351549bfed6cec907006ea42d1ef.zip
Branding module generator task
Diffstat (limited to 'src/main/java/org/openslx/satserver')
-rw-r--r--src/main/java/org/openslx/satserver/util/Ppm.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/satserver/util/Ppm.java b/src/main/java/org/openslx/satserver/util/Ppm.java
new file mode 100644
index 0000000..29491d7
--- /dev/null
+++ b/src/main/java/org/openslx/satserver/util/Ppm.java
@@ -0,0 +1,52 @@
+package org.openslx.satserver.util;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+public class Ppm
+{
+
+ /**
+ * Save image as ppm file.
+ *
+ * @param inImage BufferedImage to save
+ * @param fName file name to save as
+ * @param white
+ * @throws IOException
+ */
+ public static boolean write( BufferedImage inImage, String fName, Color transparent ) throws IOException
+ {
+ FileOutputStream bw = null;
+ final int tr = transparent.getRed();
+ final int tg = transparent.getGreen();
+ final int tb = transparent.getBlue();
+ try {
+ File theFile = new File( fName );
+ bw = new FileOutputStream( theFile );
+ bw.write( "P6\n".getBytes( StandardCharsets.UTF_8 ) );
+ bw.write( ( inImage.getWidth() + " " + inImage.getHeight() + " 255\n" ).getBytes( StandardCharsets.UTF_8 ) );
+
+ for ( int y = 0; y < inImage.getHeight(); ++y ) {
+ for ( int x = 0; x < inImage.getWidth(); ++x ) {
+ int color = inImage.getRGB( x, y );
+ int alpha = ( color >>> 24 ) & 0xFF;
+ int red = ( color >>> 16 ) & 0xFF;
+ int green = ( color >>> 8 ) & 0xFF;
+ int blue = ( color ) & 0xFF;
+ bw.write( ( ( red * alpha ) + ( tr * ( 255 - alpha ) ) ) / 255 );
+ bw.write( ( ( green * alpha ) + ( tg * ( 255 - alpha ) ) ) / 255 );
+ bw.write( ( ( blue * alpha ) + ( tb * ( 255 - alpha ) ) ) / 255 );
+ }
+ }
+ bw.close();
+ } finally {
+ Util.multiClose( bw );
+ }
+ return true;
+ }
+
+}