Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
808 changes: 404 additions & 404 deletions Program.cs

Large diffs are not rendered by default.

814 changes: 407 additions & 407 deletions exporters/ObjExporter.cs

Large diffs are not rendered by default.

1,330 changes: 665 additions & 665 deletions exporters/RfgExporter.cs

Large diffs are not rendered by default.

96 changes: 48 additions & 48 deletions exporters/TgaExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,57 @@

namespace redux.exporters
{
public static class TgaExporter
{
private const string logSrc = "TgaExporter";
public static void Write24BitTga(string outputPath, Lightmap lm)
{
Logger.Dev(logSrc, $"Starting TGA export: \"{outputPath}\" (Dimensions: {lm.Width}×{lm.Height})");
public static class TgaExporter
{
private const string logSrc = "TgaExporter";
public static void Write24BitTga(string outputPath, Lightmap lm)
{
Logger.Dev(logSrc, $"Starting TGA export: \"{outputPath}\" (Dimensions: {lm.Width}×{lm.Height})");

using var fs = File.OpenWrite(outputPath);
using var bw = new BinaryWriter(fs);
using var fs = File.OpenWrite(outputPath);
using var bw = new BinaryWriter(fs);

// 1) Header: 18 bytes
Logger.Dev(logSrc, "Writing TGA header...");
bw.Write((byte)0); // 0: no ID field
bw.Write((byte)0); // 1: no color map
bw.Write((byte)2); // 2: uncompressed true‐color image
bw.Write((short)0); // 3–4: color map origin
bw.Write((short)0); // 5–6: color map length
bw.Write((byte)0); // 7: color map depth
bw.Write((short)0); // 8–9: x‐origin (low, high)
bw.Write((short)0); // 10–11: y‐origin
bw.Write((short)lm.Width); // 12–13: width
bw.Write((short)lm.Height); // 14–15: height
bw.Write((byte)24); // 16: pixel depth (24 bits)
bw.Write((byte)0); // 17: image descriptor (no alpha, origin bottom‐left)
Logger.Dev(logSrc, "Header written.");
// 1) Header: 18 bytes
Logger.Dev(logSrc, "Writing TGA header...");
bw.Write((byte)0); // 0: no ID field
bw.Write((byte)0); // 1: no color map
bw.Write((byte)2); // 2: uncompressed true‐color image
bw.Write((short)0); // 3–4: color map origin
bw.Write((short)0); // 5–6: color map length
bw.Write((byte)0); // 7: color map depth
bw.Write((short)0); // 8–9: x‐origin (low, high)
bw.Write((short)0); // 10–11: y‐origin
bw.Write((short)lm.Width); // 12–13: width
bw.Write((short)lm.Height); // 14–15: height
bw.Write((byte)24); // 16: pixel depth (24 bits)
bw.Write((byte)0); // 17: image descriptor (no alpha, origin bottom‐left)
Logger.Dev(logSrc, "Header written.");

// 2) Pixel data: bottom row first, BGR order
int w = lm.Width, h = lm.Height;
byte[] data = lm.PixelData; // assumed RGB row-major from top‐left
Logger.Dev(logSrc, $"Writing pixel data ({w * h * 3} bytes total)…");
// 2) Pixel data: bottom row first, BGR order
int w = lm.Width, h = lm.Height;
byte[] data = lm.PixelData; // assumed RGB row-major from top‐left
Logger.Dev(logSrc, $"Writing pixel data ({w * h * 3} bytes total)…");

for (int row = h - 1; row >= 0; row--)
{
int rowStart = row * (w * 3);
for (int col = 0; col < w; col++)
{
int pixelIndex = rowStart + col * 3;
byte r = data[pixelIndex + 0];
byte g = data[pixelIndex + 1];
byte b = data[pixelIndex + 2];
// Write in BGR order
bw.Write(b);
bw.Write(g);
bw.Write(r);
}
}
Logger.Dev(logSrc, "Pixel data written.");
for (int row = h - 1; row >= 0; row--)
{
int rowStart = row * (w * 3);
for (int col = 0; col < w; col++)
{
int pixelIndex = rowStart + col * 3;
byte r = data[pixelIndex + 0];
byte g = data[pixelIndex + 1];
byte b = data[pixelIndex + 2];
// Write in BGR order
bw.Write(b);
bw.Write(g);
bw.Write(r);
}
}
Logger.Dev(logSrc, "Pixel data written.");

// 3) No footer/trailer needed for a simple TGA
bw.Flush();
Logger.Dev(logSrc, $"Finished TGA export: \"{outputPath}\"");
}
}
// 3) No footer/trailer needed for a simple TGA
bw.Flush();
Logger.Dev(logSrc, $"Finished TGA export: \"{outputPath}\"");
}
}
}
Loading