From 9d209d3b6ae12604e666d7b655bd1f19e70ee48b Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Fri, 27 May 2005 19:45:51 +0000 Subject: Added Java/JOGL port of NVidia HDR demo. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@80 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4 --- src/demos/hdr/HDRTexture.java | 494 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 494 insertions(+) create mode 100755 src/demos/hdr/HDRTexture.java (limited to 'src/demos/hdr/HDRTexture.java') diff --git a/src/demos/hdr/HDRTexture.java b/src/demos/hdr/HDRTexture.java new file mode 100755 index 0000000..fcaac11 --- /dev/null +++ b/src/demos/hdr/HDRTexture.java @@ -0,0 +1,494 @@ +package demos.hdr; + +import java.io.*; + +import net.java.games.jogl.*; + +public class HDRTexture { + private RGBE.Header header; + private byte[] m_data; + private float[] m_floatdata; + private int m_width, m_height; + private float m_max_r, m_max_g, m_max_b; + private float m_min_r, m_min_g, m_min_b; + private float m_max; + private int m_target; + + public HDRTexture(String filename) throws IOException { + this(new FileInputStream(filename)); + } + + public HDRTexture(InputStream in) throws IOException { + DataInputStream datain = new DataInputStream(new BufferedInputStream(in)); + header = RGBE.readHeader(datain); + m_width = header.getWidth(); + m_height = header.getHeight(); + m_data = new byte[m_width * m_height * 4]; + RGBE.readPixelsRawRLE(datain, m_data, 0, m_width, m_height); + System.err.println("Loaded HDR image " + m_width + " x " + m_height); + } + + public byte[] getData() { return m_data; } + public int getPixelIndex(int x, int y) { + return ((m_width * (m_height - 1 - y)) + x) * 4; + } + public float[] getFloatData() { return m_floatdata; } + public int getPixelFloatIndex(int x, int y) { + return ((m_width * (m_height - 1 - y)) + x) * 3; + } + + public void analyze() { + m_max_r = m_max_g = m_max_b = 0.0f; + m_min_r = m_min_g = m_min_b = 1e10f; + int mine = 255; + int maxe = 0; + + int ptr = 0; + float[] rgb = new float[3]; + for(int i=0; i maxe) maxe = e; + + RGBE.rgbe2float(rgb, m_data, ptr); + float r = rgb[0]; + float g = rgb[1]; + float b = rgb[2]; + if (r > m_max_r) m_max_r = r; + if (g > m_max_g) m_max_g = g; + if (b > m_max_b) m_max_b = b; + if (r < m_min_r) m_min_r = r; + if (g < m_min_g) m_min_g = g; + if (b < m_min_b) m_min_b = b; + ptr += 4; + } + System.err.println("max intensity: " + m_max_r + " " + m_max_g + " " + m_max_b); + System.err.println("min intensity: " + m_min_r + " " + m_min_g + " " + m_min_b); + System.err.println("max e: " + maxe + " = " + RGBE.ldexp(1.0, maxe-128)); + System.err.println("min e: " + mine + " = " + RGBE.ldexp(1.0, mine-128)); + + m_max = m_max_r; + if (m_max_g > m_max) m_max = m_max_g; + if (m_max_b > m_max) m_max = m_max_b; + System.err.println("max: " + m_max); + } + + /** Converts from RGBE to floating-point RGB data. */ + public void convert() { + m_floatdata = new float [m_width*m_height*3]; + + int src = 0; + int dest = 0; + float[] rgb = new float[3]; + for(int i=0; i max) x = max; + return (float) Math.sqrt(x / max); + } + + public static void main(String[] args) { + for (int i = 0; i < args.length; i++) { + try { + HDRTexture tex = new HDRTexture(args[i]); + tex.analyze(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} -- cgit v1.2.3