Skip to content

Commit

Permalink
Added optional size parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Shapiro committed Jul 10, 2021
1 parent 2d95b71 commit 1c5709a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/MyraTexturePacker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Description>Console Texture Packer Utility</Description>
<PackageProjectUrl>https://github.com/rds1983/MyraTexturePacker</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>0.9.1</Version>
<Version>0.9.2</Version>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
Expand Down
29 changes: 19 additions & 10 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,8 @@ private static void ProcessNinePatch(ImageInfo imageInfo)
image.Data = newData;
}

private static Packer PackImages(string[] imageFiles)
private static Packer PackImages(string[] imageFiles, int width, int height)
{
var width = 256;
var height = 256;

Console.WriteLine("Atlas Size: {0}x{1}", width, height);

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

private static byte[] BuildAtlasBitmap(Packer packer)
{
var bitmap = new byte[packer.Width * packer.Height * 4];
var bitmap = new byte[(long)packer.Width * packer.Height * 4];
foreach (var packRectangle in packer.PackRectangles)
{
var imageInfo = (ImageInfo)packRectangle.Data;
Expand All @@ -274,7 +271,7 @@ private static byte[] BuildAtlasBitmap(Packer packer)
for (var y = 0; y < image.Height; ++y)
{
var sourcePos = (y * image.Width) * 4;
var destPos = (((y + packRectangle.Y) * packer.Width) + packRectangle.X) * 4;
var destPos = (((y + packRectangle.Y) * (long)packer.Width) + packRectangle.X) * 4;

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

private static void Process(string inputFolder, string outputFile)
private static void Process(string inputFolder, string outputFile, int width, int height)
{
var outputType = DetermineOutputType(outputFile);
var imageFiles = GetImageFiles(inputFolder);
Expand All @@ -360,7 +357,7 @@ private static void Process(string inputFolder, string outputFile)

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

var packer = PackImages(imageFiles);
var packer = PackImages(imageFiles, width, height);

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

try
{
Process(args[0], args[1]);
var width = 256;
if (args.Length > 2)
{
width = int.Parse(args[2]);
}

var height = 256;
if (args.Length > 3)
{
height = int.Parse(args[3]);
}

Process(args[0], args[1], width, height);
}
catch (Exception ex)
{
Expand Down

0 comments on commit 1c5709a

Please sign in to comment.