git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1070 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
20
OpenRa.FileFormats/BitmapBuilder.cs
Normal file
20
OpenRa.FileFormats/BitmapBuilder.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public static class BitmapBuilder
|
||||
{
|
||||
public static Bitmap FromBytes( byte[] imageBytes, int width, int height, Palette pal )
|
||||
{
|
||||
Bitmap bitmap = new Bitmap( width, height );
|
||||
for( int x = 0 ; x < width ; x++ )
|
||||
for( int y = 0 ; y < height ; y++ )
|
||||
bitmap.SetPixel( x, y, pal.GetColor( imageBytes[ x + width * y ] ) );
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,17 @@
|
||||
<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.Drawing" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BitmapBuilder.cs" />
|
||||
<Compile Include="Blowfish.cs" />
|
||||
<Compile Include="Format40.cs" />
|
||||
<Compile Include="Format80.cs" />
|
||||
@@ -42,12 +47,7 @@
|
||||
<Compile Include="Palette.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ShpReader.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MixDecrypt\MixDecrypt.vcproj">
|
||||
<Project>{6F5D4280-3D23-41FF-AE2A-511B5553E377}</Project>
|
||||
<Name>MixDecrypt</Name>
|
||||
</ProjectReference>
|
||||
<Compile Include="Terrain.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.
|
||||
|
||||
76
OpenRa.FileFormats/Terrain.cs
Normal file
76
OpenRa.FileFormats/Terrain.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public class Terrain
|
||||
{
|
||||
public readonly int Width;
|
||||
public readonly int Height;
|
||||
public readonly int XDim;
|
||||
public readonly int YDim;
|
||||
public readonly int NumTiles;
|
||||
|
||||
readonly byte[] index;
|
||||
readonly List<Bitmap> TileBitmaps = new List<Bitmap>();
|
||||
|
||||
public Terrain( Stream stream, Palette pal )
|
||||
{
|
||||
BinaryReader reader = new BinaryReader( stream );
|
||||
Width = reader.ReadUInt16();
|
||||
Height = reader.ReadUInt16();
|
||||
|
||||
if( Width != 24 || Height != 24 )
|
||||
throw new InvalidDataException();
|
||||
|
||||
NumTiles = reader.ReadUInt16();
|
||||
reader.ReadUInt16();
|
||||
XDim = reader.ReadUInt16();
|
||||
YDim = reader.ReadUInt16();
|
||||
uint FileSize = reader.ReadUInt32();
|
||||
uint ImgStart = reader.ReadUInt32();
|
||||
reader.ReadUInt32();
|
||||
reader.ReadUInt32();
|
||||
int IndexEnd = reader.ReadInt32();
|
||||
reader.ReadUInt32();
|
||||
int IndexStart = reader.ReadInt32();
|
||||
|
||||
stream.Position = IndexStart;
|
||||
index = new byte[ IndexEnd - IndexStart ];
|
||||
stream.Read( index, 0, IndexEnd - IndexStart );
|
||||
|
||||
for( int i = 0 ; i < index.Length ; i++ )
|
||||
{
|
||||
if( index[ i ] != 255 )
|
||||
{
|
||||
byte[] tileData = new byte[ 24 * 24 ];
|
||||
stream.Position = ImgStart + index[ i ] * 24 * 24;
|
||||
stream.Read( tileData, 0, 24 * 24 );
|
||||
TileBitmaps.Add( BitmapBuilder.FromBytes( tileData, 24, 24, pal ) );
|
||||
}
|
||||
else
|
||||
TileBitmaps.Add( null );
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap GetTile( int index )
|
||||
{
|
||||
return TileBitmaps[ index ];
|
||||
}
|
||||
|
||||
public Bitmap[ , ] GetTiles( int tileNum )
|
||||
{
|
||||
int startIndex = tileNum * XDim * YDim;
|
||||
Bitmap[ , ] ret = new Bitmap[ XDim, YDim ];
|
||||
|
||||
for( int x = 0 ; x < XDim ; x++ )
|
||||
for( int y = 0 ; y < YDim ; y++ )
|
||||
ret[ x, y ] = GetTile( startIndex + x + XDim * y );
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace ShpViewer
|
||||
try
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Filter = "SHP Files|*.shp";
|
||||
ofd.Filter = "SHP Files (*.shp)|*.shp|Terrain Files (*.tem; *.sno; *.int)|*.tem;*.sno;*.int|All Files (*.*)|*.*";
|
||||
ofd.RestoreDirectory = true;
|
||||
if( ofd.ShowDialog() == DialogResult.OK )
|
||||
Application.Run( new ShpViewForm( ofd.FileName ) );
|
||||
|
||||
12
ShpViewer/ShpViewForm.Designer.cs
generated
12
ShpViewer/ShpViewForm.Designer.cs
generated
@@ -34,20 +34,20 @@ namespace ShpViewer
|
||||
// flowLayoutPanel1
|
||||
//
|
||||
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.flowLayoutPanel1.Location = new System.Drawing.Point( 0, 0 );
|
||||
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
|
||||
this.flowLayoutPanel1.Size = new System.Drawing.Size(292, 273);
|
||||
this.flowLayoutPanel1.Size = new System.Drawing.Size( 292, 273 );
|
||||
this.flowLayoutPanel1.TabIndex = 0;
|
||||
//
|
||||
// ShpViewForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(292, 273);
|
||||
this.Controls.Add(this.flowLayoutPanel1);
|
||||
this.ClientSize = new System.Drawing.Size( 292, 273 );
|
||||
this.Controls.Add( this.flowLayoutPanel1 );
|
||||
this.Name = "ShpViewForm";
|
||||
this.Text = "Form1";
|
||||
this.ResumeLayout(false);
|
||||
this.ResumeLayout( false );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,28 +13,47 @@ namespace ShpViewer
|
||||
{
|
||||
public partial class ShpViewForm : Form
|
||||
{
|
||||
ShpReader shpReader;
|
||||
List<Bitmap> bitmaps = new List<Bitmap>();
|
||||
|
||||
public ShpViewForm( string filename )
|
||||
{
|
||||
shpReader = new ShpReader( File.OpenRead( filename ) );
|
||||
|
||||
foreach( ImageHeader h in shpReader )
|
||||
{
|
||||
byte[] imageBytes = h.Image;
|
||||
|
||||
Palette pal = new Palette(File.OpenRead("../../../temperat.pal"));
|
||||
|
||||
Bitmap bitmap = new Bitmap( shpReader.Width, shpReader.Height );
|
||||
for( int x = 0 ; x < shpReader.Width ; x++ )
|
||||
for( int y = 0 ; y < shpReader.Height ; y++ )
|
||||
bitmap.SetPixel( x, y, pal.GetColor(imageBytes[ x + shpReader.Width * y ]) );
|
||||
bitmaps.Add( bitmap );
|
||||
}
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
string ext = Path.GetExtension( filename );
|
||||
if( ext == ".shp" )
|
||||
{
|
||||
ShpReader shpReader = new ShpReader( File.OpenRead( filename ) );
|
||||
|
||||
Palette pal = new Palette( File.OpenRead( "../../../temperat.pal" ) );
|
||||
|
||||
foreach( ImageHeader h in shpReader )
|
||||
bitmaps.Add( BitmapBuilder.FromBytes( h.Image, shpReader.Width, shpReader.Height, pal ) );
|
||||
}
|
||||
else if( ext == ".tem" || ext == ".sno" || ext == ".int" )
|
||||
{
|
||||
Palette pal = new Palette( File.OpenRead( "../../../temperat.pal" ) );
|
||||
switch( ext )
|
||||
{
|
||||
case ".sno":
|
||||
pal = new Palette( File.OpenRead( "../../../snow.pal" ) );
|
||||
break;
|
||||
case ".int":
|
||||
pal = new Palette( File.OpenRead( "../../../interior.pal" ) );
|
||||
break;
|
||||
}
|
||||
|
||||
Terrain t = new Terrain( File.OpenRead( filename ), pal );
|
||||
|
||||
Bitmap bigTile = new Bitmap( 24 * t.XDim, 24 * t.YDim );
|
||||
using( Graphics g = Graphics.FromImage( bigTile ) )
|
||||
{
|
||||
for( int x = 0 ; x < t.XDim ; x++ )
|
||||
for( int y = 0 ; y < t.YDim ; y++ )
|
||||
g.DrawImageUnscaled( t.GetTile( x + y * t.XDim ) ?? new Bitmap( 24, 24 ), x * 24, y * 24 );
|
||||
}
|
||||
bitmaps.Add( bigTile );
|
||||
}
|
||||
|
||||
foreach (Bitmap b in bitmaps)
|
||||
{
|
||||
PictureBox p = new PictureBox();
|
||||
@@ -44,6 +63,7 @@ namespace ShpViewer
|
||||
}
|
||||
|
||||
Focus();
|
||||
BringToFront();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
interior.pal
Normal file
BIN
interior.pal
Normal file
Binary file not shown.
BIN
xtra0014.int
Normal file
BIN
xtra0014.int
Normal file
Binary file not shown.
Reference in New Issue
Block a user