JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestJPEGJoglAWTBenchmarkNewtAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.util.texture;
30
31
32import com.jogamp.common.util.IOUtil;
33import com.jogamp.opengl.test.junit.util.UITestCase;
34
35import javax.imageio.ImageIO;
36import com.jogamp.opengl.GL;
37import com.jogamp.opengl.GLProfile;
38
39import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
40import com.jogamp.opengl.util.texture.TextureData;
41import com.jogamp.opengl.util.texture.awt.AWTTextureData;
42import com.jogamp.opengl.util.texture.spi.JPEGImage;
43
44import java.awt.image.BufferedImage;
45import java.io.IOException;
46import java.io.InputStream;
47import java.net.URLConnection;
48import java.nio.Buffer;
49
50import org.junit.Test;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
53
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
56 static boolean showFPS = false;
57 static String fname = "j1-baseline.jpg";
58
59 @Test
60 public void benchmark() throws IOException {
61 benchmarkImpl(100, fname);
62 }
63 void benchmarkImpl(final int loops, final String fname) throws IOException {
64 {
65 final long t0 = System.currentTimeMillis();
66 for(int i = 0; i< loops; i++ ) {
67 final URLConnection urlConn = IOUtil.getResource(fname, this.getClass().getClassLoader(), this.getClass());
68 final InputStream istream = urlConn.getInputStream();
69 final JPEGImage image = JPEGImage.read(istream); // parsing & completion done !!!
70 final int internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB;
71 final TextureData texData = new TextureData(GLProfile.getGL2ES2(), internalFormat,
72 image.getWidth(),
73 image.getHeight(),
74 0,
75 new GLPixelAttributes(image.getGLFormat(), image.getGLType()),
76 false /* mipmap */,
77 false /* compressed */,
78 false /* must flip-vert */,
79 image.getData(),
80 null);
81 if(0==i || loops-1==i) {
82 System.err.println(i+": "+image.toString());
83 System.err.println(i+": "+texData+", buffer "+texData.getBuffer());
84 }
85 istream.close();
86 }
87 final long t1 = System.currentTimeMillis();
88 final long dt = t1 - t0;
89 final float msPl = (float)dt / (float)loops ;
90 System.err.println("JOGL.RGB Loops "+loops+", dt "+dt+" ms, "+msPl+" ms/l");
91 }
92 {
93 final long t0 = System.currentTimeMillis();
94 for(int i = 0; i< loops; i++ ) {
95 final URLConnection urlConn = IOUtil.getResource(fname, this.getClass().getClassLoader(), this.getClass());
96 final InputStream istream = urlConn.getInputStream();
97 final JPEGImage image = JPEGImage.read(istream, TextureData.ColorSpace.YCbCr); // parsing & completion done !!!
98 final int internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB;
99 final TextureData texData = new TextureData(GLProfile.getGL2ES2(), internalFormat,
100 image.getWidth(),
101 image.getHeight(),
102 0,
103 new GLPixelAttributes(image.getGLFormat(), image.getGLType()),
104 false /* mipmap */,
105 false /* compressed */,
106 false /* must flip-vert */,
107 image.getData(),
108 null);
109 if(0==i || loops-1==i) {
110 System.err.println(i+": "+image.toString());
111 System.err.println(i+": "+texData+", buffer "+texData.getBuffer());
112 }
113 istream.close();
114 }
115 final long t1 = System.currentTimeMillis();
116 final long dt = t1 - t0;
117 final float msPl = (float)dt / (float)loops ;
118 System.err.println("JOGL.YUV Loops "+loops+", dt "+dt+" ms, "+msPl+" ms/l");
119 }
120 {
121 final long t0 = System.currentTimeMillis();
122 for(int i = 0; i< loops; i++ ) {
123 final URLConnection urlConn = IOUtil.getResource(fname, this.getClass().getClassLoader(), this.getClass());
124 final InputStream istream = urlConn.getInputStream();
125 Buffer data = null;
126 try {
127 final BufferedImage img = ImageIO.read(istream);
128 final AWTTextureData texData = new AWTTextureData(GLProfile.getGL2ES2(), 0, 0, false, img);
129 data = texData.getBuffer(); // completes data conversion !!!
130 if(0==i || loops-1==i) {
131 System.err.println(i+": "+texData+", buffer "+data);
132 }
133 } catch (final Exception e) {
134 System.err.println("AWT ImageIO failure w/ file "+fname+": "+e.getMessage());
135 }
136 istream.close();
137 }
138 final long t1 = System.currentTimeMillis();
139 final long dt = t1 - t0;
140 final float msPl = (float)dt / (float)loops ;
141 System.err.println("AWT..... Loops "+loops+", dt "+dt+" ms, "+msPl+" ms/l");
142 }
143 }
144
145 public static void main(final String args[]) throws IOException {
146 for(int i=0; i<args.length; i++) {
147 if(args[i].equals("-file")) {
148 i++;
149 fname = args[i];
150 }
151 }
152 org.junit.runner.JUnitCore.main(TestJPEGJoglAWTBenchmarkNewtAWT.class.getName());
153 }
154}
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
Represents the data for an OpenGL texture.
ByteBuffer getData()
Returns the raw data for this texture in the correct (bottom-to-top) order for calls to glTexImage2D.
Definition: JPEGImage.java:173
int getBytesPerPixel()
Returns the bytes per pixel.
Definition: JPEGImage.java:169
int getGLFormat()
Returns the OpenGL format for this texture; e.g.
Definition: JPEGImage.java:163
int getWidth()
Returns the width of the image.
Definition: JPEGImage.java:154
int getHeight()
Returns the height of the image.
Definition: JPEGImage.java:157
int getGLType()
Returns the OpenGL data type: GL.GL_UNSIGNED_BYTE.
Definition: JPEGImage.java:166
static JPEGImage read(final InputStream in, final ColorSpace cs)
Reads a JPEG image from the specified InputStream, using the given color space for storage.
Definition: JPEGImage.java:54
static final int GL_RGB
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGB" with expression ...
Definition: GL.java:374
static final int GL_RGBA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGBA" with expression...
Definition: GL.java:150