28package com.jogamp.opengl.test.junit.jogl.util.texture;
30import java.io.BufferedOutputStream;
32import java.io.IOException;
33import java.io.OutputStream;
34import java.net.MalformedURLException;
35import java.net.URLConnection;
37import com.jogamp.nativewindow.util.PixelFormat;
38import com.jogamp.nativewindow.util.PixelFormatUtil;
40import org.junit.Assert;
42import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
45import com.jogamp.common.util.IOUtil;
46import com.jogamp.opengl.test.junit.util.UITestCase;
47import com.jogamp.opengl.util.PNGPixelRect;
49@FixMethodOrder(MethodSorters.NAME_ASCENDING)
52 public void testPNGRead01_All() throws InterruptedException, IOException, MalformedURLException {
55 final String pathname=
"";
56 testPNG01Impl(pathname, basename,
null, 0 ,
false );
62 final String basename =
"test-ntscN_3-01-160x90";
63 final String pathname=
"";
69 final String basename =
"test-ntscN_3-01-160x90";
70 final String pathname=
"";
76 final String basename =
"test-ntscN_3-01-160x90";
77 final String pathname=
"";
83 final String basename =
"test-ntscN_4-01-160x90";
84 final String pathname=
"";
90 final String basename =
"test-ntscN_4-01-160x90";
91 final String pathname=
"";
97 final String basename =
"test-ntscN_4-01-160x90";
98 final String pathname=
"";
104 final String basename =
"test-ntscN_4-01-160x90";
105 final String pathname=
"";
110 final String basename =
"test-ntscN_4-01-160x90";
111 final String pathname=
"";
116 final String basename =
"test-ntscN_4-01-160x90";
117 final String pathname=
"";
121 private void testPNG01Impl(
final String pathname,
final String basename,
122 final PixelFormat destFmt,
final int destMinStrideInBytes,
final boolean destIsGLOriented)
123 throws InterruptedException, IOException, MalformedURLException
125 System.err.println(
"Test01: "+pathname+basename+
".png, destFmt "+destFmt+
", destMinStrideInBytes "+destMinStrideInBytes+
", destIsGLOriented "+destIsGLOriented);
127 final File out1_f=
new File(getSimpleTestName(
".")+
"-01-"+basename+
"-orig.png");
128 final File out2F_f=
new File(getSimpleTestName(
".")+
"-02-"+basename+
"-flipped.png");
129 final File out2R_f=
new File(getSimpleTestName(
".")+
"-03-"+basename+
"-reversed.png");
130 final File out2RF_f=
new File(getSimpleTestName(
".")+
"-04-"+basename+
"-reversed_flipped.png");
131 final URLConnection urlConn = IOUtil.getResource(pathname+basename+
".png", this.getClass().getClassLoader(), this.getClass());
132 if(
null == urlConn ) {
133 throw new IOException(
"Cannot find "+pathname+basename+
".png");
135 final PNGPixelRect image1 = PNGPixelRect.read(urlConn.getInputStream(), destFmt,
false , destMinStrideInBytes, destIsGLOriented);
136 System.err.println(
"PNGPixelRect - Orig: "+image1);
138 final OutputStream outs =
new BufferedOutputStream(IOUtil.getFileOutputStream(out1_f,
true ));
139 image1.write(outs,
true );
141 final PNGPixelRect image1_R = PNGPixelRect.read(out1_f.toURI().toURL().openStream(), image1.getPixelformat(),
false , destMinStrideInBytes, destIsGLOriented);
142 System.err.println(
"PNGPixelRect - Orig (Read Back): "+image1_R);
143 Assert.assertEquals(image1.getPixels(), image1_R.getPixels());
151 final PNGPixelRect image2F =
new PNGPixelRect(image1.getPixelformat(), image1.getSize(),
152 image1.getStride(), !image1.isGLOriented(), image1.getPixels(),
153 image1.getDpi()[0], image1.getDpi()[1]);
154 System.err.println(
"PNGPixelRect - Flip : "+image2F);
155 final OutputStream outs =
new BufferedOutputStream(IOUtil.getFileOutputStream(out2F_f,
true ));
156 image2F.write(outs,
true );
159 final PNGPixelRect image2F_R = PNGPixelRect.read(out2F_f.toURI().toURL().openStream(), image1.getPixelformat(),
false , destMinStrideInBytes, !destIsGLOriented);
160 System.err.println(
"PNGPixelRect - Flip (Read Back): "+image2F_R);
161 Assert.assertEquals(image1.getPixels(), image2F_R.getPixels());
168 final PixelFormat revFmt = PixelFormatUtil.getReversed(image1.getPixelformat());
170 final PNGPixelRect image2R =
new PNGPixelRect(revFmt, image1.getSize(),
171 image1.getStride(), image1.isGLOriented(), image1.getPixels(),
172 image1.getDpi()[0], image1.getDpi()[1]);
173 System.err.println(
"PNGPixelRect - Reversed : "+image2R);
174 final OutputStream outs =
new BufferedOutputStream(IOUtil.getFileOutputStream(out2R_f,
true ));
175 image2R.write(outs,
true );
178 final PNGPixelRect image2R_R = PNGPixelRect.read(out2R_f.toURI().toURL().openStream(), revFmt,
false , destMinStrideInBytes, destIsGLOriented);
179 System.err.println(
"PNGPixelRect - Reversed (Read Back): "+image2R_R);
180 Assert.assertEquals(image1.getPixels(), image2R_R.getPixels());
186 final PNGPixelRect image2RF =
new PNGPixelRect(revFmt, image1.getSize(),
187 image1.getStride(), !image1.isGLOriented(), image1.getPixels(),
188 image1.getDpi()[0], image1.getDpi()[1]);
189 System.err.println(
"PNGPixelRect - Reversed+Flipped : "+image2RF);
190 final OutputStream outs =
new BufferedOutputStream(IOUtil.getFileOutputStream(out2RF_f,
true ));
191 image2RF.write(outs,
true );
194 final PNGPixelRect image2RF_R = PNGPixelRect.read(out2RF_f.toURI().toURL().openStream(), revFmt,
false , destMinStrideInBytes, !destIsGLOriented);
195 System.err.println(
"PNGPixelRect - Reversed+FLipped (Read Back): "+image2RF_R);
196 Assert.assertEquals(image1.getPixels(), image2RF_R.getPixels());
201 private void testPNG02Impl(
final String pathname,
final String basename,
202 final PixelFormat destFmt,
final int destMinStrideInBytes,
final boolean destIsGLOriented)
203 throws InterruptedException, IOException, MalformedURLException
205 System.err.println(
"Test02: "+pathname+basename+
".png, destFmt "+destFmt+
", destMinStrideInBytes "+destMinStrideInBytes+
", destIsGLOriented "+destIsGLOriented);
207 final File out1_f=
new File(getSimpleTestName(
".")+
"-"+basename+
"-orig.png");
208 final URLConnection urlConn = IOUtil.getResource(pathname+basename+
".png", this.getClass().getClassLoader(), this.getClass());
210 final PNGPixelRect image1 = PNGPixelRect.read(urlConn.getInputStream(), destFmt,
false , destMinStrideInBytes, destIsGLOriented);
211 System.err.println(
"PNGPixelRect - Orig: "+image1);
213 final OutputStream outs =
new BufferedOutputStream(IOUtil.getFileOutputStream(out1_f,
true ));
214 image1.write(outs,
true );
216 final PNGPixelRect image1_R = PNGPixelRect.read(out1_f.toURI().toURL().openStream(), image1.getPixelformat(),
false , destMinStrideInBytes, destIsGLOriented);
217 System.err.println(
"PNGPixelRect - Orig (Read Back): "+image1_R);
218 Assert.assertEquals(image1.getPixels(), image1_R.getPixels());
223 public static void main(
final String args[]) {
static final String[] allBasenames
void testPNGRead11_RGBA8888_to_LUMINA()
void testPNGRead04_RGB888_to_RGBA8888_stride999()
void testPNGRead15_RGBA8888_to_ARGB8888()
void testPNGRead13_RGBA8888_to_BGR888()
void testPNGRead03_RGB888_to_RGBA8888_stride1000()
void testPNGRead02_RGB888_to_RGBA8888()
void testPNGRead12_RGBA8888_to_RGB888()
static void main(final String args[])
void testPNGRead16_RGBA8888_to_ABGR8888()
void testPNGRead14_RGBA8888_to_BGRA8888()