Skip to content

Commit 1c5709a

Browse files
author
Roman Shapiro
committed
Added optional size parameters
1 parent 2d95b71 commit 1c5709a

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/MyraTexturePacker.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Description>Console Texture Packer Utility</Description>
88
<PackageProjectUrl>https://github.com/rds1983/MyraTexturePacker</PackageProjectUrl>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>
10-
<Version>0.9.1</Version>
10+
<Version>0.9.2</Version>
1111
<OutputType>Exe</OutputType>
1212
</PropertyGroup>
1313
<ItemGroup>

src/Program.cs

+19-10
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,8 @@ private static void ProcessNinePatch(ImageInfo imageInfo)
202202
image.Data = newData;
203203
}
204204

205-
private static Packer PackImages(string[] imageFiles)
205+
private static Packer PackImages(string[] imageFiles, int width, int height)
206206
{
207-
var width = 256;
208-
var height = 256;
209-
210207
Console.WriteLine("Atlas Size: {0}x{1}", width, height);
211208

212209
var packer = new Packer(width, height);
@@ -263,7 +260,7 @@ private static Packer PackImages(string[] imageFiles)
263260

264261
private static byte[] BuildAtlasBitmap(Packer packer)
265262
{
266-
var bitmap = new byte[packer.Width * packer.Height * 4];
263+
var bitmap = new byte[(long)packer.Width * packer.Height * 4];
267264
foreach (var packRectangle in packer.PackRectangles)
268265
{
269266
var imageInfo = (ImageInfo)packRectangle.Data;
@@ -274,7 +271,7 @@ private static byte[] BuildAtlasBitmap(Packer packer)
274271
for (var y = 0; y < image.Height; ++y)
275272
{
276273
var sourcePos = (y * image.Width) * 4;
277-
var destPos = (((y + packRectangle.Y) * packer.Width) + packRectangle.X) * 4;
274+
var destPos = (((y + packRectangle.Y) * (long)packer.Width) + packRectangle.X) * 4;
278275

279276
Array.Copy(image.Data, sourcePos, bitmap, destPos, image.Width * 4);
280277
}
@@ -348,7 +345,7 @@ private static XDocument CreateOutputXML(string outputFile, Packer packer)
348345
return doc;
349346
}
350347

351-
private static void Process(string inputFolder, string outputFile)
348+
private static void Process(string inputFolder, string outputFile, int width, int height)
352349
{
353350
var outputType = DetermineOutputType(outputFile);
354351
var imageFiles = GetImageFiles(inputFolder);
@@ -360,7 +357,7 @@ private static void Process(string inputFolder, string outputFile)
360357

361358
Console.WriteLine("{0} image files found at {1}.", imageFiles.Length, inputFolder);
362359

363-
var packer = PackImages(imageFiles);
360+
var packer = PackImages(imageFiles, width, height);
364361

365362
// All images had been packed
366363
// Now build up the atlas bitmap
@@ -384,13 +381,25 @@ public static void Main(string[] args)
384381
{
385382
if (args.Length < 2)
386383
{
387-
Console.WriteLine("Usage: MyraTexturePacker.exe <input_folder> <output_file>");
384+
Console.WriteLine("Usage: MyraTexturePacker.exe <input_folder> <output_file> [width] [height]");
388385
return;
389386
}
390387

391388
try
392389
{
393-
Process(args[0], args[1]);
390+
var width = 256;
391+
if (args.Length > 2)
392+
{
393+
width = int.Parse(args[2]);
394+
}
395+
396+
var height = 256;
397+
if (args.Length > 3)
398+
{
399+
height = int.Parse(args[3]);
400+
}
401+
402+
Process(args[0], args[1], width, height);
394403
}
395404
catch (Exception ex)
396405
{

0 commit comments

Comments
 (0)