Class RGBE


  • final class RGBE
    extends java.lang.Object
    This file contains code to read and write four byte rgbe file format developed by Greg Ward. It handles the conversions between rgbe and pixels consisting of floats. The data is assumed to be an array of floats. By default there are three floats per pixel in the order red, green, blue. (RGBE_DATA_??? values control this.) Only the mimimal header reading and writing is implemented. Each routine does error checking and will return a status value as defined below. This code is intended as a skeleton so feel free to modify it to suit your needs.

    Ported to Java and restructured by Kenneth Russell. posted to www.graphics.cornell.edu/~bjw/ written by Bruce Walter (bjw@graphics.cornell.edu) 5/26/95 based on code written by Greg Ward

    See Also:
    Source
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  RGBE.FracExp  
      static class  RGBE.Header  
    • Constructor Summary

      Constructors 
      Constructor Description
      RGBE()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static double copysign​(double x, double y)
      copysign(double x, double y)
      copysign(x,y) returns a value with the magnitude of x and with the sign bit of y.
      private static boolean finite​(double x)  
      static void float2rgbe​(byte[] rgbe, float red, float green, float blue)
      Standard conversion from float pixels to rgbe pixels.
      private static RGBE.FracExp frexp​(double x)  
      private static double fromhilo​(int hi, int lo)  
      private static int hi​(double x)  
      static double ldexp​(double value, int exp)  
      private static int lo​(double x)  
      static void main​(java.lang.String[] args)  
      static RGBE.Header readHeader​(java.io.DataInput in)  
      static void readPixels​(java.io.DataInput in, float[] data, int numpixels)
      Simple read routine.
      static void readPixelsRaw​(java.io.DataInput in, byte[] data, int offset, int numpixels)  
      static void readPixelsRawRLE​(java.io.DataInput in, byte[] data, int offset, int scanline_width, int num_scanlines)  
      static void rgbe2float​(float[] rgb, byte[] rgbe, int startRGBEOffset)
      Standard conversion from rgbe to float pixels.
      private static double scalbn​(double x, int n)
      scalbn (double x, int n)
      scalbn(x,n) returns x* 2**n computed by exponent manipulation rather than by actually performing an exponentiation or a multiplication.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RGBE

        RGBE()
    • Method Detail

      • readHeader

        public static RGBE.Header readHeader​(java.io.DataInput in)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • readPixels

        public static void readPixels​(java.io.DataInput in,
                                      float[] data,
                                      int numpixels)
                               throws java.io.IOException
        Simple read routine. Will not correctly handle run length encoding.
        Throws:
        java.io.IOException
      • readPixelsRaw

        public static void readPixelsRaw​(java.io.DataInput in,
                                         byte[] data,
                                         int offset,
                                         int numpixels)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readPixelsRawRLE

        public static void readPixelsRawRLE​(java.io.DataInput in,
                                            byte[] data,
                                            int offset,
                                            int scanline_width,
                                            int num_scanlines)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • float2rgbe

        public static void float2rgbe​(byte[] rgbe,
                                      float red,
                                      float green,
                                      float blue)
        Standard conversion from float pixels to rgbe pixels.
      • rgbe2float

        public static void rgbe2float​(float[] rgb,
                                      byte[] rgbe,
                                      int startRGBEOffset)
        Standard conversion from rgbe to float pixels. Note: Ward uses ldexp(col+0.5,exp-(128+8)). However we wanted pixels in the range [0,1] to map back into the range [0,1].
      • ldexp

        public static double ldexp​(double value,
                                   int exp)
      • hi

        private static int hi​(double x)
      • lo

        private static int lo​(double x)
      • fromhilo

        private static double fromhilo​(int hi,
                                       int lo)
      • finite

        private static boolean finite​(double x)
      • copysign

        private static double copysign​(double x,
                                       double y)
        copysign(double x, double y)
        copysign(x,y) returns a value with the magnitude of x and with the sign bit of y.
      • scalbn

        private static double scalbn​(double x,
                                     int n)
        scalbn (double x, int n)
        scalbn(x,n) returns x* 2**n computed by exponent manipulation rather than by actually performing an exponentiation or a multiplication.
      • main

        public static void main​(java.lang.String[] args)