Exemple #1
0
        private ChannelType ConvertChannel(STChannelType channel)
        {
            switch (channel)
            {
            case STChannelType.Red:
                return(ChannelType.Red);

            case STChannelType.Green:
                return(ChannelType.Green);

            case STChannelType.Blue:
                return(ChannelType.Blue);

            case STChannelType.Alpha:
                return(ChannelType.Alpha);

            case STChannelType.One:
                return(ChannelType.One);

            case STChannelType.Zero:
                return(ChannelType.Zero);

            default:
                throw new Exception("Unsupported format! " + channel);
            }
        }
        public void LoadDDS(string FileName, byte[] FileData = null)
        {
            TexName = STGenericTexture.SetNameFromPath(FileName);

            DDS dds = new DDS();

            if (FileData != null)
            {
                dds.Load(new FileReader(new MemoryStream(FileData)));
            }
            else
            {
                dds.Load(new FileReader(FileName));
            }
            MipCount  = dds.header.mipmapCount;
            TexWidth  = dds.header.width;
            TexHeight = dds.header.height;

            var surfaces = DDS.GetArrayFaces(dds, dds.ArrayCount);

            RedComp   = dds.RedChannel;
            GreenComp = dds.GreenChannel;
            BlueComp  = dds.BlueChannel;
            AlphaComp = dds.AlphaChannel;

            foreach (var surface in surfaces)
            {
                DataBlockOutput.Add(Utils.CombineByteArray(surface.mipmaps.ToArray()));
            }

            Format = dds.Format;
        }
Exemple #3
0
        public static STChannelType[] SetChannelsByFormat(TEX_FORMAT Format)
        {
            STChannelType[] channels = new STChannelType[4];

            switch (Format)
            {
            case TEX_FORMAT.BC5:
                channels[0] = STChannelType.Red;
                channels[1] = STChannelType.Green;
                channels[2] = STChannelType.Zero;
                channels[3] = STChannelType.One;
                break;

            case TEX_FORMAT.BC4:
                channels[0] = STChannelType.Red;
                channels[1] = STChannelType.Red;
                channels[2] = STChannelType.Red;
                channels[3] = STChannelType.Red;
                break;

            default:
                channels[0] = STChannelType.Red;
                channels[1] = STChannelType.Green;
                channels[2] = STChannelType.Blue;
                channels[3] = STChannelType.Alpha;
                break;
            }
            return(channels);
        }
        public void LoadDDS(string FileName, byte[] FileData = null)
        {
            TexName = STGenericTexture.SetNameFromPath(FileName);

            DDS dds = new DDS();

            if (FileData != null)
            {
                dds.Load(new FileReader(new MemoryStream(FileData)));
            }
            else
            {
                dds.Load(new FileReader(FileName));
            }
            MipCount    = dds.header.mipmapCount;
            TexWidth    = dds.header.width;
            TexHeight   = dds.header.height;
            arrayLength = 1;
            if (dds.header.caps2 == (uint)DDS.DDSCAPS2.CUBEMAP_ALLFACES)
            {
                arrayLength = 6;
            }
            DataBlockOutput.Add(dds.bdata);

            RedComp   = dds.RedChannel;
            GreenComp = dds.GreenChannel;
            BlueComp  = dds.BlueChannel;
            AlphaComp = dds.AlphaChannel;

            Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(dds.Format);;
        }
Exemple #5
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;
                }
            }
        }
        public void EditChannel(STChannelType ChannelType)
        {
            var Image = imageEditor.BaseImage;

            if (Image != null)
            {
            }
        }
            public GUISettings()
            {
                FormatCombobox = new Controls.ComboBox();
                MipCount       = new Controls.NumericUpDown(0, 13, 0);

                FormatCombobox.Bind(this, Format, FormatList);

                RedChannel   = STChannelType.Red;
                GreenChannel = STChannelType.Green;
                BlueChannel  = STChannelType.Blue;
                AlphaChannel = STChannelType.Alpha;
                Surface      = STSurfaceType.Texture2D;
            }
        public static Bitmap SetChannel(Bitmap b,
                                        STChannelType channelR,
                                        STChannelType channelG,
                                        STChannelType channelB,
                                        STChannelType channelA)
        {
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
                                           ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            int stride = bmData.Stride;

            System.IntPtr Scan0 = bmData.Scan0;

            unsafe
            {
                byte *p = (byte *)(void *)Scan0;

                int nOffset = stride - b.Width * 4;

                byte red, green, blue, alpha;

                for (int y = 0; y < b.Height; ++y)
                {
                    for (int x = 0; x < b.Width; ++x)
                    {
                        blue  = p[0];
                        green = p[1];
                        red   = p[2];
                        alpha = p[3];

                        p[2] = SetChannelByte(channelR, red, green, blue, alpha);
                        p[1] = SetChannelByte(channelG, red, green, blue, alpha);
                        p[0] = SetChannelByte(channelB, red, green, blue, alpha);
                        p[3] = SetChannelByte(channelA, red, green, blue, alpha);

                        p += 4;
                    }
                    p += nOffset;
                }
            }

            b.UnlockBits(bmData);

            return(b);
        }
Exemple #9
0
        public static int GetSwizzle(STChannelType channel)
        {
            switch (channel)
            {
            case STChannelType.Red: return((int)All.Red);

            case STChannelType.Green: return((int)All.Green);

            case STChannelType.Blue: return((int)All.Blue);

            case STChannelType.Alpha: return((int)All.Alpha);

            case STChannelType.One: return((int)All.One);

            case STChannelType.Zero: return((int)All.Zero);

            default: return(0);
            }
        }
        private static int ConvertChannel(STChannelType type)
        {
            switch (type)
            {
            case STChannelType.Red: return((int)TextureSwizzle.Red);

            case STChannelType.Green: return((int)TextureSwizzle.Green);

            case STChannelType.Blue: return((int)TextureSwizzle.Blue);

            case STChannelType.Alpha: return((int)TextureSwizzle.Alpha);

            case STChannelType.Zero: return((int)TextureSwizzle.Zero);

            case STChannelType.One: return((int)TextureSwizzle.One);

            default: return(0);
            }
        }
        private static byte SetChannelByte(STChannelType channel, byte r, byte g, byte b, byte a)
        {
            switch (channel)
            {
            case STChannelType.Red: return(r);

            case STChannelType.Green: return(g);

            case STChannelType.Blue: return(b);

            case STChannelType.Alpha: return(a);

            case STChannelType.One: return(255);

            case STChannelType.Zero: return(0);

            default:
                throw new Exception("Unknown channel type! " + channel);
            }
        }
Exemple #12
0
        public void EditChannel(STChannelType ChannelType)
        {
            var Image = imageEditor.BaseImage;

            if (Image != null)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.FileName = Text;
                ofd.Filter   = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
                               "Microsoft DDS |*.dds|" +
                               "Portable Network Graphics |*.png|" +
                               "Joint Photographic Experts Group |*.jpg|" +
                               "Bitmap Image |*.bmp|" +
                               "Tagged Image File Format |*.tiff|" +
                               "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Bitmap ImportedImage = null;
                    string ext           = Utils.GetExtension(ofd.FileName);
                    if (ext == ".dds")
                    {
                        DDS dds = new DDS(ofd.FileName);
                        ImportedImage = dds.GetBitmap();
                    }
                    else if (ext == ".tga")
                    {
                        ImportedImage = Paloma.TargaImage.LoadTargaImage(ofd.FileName);
                    }
                    else
                    {
                        ImportedImage = new Bitmap(ofd.FileName);
                    }

                    Bitmap newImage = BitmapExtension.ReplaceChannel(Image, ImportedImage, ChannelType);
                    imageEditor.SaveAndApplyImage(newImage, true, ext == ".dds");
                }
            }
        }
        public static Bitmap ShowChannel(Bitmap b, STChannelType channel)
        {
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
                                           ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            int stride = bmData.Stride;

            System.IntPtr Scan0 = bmData.Scan0;

            unsafe
            {
                byte *p = (byte *)(void *)Scan0;

                int nOffset = stride - b.Width * 4;

                byte red, green, blue, alpha;

                for (int y = 0; y < b.Height; ++y)
                {
                    for (int x = 0; x < b.Width; ++x)
                    {
                        blue  = p[0];
                        green = p[1];
                        red   = p[2];
                        alpha = p[3];

                        if (channel == STChannelType.Red)
                        {
                            p[0] = red;
                            p[1] = red;
                            p[2] = red;
                            p[3] = 255;
                        }
                        else if (channel == STChannelType.Green)
                        {
                            p[0] = green;
                            p[1] = green;
                            p[2] = green;
                            p[3] = 255;
                        }
                        else if (channel == STChannelType.Blue)
                        {
                            p[0] = blue;
                            p[1] = blue;
                            p[2] = blue;
                            p[3] = 255;
                        }
                        else if (channel == STChannelType.Alpha)
                        {
                            p[0] = alpha;
                            p[1] = alpha;
                            p[2] = alpha;
                            p[3] = 255;
                        }

                        p += 4;
                    }
                    p += nOffset;
                }
            }

            b.UnlockBits(bmData);

            return(b);
        }
        public static Bitmap ReplaceChannel(Image OriginalImage, Image ChannelImage, STChannelType ChannelType)
        {
            Bitmap b = new Bitmap(OriginalImage);
            Bitmap c = new Bitmap(ChannelImage, new Size(b.Width, b.Height)); //Force to be same size

            c = GrayScale(c);                                                 //Convert to grayscale

            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
                                           ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            int stride = bmData.Stride;

            System.IntPtr Scan0 = bmData.Scan0;



            BitmapData cmData = c.LockBits(new Rectangle(0, 0, c.Width, c.Height),
                                           ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            int cstride = cmData.Stride;

            System.IntPtr cScan0 = cmData.Scan0;

            unsafe
            {
                byte *p = (byte *)(void *)Scan0;
                byte *channelPointer = (byte *)(void *)cScan0;

                int nOffset = stride - b.Width * 4;

                byte red, green, blue, alpha;

                for (int y = 0; y < b.Height; ++y)
                {
                    for (int x = 0; x < b.Width; ++x)
                    {
                        blue  = p[0];
                        green = p[1];
                        red   = p[2];
                        alpha = p[3];

                        if (ChannelType == STChannelType.Red)
                        {
                            p[2] = channelPointer[2];
                            p[1] = green;
                            p[0] = blue;
                            p[3] = alpha;
                        }
                        else if (ChannelType == STChannelType.Green)
                        {
                            p[2] = red;
                            p[1] = channelPointer[2];
                            p[0] = blue;
                            p[3] = alpha;
                        }
                        else if (ChannelType == STChannelType.Blue)
                        {
                            p[2] = red;
                            p[1] = green;
                            p[0] = channelPointer[2];
                            p[3] = alpha;
                        }
                        else if (ChannelType == STChannelType.Alpha)
                        {
                            p[2] = red;
                            p[1] = green;
                            p[0] = blue;
                            p[3] = channelPointer[2];
                        }

                        p += 4;
                        channelPointer += 4;
                    }
                    p += nOffset;
                    channelPointer += nOffset;
                }
            }

            b.UnlockBits(bmData);
            c.UnlockBits(cmData);

            return(b);
        }
Exemple #15
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);
                }
            }
        }
Exemple #16
0
        public static Bitmap ColorComponentSelector(Bitmap image, STChannelType R, STChannelType G, STChannelType B, STChannelType A)
        {
            BitmapExtension.ColorSwapFilter color = new BitmapExtension.ColorSwapFilter();
            if (R == STChannelType.Red)
            {
                color.CompRed = BitmapExtension.ColorSwapFilter.Red.Red;
            }
            if (R == STChannelType.Green)
            {
                color.CompRed = BitmapExtension.ColorSwapFilter.Red.Green;
            }
            if (R == STChannelType.Blue)
            {
                color.CompRed = BitmapExtension.ColorSwapFilter.Red.Blue;
            }
            if (R == STChannelType.Alpha)
            {
                color.CompRed = BitmapExtension.ColorSwapFilter.Red.Alpha;
            }
            if (R == STChannelType.One)
            {
                color.CompRed = BitmapExtension.ColorSwapFilter.Red.One;
            }
            if (R == STChannelType.Zero)
            {
                color.CompRed = BitmapExtension.ColorSwapFilter.Red.Zero;
            }

            if (G == STChannelType.Red)
            {
                color.CompGreen = BitmapExtension.ColorSwapFilter.Green.Red;
            }
            if (G == STChannelType.Green)
            {
                color.CompGreen = BitmapExtension.ColorSwapFilter.Green.Green;
            }
            if (G == STChannelType.Blue)
            {
                color.CompGreen = BitmapExtension.ColorSwapFilter.Green.Blue;
            }
            if (G == STChannelType.Alpha)
            {
                color.CompGreen = BitmapExtension.ColorSwapFilter.Green.Alpha;
            }
            if (G == STChannelType.One)
            {
                color.CompGreen = BitmapExtension.ColorSwapFilter.Green.One;
            }
            if (G == STChannelType.Zero)
            {
                color.CompGreen = BitmapExtension.ColorSwapFilter.Green.Zero;
            }

            if (B == STChannelType.Red)
            {
                color.CompBlue = BitmapExtension.ColorSwapFilter.Blue.Red;
            }
            if (B == STChannelType.Green)
            {
                color.CompBlue = BitmapExtension.ColorSwapFilter.Blue.Green;
            }
            if (B == STChannelType.Blue)
            {
                color.CompBlue = BitmapExtension.ColorSwapFilter.Blue.Blue;
            }
            if (B == STChannelType.Alpha)
            {
                color.CompBlue = BitmapExtension.ColorSwapFilter.Blue.Alpha;
            }
            if (B == STChannelType.One)
            {
                color.CompBlue = BitmapExtension.ColorSwapFilter.Blue.One;
            }
            if (B == STChannelType.Zero)
            {
                color.CompBlue = BitmapExtension.ColorSwapFilter.Blue.Zero;
            }

            if (A == STChannelType.Red)
            {
                color.CompAlpha = BitmapExtension.ColorSwapFilter.Alpha.Red;
            }
            if (A == STChannelType.Green)
            {
                color.CompAlpha = BitmapExtension.ColorSwapFilter.Alpha.Green;
            }
            if (A == STChannelType.Blue)
            {
                color.CompAlpha = BitmapExtension.ColorSwapFilter.Alpha.Blue;
            }
            if (A == STChannelType.Alpha)
            {
                color.CompAlpha = BitmapExtension.ColorSwapFilter.Alpha.Alpha;
            }
            if (A == STChannelType.One)
            {
                color.CompAlpha = BitmapExtension.ColorSwapFilter.Alpha.One;
            }
            if (A == STChannelType.Zero)
            {
                color.CompAlpha = BitmapExtension.ColorSwapFilter.Alpha.Zero;
            }

            return(BitmapExtension.SwapRGB(image, color));
        }