Beispiel #1
0
        private void LoadTextureIcon(int index, STGenericTexture texture)
        {
            Bitmap temp = texture.GetBitmap();

            if (temp == null)
            {
                return;
            }

            temp = texture.GetComponentBitmap(temp, true);
            temp = BitmapExtension.CreateImageThumbnail(temp, 80, 80);

            if (listViewCustom1.InvokeRequired)
            {
                listViewCustom1.Invoke((MethodInvoker) delegate {
                    var item        = listViewCustom1.Items[index];
                    item.ImageIndex = imgListBig.Images.Count;
                    item.SubItems.Add(texture.Format.ToString());
                    item.SubItems.Add(texture.Width.ToString());
                    item.SubItems.Add(texture.Height.ToString());
                    item.SubItems.Add(texture.DataSize);

                    // Running on the UI thread
                    imgListBig.Images.Add(temp);
                    imgListSmall.Images.Add(temp);

                    var dummy  = imgListBig.Handle;
                    var dummy2 = imgListSmall.Handle;
                });
            }

            temp.Dispose();
        }
        private void ReloadTexture(STGenericTexture tex, ListViewItem listItem)
        {
            Thread Thread = new Thread((ThreadStart)(() =>
            {
                Bitmap temp = tex.GetBitmap();
                if (temp == null)
                {
                    return;
                }

                temp = BitmapExtension.Resize(temp, ImageList.ImageSize);

                if (listViewCustom1.InvokeRequired)
                {
                    listViewCustom1.Invoke((MethodInvoker) delegate {
                        ImageList.Images[listItem.ImageIndex] = temp;
                        // Running on the UI thread
                        var dummy = ImageList.Handle;
                    });
                }
                else
                {
                    ListViewItem item = new ListViewItem(tex.Text, ImageList.Images.Count);
                    item.Tag = tex;

                    listViewCustom1.Items.Add(item);
                    ImageList.Images.Add(temp);
                    var dummy = ImageList.Handle;
                }

                temp.Dispose();
            }));

            Thread.Start();
        }
Beispiel #3
0
        public TextureView(string directory, STGenericTexture texture)
        {
            Name         = texture.Name;
            RedChannel   = texture.RedChannel;
            GreenChannel = texture.GreenChannel;
            BlueChannel  = texture.BlueChannel;
            AlphaChannel = texture.AlphaChannel;

            if (TextureCache.CacheTexturesToDisk)
            {
                if (!TextureCache.HasTextueCached(directory, texture.Name))
                {
                    TextureCache.SaveTextureToDisk(directory, texture);
                }
                RenderableTex = TextureCache.LoadTextureFromDisk(directory, texture.Name);
            }
            else
            {
                if (!IsPow2(texture.Width) || !IsPow2(texture.Height))
                {
                    RenderableTex = TextureCache.LoadTextureDecompressed(texture.GetBitmap(), texture.IsSRGB);
                }
                else
                {
                    texture.LoadRenderableTexture();
                    RenderableTex = (GLTexture)texture.RenderableTex;
                }
            }
        }
Beispiel #4
0
        static HSFTexture CreateTexture(STGenericTexture texture)
        {
            var format = Decode_Gamecube.TextureFormats.CMPR;
            var info   = new TextureInfo();

            info.Bpp            = 4;
            info.Width          = (ushort)texture.Width;
            info.Height         = (ushort)texture.Height;
            info.PaletteEntries = 0;
            info.TextureTint    = 0;
            info.PaletteIndex   = -1;
            info.Format         = (byte)MPLibrary.GCN.HSFTexture.GetFormatId(format);
            info.MaxLOD         = 0;

            var data = Decode_Gamecube.EncodeFromBitmap(texture.GetBitmap(),
                                                        Decode_Gamecube.TextureFormats.CMPR);

            return(new HSFTexture(texture.Name, info, data.Item1));
        }
        private bool DecodeProcessFinished = false; //Used to determine when the decode process is done

        private void UpdatePictureBox(int ChannelIndex = 0)
        {
            DecodeProcessFinished = false;

            PushImage(Properties.Resources.LoadingImage);

            var image = ActiveTexture.GetBitmap(CurArrayDisplayLevel, CurMipDisplayLevel);

            if (image != null)
            {
                if (ChannelIndex == 1)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.One);
                }
                else if (ChannelIndex == 2)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Green, STChannelType.Green, STChannelType.Green, STChannelType.One);
                }
                else if (ChannelIndex == 3)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Blue, STChannelType.Blue, STChannelType.Blue, STChannelType.One);
                }
                else if (ChannelIndex == 4)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.One);
                }
                else
                {
                    if (!toggleAlphaChk.Checked)
                    {
                        BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Green, STChannelType.Blue, STChannelType.One);
                    }
                }

                DecodeProcessFinished = true;

                // BitmapExtension.SetChannels(image, HasRedChannel, HasBlueChannel, HasGreenChannel, HasAlphaChannel);
                PushImage(image);
            }
        }
        public void LoadFrame(STGenericTexture texture, int Frame, int FrameCount, Action selectListItems)
        {
            SelectListItems = selectListItems;

            if (frameCounterLbl.InvokeRequired)
            {
                frameCounterLbl.Invoke((MethodInvoker) delegate {
                    frameCounterLbl.Text = $"Frame: {Frame}/{FrameCount}";
                });
            }
            else
            {
                frameCounterLbl.Text = $"Frame: {Frame}/{FrameCount}";
            }

            Bitmap image = texture.GetBitmap();

            if (pictureBoxCustom1.InvokeRequired)
            {
                pictureBoxCustom1.Invoke((MethodInvoker) delegate {
                    pictureBoxCustom1.Image = image;
                });
            }
            else
            {
                pictureBoxCustom1.Image = image;
            }

            if (textureNameLbl.InvokeRequired)
            {
                textureNameLbl.Invoke((MethodInvoker) delegate {
                    textureNameLbl.Text = $"Name: {texture.Text}";
                });
            }
            else
            {
                textureNameLbl.Text = $"Name: {texture.Text}";
            }
        }
        private void DisplayTexture(STGenericTexture texData)
        {
            pictureBoxCustom1.Image = null;

            Thread = new Thread((ThreadStart)(() =>
            {
                pictureBoxCustom1.Image = Toolbox.Library.Imaging.GetLoadingImage();
                var image = texData.GetBitmap();

                if (pictureBoxCustom1.InvokeRequired)
                {
                    pictureBoxCustom1.Invoke((MethodInvoker) delegate {
                        pictureBoxCustom1.Image = image;
                        pictureBoxCustom1.Refresh();
                    });
                }
                else
                {
                    pictureBoxCustom1.Image = image;
                }
            }));
            Thread.Start();
        }
        private void UpdateImage()
        {
            if (activeTexture == null)
            {
                return;
            }

            Thread = new Thread((ThreadStart)(() =>
            {
                pictureBoxCustom1.Image = Properties.Resources.LoadingImage;
                var image = activeTexture.GetBitmap(0, 0);

                /*  var mipmaps = STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(activeImage),
                 *                        activeImage.Width, activeImage.Height, Format, 0.5f);
                 *
                 * newImage = BitmapExtension.SwapBlueRedChannels(STGenericTexture.DecodeBlockGetBitmap(mipmaps, (uint)image.Width, (uint)image.Height, Format, new byte[0]));
                 * (*/
                pictureBoxCustom1.Image = newImage;
            }));
            Thread.Start();


            pictureBoxCustom1.Image = newImage;
        }
Beispiel #9
0
        private void UpdatePictureBox(int ChannelIndex = 0)
        {
            if (ActiveTexture == null)
            {
                return;
            }

            DecodeProcessFinished = false;

            PushImage(Properties.Resources.LoadingImage);

            var image = ActiveTexture.GetBitmap(CurArrayDisplayLevel, CurMipDisplayLevel);

            //Keep base image for channel viewer updating/editing
            if (image != null)
            {
                BaseImage = new Bitmap(image);
            }
            else
            {
                BaseImage = null;
            }

            if (propertiesEditor.InvokeRequired)
            {
                propertiesEditor.Invoke(new MethodInvoker(
                                            delegate()
                {
                    LoadChannelEditor(image);
                }));
            }
            else
            {
                LoadChannelEditor(image);
            }

            if (image != null)
            {
                if (ActiveTexture.Parameters.FlipY)
                {
                    image.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }

                if (ChannelIndex == 1)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.One);
                }
                else if (ChannelIndex == 2)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Green, STChannelType.Green, STChannelType.Green, STChannelType.One);
                }
                else if (ChannelIndex == 3)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Blue, STChannelType.Blue, STChannelType.Blue, STChannelType.One);
                }
                else if (ChannelIndex == 4)
                {
                    BitmapExtension.SetChannel(image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.One);
                }
                else
                {
                    STChannelType AlphaDisplay = ActiveTexture.AlphaChannel;
                    if (!Runtime.ImageEditor.DisplayAlpha || HasZeroAlpha())
                    {
                        AlphaDisplay = STChannelType.One;
                    }

                    //For RGBA types try to only load the alpha toggle to load quicker
                    //Loading components would not be necessary as it is default to RGBA
                    if (UseRGBA())
                    {
                        if (!Runtime.ImageEditor.DisplayAlpha)
                        {
                            BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Green, STChannelType.Blue, AlphaDisplay);
                        }
                    }
                    else
                    {
                        //Check components for the channels
                        if (Runtime.ImageEditor.UseComponetSelector)
                        {
                            BitmapExtension.SetChannel(image, ActiveTexture.RedChannel, ActiveTexture.GreenChannel, ActiveTexture.BlueChannel, AlphaDisplay);
                        }
                        else
                        {
                            if (!Runtime.ImageEditor.DisplayAlpha)
                            {
                                BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Green, STChannelType.Blue, AlphaDisplay);
                            }
                        }
                    }
                }

                DecodeProcessFinished = true;

                if (Runtime.ImageEditor.PreviewGammaFix && image != null)
                {
                    image = BitmapExtension.AdjustGamma(image, 1.0f / 2.2f);
                }

                // BitmapExtension.SetChannels(image, HasRedChannel, HasBlueChannel, HasGreenChannel, HasAlphaChannel);
                PushImage(image);


                if (image != null)
                {
                    UpdateTreeIcon(ActiveTexture, image);
                }
            }
        }
        private void UpdateArrayLevel()
        {
            if (ActiveTexture == null)
            {
                return;
            }

            TotalArrayCount = (int)(ActiveTexture.ArrayCount / 6) - 1;

            arrayLevelCounterLabel.Text = $"Array Level: {CurArrayDisplayLevel} / {TotalArrayCount}";

            for (int i = 0; i < 6; i++)
            {
                var CubeFaceBitmap = ActiveTexture.GetBitmap(i + (CurArrayDisplayLevel * 6));
                if (!DisplayAlpha)
                {
                    BitmapExtension.SetChannel(CubeFaceBitmap, ActiveTexture.RedChannel, ActiveTexture.GreenChannel, ActiveTexture.BlueChannel, STChannelType.One);
                }

                if (i == FRONT_FACE)
                {
                    pbFrontFace.Image = CubeFaceBitmap;
                }
                else if (i == BACK_FACE)
                {
                    pbBackFace.Image = CubeFaceBitmap;
                }
                else if (i == BOTTOM_FACE)
                {
                    pbBottomFace.Image = CubeFaceBitmap;
                }
                else if (i == TOP_FACE)
                {
                    pbTopFace.Image = CubeFaceBitmap;
                }
                else if (i == LEFT_FACE)
                {
                    pbLeftFace.Image = CubeFaceBitmap;
                }
                else if (i == RIGHT_FACE)
                {
                    pbRightFace.Image = CubeFaceBitmap;
                }
            }

            if (CurArrayDisplayLevel != TotalArrayCount)
            {
                btnRightArray.Enabled = true;
            }
            else
            {
                btnRightArray.Enabled = false;
            }

            if (CurArrayDisplayLevel != 0)
            {
                btnLeftArray.Enabled = true;
            }
            else
            {
                btnLeftArray.Enabled = false;
            }
        }