Beispiel #1
0
        static void Main()
        {
            var args = CommandLineArguments.Parse();

            var img  = EXRFile.FromFile(args[0]);
            var part = img.Parts[0];

            //part.OpenParallel(() => { return new EXRReader(new System.IO.BinaryReader(System.IO.File.OpenRead(args[0]))); });
            part.OpenParallel(args[0]);

            var bmp       = new Bitmap(part.DataWindow.Width, part.DataWindow.Height);
            var data      = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            var destBytes = part.GetBytes(ImageDestFormat.BGRA8, GammaEncoding.sRGB, data.Stride);

            Marshal.Copy(destBytes, 0, data.Scan0, destBytes.Length);
            bmp.UnlockBits(data);

            part.Close();

            var frm = new Form();

            frm.BackgroundImage = bmp;
            frm.FormBorderStyle = FormBorderStyle.FixedDialog;
            frm.MaximizeBox     = false;
            frm.ClientSize      = new System.Drawing.Size(bmp.Width, bmp.Height);
            frm.ShowDialog();
        }
        Texture2D GetModelTexture(int id)
        {
            Texture2D tex;
            if (id == 1)
            {
                var mat = currentMeshRenderer.sharedMaterial;
                return mat.GetTexture("_MainTex") as Texture2D;
            }
            else if (currentMeshRenderer.lightmapIndex >= 0)
            {
                if (LightmapSettings.lightmaps.Length > currentMeshRenderer.lightmapIndex)
                {
                    var data = LightmapSettings.lightmaps[currentMeshRenderer.lightmapIndex];
                    var path = AssetDatabase.GetAssetPath(data.lightmapColor);
                    var lightmap = data.lightmapColor;
                    Debug.Log("Load file: " + path);

                    var exrFile = EXRFile.FromFile(path);
                    var part = exrFile.Parts[0];
                    // open part while reading pixel data in parallel
                    part.OpenParallel(path);
                    var floats = part.GetFloats(ChannelConfiguration.RGB, true, GammaEncoding.Linear, true);

                    tex = new Texture2D(lightmap.width, lightmap.height, TextureFormat.RGBAFloat, false);
                    var fulllength = lightmap.width * lightmap.height;
                    Color[] cols = new Color[fulllength];
                    for (int y = 0; y < lightmap.height; y++)
                    {
                        for (int x = 0; x < lightmap.width; x++)
                        {
                            int pid = y * lightmap.width + x;
                            cols[id] = new Color(floats[pid], floats[pid + fulllength], floats[pid + fulllength * 2], floats[pid + fulllength * 3]);
                        }
                    }
                    tex.SetPixels(cols);
                    //tex.LoadImage(bytes);

                    part.Close();
                    Debug.Log("File Loaded");
                    return tex;
                }
            }
            return null;
        }
Beispiel #3
0
        static void Main()
        {
            var args = CommandLineArguments.Parse();

            var img  = EXRFile.FromFile(args[0]);
            var part = img.Parts[0];

            //part.OpenParallel(() => { return new EXRReader(new System.IO.BinaryReader(System.IO.File.OpenRead(args[0]))); });
            part.OpenParallel(args[0]);

            var bmp       = new Bitmap(part.DataWindow.Width, part.DataWindow.Height);
            var data      = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            var destBytes = part.GetBytes(ImageDestFormat.BGRA8, GammaEncoding.sRGB, data.Stride);

            Marshal.Copy(destBytes, 0, data.Scan0, destBytes.Length);
            bmp.UnlockBits(data);

            part.Close();

            var ms = new MemoryStream();

            bmp.Save(ms, ImageFormat.Png);
            var buffer = new byte[ms.Position];

            ms.Position = 0;
            ms.Read(buffer, 0, buffer.Length);
            ms.Dispose();

            var image64 = System.Convert.ToBase64String(buffer);

            var html = $@"
                <html>
                    <header><title>{args[0]}</title></header>
                    <body>
                        <img src=""data: image / png; base64,{image64}""
                    </body>
                </html>
            ";

            var htmlFile = Path.GetTempFileName() + ".html";

            File.WriteAllText(htmlFile, html);

            var openCommand = "";

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                openCommand = "start";
                break;

            case PlatformID.MacOSX:
                openCommand = "open";
                break;

            case PlatformID.Unix:
                openCommand = "xdg-open";
                break;
            }

            Console.WriteLine($"{openCommand} {htmlFile}".Sh());
        }