(IImageDecoder): new interface.

This commit is contained in:
morkt
2016-10-25 18:18:51 +04:00
parent 27dbb52b89
commit b05c54047d
6 changed files with 118 additions and 27 deletions

View File

@@ -306,31 +306,35 @@ namespace GARbro.GUI
void ExtractImage (ArcFile arc, Entry entry, ImageFormat target_format)
{
using (var file = arc.OpenBinaryEntry (entry))
try
{
var src_format = ImageFormat.FindFormat (file);
if (null == src_format)
throw new InvalidFormatException (string.Format ("{1}: {0}", guiStrings.MsgUnableInterpretImage, entry.Name));
file.Position = 0;
string target_ext = target_format.Extensions.FirstOrDefault() ?? "";
string outname = FindUniqueFileName (entry.Name, target_ext);
if (src_format.Item1 == target_format)
using (var decoder = arc.OpenImage (entry))
{
// source format is the same as a target, copy file as is
using (var output = ArchiveFormat.CreateFile (outname))
file.AsStream.CopyTo (output);
return;
}
ImageData image = src_format.Item1.Read (file, src_format.Item2);
if (m_adjust_image_offset)
{
image = AdjustImageOffset (image);
}
using (var outfile = ArchiveFormat.CreateFile (outname))
{
target_format.Write (outfile, image);
var src_format = decoder.Format; // could be null
string target_ext = target_format.Extensions.FirstOrDefault() ?? "";
string outname = FindUniqueFileName (entry.Name, target_ext);
if (src_format == target_format)
{
// source format is the same as a target, copy file as is
using (var output = ArchiveFormat.CreateFile (outname))
decoder.Input.CopyTo (output);
return;
}
ImageData image = decoder.Image;
if (m_adjust_image_offset)
{
image = AdjustImageOffset (image);
}
using (var outfile = ArchiveFormat.CreateFile (outname))
{
target_format.Write (outfile, image);
}
}
}
catch
{
throw new InvalidFormatException (string.Format ("{1}: {0}", guiStrings.MsgUnableInterpretImage, entry.Name));
}
}
static ImageData AdjustImageOffset (ImageData image)