コード例 #1
0
ファイル: ConsoleBrowser.cs プロジェクト: Bioruebe/GARbro
        void ExtractImage(ArcFile arc, Entry entry, ImageFormat targetFormat)
        {
            using (var decoder = arc.OpenImage(entry)) {
                var src_format = decoder.SourceFormat;                 // could be null

                if (autoImageFormat && src_format != null)
                {
                    targetFormat = CommonImageFormats.Contains(src_format.Tag.ToLower())? src_format: ImageFormat.Png;
                }

                var target_ext = targetFormat.Extensions.FirstOrDefault() ?? "";
                var outputName = Path.ChangeExtension(entry.Name, target_ext);
                if (src_format == targetFormat)
                {
                    // source format is the same as a target, copy file as is
                    using (var output = CreateNewFile(outputName)) decoder.Source.CopyTo(output);
                    return;
                }

                var image = decoder.Image;
                if (adjustImageOffset)
                {
                    image = AdjustImageOffset(image);
                }

                using (var outfile = CreateNewFile(outputName)) {
                    targetFormat.Write(outfile, image);
                }
            }
        }
コード例 #2
0
 void ExtractImage(ArcFile arc, Entry entry, ImageFormat target_format)
 {
     using (var decoder = arc.OpenImage(entry))
     {
         var    src_format = decoder.SourceFormat; // could be null
         string target_ext = target_format.Extensions.FirstOrDefault() ?? "";
         string outname    = Path.ChangeExtension(entry.Name, target_ext);
         if (src_format == target_format)
         {
             // source format is the same as a target, copy file as is
             using (var output = CreateNewFile(outname, true))
                 decoder.Source.CopyTo(output);
             return;
         }
         ImageData image = decoder.Image;
         if (m_adjust_image_offset)
         {
             image = AdjustImageOffset(image);
         }
         using (var outfile = CreateNewFile(outname, true))
         {
             target_format.Write(outfile, image);
         }
     }
 }
コード例 #3
0
ファイル: ImageDREF.cs プロジェクト: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var     meta = (DrefMetaData)info;
            ArcFile dpak = null;

            try
            {
                int             layers_count = meta.Layers.Count();
                WriteableBitmap canvas       = null;
                foreach (var path in meta.Layers)
                {
                    if (null == dpak || dpak.File.Name != path.Item1)
                    {
                        if (dpak != null)
                        {
                            dpak.Dispose();
                            dpak = null;
                        }
                        var view = VFS.OpenView(path.Item1);
                        try
                        {
                            dpak = Psb.Value.TryOpen(view);
                            if (null == dpak)
                            {
                                throw new InvalidFormatException();
                            }
                        }
                        catch
                        {
                            view.Dispose();
                            throw;
                        }
                    }
                    var entry = dpak.Dir.FirstOrDefault(e => e.Name == path.Item2);
                    if (null == entry)
                    {
                        throw new InvalidFormatException();
                    }
                    using (var decoder = dpak.OpenImage(entry))
                    {
                        if (1 == layers_count)
                        {
                            return(decoder.Image);
                        }
                        if (null == canvas)
                        {
                            canvas       = new WriteableBitmap(decoder.Image.Bitmap);
                            meta.Width   = decoder.Info.Width;
                            meta.Height  = decoder.Info.Height;
                            meta.OffsetX = decoder.Info.OffsetX;
                            meta.OffsetY = decoder.Info.OffsetY;
                        }
                        else
                        {
                            BlendLayer(canvas, decoder.Image);
                        }
                    }
                }
                if (null == canvas)
                {
                    throw new InvalidFormatException();
                }
                canvas.Freeze();
                return(new ImageData(canvas, meta));
            }
            finally
            {
                if (dpak != null)
                {
                    dpak.Dispose();
                }
            }
        }