Пример #1
0
        public TexturePalette(Bitmap bitmap, bool saCompatible = true)
        {
            IsGVP = false;
            System.Windows.Forms.DialogResult rd = System.Windows.Forms.MessageBox.Show("Import as ARGB8888?", "Texture Editor", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
            if (rd == System.Windows.Forms.DialogResult.No)
            {
                int tlevel = TextureFunctions.GetAlphaLevelFromBitmap(bitmap);
                switch (tlevel)
                {
                // No transparency
                case 0:
                    pixelCodec = PixelCodec.RGB565;
                    break;

                // 1 bit transparency
                case 1:
                    if (saCompatible)
                    {
                        pixelCodec = PixelCodec.ARGB1555;
                    }
                    else
                    {
                        pixelCodec = PixelCodec.RGB5A3;
                    }
                    break;

                // Full transparency
                case 2:
                    if (saCompatible)
                    {
                        pixelCodec = PixelCodec.ARGB4444;
                    }
                    else
                    {
                        pixelCodec = PixelCodec.RGB5A3;
                    }
                    break;
                }
            }
            else
            {
                pixelCodec = PixelCodec.ARGB8888;
            }
            Colors = new List <Color>();
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    if (pixelCodec == PixelCodec.ARGB8888) // This is done separately because ARGB888 is encoded in a different order in PVP/GVP
                    {
                        Colors.Add(bitmap.GetPixel(x, y));
                    }
                    else
                    {
                        Colors.Add(DecodeColor(EncodeColor(bitmap.GetPixel(x, y), pixelCodec), pixelCodec));
                    }
                }
            }
        }
Пример #2
0
        private void ProcessBitmap()
        {
            int usedColors  = 0;
            int totalColors = 0;

            if (texinfo is PvrTextureInfo)
            {
                radioButtonRGB5A3.Enabled = radioButtonIntensity8A.Enabled = false;
            }

            using (var snoop_u = new BmpPixelSnoop(new Bitmap(bitmap)))
            {
                for (int p = 0; p < bitmap.Palette.Entries.Length; p++)
                {
                    totalColors += 1;
                    bool match = false;
                    for (int h = 0; h < bitmap.Height; h++)
                    {
                        for (int w = 0; w < bitmap.Width; w++)
                        {
                            if (snoop_u.GetPixel(w, h) == bitmap.Palette.Entries[p])
                            {
                                match = true;
                            }
                        }
                    }
                    if (match)
                    {
                        usedColors += 1;
                    }
                }
            }
            if (usedColors <= 16)
            {
                radioButtonIndex4.Checked = true;
                radioButtonIndex4.Enabled = true;
            }
            else if (usedColors <= 256)
            {
                radioButtonIndex8.Checked = true;
                radioButtonIndex4.Enabled = false;
            }
            else
            {
                radioButtonIndex4.Enabled     = radioButtonIndex8.Enabled = false;
                radioButtonNonIndexed.Checked = true;
            }
            int    tlevel       = TextureFunctions.GetAlphaLevelFromBitmap(bitmap);
            string transparency = "";

            switch (tlevel)
            {
            case 0:
                radioButtonRGB565.Checked = true;
                transparency = "no transparency";
                break;

            case 1:
                transparency = "1-bit transparency";
                if (SACompatible || !gamecube)
                {
                    radioButtonARGB1555.Checked = true;
                }
                else
                {
                    radioButtonRGB5A3.Checked = true;
                }
                break;

            case 2:
                transparency = "partial transparency";
                if (SACompatible || !gamecube)
                {
                    radioButtonARGB4444.Checked = true;
                }
                else
                {
                    radioButtonRGB5A3.Checked = true;
                }
                break;
            }

            labelPaletteInfo.Text = "Palette: " + totalColors.ToString() + " colors (" + usedColors.ToString() + " colors used) , " + transparency;
            groupBoxMask.Enabled  = groupBoxPalette.Enabled = buttonAuto.Enabled = buttonOK.Enabled = true;
            if (!gamecube)
            {
                radioButtonIntensity8A.Enabled = radioButtonRGB5A3.Enabled = false;
            }
            else
            {
                radioButtonIntensity8A.Enabled = radioButtonRGB5A3.Enabled = true;
            }
        }