diff options
author | Kenneth Russel <[email protected]> | 2006-02-01 23:11:22 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-02-01 23:11:22 +0000 |
commit | e71a8145d335a28a3bef3f20a85d2a430189f943 (patch) | |
tree | 9090b4df4e51098827720e3327266d7c91117ba4 /src/classes/com/sun/opengl/util/Screenshot.java | |
parent | cf73e0b56b38f87f616d7ef9741f1d05cf68d5bd (diff) |
Refactored fast TGA writer into its own class to be able to share the
code between the Screenshot class and the anticipated tile rendering
library.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@577 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/util/Screenshot.java')
-rwxr-xr-x | src/classes/com/sun/opengl/util/Screenshot.java | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/src/classes/com/sun/opengl/util/Screenshot.java b/src/classes/com/sun/opengl/util/Screenshot.java index d91e7f8f5..e552da53e 100755 --- a/src/classes/com/sun/opengl/util/Screenshot.java +++ b/src/classes/com/sun/opengl/util/Screenshot.java @@ -48,8 +48,6 @@ import javax.media.opengl.glu.*; /** Utilities for taking screenshots of OpenGL applications. */ public class Screenshot { - private static final int TARGA_HEADER_SIZE = 18; - private Screenshot() {} /** @@ -98,32 +96,13 @@ public class Screenshot { int width, int height, boolean alpha) throws GLException, IOException { - RandomAccessFile out = new RandomAccessFile(file, "rw"); - FileChannel ch = out.getChannel(); - int pixelSize = (alpha ? 32 : 24); - int numChannels = (alpha ? 4 : 3); - int readbackType = (alpha ? GL.GL_ABGR_EXT : GL.GL_BGR); if (alpha) { checkExtABGR(); } - int fileLength = TARGA_HEADER_SIZE + width * height * numChannels; - out.setLength(fileLength); - MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, fileLength); - - // write the TARGA header - image.put(0, (byte) 0).put(1, (byte) 0); - image.put(2, (byte) 2); // uncompressed type - image.put(12, (byte) (width & 0xFF)); // width - image.put(13, (byte) (width >> 8)); // width - image.put(14, (byte) (height & 0xFF)); // height - image.put(15, (byte) (height >> 8)); // height - image.put(16, (byte) pixelSize); // pixel size - - // go to image data position - image.position(TARGA_HEADER_SIZE); - // jogl needs a sliced buffer - ByteBuffer bgr = image.slice(); + TGAWriter writer = new TGAWriter(); + writer.open(file, width, height, alpha); + ByteBuffer bgr = writer.getImageData(); GL gl = GLU.getCurrentGL(); @@ -131,6 +110,8 @@ public class Screenshot { PixelStorageModes psm = new PixelStorageModes(); psm.save(gl); + int readbackType = (alpha ? GL.GL_ABGR_EXT : GL.GL_BGR); + // read the BGR values into the image buffer gl.glReadPixels(0, 0, width, height, readbackType, GL.GL_UNSIGNED_BYTE, bgr); @@ -138,8 +119,8 @@ public class Screenshot { // Restore pixel storage modes psm.restore(gl); - // close the file channel - ch.close(); + // close the file + writer.close(); } /** |