示例#1
0
        public void OpenPNG(string filename)
        {
            pictureBox1.Image = new Bitmap(filename);

            if (formatSelector.SelectedIndex < 0)
            {
                formatSelector.SelectedIndex = 0x0D;
            }

            if (formatSelector.SelectedIndex == 0x0C)
            {
                pictureBox1.Image = Pixel.decodeETC(Pixel.encodeETC(new Bitmap(pictureBox1.Image)), pictureBox1.Image.Width, pictureBox1.Image.Height);
            }
            if (formatSelector.SelectedIndex == 0x0D)
            {
                pictureBox1.Image = Pixel.decodeAlpha(Pixel.encodeETCa4(new Bitmap(pictureBox1.Image)), pictureBox1.Image.Width, pictureBox1.Image.Height);
            }

            nameBox.Text = Path.GetFileNameWithoutExtension(filename);
            label3.Text  = "Width: " + pictureBox1.Image.Width;
            label4.Text  = "Height: " + pictureBox1.Image.Height;
        }
示例#2
0
        public void OpenTEX(string fname)
        {
            FileData d = new FileData(fname);

            d.Endian = System.IO.Endianness.Little;

            int width  = d.readInt();
            int height = d.readInt();
            int type   = d.readByte();
            int dunno  = d.readByte();

            d.skip(2); // padding

            string name = "";

            int i = d.readByte();

            while (i != 0x00)
            {
                name += (char)i;
                i     = d.readByte();
            }

            if (type > 0xD || type < 0)
            {
                return;
            }

            nameBox.Text = name;
            formatSelector.SelectedIndex = type;
            label3.Text = "Width: " + width;
            label4.Text = "Height: " + height;

            byte[] data = d.getSection(0x80, d.size() - 0x80);
            pictureBox1.Image = Pixel.decodeAlpha(data, width, height);
            pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
        }
示例#3
0
        public static Bitmap DecodeImage(byte[] data, int width, int height, Tex_Formats type)
        {
            if (type == Tex_Formats.ETC1)
            {
                return(Pixel.decodeETC(data, width, height));
            }
            if (type == Tex_Formats.ETC1a4)
            {
                return(Pixel.decodeAlpha(data, width, height));
            }

            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            int[] pixels = new int[width * height];

            int p = 0;

            for (int h = 0; h < height; h += 8)
            {
                for (int w = 0; w < width; w += 8)
                {
                    // 8x8 block
                    int[] colors = new int[64];
                    for (int i = 0; i < 64; i++)
                    {
                        switch (type)
                        {
                        case Tex_Formats.RGBA8: colors[i] = decode8888(data[p++], data[p++], data[p++], data[p++]); break;

                        case Tex_Formats.RGB8: colors[i] = decode888(data[p++], data[p++], data[p++]); break;

                        case Tex_Formats.RGBA5551: colors[i] = decode5551(data[p++], data[p++]); break;

                        case Tex_Formats.RGB565: colors[i] = decode565(data[p++], data[p++]); break;

                        case Tex_Formats.RGBA4444: colors[i] = decode4444(data[p++], data[p++]); break;

                        case Tex_Formats.LA8: colors[i] = decodeLA8(data[p++], data[p++]); break;

                        case Tex_Formats.HILO8: colors[i] = decodeHILO8(data[p++], data[p++]); break;

                        case Tex_Formats.L8: colors[i] = decodeL8(data[p++]); break;

                        case Tex_Formats.A8: colors[i] = decodeA8(data[p++]); break;

                        case Tex_Formats.LA4: colors[i] = decodeLA4(data[p++]); break;

                        case Tex_Formats.L4:
                        {
                            colors[i++] = decodeL8((data[p] & 0xF) | ((data[p] & 0xF) << 4));
                            colors[i]   = decodeL8((data[p] & 0xF0) | ((data[p] & 0xF0) >> 4));
                            p++;
                            break;
                        }

                        case Tex_Formats.A4:
                        {
                            colors[i++] = decodeA8((data[p] & 0xF) | ((data[p] & 0xF) << 4));
                            colors[i]   = decodeA8((data[p] & 0xF0) | ((data[p] & 0xF0) >> 4));
                            p++;
                            break;
                        }

                        default: throw new Exception("Unsuppored format " + type.ToString("x"));
                        }
                    }

                    for (int bh = 0; bh < 8; bh++)
                    {
                        for (int bw = 0; bw < 8; bw++)
                        {
                            pixels[((w + bw) + (h + bh) * width)] = colors[calcZOrder(bw, bh)];
                        }
                    }
                }
            }

            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);

            Marshal.Copy(pixels, 0, bmpData.Scan0, pixels.Length);
            bmp.UnlockBits(bmpData);

            return(bmp);
        }