aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-04-01 05:16:35 +0200
committerSven Gothel <[email protected]>2013-04-01 05:16:35 +0200
commita54bd3e963a7be320dee0c9692d237607fcd0f96 (patch)
treee365b6baeda020429355f9a7a98a7c3e65da713b /src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
parent00c65b4a34445d140ca9e6ee531dfa4278b8e770 (diff)
Fix Bug 671: Add JPEG Decoder w/o AWT Dependencies
Original JavaScript code from <https://github.com/notmasteryet/jpgjs/blob/master/jpg.js>, author 'notmasteryet' <async.processingjs at yahoo.com>. Ported to Java. Enhancements: * InputStream instead of memory buffer * User provided memory handler * Fixed JPEG Component ID/Index mapping * Color space conversion (YCCK, CMYK -> RGB) * More error tolerant +++ Features: JOGL AWT RGB ok ok YCCK ok Exception CMYK ok Exception YUV Store ok n/a Need Y-Flip no yes +++ Benchmark: TestJPEGJoglAWTBenchmarkNewtAWT JOGL.RGB Loops 100, dt 1199 ms, 11.99 ms/l JOGL.YUV Loops 100, dt 351 ms, 3.51 ms/l AWT..... Loops 100, dt 2144 ms, 21.44 ms/l File: jogl/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j1-baseline.jpg Machine: GNU/Linux PC (AMD 8 core), JavaSE 6 (1.6.0_38) .++++ UITestCase.setUp: com.jogamp.opengl.test.junit.jogl.util.texture.TestJPEGJoglAWTBenchmarkNewtAWT - benchmark libEGL warning: DRI2: failed to authenticate 0: JPEGImage[261x202, bytesPerPixel 3, reversedChannels false, JPEGPixels[261x202, sourceComp 3, sourceCS YCbCr, storageCS RGB, storageComp 3], java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166]] 0: TextureData[261x202, y-flip false, internFormat 0x1907, pixelFormat 0x1907, pixelType 0x1401, border 0, estSize 158166, alignment 1, rowlen 0, buffer java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166] JOGL.RGB Loops 100, dt 1199 ms, 11.99 ms/l 0: JPEGImage[261x202, bytesPerPixel 3, reversedChannels false, JPEGPixels[261x202, sourceComp 3, sourceCS YCbCr, storageCS YCbCr, storageComp 3], java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166]] 0: TextureData[261x202, y-flip false, internFormat 0x1907, pixelFormat 0x1907, pixelType 0x1401, border 0, estSize 158166, alignment 1, rowlen 0, buffer java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166] JOGL.YUV Loops 100, dt 351 ms, 3.51 ms/l 0: TextureData[261x202, y-flip true, internFormat 0x1907, pixelFormat 0x80e0, pixelType 0x1401, border 0, estSize 158166, alignment 1, rowlen 261, buffer java.nio.HeapByteBuffer[pos=0 lim=158166 cap=158166] AWT..... Loops 100, dt 2144 ms, 21.44 ms/l ++++ UITestCase.tearDown: com.jogamp.opengl.test.junit.jogl.util.texture.TestJPEGJoglAWTBenchmarkNewtAWT - benchmark
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java57
1 files changed, 52 insertions, 5 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
index b878c6002..0b0af5625 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
@@ -63,6 +63,7 @@ import jogamp.opengl.Debug;
import com.jogamp.common.util.IOUtil;
import com.jogamp.opengl.util.texture.spi.DDSImage;
+import com.jogamp.opengl.util.texture.spi.JPEGImage;
import com.jogamp.opengl.util.texture.spi.NetPbmTextureWriter;
import com.jogamp.opengl.util.texture.spi.PNGImage;
import com.jogamp.opengl.util.texture.spi.SGIImage;
@@ -714,8 +715,12 @@ public class TextureIO {
// SPI support
//
- /** Adds a TextureProvider to support reading of a new file
- format. */
+ /**
+ * Adds a TextureProvider to support reading of a new file format.
+ * <p>
+ * The last provider added, will be the first provider to be tested.
+ * </p>
+ */
public static void addTextureProvider(TextureProvider provider) {
// Must always add at the front so the ImageIO provider is last,
// so we don't accidentally use it instead of a user's possibly
@@ -723,8 +728,12 @@ public class TextureIO {
textureProviders.add(0, provider);
}
- /** Adds a TextureWriter to support writing of a new file
- format. */
+ /**
+ * Adds a TextureWriter to support writing of a new file format.
+ * <p>
+ * The last provider added, will be the first provider to be tested.
+ * </p>
+ */
public static void addTextureWriter(TextureWriter writer) {
// Must always add at the front so the ImageIO writer is last,
// so we don't accidentally use it instead of a user's possibly
@@ -768,7 +777,7 @@ public class TextureIO {
private static List<TextureProvider> textureProviders = new ArrayList<TextureProvider>();
private static List<TextureWriter> textureWriters = new ArrayList<TextureWriter>();
- static {
+ static {
// ImageIO provider, the fall-back, must be the first one added
if(GLProfile.isAWTAvailable()) {
try {
@@ -787,6 +796,7 @@ public class TextureIO {
addTextureProvider(new DDSTextureProvider());
addTextureProvider(new SGITextureProvider());
addTextureProvider(new TGATextureProvider());
+ addTextureProvider(new JPGTextureProvider());
addTextureProvider(new PNGTextureProvider());
// ImageIO writer, the fall-back, must be the first one added
@@ -1174,6 +1184,43 @@ public class TextureIO {
}
//----------------------------------------------------------------------
+ // JPEG image provider
+ static class JPGTextureProvider extends StreamBasedTextureProvider {
+ public TextureData newTextureData(GLProfile glp, InputStream stream,
+ int internalFormat,
+ int pixelFormat,
+ boolean mipmap,
+ String fileSuffix) throws IOException {
+ if (JPG.equals(fileSuffix)) {
+ JPEGImage image = JPEGImage.read(/*glp, */ stream);
+ if (pixelFormat == 0) {
+ pixelFormat = image.getGLFormat();
+ }
+ if (internalFormat == 0) {
+ if(glp.isGL2GL3()) {
+ internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA8:GL.GL_RGB8;
+ } else {
+ internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB;
+ }
+ }
+ return new TextureData(glp, internalFormat,
+ image.getWidth(),
+ image.getHeight(),
+ 0,
+ pixelFormat,
+ image.getGLType(),
+ mipmap,
+ false,
+ false,
+ image.getData(),
+ null);
+ }
+
+ return null;
+ }
+ }
+
+ //----------------------------------------------------------------------
// DDS texture writer
//
static class DDSTextureWriter implements TextureWriter {