Skip to content

Commit

Permalink
Add data size auto calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
LITTOMA committed Feb 27, 2019
1 parent e6c1c72 commit 5eb8eca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/texdump/CTR_Textures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private static int GetPixelDataOffset(Size size, int x, int y, float bytesPerPix
return (int)((((x / 8) + (y / 8) * ((size.Width % 8 == 0 ? size.Width : size.Width + 8 - (size.Width % 8)) / 8))) * 64.0 * bytesPerPixel);
}

private static float GetBytesPerPixel(TextureFormat format)
public static float GetBytesPerPixel(TextureFormat format)
{
switch (format)
{
Expand Down
23 changes: 13 additions & 10 deletions src/texdump/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CommandLine;
using CommandLine;
using CommandLine.Text;
using System.Drawing;
using CTR;
using System;
using System.Drawing;
using System.IO;

namespace texdump
{
Expand All @@ -34,7 +29,15 @@ static void Main(string[] args)
var fs = File.OpenRead(options.Input);
BinaryReader reader = new BinaryReader(fs);
fs.Position = options.Position;
texture.ImageData = reader.ReadBytes(options.Length);
if (options.Length > 0)
{
texture.ImageData = reader.ReadBytes(options.Length);
}
else
{
var length = (int)(options.Width * options.Height * TextureUtil.GetBytesPerPixel(options.Format));
texture.ImageData = reader.ReadBytes(length);
}

Bitmap bmp = TextureUtil.DecodeTexture(texture);

Expand Down
2 changes: 1 addition & 1 deletion src/texdumpcore/CTR_Textures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private static int GetPixelDataOffset(Size size, int x, int y, float bytesPerPix
return (int)((((x / 8) + (y / 8) * ((size.Width % 8 == 0 ? size.Width : size.Width + 8 - (size.Width % 8)) / 8))) * 64.0 * bytesPerPixel);
}

private static float GetBytesPerPixel(TextureFormat format)
public static float GetBytesPerPixel(TextureFormat format)
{
switch (format)
{
Expand Down
10 changes: 9 additions & 1 deletion src/texdumpcore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ static void Main(string[] args)
var fs = File.OpenRead(options.Input);
BinaryReader reader = new BinaryReader(fs);
fs.Position = options.Position;
texture.ImageData = reader.ReadBytes(options.Length);
if (options.Length > 0)
{
texture.ImageData = reader.ReadBytes(options.Length);
}
else
{
var length = (int)(options.Width * options.Height * TextureUtil.GetBytesPerPixel(options.Format));
texture.ImageData = reader.ReadBytes(length);
}

var bmp = TextureUtil.DecodeTexture(texture);

Expand Down

0 comments on commit 5eb8eca

Please sign in to comment.