JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug362DDSImageCreateFromData.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.util.texture;
2
3import java.io.File;
4import java.io.IOException;
5import java.net.URISyntaxException;
6import java.net.URL;
7import java.net.URLConnection;
8import java.nio.ByteBuffer;
9
10import org.junit.After;
11import org.junit.Assert;
12import org.junit.Before;
13import org.junit.Test;
14
15import com.jogamp.common.util.IOUtil;
16import com.jogamp.opengl.util.texture.spi.DDSImage;
17import com.jogamp.opengl.util.texture.spi.DDSImage.ImageInfo;
18
19/**
20 * This test uses the DDSImage class to read a dds image from file, extract the data,
21 * and use the class to create a new DDSImage from the extracted data
22 * <br></br>
23 * Bug Reference: https://jogamp.org/bugzilla/show_bug.cgi?id=362
24 * <br></br>
25 * The bug pertains to incorrect size calculation for checking validity of data. Compressed DXT1 has min of 8 bytes, DXT5 has min of 16 bytes.
26 * It exists in {@link DDSImage#createFromData(int, int, int, ByteBuffer[])}
27 * where an {@link IllegalArgumentException} is thrown for Mipmap level size mismatch.
28 * <br></br>
29 * <ul>The following cases are tested:
30 * <li>Uncompressed 64x32 RGB DDS Image with all mipmap levels (64x32 --> 1x1)</li>
31 * <li>DXT1 compressed 64x32 RGB DDS Image with all mipmap levels (64x32 --> 1x1)</li>
32 * <li>DXT5 compressed 64x32 RGB DDS Image with all mipmap levels (64x32 --> 1x1)</li>
33 * </ul>
34 *
35 * @author Michael Esemplare
36 *
37 */
39
40 File testDDSImage01Uncompressed;
41 File testDDSImage02DXT1;
42 File testDDSImage03DXT5;
43
44 @Before
45 public void setup() throws Throwable {
46 testDDSImage01Uncompressed = initFile("test-64x32_uncompressed.dds");
47 testDDSImage02DXT1 = initFile("test-64x32_DXT1.dds");
48 testDDSImage03DXT5 = initFile("test-64x32_DXT5.dds");
49 }
50
51 @After
52 public void teardown() {
53 testDDSImage01Uncompressed = null;
54 testDDSImage02DXT1 = null;
55 testDDSImage03DXT5 = null;
56 }
57
58 private File initFile(final String filename) throws URISyntaxException {
59 final URLConnection connection = IOUtil.getResource(filename, getClass().getClassLoader(), getClass());
60 Assert.assertNotNull(connection);
61 final URL url = connection.getURL();
62 final File file = new File(url.toURI());
63 Assert.assertTrue(file.exists());
64 return file;
65 }
66
67 private void testImpl(final File file) throws IOException {
68 final DDSImage ddsImage = DDSImage.read(file);
69 Assert.assertNotNull(ddsImage);
70 final int numMipMaps = ddsImage.getNumMipMaps();
71 final ByteBuffer[] mipMapArray = new ByteBuffer[numMipMaps];
72 for (int i=0;i<numMipMaps;i++){
73 final ImageInfo info = ddsImage.getMipMap(i);
74 mipMapArray[i] = info.getData();
75 }
76 final DDSImage newImage = DDSImage.createFromData(ddsImage.getPixelFormat(), ddsImage.getWidth(), ddsImage.getHeight(), mipMapArray);
77 Assert.assertNotNull(newImage);
78 }
79
80 @Test
81 public void test00_DDSImage_CreateFromData_Uncompressed_RGB () throws IOException {
82 testImpl(testDDSImage01Uncompressed);
83 }
84
85 @Test
86 public void test01_DDSImage_CreateFromData_DXT1_RGB () throws IOException {
87 testImpl(testDDSImage02DXT1);
88 }
89
90 @Test
91 public void test02_DDSImage_CreateFromData_DXT5_RGB () throws IOException {
92 testImpl(testDDSImage03DXT5);
93 }
94
95 public static void main(final String[] args) {
96 org.junit.runner.JUnitCore.main(TestBug362DDSImageCreateFromData.class.getName());
97 }
98}
This test uses the DDSImage class to read a dds image from file, extract the data,...