Exemple #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));
                    }
                }
            }
        }
Exemple #2
0
 public PvrTextureInfo(string name, uint gbix, Bitmap bitmap)
 {
     Name        = name;
     GlobalIndex = gbix;
     DataFormat  = PvrDataFormat.Unknown;
     PixelFormat = PvrPixelFormat.Unknown;
     if (!TextureFunctions.CheckTextureDimensions(bitmap.Width, bitmap.Height))
     {
         Image = new Bitmap(TextureEditor.Properties.Resources.error);
     }
     else
     {
         Image = bitmap;
     }
 }
Exemple #3
0
        public PvrTextureInfo(TextureInfo tex)
        {
            Name        = tex.Name;
            GlobalIndex = tex.GlobalIndex;
            Image       = tex.Image;
            Mipmap      = tex.Mipmap;
            PixelFormat = PvrPixelFormat.Unknown;
            DataFormat  = PvrDataFormat.Unknown;
            if (tex is PvrTextureInfo pv)
            {
                TextureData = pv.TextureData;
                PixelFormat = pv.PixelFormat;
                DataFormat  = pv.DataFormat;
            }
            else if (tex is GvrTextureInfo gv)
            {
                switch (gv.DataFormat)
                {
                case GvrDataFormat.Index4:
                    DataFormat = PvrDataFormat.Index4;
                    break;

                case GvrDataFormat.Index8:
                    DataFormat = PvrDataFormat.Index8;
                    break;

                default:
                    DataFormat  = TextureFunctions.GetPvrDataFormatFromBitmap(tex.Image, tex.Mipmap, true);
                    PixelFormat = TextureFunctions.GetPvrPixelFormatFromBitmap(tex.Image);
                    break;
                }
            }
            else
            {
                DataFormat  = TextureFunctions.GetPvrDataFormatFromBitmap(tex.Image, tex.Mipmap, true);
                PixelFormat = TextureFunctions.GetPvrPixelFormatFromBitmap(tex.Image);
            }
        }
Exemple #4
0
        public GvrTextureInfo(TextureInfo tex)
        {
            Name        = tex.Name;
            GlobalIndex = tex.GlobalIndex;
            Image       = tex.Image;
            Mipmap      = tex.Mipmap;
            PixelFormat = GvrPixelFormat.Unknown;
            DataFormat  = GvrDataFormat.Unknown;
            if (tex is GvrTextureInfo gvrt)
            {
                PixelFormat = gvrt.PixelFormat;
                DataFormat  = gvrt.DataFormat;
                TextureData = gvrt.TextureData;
            }
            else if (tex is PvrTextureInfo pvrt)
            {
                switch (pvrt.DataFormat)
                {
                case PvrDataFormat.Index4:
                    DataFormat = GvrDataFormat.Index4;
                    break;

                case PvrDataFormat.Index8:
                    DataFormat = GvrDataFormat.Index8;
                    break;

                default:
                    DataFormat = TextureFunctions.GetGvrDataFormatFromBitmap(pvrt.Image, false, true);
                    break;
                }
            }
            else
            {
                DataFormat = TextureFunctions.GetGvrDataFormatFromBitmap(Image, false, true);
            }
        }
Exemple #5
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;
            }
        }