Example #1
0
        private void btnToTpl_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbToTplInput.Text) && !string.IsNullOrEmpty(tbToTplOutput.Text))
            {
                try
                {
                    TPL_TextureFormat tplFormat = TPL_TextureFormat.RGBA8;

                    switch (cmbToTplFormat.SelectedIndex)
                    {
                    case 0:
                        tplFormat = TPL_TextureFormat.RGBA8; break;

                    case 1:
                        tplFormat = TPL_TextureFormat.RGB565; break;

                    case 2:
                        tplFormat = TPL_TextureFormat.RGB5A3; break;

                    case 3:
                        tplFormat = TPL_TextureFormat.IA8; break;

                    case 4:
                        tplFormat = TPL_TextureFormat.IA4; break;

                    case 5:
                        tplFormat = TPL_TextureFormat.I8; break;

                    case 6:
                        tplFormat = TPL_TextureFormat.I4; break;
                    }

                    TPL t = TPL.FromImage(inputImage, tplFormat);
                    t.Save(tbToTplOutput.Text);

                    MessageBox.Show("Successfully saved TPL to:\n" + tbToTplOutput.Text, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
        }
Example #2
0
        private static void To(string[] args)
        {
            //Setting up variables
            string input     = args[2];
            string output    = args[3];
            string tplFormat = "RGB565";

            //Check if file exists
            if (File.Exists(input) == false)
            {
                Console.WriteLine("ERROR: Unable to open file: {0}", input);
                Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_FILE_ERR_01");
                Environment.Exit(0x00003E81);
                return;
            }

            //Check for arguments
            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-FORMAT":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No format set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_TPL_NO_FORMAT_01");
                        Environment.Exit(0x00003E91);
                        return;
                    }
                    tplFormat = args[i + 1];
                    break;

                case "-F":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No format set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_TPL_NO_FORMAT_01");
                        Environment.Exit(0x00003E91);
                        return;
                    }
                    tplFormat = args[i + 1];
                    break;
                }
            }

            //Check if valid format was entered
            if (tplFormat != "I4" & tplFormat != "I8" & tplFormat != "IA4" & tplFormat != "IA8" & tplFormat != "RGB565" & tplFormat != "RGB5A3" & tplFormat != "RGBA8")
            {
                Console.WriteLine("ERROR: Unknown format type: {0}", tplFormat);
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_UNKNOWN_FORMAT_01");
                Environment.Exit(0x00003E92);
                return;
            }


            //Run main part, and check for exceptions
            try
            {
                //Set format
                TPL_TextureFormat format = TPL_TextureFormat.RGB565;
                if (tplFormat == "I4")
                {
                    format = TPL_TextureFormat.I4;
                }
                if (tplFormat == "I8")
                {
                    format = TPL_TextureFormat.I8;
                }
                if (tplFormat == "IA4")
                {
                    format = TPL_TextureFormat.IA4;
                }
                if (tplFormat == "IA8")
                {
                    format = TPL_TextureFormat.IA8;
                }
                if (tplFormat == "RGB565")
                {
                    format = TPL_TextureFormat.RGB565;
                }
                if (tplFormat == "RGB5A3")
                {
                    format = TPL_TextureFormat.RGB5A3;
                }
                if (tplFormat == "RGBA8")
                {
                    format = TPL_TextureFormat.RGBA8;
                }

                if (BeQuiet.quiet > 2)
                {
                    Console.WriteLine("Format set to: {0}", tplFormat);
                }

                //Make tpl
                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Creating tpl file...");
                }

                TPL tplfile = libWiiSharp.TPL.FromImage(input, format);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                //save
                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Saving tpl file...");
                }

                if (output.Substring(output.Length - 4, 4).ToUpper() != ".TPL")
                {
                    output = output + ".tpl";
                }

                tplfile.Save(output);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Operation completed succesfully!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again");
                Console.WriteLine("");
                Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_UNKNOWN_01");
                Environment.Exit(0x00003E82);
                return;
            }
        }
Example #3
0
        private void createFromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            tplHeader = new TPL_Header();
            tplTextureEntries = new List<TPL_TextureEntry>();
            tplTextureHeaders = new List<TPL_TextureHeader>();
            tplPaletteHeaders = new List<TPL_PaletteHeader>();
            textureData = new List<byte[]>();
            paletteData = new List<byte[]>();

            tplHeader.NumOfTextures = (uint)images.Length;

            for (int i = 0; i < images.Length; i++)
            {
                Image img = images[i];

                TPL_TextureEntry tempTexture = new TPL_TextureEntry();
                TPL_TextureHeader tempTextureHeader = new TPL_TextureHeader();
                TPL_PaletteHeader tempPaletteHeader = new TPL_PaletteHeader();
                byte[] tempTextureData = imageToTpl(img, tplFormats[i]);
                byte[] tempPaletteData = new byte[0];

                tempTextureHeader.TextureHeight = (ushort)img.Height;
                tempTextureHeader.TextureWidth = (ushort)img.Width;
                tempTextureHeader.TextureFormat = (uint)tplFormats[i];

                if (tplFormats[i] == TPL_TextureFormat.CI4 || tplFormats[i] == TPL_TextureFormat.CI8 || tplFormats[i] == TPL_TextureFormat.CI14X2)
                {
                    ColorIndexConverter cic = new ColorIndexConverter(imageToRgba(img), img.Width, img.Height, tplFormats[i], paletteFormats[i]);

                    tempTextureData = cic.Data;
                    tempPaletteData = cic.Palette;

                    tempPaletteHeader.NumberOfItems = (ushort)(tempPaletteData.Length / 2);
                    tempPaletteHeader.PaletteFormat = (uint)paletteFormats[i];
                }

                tplTextureEntries.Add(tempTexture);
                tplTextureHeaders.Add(tempTextureHeader);
                tplPaletteHeaders.Add(tempPaletteHeader);
                textureData.Add(tempTextureData);
                paletteData.Add(tempPaletteData);
            }
        }
Example #4
0
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="images"></param>
        /// <param name="tplFormats"></param>
        public void CreateFromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < images.Length)
                throw new Exception("You must specify a format for each image!");

            createFromImages(images, tplFormats, paletteFormats);
        }
Example #5
0
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="imagePaths"></param>
        /// <param name="tplFormats"></param>
        public void CreateFromImages(string[] imagePaths, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < imagePaths.Length)
                throw new Exception("You must specify a format for each image!");

            List<Image> images = new List<Image>();
            foreach (string imagePath in imagePaths)
                images.Add(Image.FromFile(imagePath));

            createFromImages(images.ToArray(), tplFormats, paletteFormats);
        }
Example #6
0
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="img"></param>
 /// <param name="tplFormat"></param>
 public void CreateFromImage(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     CreateFromImages(new Image[] { img }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
Example #7
0
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="pathToImage"></param>
 /// <param name="tplFormat"></param>
 public void CreateFromImage(string pathToImage, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     CreateFromImages(new string[] { pathToImage }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
Example #8
0
        /// <summary>
        /// Adds a Texture to the TPL.
        /// </summary>
        /// <param name="img"></param>
        /// <param name="tplFormat"></param>
        public void AddTexture(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
        {
            TPL_TextureEntry tempTexture = new TPL_TextureEntry();
            TPL_TextureHeader tempTextureHeader = new TPL_TextureHeader();
            TPL_PaletteHeader tempPaletteHeader = new TPL_PaletteHeader();
            byte[] tempTextureData = imageToTpl(img, tplFormat);
            byte[] tempPaletteData = new byte[0];

            tempTextureHeader.TextureHeight = (ushort)img.Height;
            tempTextureHeader.TextureWidth = (ushort)img.Width;
            tempTextureHeader.TextureFormat = (uint)tplFormat;

            if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8 || tplFormat == TPL_TextureFormat.CI14X2)
            {
                ColorIndexConverter cic = new ColorIndexConverter(imageToRgba(img), img.Width, img.Height, tplFormat, paletteFormat);

                tempTextureData = cic.Data;
                tempPaletteData = cic.Palette;

                tempPaletteHeader.NumberOfItems = (ushort)(tempPaletteData.Length / 2);
                tempPaletteHeader.PaletteFormat = (uint)paletteFormat;
            }

            tplTextureEntries.Add(tempTexture);
            tplTextureHeaders.Add(tempTextureHeader);
            tplPaletteHeaders.Add(tempPaletteHeader);
            textureData.Add(tempTextureData);
            paletteData.Add(tempPaletteData);

            tplHeader.NumOfTextures++;
        }
Example #9
0
 /// <summary>
 /// Adds a Texture to the TPL.
 /// </summary>
 /// <param name="imagePath"></param>
 /// <param name="tplFormat"></param>
 public void AddTexture(string imagePath, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     Image img = Image.FromFile(imagePath);
     AddTexture(img, tplFormat, paletteFormat);
 }
Example #10
0
        public ColorIndexConverter(uint[] rgbaData, int width, int height, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat)
        {
            if (tplFormat != TPL_TextureFormat.CI4 && tplFormat != TPL_TextureFormat.CI8) // && tplFormat != TPL_TextureFormat.CI14X2)
                throw new Exception("Texture format must be either CI4 or CI8"); // or CI14X2!");
            if (paletteFormat != TPL_PaletteFormat.IA8 && paletteFormat != TPL_PaletteFormat.RGB565 && paletteFormat != TPL_PaletteFormat.RGB5A3)
                throw new Exception("Palette format must be either IA8, RGB565 or RGB5A3!");

            this.rgbaData = rgbaData;
            this.width = width;
            this.height = height;
            this.tplFormat = tplFormat;
            this.paletteFormat = paletteFormat;

            buildPalette();

            if (tplFormat == TPL_TextureFormat.CI4) toCI4();
            else if (tplFormat == TPL_TextureFormat.CI8) toCI8();
            else toCI14X2();
        }
Example #11
0
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="images"></param>
        /// <param name="tplFormats"></param>
        /// <returns></returns>
        public static TPL FromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < images.Length)
                throw new Exception("You must specify a format for each image!");

            TPL tmpTpl = new TPL();
            tmpTpl.createFromImages(images, tplFormats, paletteFormats);
            return tmpTpl;
        }
Example #12
0
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="img"></param>
 /// <param name="tplFormat"></param>
 /// <returns></returns>
 public static TPL FromImage(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     return FromImages(new Image[] { img }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
Example #13
0
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="pathToImage"></param>
 /// <param name="tplFormat"></param>
 /// <returns></returns>
 public static TPL FromImage(string pathToImage, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     return FromImages(new string[] { pathToImage }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
Example #14
0
 private int textureByteSize(TPL_TextureFormat tplFormat, int width, int height)
 {
     switch (tplFormat)
     {
         case TPL_TextureFormat.I4:
             return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 8) / 2;
         case TPL_TextureFormat.I8:
         case TPL_TextureFormat.IA4:
             return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 4);
         case TPL_TextureFormat.IA8:
         case TPL_TextureFormat.RGB565:
         case TPL_TextureFormat.RGB5A3:
             return Shared.AddPadding(width, 4) * Shared.AddPadding(height, 4) * 2;
         case TPL_TextureFormat.RGBA8:
             return Shared.AddPadding(width, 4) * Shared.AddPadding(height, 4) * 4;
         case TPL_TextureFormat.CI4:
             return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 8) / 2;
         case TPL_TextureFormat.CI8:
             return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 4);
         case TPL_TextureFormat.CI14X2:
             return Shared.AddPadding(width, 4) * Shared.AddPadding(height, 4) * 2;
         case TPL_TextureFormat.CMP:
             return width * height;
         default:
             throw new FormatException("Unsupported Texture Format!");
     }
 }
Example #15
0
 private byte[] imageToTpl(Image img, TPL_TextureFormat tplFormat)
 {
     switch (tplFormat)
     {
         case TPL_TextureFormat.I4:
             return toI4((Bitmap)img);
         case TPL_TextureFormat.I8:
             return toI8((Bitmap)img);
         case TPL_TextureFormat.IA4:
             return toIA4((Bitmap)img);
         case TPL_TextureFormat.IA8:
             return toIA8((Bitmap)img);
         case TPL_TextureFormat.RGB565:
             return toRGB565((Bitmap)img);
         case TPL_TextureFormat.RGB5A3:
             return toRGB5A3((Bitmap)img);
         case TPL_TextureFormat.RGBA8:
             return toRGBA8((Bitmap)img);
         case TPL_TextureFormat.CI4:
         case TPL_TextureFormat.CI8:
         case TPL_TextureFormat.CI14X2:
             return new byte[0];
         case TPL_TextureFormat.CMP:
         default:
             throw new FormatException("Format not supported!\nCurrently, images can only be converted to the following formats:\nI4, I8, IA4, IA8, RGB565, RGB5A3, RGBA8, CI4, CI8 , CI14X2.");
     }
 }