JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestPixelFormatUtil01NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 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 */
28package com.jogamp.opengl.test.junit.jogl.util.texture;
29
30import java.io.IOException;
31import java.net.MalformedURLException;
32import java.net.URLConnection;
33
34import com.jogamp.nativewindow.util.PixelFormat;
35import com.jogamp.nativewindow.util.PixelFormatUtil;
36import com.jogamp.nativewindow.util.PixelRectangle;
37
38import org.junit.Assert;
39import org.junit.Test;
40import org.junit.FixMethodOrder;
41import org.junit.runners.MethodSorters;
42
43import com.jogamp.common.util.Bitstream;
44import com.jogamp.common.util.IOUtil;
45import com.jogamp.opengl.test.junit.util.UITestCase;
46import com.jogamp.opengl.util.PNGPixelRect;
47
48/**
49 * Testing PixelFormatUtil's Conversion using PNG test data
50 * including strides, endian-order and PixelFormat conversions:
51 * { PixelFormat.RGBA8888, PixelFormat.ABGR8888, PixelFormat.BGRA8888, PixelFormat.ARGB8888 }
52 */
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55 @Test
56 public void testPNGRead11_fromRGBA8888() throws InterruptedException, IOException, MalformedURLException {
57 final String basename ="test-ntscN_4-01-160x90";
58 final String pathname="";
59 testPNG01Impl(pathname, basename, PixelFormat.RGBA8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
60 }
61 @Test
62 public void testPNGRead12_fromABGR8888() throws InterruptedException, IOException, MalformedURLException {
63 final String basename ="test-ntscN_4-01-160x90";
64 final String pathname="";
65 testPNG01Impl(pathname, basename, PixelFormat.ABGR8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
66 }
67 @Test
68 public void testPNGRead13_fromBGRA8888() throws InterruptedException, IOException, MalformedURLException {
69 final String basename ="test-ntscN_4-01-160x90";
70 final String pathname="";
71 testPNG01Impl(pathname, basename, PixelFormat.BGRA8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
72 }
73 @Test
74 public void testPNGRead14_fromARGB8888() throws InterruptedException, IOException, MalformedURLException {
75 final String basename ="test-ntscN_4-01-160x90";
76 final String pathname="";
77 testPNG01Impl(pathname, basename, PixelFormat.ARGB8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
78 }
79
80 private void testPNG01Impl(final String pathname, final String basename, final PixelFormat srcFmt,
81 final int destMinStrideInBytes, final boolean destIsGLOriented)
82 throws InterruptedException, IOException, MalformedURLException
83 {
84 System.err.println("Test01: "+pathname+basename+".png, srcFmt "+srcFmt+", destMinStrideInBytes "+destMinStrideInBytes+", destIsGLOriented "+destIsGLOriented);
85
86 final URLConnection urlConn = IOUtil.getResource(pathname+basename+".png", this.getClass().getClassLoader(), this.getClass());
87
88 final PNGPixelRect image1 = PNGPixelRect.read(urlConn.getInputStream(), srcFmt, false /* directBuffer */, destMinStrideInBytes, false /* isGLOriented */);
89 System.err.println("PNGPixelRect - Orig: "+image1);
90 System.err.printf("Image Data: %s%n", Bitstream.toHexBinString(true, image1.getPixels(), 0, image1.getPixelformat().comp.bytesPerPixel()));
91 TestPixelFormatUtil00NEWT.dumpComponents(image1, 0, 0, 3, 3);
92
93 final PixelFormat[] formats = new PixelFormat[] { PixelFormat.RGBA8888, PixelFormat.ABGR8888, PixelFormat.BGRA8888, PixelFormat.ARGB8888 };
94 for(int i=0; i<formats.length; i++) {
95 final PixelFormat destFmt = formats[i];
96 System.err.println("CONVERT["+i+"]: "+srcFmt+" -> "+destFmt);
97 final PixelRectangle imageConv1 = PixelFormatUtil.convert(image1, destFmt, destMinStrideInBytes, destIsGLOriented, false /* nio */);
98 System.err.println("PNGPixelRect - Conv1: "+imageConv1);
99 System.err.printf("Conv1 Data: %s%n", Bitstream.toHexBinString(true, imageConv1.getPixels(), 0, imageConv1.getPixelformat().comp.bytesPerPixel()));
100 TestPixelFormatUtil00NEWT.dumpComponents(imageConv1, 0, 0, 3, 3);
101 final PixelRectangle imageConv2 = PixelFormatUtil.convert(imageConv1, image1.getPixelformat(), image1.getStride(), image1.isGLOriented(), false /* nio */);
102 System.err.println("PNGPixelRect - Conv2: "+imageConv2);
103 System.err.printf("Conv2 Data: %s%n", Bitstream.toHexBinString(true, imageConv2.getPixels(), 0, imageConv2.getPixelformat().comp.bytesPerPixel()));
104 TestPixelFormatUtil00NEWT.dumpComponents(imageConv2, 0, 0, 3, 3);
105 Assert.assertEquals(image1.getPixels(), imageConv2.getPixels());
106 }
107 }
108
109 public static void main(final String args[]) {
110 org.junit.runner.JUnitCore.main(TestPixelFormatUtil01NEWT.class.getName());
111 }
112}
Testing PixelFormatUtil's Conversion using synthetic test data including strides, endian-order and al...
Testing PixelFormatUtil's Conversion using PNG test data including strides, endian-order and PixelFor...
static PNGPixelRect read(final InputStream in, final PixelFormat ddestFmt, final boolean destDirectBuffer, final int destMinStrideInBytes, final boolean destIsGLOriented)
Reads a PNG image from the specified InputStream.
ABGR8888
Stride is 32 bits, 32 bits per pixel, 4 uniform components of 8 bits.
BGRA8888
Stride is 32 bits, 32 bits per pixel, 4 uniform components of 8 bits.
final Composition comp
Unique Pixel Composition, i.e.
RGBA8888
Stride is 32 bits, 32 bits per pixel, 4 uniform components of 8 bits.
ARGB8888
Stride is 32 bits, 32 bits per pixel, 4 uniform components of 8 bits.
int bytesPerPixel()
Number of bytes per pixel, i.e.