From cf7cfa1c792eebba606a48aa648893f6e4873263 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 22 Jul 2019 23:03:04 -0400
Subject: [PATCH] Embed JPEG.
---
ObjEditor.java | 1
CameraPane.java | 122 ++++++++++++++++++++++++++++++++++------
Grafreed.java | 4
3 files changed, 105 insertions(+), 22 deletions(-)
diff --git a/CameraPane.java b/CameraPane.java
index cef7cdb..ffbe72c 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -18,7 +18,10 @@
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
+import javax.imageio.ImageReadParam;
+import javax.imageio.ImageReader;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
+import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.ImageWriteParam;
@@ -30,6 +33,7 @@
import java.nio.*;
import gleem.linalg.Mat4f;
+import javax.imageio.ImageTypeSpecifier;
class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
{
@@ -93,7 +97,7 @@
//boolean REDUCETEXTURE = true;
boolean CACHETEXTURE = true;
boolean CLEANCACHE = false; // true;
- boolean MIPMAP = true; // false; // true;
+ boolean MIPMAP = false; // true; // never works...
boolean COMPRESSTEXTURE = false;
boolean KOMPACTTEXTURE = false; // true;
boolean RESIZETEXTURE = false;
@@ -8358,14 +8362,26 @@
{
TextureData texturedata = null;
- if (texdata != null)
+ if (texdata != null && textureon)
{
- BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
- CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
+ try
+ {
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
+ }
+ catch (Exception e)
+ {
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
+ }
texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
bimtextures.put(texdata, texturecache);
+
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
+
+ //Object bim2 = CreateBim(texturecache.texturedata);
+ //bim2 = bim;
}
else
if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
@@ -8560,29 +8576,32 @@
{
if (tex.pigmentdata == null)
{
- String texname = Object3D.GetPigment(tex);
+ //String texname = Object3D.GetPigment(tex);
CacheTexture texturecache = texturepigment.get(tex);
if (texturecache != null)
{
- tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
tex.pw = texturecache.texturedata.getWidth();
tex.ph = texturecache.texturedata.getHeight();
+ tex.pigmentdata = //CompressJPEG(CreateBim
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
+ ;
+ //, tex.pw, tex.ph), 0.5f);
}
}
if (tex.bumpdata == null)
{
- String texname = Object3D.GetBump(tex);
+ //String texname = Object3D.GetBump(tex);
CacheTexture texturecache = texturebump.get(tex);
if (texturecache != null)
{
- tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
tex.bw = texturecache.texturedata.getWidth();
tex.bh = texturecache.texturedata.getHeight();
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
}
}
}
@@ -8654,6 +8673,72 @@
return true; // Warning: not used.
}
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
+ ImageWriter writer = writers.next();
+
+ ImageWriteParam param = writer.getDefaultWriteParam();
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
+ param.setCompressionQuality(quality);
+
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
+ writer.setOutput(ios);
+ writer.write(null, new IIOImage(image, null, null), param);
+
+ byte[] data = baos.toByteArray();
+ writer.dispose();
+ return data;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
+ {
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
+ ImageReader reader = writers.next();
+
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setDestination(bim);
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
+
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
+ reader.setInput(ios);
+ BufferedImage bim2 = reader.read(0, param);
+ reader.dispose();
+
+// WritableRaster raster = bim2.getRaster();
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
+// byte[] bytes = data.getData();
+//
+// int[] pixels = new int[bytes.length/3];
+// for (int i=pixels.length; --i>=0;)
+// {
+// int i3 = i*3;
+// pixels[i] = 0xFF;
+// pixels[i] <<= 8;
+// pixels[i] |= bytes[i3+2] & 0xFF;
+// pixels[i] <<= 8;
+// pixels[i] |= bytes[i3+1] & 0xFF;
+// pixels[i] <<= 8;
+// pixels[i] |= bytes[i3] & 0xFF;
+// }
+//
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
+
+ return bim;
+ }
+
ShadowBuffer shadowPBuf;
AntialiasBuffer antialiasPBuf;
int MAXSTACK;
@@ -11399,7 +11484,7 @@
}
}
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
{
//gl.glDepthFunc(GL.GL_LEQUAL);
//gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
@@ -11407,24 +11492,21 @@
boolean texon = textureon;
- if (RENDERPROGRAM > 0)
- {
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
- textureon = false;
- }
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
+ textureon = false;
+
//gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
//System.out.println("ALLO");
gl.glColorMask(false, false, false, false);
DrawObject(gl);
- if (RENDERPROGRAM > 0)
- {
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
- textureon = texon;
- }
+
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
+ textureon = texon;
+
gl.glColorMask(true, true, true, true);
gl.glDepthFunc(GL.GL_EQUAL);
- //gl.glDepthMask(false);
+ gl.glDepthMask(false);
}
if (false) // DrawMode() == SHADOW)
diff --git a/Grafreed.java b/Grafreed.java
index 7007edf..4f0341c 100644
--- a/Grafreed.java
+++ b/Grafreed.java
@@ -626,12 +626,12 @@
System.out.println("jarfile = " + jarfile);
- String command = javaPath + " -Xmx1024m -Djava.library.path=" + jarpath;
+ String command = javaPath + " -Xmx2048m -Djava.library.path=" + jarpath;
// -Djava.library.path=/Users/nbriere/Projects/shared/lib
if (jarfile.charAt(2) == ':')
{
- command = "\"" + javaPath + "\" -Xmx1024m -Djava.library.path=" + jarpath;
+ command = "\"" + javaPath + "\" -Xmx2048m -Djava.library.path=" + jarpath;
// On Windows systems, the path is /C:/
jarfile = jarfile.substring(1, jarfile.length());
System.out.println("jarfile = " + jarfile);
diff --git a/ObjEditor.java b/ObjEditor.java
index 5b2dae6..c67953d 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -4889,6 +4889,7 @@
}
} catch (ClassCastException e)
{
+ e.printStackTrace();
assert (false);
Composite c = (Composite) copy;
c.children.clear();
--
Gitblit v1.6.2