handle transparency correctly

yeah, a little surprising I hadn’t done this before now.
This commit is contained in:
Justin Kunimune 2023-03-15 12:14:57 -04:00
parent eaaadbb188
commit 96e96d07e3
3 changed files with 61 additions and 33 deletions

View File

@ -17,27 +17,9 @@
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="mfc.jar">
<library>
<CLASSES>
<root url="jar://$USER_HOME$/eclipse-workspace/JTEM/mfc.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="ellipticFunctions.jar">
<CLASSES>
<root url="jar://$USER_HOME$/eclipse-workspace/JTEM/ellipticFunctions.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="commons-math3-3.6.1.jar">
<CLASSES>
<root url="jar://$USER_HOME$/eclipse-workspace/commons-math3-3.6.1/commons-math3-3.6.1.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx-swt.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -46,7 +28,7 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/javafx-sdk-11.0.2/lib/javafx-swt.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx.base.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -55,7 +37,7 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/javafx-sdk-11.0.2/lib/javafx.base.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx.controls.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -64,7 +46,7 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/javafx-sdk-11.0.2/lib/javafx.controls.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx.fxml.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -73,7 +55,7 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/javafx-sdk-11.0.2/lib/javafx.fxml.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx.graphics.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -82,7 +64,7 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/javafx-sdk-11.0.2/lib/javafx.graphics.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx.media.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -91,7 +73,7 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/javafx-sdk-11.0.2/lib/javafx.media.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx.swing.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -100,7 +82,38 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/javafx-sdk-11.0.2/lib/javafx.swing.jar!/" />
<root url="jar://C:/Program Files/Java/javafx-sdk-19.0.2.1/lib/javafx.web.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/ellipticFunctions.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://C:/Program Files/Java/ellipticFunctions.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/mfc.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://C:/Program Files/Java/mfc.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/Program Files/Java/commons-math3-3.6.1/commons-math3-3.6.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@ -43,7 +43,7 @@ public class MapConverter {
public static void main(String[] args) throws IOException {
// the directory with the equirectangular maps to convert
String directory = "C:/Users/Justin Kunimune/Downloads/AR Dymaxion Selections-20220212T141615Z-001/AR Dymaxion Selections";
String directory = "C:\\Users\\justi\\Downloads\\new_dymaxion_maps";
// the desired map projection
Projection projection = Polyhedral.DYMAXION;
@ -53,8 +53,10 @@ public class MapConverter {
// iterate thru the directory
for (Path inputPath: pathIterable) {
// look for images that are not dymaxion projections
if (inputPath.toString().endsWith(".png") &&
!inputPath.toString().endsWith(".dymaxion.png")) {
if (inputPath.toString().endsWith(".jpg") ||
inputPath.toString().endsWith(".tif") ||
inputPath.toString().endsWith(".png") &&
!inputPath.toString().endsWith(".dymaxion.png")) {
System.out.println(inputPath);
PixelMap inputImage = new PixelMap(inputPath.toFile());
@ -71,8 +73,10 @@ public class MapConverter {
null, null, null);
// update the filename and save to disk
String outputPath = inputPath.toString().replace(
".png", ".dymaxion.png");
String outputPath = inputPath.toString();
outputPath = outputPath.replace(".jpg", ".png");
outputPath = outputPath.replace(".tif", ".png");
outputPath = outputPath.replace(".png", ".dymaxion.png");
SavableImage.savable(outputImage).save(new File(outputPath));
}
}

View File

@ -23,7 +23,9 @@
*/
package image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
@ -37,10 +39,12 @@ import javax.imageio.ImageIO;
public class PixelMap {
private final BufferedImage pixels;
private final WritableRaster alphaPixels;
public PixelMap(File f) throws IOException {
pixels = ImageIO.read(f);
alphaPixels = pixels.getAlphaRaster();
}
@ -63,7 +67,14 @@ public class PixelMap {
y = 0;
else if (y >= pixels.getHeight())
y = pixels.getHeight() - 1;
int alpha;
if (pixels.getTransparency() != Transparency.OPAQUE)
alpha = alphaPixels.getPixel((int) x, (int) y, new int[1])[0];
else
alpha = 0xFF;
int rgb = pixels.getRGB((int) x, (int) y);
return (0xFF000000) | pixels.getRGB((int) x, (int) y);
return (alpha << 24) | rgb;
}
}