コード例 #1
0
        /* read or write headers */
        /* you may set rgbe_header_info to null if you want to */
        //int RGBE_WriteHeader(FILE* fp, int width, int height, rgbe_header_info* info);
        public static int RGBE_WriteHeader(StreamWriter fp, int width, int height, ref rgbe_header_info info)
        {
            string programtype = "RGBE";

            if ((info.valid & RGBE_VALID_PROGRAMTYPE) != 0)
            {
                programtype = info.programtype;
            }

            fp.Write(string.Format("#?{0}{1}", programtype, Environment.NewLine));
            /* The #? is to identify file type, the programtype is optional. */

            if ((info.valid & RGBE_VALID_GAMMA) != 0)
            {
                fp.Write(string.Format("GAMMA={0}{1}", info.gamma, Environment.NewLine));
            }

            if ((info.valid & RGBE_VALID_EXPOSURE) != 0)
            {
                fp.Write(string.Format("EXPOSURE={0}{1}", info.exposure, Environment.NewLine));
            }

            fp.Write(string.Format("FORMAT=32-bit_rle_rgbe{0}{0}", Environment.NewLine));
            fp.Write(string.Format("-Y {0} +X {1}{2}", height, width, Environment.NewLine));

            return(RGBE_RETURN_SUCCESS);
        }
コード例 #2
0
        /* read or write headers */
        /* you may set rgbe_header_info to null if you want to */
        //int RGBE_WriteHeader(FILE* fp, int width, int height, rgbe_header_info* info);
        public static int RGBE_ReadHeader(StreamReader fp, out int width, out int height, ref rgbe_header_info info)
        {
            width      = 0; height = 0;
            info.valid = 0; info.programtype = string.Empty;
            info.gamma = 1.0f; info.exposure = 1.0f;

            string line = fp.ReadLine();

            if (!line.StartsWith("#?"))
            {
                return(rgbe_error(rgbe_error_codes.rgbe_format_error, "bad initial token"));
            }
            else
            {
                info.valid      |= RGBE_VALID_PROGRAMTYPE;
                info.programtype = line.Substring(2);
            }
            while (true)
            {
                line = fp.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    return(rgbe_error(rgbe_error_codes.rgbe_format_error, "no FORMAT specifier found"));
                }
                else if (line == "FORMAT=32-bit_rle_rgbe\n")
                {
                    break;
                }
                else if (line.StartsWith("GAMMA="))
                {
                    string[] parts = line.Split('=');
                    float    gamma = float.Parse(parts[1]);
                    info.gamma = gamma; info.valid |= RGBE_VALID_GAMMA;
                }
                else if (line.StartsWith("EXPOSURE="))
                {
                    string[] parts    = line.Split('=');
                    float    exposure = float.Parse(parts[1]);
                    info.exposure = exposure; info.valid |= RGBE_VALID_EXPOSURE;
                }
            }
            line = fp.ReadLine();
            if (string.IsNullOrEmpty(line))
            {
                return(rgbe_error(rgbe_error_codes.rgbe_format_error, "missing blank line after FORMAT specifier"));
            }

            {
                line = fp.ReadLine();
                string[] parts = line.Split(' ');
                if (parts.Length != 4)
                {
                    return(rgbe_error(rgbe_error_codes.rgbe_format_error, "missing image size specifier"));
                }
                height = int.Parse(parts[1]);
                width  = int.Parse(parts[3]);
            }

            return(RGBE_RETURN_SUCCESS);
        }