示例#1
0
文件: ImageAGF.cs 项目: zxc120/GARbro
        void BlendImage(AgfMetaData info, byte[] overlay, BitmapSource bitmap)
        {
            if (bitmap.PixelWidth != info.Width || bitmap.PixelHeight != info.Height)
            {
                return;
            }
            if (bitmap.Format.BitsPerPixel != 32)
            {
                bitmap = new FormatConvertedBitmap(bitmap, PixelFormats.Bgra32, null, 0);
            }

            int stride = bitmap.PixelWidth * 4;

            byte[] pixels = new byte[stride * bitmap.PixelHeight];
            bitmap.CopyPixels(pixels, stride, 0);
            for (int i = 0; i < pixels.Length; i += 4)
            {
                int pix = overlay[i] | overlay[i + 1] | overlay[i + 2] | overlay[i + 3];
                if (0 == pix)
                {
                    overlay[i]     = pixels[i];
                    overlay[i + 1] = pixels[i + 1];
                    overlay[i + 2] = pixels[i + 2];
                    overlay[i + 3] = pixels[i + 3];
                }
            }
        }
示例#2
0
文件: ImageAGF.cs 项目: zxc120/GARbro
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            var header  = stream.ReadHeader(0x80);
            int version = header.ToInt32(4);

            if (version != 1 && version != 2)
            {
                return(null);
            }
            var info = new AgfMetaData
            {
                Width   = header.ToUInt32(0x1C),
                Height  = header.ToUInt32(0x20),
                BPP     = 32,
                Version = version,
            };

            if (1 == version)
            {
                info.DataOffset = header.ToUInt32(0x0C);
            }
            else
            {
                info.DataOffset     = header.ToUInt32(0x10);
                info.Flags          = header.ToUInt32(0x54);
                info.BaseNameOffset = header.ToUInt32(0x6C);
            }
            return(info);
        }
示例#3
0
文件: ImageAGF.cs 项目: zxc120/GARbro
 string ReadBaseName(IBinaryStream input, AgfMetaData info)
 {
     input.Position = info.DataOffset + info.BaseNameOffset;
     using (var reader = new BinaryReader(input.AsStream, Encoding.Unicode, true))
     {
         var name = new StringBuilder();
         for (;;)
         {
             char c = reader.ReadChar();
             if (0 == c)
             {
                 break;
             }
             name.Append(c);
         }
         var dir_name = VFS.GetDirectoryName(info.FileName);
         return(VFS.CombinePath(dir_name, name.ToString()));
     }
 }