git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1057 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
98
ImageDecode/Format40.cs
Normal file
98
ImageDecode/Format40.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace ImageDecode
|
||||
{
|
||||
public static class Format40
|
||||
{
|
||||
static byte ReadByte( MemoryStream input )
|
||||
{
|
||||
int inp = input.ReadByte();
|
||||
if( inp == -1 )
|
||||
throw new InvalidDataException();
|
||||
|
||||
return (byte)inp;
|
||||
}
|
||||
|
||||
static int ReadWord( MemoryStream input )
|
||||
{
|
||||
int inp = ReadByte( input );
|
||||
return inp + ( ReadByte( input ) << 8 );
|
||||
}
|
||||
|
||||
//static void ReplicatePrevious( byte[] dest, int destIndex, int srcIndex, int count )
|
||||
//{
|
||||
// for( int i = 0 ; i < Math.Min( count, destIndex - srcIndex ) ; i++ )
|
||||
// dest[ destIndex + i ] = dest[ srcIndex + i ];
|
||||
|
||||
// if( srcIndex + count <= destIndex )
|
||||
// return;
|
||||
|
||||
// for( int i = destIndex + destIndex - srcIndex ; i < destIndex + count ; i++ )
|
||||
// dest[ i ] = dest[ destIndex - 1 ];
|
||||
//}
|
||||
|
||||
public static int DecodeInto( MemoryStream input, byte[] dest )
|
||||
{
|
||||
int destIndex = 0;
|
||||
while( true )
|
||||
{
|
||||
byte i = ReadByte( input );
|
||||
if( ( i & 0x80 ) == 0 )
|
||||
{
|
||||
int count = i & 0x7F;
|
||||
if( count == 0 )
|
||||
{
|
||||
// case 6
|
||||
count = ReadByte( input );
|
||||
byte value = ReadByte( input );
|
||||
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
||||
dest[ destIndex ] ^= value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// case 5
|
||||
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
||||
dest[ destIndex ] ^= ReadByte( input );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = i & 0x7F;
|
||||
if( count == 0 )
|
||||
{
|
||||
count = ReadWord( input );
|
||||
if( count == 0 )
|
||||
return destIndex;
|
||||
|
||||
if( ( count & 0x8000 ) == 0 )
|
||||
{
|
||||
// case 2
|
||||
destIndex += ( count & 0x7FFF );
|
||||
}
|
||||
else if( ( count & 0x4000 ) == 0 )
|
||||
{
|
||||
// case 3
|
||||
for( int end = destIndex + ( count & 0x3FFF ) ; destIndex < end ; destIndex++ )
|
||||
dest[ destIndex ] ^= ReadByte( input );
|
||||
}
|
||||
else
|
||||
{
|
||||
// case 4
|
||||
byte value = ReadByte( input );
|
||||
for( int end = destIndex + ( count & 0x3FFF ) ; destIndex < end ; destIndex++ )
|
||||
dest[ destIndex ] ^= value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// case 1
|
||||
destIndex += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
104
ImageDecode/Format80.cs
Normal file
104
ImageDecode/Format80.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace ImageDecode
|
||||
{
|
||||
public static class Format80
|
||||
{
|
||||
static byte ReadByte( MemoryStream input )
|
||||
{
|
||||
int inp = input.ReadByte();
|
||||
if( inp == -1 )
|
||||
throw new InvalidDataException();
|
||||
|
||||
return (byte)inp;
|
||||
}
|
||||
|
||||
static int ReadWord( MemoryStream input )
|
||||
{
|
||||
int inp = ReadByte( input );
|
||||
return inp + ( ReadByte( input ) << 8 );
|
||||
}
|
||||
|
||||
static void ReplicatePrevious( byte[] dest, int destIndex, int srcIndex, int count )
|
||||
{
|
||||
if( srcIndex >= destIndex )
|
||||
throw new NotImplementedException( string.Format( "srcIndex >= destIndex {0} {1}", srcIndex, destIndex ) );
|
||||
|
||||
for( int i = 0 ; i < Math.Min( count, destIndex - srcIndex ) ; i++ )
|
||||
dest[ destIndex + i ] = dest[ srcIndex + i ];
|
||||
|
||||
if( srcIndex + count <= destIndex )
|
||||
return;
|
||||
|
||||
for( int i = destIndex + destIndex - srcIndex ; i < destIndex + count ; i++ )
|
||||
dest[ i ] = dest[ destIndex - 1 ];
|
||||
}
|
||||
|
||||
public static int DecodeInto( MemoryStream input, byte[] dest )
|
||||
{
|
||||
int destIndex = 0;
|
||||
while( true )
|
||||
{
|
||||
byte i = ReadByte( input );
|
||||
if( ( i & 0x80 ) == 0 )
|
||||
{
|
||||
// case 2
|
||||
byte secondByte = ReadByte( input );
|
||||
int count = ( ( i & 0x70 ) >> 4 ) + 3;
|
||||
int rpos = ( ( i & 0xf ) << 8 ) + secondByte;
|
||||
|
||||
ReplicatePrevious( dest, destIndex, destIndex - rpos, count );
|
||||
destIndex += count;
|
||||
}
|
||||
else if( ( i & 0x40 ) == 0 )
|
||||
{
|
||||
// case 1
|
||||
int count = i & 0x3F;
|
||||
if( count == 0 )
|
||||
return destIndex;
|
||||
|
||||
input.Read( dest, destIndex, count );
|
||||
destIndex += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
int count3 = i & 0x3F;
|
||||
if( count3 == 0x3E )
|
||||
{
|
||||
// case 4
|
||||
int count = ReadWord( input );
|
||||
byte color = ReadByte( input );
|
||||
|
||||
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
||||
dest[ destIndex ] = color;
|
||||
}
|
||||
else if( count3 == 0x3F )
|
||||
{
|
||||
// case 5
|
||||
int count = ReadWord( input );
|
||||
int srcIndex = ReadWord( input );
|
||||
if( srcIndex >= destIndex )
|
||||
throw new NotImplementedException( string.Format( "srcIndex >= destIndex {0} {1}", srcIndex, destIndex ) );
|
||||
|
||||
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
||||
dest[ destIndex ] = dest[ srcIndex++ ];
|
||||
}
|
||||
else
|
||||
{
|
||||
// case 3
|
||||
int count = count3 + 3;
|
||||
int srcIndex = ReadWord( input );
|
||||
if( srcIndex >= destIndex )
|
||||
throw new NotImplementedException( string.Format( "srcIndex >= destIndex {0} {1}", srcIndex, destIndex ) );
|
||||
|
||||
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
||||
dest[ destIndex ] = dest[ srcIndex++ ];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
ImageDecode/ImageDecode.csproj
Normal file
55
ImageDecode/ImageDecode.csproj
Normal file
@@ -0,0 +1,55 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ImageDecode</RootNamespace>
|
||||
<AssemblyName>ImageDecode</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Format40.cs" />
|
||||
<Compile Include="Format80.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ShpReader.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\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>
|
||||
17
ImageDecode/Program.cs
Normal file
17
ImageDecode/Program.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ImageDecode
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
ShpReader.Read( File.OpenRead( "stek.shp" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
35
ImageDecode/Properties/AssemblyInfo.cs
Normal file
35
ImageDecode/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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( "ImageDecode" )]
|
||||
[assembly: AssemblyDescription( "" )]
|
||||
[assembly: AssemblyConfiguration( "" )]
|
||||
[assembly: AssemblyCompany( "" )]
|
||||
[assembly: AssemblyProduct( "ImageDecode" )]
|
||||
[assembly: AssemblyCopyright( "Copyright © 2007" )]
|
||||
[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( "f236056f-1b46-4a95-9d44-e2c77a9e91c0" )]
|
||||
|
||||
// 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 Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion( "1.0.0.0" )]
|
||||
[assembly: AssemblyFileVersion( "1.0.0.0" )]
|
||||
84
ImageDecode/ShpReader.cs
Normal file
84
ImageDecode/ShpReader.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace ImageDecode
|
||||
{
|
||||
public class ImageHeader
|
||||
{
|
||||
public uint Offset;
|
||||
public Format Format;
|
||||
public uint RefOffset;
|
||||
public Format RefFormat;
|
||||
public byte[] Image;
|
||||
|
||||
public ImageHeader( BinaryReader reader )
|
||||
{
|
||||
Offset = reader.ReadUInt32();
|
||||
Format = (Format)( Offset >> 24 );
|
||||
Offset &= 0xFFFFFF;
|
||||
|
||||
RefOffset = reader.ReadUInt16();
|
||||
RefFormat = (Format)reader.ReadUInt16();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Format
|
||||
{
|
||||
Format20 = 0x20,
|
||||
Format40 = 0x40,
|
||||
Format80 = 0x80,
|
||||
}
|
||||
|
||||
public static class ShpReader
|
||||
{
|
||||
public static IEnumerable<byte[]> Read( Stream stream )
|
||||
{
|
||||
BinaryReader reader = new BinaryReader( stream );
|
||||
|
||||
ushort numImages = reader.ReadUInt16();
|
||||
reader.ReadUInt16();
|
||||
reader.ReadUInt16();
|
||||
ushort width = reader.ReadUInt16();
|
||||
ushort height = reader.ReadUInt16();
|
||||
reader.ReadUInt32();
|
||||
|
||||
List<ImageHeader> headers = new List<ImageHeader>();
|
||||
for( int i = 0 ; i < numImages ; i++ )
|
||||
headers.Add( new ImageHeader( reader ) );
|
||||
|
||||
new ImageHeader( reader ); // end-of-file header
|
||||
new ImageHeader( reader ); // all-zeroes header
|
||||
|
||||
foreach( ImageHeader h in headers )
|
||||
{
|
||||
reader.BaseStream.Position = h.Offset;
|
||||
switch( h.Format )
|
||||
{
|
||||
case Format.Format20:
|
||||
//throw new NotImplementedException();
|
||||
break;
|
||||
case Format.Format40:
|
||||
//throw new NotImplementedException();
|
||||
break;
|
||||
case Format.Format80:
|
||||
{
|
||||
byte[] compressedBytes = reader.ReadBytes( (int)( reader.BaseStream.Length - reader.BaseStream.Position ) );
|
||||
MemoryStream ms = new MemoryStream( compressedBytes );
|
||||
byte[] imageBytes = new byte[ width * height ];
|
||||
Format80.DecodeInto( ms, imageBytes );
|
||||
h.Image = imageBytes;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
|
||||
if( h.Image != null )
|
||||
yield return h.Image;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MixDecrypt, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\debug\MixDecrypt.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
@@ -41,12 +45,6 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MixDecrypt\MixDecrypt.vcproj">
|
||||
<Project>{6F5D4280-3D23-41FF-AE2A-511B5553E377}</Project>
|
||||
<Name>MixDecrypt</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\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.
|
||||
|
||||
12
OpenRa.sln
12
OpenRa.sln
@@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MixBrowser", "MixBrowser\Mi
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MixDecrypt", "MixDecrypt\MixDecrypt.vcproj", "{6F5D4280-3D23-41FF-AE2A-511B5553E377}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageDecode", "ImageDecode\ImageDecode.csproj", "{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -35,6 +37,16 @@ Global
|
||||
{6F5D4280-3D23-41FF-AE2A-511B5553E377}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||
{6F5D4280-3D23-41FF-AE2A-511B5553E377}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{6F5D4280-3D23-41FF-AE2A-511B5553E377}.Release|Win32.Build.0 = Release|Win32
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{39352FD2-28B0-4DF5-97C7-499CE1AECCB9}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user