Exemplo n.º 1
0
        static void FracReader(string fracFile)
        {
            string outPath = Path.ChangeExtension(fracFile, null);

            using (var stream = File.OpenRead(fracFile))
                using (var farcArchive = BinaryFile.Load <FarcArchive>(stream))
                {
                    Directory.CreateDirectory(outPath);

                    foreach (string fileName in farcArchive)
                    {
                        using (var source = farcArchive.Open(fileName, EntryStreamMode.MemoryStream))
                            using (var spriteSet = BinaryFile.Load <SpriteSet>(source))
                            {
                                Bitmap[] sourceBitmaps = new Bitmap[spriteSet.TextureSet.Textures.Count];
                                for (var i = 0; i < sourceBitmaps.Length; i++)
                                {
                                    sourceBitmaps[i] = TextureDecoder.Decode(spriteSet.TextureSet.Textures[i]);
                                    sourceBitmaps[i].RotateFlip(RotateFlipType.RotateNoneFlipY);
                                }

                                foreach (Sprite sprite in spriteSet.Sprites)
                                {
                                    Console.WriteLine("Writing {0} - {1}", Path.GetFileName(fracFile), sprite.Name);
                                    Rectangle rec          = new Rectangle((int)sprite.X, (int)sprite.Y, (int)sprite.Width, (int)sprite.Height);
                                    Bitmap    targetBitmap = new Bitmap(rec.Width, rec.Height);
                                    Graphics  graphics     = Graphics.FromImage(targetBitmap);
                                    graphics.DrawImage(sourceBitmaps[sprite.TextureIndex], -rec.X, -rec.Y);
                                    targetBitmap.Save(Path.Combine(outPath, sprite.Name + ".png"), ImageFormat.Png);
                                }
                            }
                    }
                }
        }
Exemplo n.º 2
0
        public static Dictionary <Sprite, Bitmap> Crop(SpriteSet spriteSet)
        {
            var bitmaps = new List <Bitmap>(spriteSet.TextureSet.Textures.Count);

            foreach (var texture in spriteSet.TextureSet.Textures)
            {
                var bitmap = TextureDecoder.Decode(texture);
                bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
                bitmaps.Add(bitmap);
            }

            var sprites = new Dictionary <Sprite, Bitmap>(spriteSet.Sprites.Count);

            foreach (var sprite in spriteSet.Sprites)
            {
                var sourceBitmap = bitmaps[sprite.TextureIndex];
                var bitmap       = sourceBitmap.Clone(
                    new RectangleF(sprite.X, sprite.Y, sprite.Width, sprite.Height), sourceBitmap.PixelFormat);
                sprites.Add(sprite, bitmap);
            }

            foreach (var bitmap in bitmaps)
            {
                bitmap.Dispose();
            }

            return(sprites);
        }
Exemplo n.º 3
0
        public static Dictionary <string, string> ExportTextures(TextureDictionary textureDictionary, string dirPath)
        {
            Directory.CreateDirectory(dirPath);
            var texPaths = new Dictionary <string, string>();

            foreach (var tex in textureDictionary.Textures)
            {
                string texPath;

                switch (tex.Format)
                {
                case TextureFormat.DDS:
                    texPath = Path.Combine(dirPath, Path.ChangeExtension(tex.Name, ".dds"));
                    File.WriteAllBytes(texPath, tex.Data);
                    break;

                default:
                    texPath = Path.Combine(dirPath, Path.ChangeExtension(tex.Name, ".png"));
                    TextureDecoder.Decode(tex).Save(texPath);
                    break;
                }

                texPaths[tex.Name] = texPath;
            }

            return(texPaths);
        }
        private void ExtractGMD(string file)
        {
            var gmd = Resource.Load <ModelPack>(file);

            if (gmd.Textures != null)
            {
                foreach (var texture in gmd.Textures.Textures)
                {
                    string output = txtBox_OutputDir.Text;
                    if (chkBox_KeepFolderStructure.Checked)
                    {
                        output += Path.DirectorySeparatorChar + Path.GetDirectoryName(file).Substring(txtBox_SearchDir.Text.Length);
                    }
                    if (chkBox_NameAfterContainers.Checked)
                    {
                        output += Path.DirectorySeparatorChar + Path.GetFileName(file) + "_extracted";
                    }
                    Directory.CreateDirectory(output);

                    var bitmap = TextureDecoder.Decode(texture);
                    bitmap.Save(output + Path.DirectorySeparatorChar + Path.ChangeExtension(texture.Name, "png"));
                    txtBox_Log.Text += $"Saving texture: {texture.Name}\n";
                }
            }
        }
Exemplo n.º 5
0
        public static Bitmap Crop(Sprite sprite, SpriteSet parentSet)
        {
            var bitmap = TextureDecoder.Decode(
                parentSet.TextureSet.Textures[sprite.TextureIndex]);

            var croppedBitmap = Crop(bitmap, sprite.GetSourceRectangle());

            bitmap.Dispose();
            return(croppedBitmap);
        }
Exemplo n.º 6
0
        public static Bitmap Crop(Sprite sprite, SpriteSet parentSet)
        {
            var bitmap = TextureDecoder.Decode(
                parentSet.TextureSet.Textures[sprite.TextureIndex]);

            bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);

            var croppedBitmap = bitmap.Clone(
                new RectangleF(sprite.X, sprite.Y, sprite.Width, sprite.Height), bitmap.PixelFormat);

            bitmap.Dispose();
            return(croppedBitmap);
        }
Exemplo n.º 7
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Bitmap>((path) => TextureDecoder.Decode(Data).Save(path));
            RegisterExportHandler <Texture>((path) => TextureDecoder.DecodeToDDS(Data, path));

            RegisterReplaceHandler <Bitmap>((path) =>
            {
                using (var bitmap = new Bitmap(path))
                {
                    if (Data.IsYCbCr)
                    {
                        var format = DDSCodec.HasTransparency(bitmap) ? TextureFormat.RGBA : TextureFormat.RGB;

                        return(TextureEncoder.Encode(bitmap, format, false));
                    }

                    return(TextureEncoder.Encode(bitmap, Data.Format, Data.MipMapCount != 0));
                }
            });
            RegisterReplaceHandler <Texture>(TextureEncoder.Encode);
        }
Exemplo n.º 8
0
 public Image Decode(int level)
 {
     return(TextureDecoder.Decode(this, level));
 }
 protected override Bitmap GetBitmapCore(FieldTexturePS3 obj)
 {
     return(TextureDecoder.Decode(obj));
 }
Exemplo n.º 10
0
        public unsafe GLTexture(Texture texture)
        {
            Id = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, Id);

            switch (texture.Format)
            {
            case TextureFormat.DDS:
            {
                var ddsHeader = new DDSHeader(new MemoryStream(texture.Data));

                // todo: identify and retrieve values from texture
                // todo: disable mipmaps for now, they often break and show up as black ( eg after replacing a texture )
                int mipMapCount = ddsHeader.MipMapCount;
                if (mipMapCount > 0)
                {
                    --mipMapCount;
                }
                else
                {
                    mipMapCount = 1;
                }

                SetTextureParameters(TextureWrapMode.Repeat, TextureWrapMode.Repeat, TextureMagFilter.Linear, TextureMinFilter.Linear, mipMapCount);

                var format = (PixelInternalFormat)0;

                if (ddsHeader.PixelFormat.FourCC != 0 ||
                    !ddsHeader.PixelFormat.Flags.HasFlag(DDSPixelFormatFlags.RGB) ||
                    ddsHeader.PixelFormat.RGBBitCount != 32)
                {
                    format = GetPixelInternalFormat(ddsHeader.PixelFormat.FourCC);
                }
                else if (ddsHeader.PixelFormat.Flags.HasFlag(DDSPixelFormatFlags.AlphaPixels))
                {
                    format = PixelInternalFormat.Rgba;
                }
                else
                {
                    format = PixelInternalFormat.Rgb;
                }

                UploadDDSTextureData(ddsHeader.Width, ddsHeader.Height, format, 1, texture.Data, 0x80);
            }
            break;

            default:
            {
                // rip hardware acceleration
                var bitmap = TextureDecoder.Decode(texture);
                SetTextureParameters(TextureWrapMode.Repeat, TextureWrapMode.Repeat, TextureMagFilter.Linear, TextureMinFilter.Linear, 1);

                var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                 System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                var pixels = new byte[bitmap.Width * bitmap.Height * 4];
                fixed(byte *pPixels = &pixels[0])
                {
                    var pSrc  = ( byte * )bitmapData.Scan0;
                    var pDest = pPixels;

                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            *pDest++ = pSrc[2];
                            *pDest++ = pSrc[1];
                            *pDest++ = pSrc[0];
                            *pDest++ = pSrc[3];
                            pSrc += 4;
                        }
                    }

                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, PixelFormat.Rgba,
                                  PixelType.UnsignedByte, ( IntPtr )pPixels);
                }

                bitmap.UnlockBits(bitmapData);
            }
            break;
            }
        }
Exemplo n.º 11
0
 protected override Bitmap GetBitmapCore(GNFTexture obj)
 {
     return(TextureDecoder.Decode(obj));
 }