Пример #1
0
        void ImportTexture()
        {
            string path;

            if ((path = FileDialog.Open()) != null)
            {
                var src = TextureImport.OpenFile(path);
                if (src.Type == TexLoadType.ErrorLoad ||
                    src.Type == TexLoadType.ErrorNonSquare ||
                    src.Type == TexLoadType.ErrorNonPowerOfTwo)
                {
                    main.ErrorDialog(TextureImport.LoadErrorString(src.Type, path));
                }
                else if (src.Type == TexLoadType.DDS)
                {
                    src.Texture.Dispose();
                    selectedNode.Children = null;
                    selectedNode.Data     = File.ReadAllBytes(path);
                }
                else
                {
                    teximportprev = src.Texture;
                    teximportpath = path;
                    teximportid   = ImGuiHelper.RegisterTexture(teximportprev);
                    popups.OpenPopup("Texture Import");
                }
            }
        }
 unsafe void RenderImage(string output)
 {
     try
     {
         TextureImport.LoadLibraries();
     }
     catch (Exception ex)
     {
         FLLog.Error("Render", "Could not load FreeImage");
         FLLog.Info("Exception Info", ex.Message + "\n" + ex.StackTrace);
         return;
     }
     imageViewport.Background = renderBackground ? background : Color4.TransparentBlack;
     imageViewport.Begin(imageWidth, imageHeight);
     DrawGL(imageWidth, imageHeight);
     imageViewport.End(false);
     byte[] data = new byte[imageWidth * imageHeight * 4];
     imageViewport.RenderTarget.GetData(data);
     using (var sfc = new TeximpNet.Surface(imageWidth, imageHeight, true))
     {
         byte *sfcData = (byte *)sfc.DataPtr;
         for (int i = 0; i < data.Length; i++)
         {
             sfcData[i] = data[i];
         }
         sfc.SaveToFile(TeximpNet.ImageFormat.PNG, output);
     }
 }
Пример #3
0
        public void Open(string filename, string icoName = null, bool tmp = false)
        {
            iconName    = icoName ?? Path.GetFileNameWithoutExtension(filename);
            texFilename = filename;
            error       = false;
            if (teximportprev != null)
            {
                ImGuiHelper.DeregisterTexture(teximportprev);
                teximportprev.Dispose();
                teximportprev = null;
            }

            var src = TextureImport.OpenFile(filename);

            loadType      = src.Type;
            teximportprev = src.Texture;
            if (loadType == TexLoadType.ErrorLoad ||
                loadType == TexLoadType.ErrorNonSquare ||
                loadType == TexLoadType.ErrorNonPowerOfTwo)
            {
                win.ErrorDialog(TextureImport.LoadErrorString(loadType, filename));
                return;
            }
            teximportid = ImGuiHelper.RegisterTexture(teximportprev);
            doOpen      = true;
            this.tmp    = tmp;
        }
Пример #4
0
        void TexImportDialog(PopupData data)
        {
            if (teximportprev == null)
            { //processing
                ImGui.Text("Processing...");
                if (!texImportWaiting)
                {
                    if (texImportChildren != null)
                    {
                        selectedNode.Data = null;
                        foreach (var c in texImportChildren)
                        {
                            c.Parent = selectedNode;
                        }
                        selectedNode.Children = texImportChildren;
                    }
                    else
                    {
                        selectedNode.Children = null;
                        selectedNode.Data     = texImportData;
                    }
                    texImportData     = null;
                    texImportChildren = null;
                    ImGui.CloseCurrentPopup();
                }
            }
            else
            {
                ImGui.Image((IntPtr)teximportid, new Vector2(64, 64),
                            new Vector2(0, 1), new Vector2(1, 0), Vector4.One, Vector4.Zero);
                ImGui.Text(string.Format("Dimensions: {0}x{1}", teximportprev.Width, teximportprev.Height));
                ImGui.Combo("Format", ref compressOption, texOptions);
                ImGui.Combo("Mipmaps", ref mipmapOption, mipmapOptions);
                ImGui.Checkbox("High Quality (slow)", ref compressSlow);
                if (ImGui.Button("Import"))
                {
                    ImGuiHelper.DeregisterTexture(teximportprev);
                    teximportprev.Dispose();
                    teximportprev    = null;
                    texImportWaiting = true;
                    new System.Threading.Thread(() =>
                    {
                        var format = DDSFormat.Uncompressed;
                        switch (compressOption)
                        {
                        case 1:
                            format = DDSFormat.DXT1;
                            break;

                        case 2:
                            format = DDSFormat.DXT1a;
                            break;

                        case 3:
                            format = DDSFormat.DXT3;
                            break;

                        case 4:
                            format = DDSFormat.DXT5;
                            break;
                        }
                        var mipm = MipmapMethod.None;
                        switch (mipmapOption)
                        {
                        case 1:
                            mipm = MipmapMethod.Box;
                            break;

                        case 2:
                            mipm = MipmapMethod.Bicubic;
                            break;

                        case 3:
                            mipm = MipmapMethod.Bilinear;
                            break;

                        case 4:
                            mipm = MipmapMethod.Bspline;
                            break;

                        case 5:
                            mipm = MipmapMethod.CatmullRom;
                            break;

                        case 6:
                            mipm = MipmapMethod.Lanczos3;
                            break;
                        }
                        if (mipm == MipmapMethod.None && format == DDSFormat.Uncompressed)
                        {
                            texImportData = TextureImport.TGANoMipmap(teximportpath);
                        }
                        else if (format == DDSFormat.Uncompressed)
                        {
                            texImportChildren = TextureImport.TGAMipmaps(teximportpath, mipm);
                        }
                        else
                        {
                            texImportData = TextureImport.CreateDDS(teximportpath, format, mipm, compressSlow);
                        }
                        texImportWaiting = false;
                    }).Start();
                }
                ImGui.SameLine();
                if (ImGui.Button("Cancel"))
                {
                    ImGuiHelper.DeregisterTexture(teximportprev);
                    teximportprev.Dispose();
                    teximportprev = null;
                    ImGui.CloseCurrentPopup();
                }
            }
        }