mirror of
https://github.com/lifegpc/GARbro.git
synced 2026-06-06 05:28:49 +08:00
Initial commit.
This commit is contained in:
6
Image.Convert/App.config
Normal file
6
Image.Convert/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
70
Image.Convert/Image.Convert.csproj
Normal file
70
Image.Convert/Image.Convert.csproj
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{757EB8B1-F62C-4690-AC3D-DAE4A5576B3E}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Image.Convert</RootNamespace>
|
||||
<AssemblyName>Image.Convert</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<NoWin32Manifest>true</NoWin32Manifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GameRes\GameRes.csproj">
|
||||
<Project>{453c087f-e416-4ae9-8c03-d8760da0574b}</Project>
|
||||
<Name>GameRes</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
6
Image.Convert/Image.Convert.csproj.user
Normal file
6
Image.Convert/Image.Convert.csproj.user
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<StartArguments>-t tga uninstall.hg3</StartArguments>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
174
Image.Convert/Program.cs
Normal file
174
Image.Convert/Program.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GameRes;
|
||||
|
||||
namespace GARbro
|
||||
{
|
||||
class ImageConverter
|
||||
{
|
||||
static string ProgramName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
}
|
||||
}
|
||||
|
||||
void Usage ()
|
||||
{
|
||||
Console.WriteLine("Usage: {0} [OPTIONS] IMAGE", ProgramName);
|
||||
Console.WriteLine(" -l list recognized image FormatCatalog.Instance");
|
||||
Console.WriteLine(" -t FORMAT convert image(s) to specified format");
|
||||
Console.WriteLine("Without options image metadata is displayed.");
|
||||
}
|
||||
|
||||
void ListFormats ()
|
||||
{
|
||||
Console.WriteLine("Supported image formats:");
|
||||
foreach (var impl in FormatCatalog.Instance.ImageFormats)
|
||||
{
|
||||
Console.Write ("{0,-4} ", impl.Tag);
|
||||
if (impl.IsBuiltin) Console.Write ("[builtin] ");
|
||||
Console.WriteLine (impl.Description);
|
||||
}
|
||||
}
|
||||
|
||||
ImageFormat FindFormat (string format)
|
||||
{
|
||||
var range = FormatCatalog.Instance.LookupTag<ImageFormat> (format);
|
||||
return range.FirstOrDefault();
|
||||
}
|
||||
|
||||
Tuple<ImageFormat, ImageMetaData> FindImageFormat (ArcView arc)
|
||||
{
|
||||
uint signature = arc.View.ReadUInt32 (0);
|
||||
using (var stream = arc.CreateStream())
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
var range = FormatCatalog.Instance.LookupSignature<ImageFormat> (signature);
|
||||
foreach (var impl in range)
|
||||
{
|
||||
try
|
||||
{
|
||||
ImageMetaData metadata = impl.ReadMetaData (stream);
|
||||
if (null != metadata)
|
||||
return new Tuple<ImageFormat, ImageMetaData> (impl, metadata);
|
||||
stream.Position = 0;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
if (0 == signature)
|
||||
break;
|
||||
signature = 0;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
ImageData ReadImage (ArcView file)
|
||||
{
|
||||
var format = FindImageFormat (file);
|
||||
if (null == format)
|
||||
return null;
|
||||
using (var stream = file.CreateStream())
|
||||
return format.Item1.Read (stream, format.Item2);
|
||||
}
|
||||
|
||||
void PrintMetaData (string filename)
|
||||
{
|
||||
using (ArcView file = new ArcView (filename))
|
||||
{
|
||||
var format = FindImageFormat (file);
|
||||
if (null == format)
|
||||
{
|
||||
Console.Error.WriteLine ("{0}: file format not recognized", filename);
|
||||
return;
|
||||
}
|
||||
var image = format.Item2;
|
||||
Console.WriteLine ("{0,16} [{4}] {1}x{2} {3}bpp", filename, image.Width, image.Height, image.BPP, format.Item1.Tag);
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertFile (string filename, ImageFormat format)
|
||||
{
|
||||
ImageData image;
|
||||
using (var file = new ArcView (filename))
|
||||
{
|
||||
image = ReadImage (file);
|
||||
if (null == image)
|
||||
{
|
||||
Console.Error.WriteLine ("{0}: Unknown image format", filename);
|
||||
return;
|
||||
}
|
||||
}
|
||||
string target_ext = format.Extensions.First();
|
||||
string outname = Path.GetFileNameWithoutExtension (filename)+'.'+target_ext;
|
||||
Console.WriteLine ("{0} => {1}", filename, outname);
|
||||
using (var outfile = new FileStream (outname, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
format.Write (outfile, image);
|
||||
}
|
||||
}
|
||||
|
||||
void Run (string[] args)
|
||||
{
|
||||
if (args.Length < 1 || args[0] == "/?" || args[0] == "--help")
|
||||
{
|
||||
Usage();
|
||||
}
|
||||
else if (args[0] == "-l")
|
||||
{
|
||||
ListFormats();
|
||||
}
|
||||
else if (args[0] == "-t")
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Usage();
|
||||
return;
|
||||
}
|
||||
ImageFormat format = FindFormat (args[1]);
|
||||
if (null == format)
|
||||
{
|
||||
Console.Error.WriteLine ("{0}: unknown format specified", args[1]);
|
||||
return;
|
||||
}
|
||||
for (int i = 2; i < args.Length; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConvertFile (args[i], format);
|
||||
}
|
||||
catch (Exception X)
|
||||
{
|
||||
Console.Error.WriteLine ("{0}: {1}", args[i], X.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var filename in args)
|
||||
{
|
||||
PrintMetaData (filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var program = new ImageConverter();
|
||||
program.Run (args);
|
||||
}
|
||||
catch (Exception X)
|
||||
{
|
||||
Console.Error.WriteLine ("{0}: {1}", ProgramName, X.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Image.Convert/Properties/AssemblyInfo.cs
Normal file
36
Image.Convert/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Image.Convert")]
|
||||
[assembly: AssemblyDescription("Image Conversion utility")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Image.Convert")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014 mørkt")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("5becba95-6a61-452a-8075-9b523494cc09")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user