Exemplo n.º 1
0
            public Vector3Half ToVector3Half()
            {
                Vector3Half ret = new Vector3Half();

                if (exp != 0)
                {
                    float f = (float)Math.Pow(2.0, exp - (int)(128 + 8));
                    ret.x = (Half)(red * f);
                    ret.y = (Half)(green * f);
                    ret.z = (Half)(blue * f);
                }
                return(ret);
            }
Exemplo n.º 2
0
        public override T Import <T>(System.IO.Stream source, string source_name, ResourceManager man)
        {
            Glorg2.Graphics.OpenGL.Texture2D res;
            var    rd = new StreamReader(source, false);
            string line = rd.ReadLine();
            string format = "";
            int    width = -1, height = -1;
            int    exposure = 0;
            Match  m;

            if (line != "#?RADIANCE")
            {
                throw new FormatException("Unrecognized HDR format");
            }
            while (true)
            {
                line = rd.ReadLine();
                int index = line.IndexOf('=');
                if (index > 0)
                {
                    string name  = line.Substring(0, index);
                    string value = line.Substring(index + 1);
                    if (name == "EXPOSURE")
                    {
                        exposure = int.Parse(value);
                    }
                    else if (name == "FORMAT")
                    {
                        format = value;
                    }
                }
                else if ((m = reg.Match(line)).Success)
                {
                    width  = int.Parse(m.Groups["XValue"].Value);
                    height = int.Parse(m.Groups["YValue"].Value);
                    break;
                }
            }
            if (width == -1 || height == -1)
            {
                throw new FormatException("Could not figure out the size of the HDR image");
            }


            Vector3Half[] data = new Vector3Half[width * height];

            if (format == "32-bit_rgbe" || (width < 8 || width > 0x7FFFF))
            {
                ReadRgbe(source, data);
            }
            else if (format == "32-bit_rle_rgbe")
            {
                ReadRgbeRle(source, data, width, height);
            }
            else if (format == "32-bit_rle_xyzw")
            {
                throw new NotSupportedException(format + " not supported.");
            }

            res = new Graphics.OpenGL.Texture2D(width, height, Graphics.OpenGL.InternalFormat.Rgb16, Graphics.OpenGL.PixelDataType.Float, Graphics.OpenGL.PixelType.Rgb, source_name);
            res.AssignBuffer(data);
            return(res as T);
        }