Initial commit
This commit is contained in:
commit
0f86b0434b
38 changed files with 2370 additions and 0 deletions
80
LibDgf/Txm/TxmHeader.cs
Normal file
80
LibDgf/Txm/TxmHeader.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace LibDgf.Txm
|
||||
{
|
||||
public class TxmHeader
|
||||
{
|
||||
public TxmPixelFormat ImageSourcePixelFormat { get; set; }
|
||||
public TxmPixelFormat ImageVideoPixelFormat { get; set; }
|
||||
public short ImageWidth { get; set; }
|
||||
public short ImageHeight { get; set; }
|
||||
public short ImageBufferBase { get; set; }
|
||||
public TxmPixelFormat ClutPixelFormat { get; set; }
|
||||
public byte Misc { get; set; } // 0x0f = level, 0x70 = count, 0x80 = fast count
|
||||
public short ClutWidth { get; set; }
|
||||
public short ClutHeight { get; set; }
|
||||
public short ClutBufferBase { get; set; }
|
||||
|
||||
public void Read(BinaryReader br)
|
||||
{
|
||||
ImageSourcePixelFormat = (TxmPixelFormat)br.ReadByte();
|
||||
ImageVideoPixelFormat = (TxmPixelFormat)br.ReadByte();
|
||||
ImageWidth = br.ReadInt16();
|
||||
ImageHeight = br.ReadInt16();
|
||||
ImageBufferBase = br.ReadInt16();
|
||||
ClutPixelFormat = (TxmPixelFormat)br.ReadByte();
|
||||
Misc = br.ReadByte();
|
||||
ClutWidth = br.ReadInt16();
|
||||
ClutHeight = br.ReadInt16();
|
||||
ClutBufferBase = br.ReadInt16();
|
||||
}
|
||||
|
||||
public void Write(BinaryWriter bw)
|
||||
{
|
||||
bw.Write((byte)ImageSourcePixelFormat);
|
||||
bw.Write((byte)ImageVideoPixelFormat);
|
||||
bw.Write(ImageWidth);
|
||||
bw.Write(ImageHeight);
|
||||
bw.Write(ImageBufferBase);
|
||||
bw.Write((byte)ClutPixelFormat);
|
||||
bw.Write(Misc);
|
||||
bw.Write(ClutWidth);
|
||||
bw.Write(ClutHeight);
|
||||
bw.Write(ClutBufferBase);
|
||||
}
|
||||
|
||||
public int GetImageByteSize()
|
||||
{
|
||||
return GetImageMemSize(ImageSourcePixelFormat, ImageWidth, ImageHeight);
|
||||
}
|
||||
|
||||
public int GetClutByteSize()
|
||||
{
|
||||
return GetImageMemSize(ClutPixelFormat, ClutWidth, ClutHeight);
|
||||
}
|
||||
|
||||
int GetImageMemSize(TxmPixelFormat format, int width, int height)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case TxmPixelFormat.PSMT4:
|
||||
return width * height / 2;
|
||||
case TxmPixelFormat.PSMT8:
|
||||
return width * height;
|
||||
case TxmPixelFormat.PSMCT32:
|
||||
return width * height * 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{ImageSourcePixelFormat} {ImageVideoPixelFormat} {ImageWidth}x{ImageHeight} {ImageBufferBase:x4} " +
|
||||
$"{ClutPixelFormat} {Misc:x2} {ClutWidth}x{ClutHeight} {ClutBufferBase:x4}";
|
||||
}
|
||||
}
|
||||
}
|
24
LibDgf/Txm/TxmPixelFormat.cs
Normal file
24
LibDgf/Txm/TxmPixelFormat.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace LibDgf.Txm
|
||||
{
|
||||
public enum TxmPixelFormat : byte
|
||||
{
|
||||
PSMCT32 = 0x00,
|
||||
PSMCT24 = 0x01,
|
||||
PSMCT16 = 0x02,
|
||||
PSMCT16S = 0x0a,
|
||||
PSMT8 = 0x13,
|
||||
PSMT4 = 0x14,
|
||||
PSMT8H = 0x1b,
|
||||
PSMT4HL = 0x24,
|
||||
PSMT4HH = 0x2c,
|
||||
PSMZ32 = 0x30,
|
||||
PSMZ24 = 0x31,
|
||||
PSMZ16 = 0x32,
|
||||
PSMZ16S = 0x3a,
|
||||
None = 0xff
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue