Skip to content
This repository has been archived by the owner on Dec 6, 2020. It is now read-only.

Commit

Permalink
reNX: Rename canvas to bitmap, MP3 to audio.
Browse files Browse the repository at this point in the history
Signed-off-by: angelsl <[email protected]>
  • Loading branch information
angelsl committed Jun 24, 2013
1 parent 21a5d7b commit 8af6382
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
22 changes: 11 additions & 11 deletions NXFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed unsafe class NXFile : IDisposable {
internal readonly byte* _start;
internal NXNode[] _nodes;

internal ulong* _canvasBlock = (ulong*)0;
internal ulong* _bitmapBlock = (ulong*)0;
internal ulong* _mp3Block = (ulong*)0;
internal NXNode.NodeData* _nodeBlock;
private BytePointerObject _pointerWrapper;
Expand Down Expand Up @@ -125,7 +125,7 @@ private void Parse() {
_stringBlock = (ulong*)(_start + hd.StringBlock);
_strings = new string[hd.StringCount];

if (hd.BitmapCount > 0) _canvasBlock = (ulong*)(_start + hd.BitmapBlock);
if (hd.BitmapCount > 0) _bitmapBlock = (ulong*)(_start + hd.BitmapBlock);
if (hd.SoundCount > 0) _mp3Block = (ulong*)(_start + hd.SoundBlock);
}

Expand Down Expand Up @@ -169,7 +169,7 @@ private struct HeaderData {
[Flags]
public enum NXReadSelection : byte {
/// <summary>
/// No flags are enabled, that is, lazy loading of string, MP3 and canvas properties is enabled. This is default.
/// No flags are enabled, that is, lazy loading of string, audio and bitmap properties is enabled. This is default.
/// </summary>
None = 0,

Expand All @@ -179,29 +179,29 @@ public enum NXReadSelection : byte {
EagerParseStrings = 1,

/// <summary>
/// Set this flag to disable lazy loading of MP3 properties.
/// Set this flag to disable lazy loading of audio properties.
/// </summary>
EagerParseMP3 = 2,
EagerParseAudio = 2,

/// <summary>
/// Set this flag to disable lazy loading of canvas properties.
/// Set this flag to disable lazy loading of bitmap properties.
/// </summary>
EagerParseCanvas = 4,
EagerParseBitmap = 4,

/// <summary>
/// Set this flag to completely disable loading of canvas properties. This takes precedence over EagerParseCanvas.
/// Set this flag to completely disable loading of bitmap properties. This takes precedence over EagerParseBitmap.
/// </summary>
NeverParseCanvas = 8,
NeverParseBitmap = 8,

/// <summary>
/// Set this flag to disable lazy loading of nodes (construct all nodes immediately).
/// </summary>
EagerParseFile = 32,

/// <summary>
/// Set this flag to disable lazy loading of string, MP3 and canvas properties.
/// Set this flag to disable lazy loading of string, audio and bitmap properties.
/// </summary>
EagerParseAllProperties = EagerParseCanvas | EagerParseMP3 | EagerParseStrings,
EagerParseAllProperties = EagerParseBitmap | EagerParseAudio | EagerParseStrings,
}

internal static class Util {
Expand Down
4 changes: 2 additions & 2 deletions NXProperties/NXNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ internal static unsafe NXNode ParseNode(NodeData* ptr, NXNode parent, NXFile fil
ret = new NXPointNode(ptr, file);
break;
case 5:
ret = new NXCanvasNode(ptr, file);
ret = new NXBitmapNode(ptr, file);
break;
case 6:
ret = new NXMP3Node(ptr, file);
ret = new NXAudioNode(ptr, file);
break;
default:
return Util.Die<NXNode>(string.Format("NX node has invalid type {0}; dying", ptr->Type));
Expand Down
32 changes: 16 additions & 16 deletions NXProperties/NXNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

namespace reNX.NXProperties {
/// <summary>
/// An optionally lazily-loaded canvas node, containing a bitmap.
/// An optionally lazily-loaded bitmap node, containing a bitmap.
/// </summary>
public sealed class NXCanvasNode : NXLazyValuedNode<Bitmap>, IDisposable {
public sealed class NXBitmapNode : NXLazyValuedNode<Bitmap>, IDisposable {
private GCHandle _gcH;

internal unsafe NXCanvasNode(NodeData* ptr, NXFile file) : base(ptr, file) {
if ((_file._flags & NXReadSelection.EagerParseCanvas) == NXReadSelection.EagerParseCanvas) _value = LoadValue();
internal unsafe NXBitmapNode(NodeData* ptr, NXFile file) : base(ptr, file) {
if ((_file._flags & NXReadSelection.EagerParseBitmap) == NXReadSelection.EagerParseBitmap) _value = LoadValue();
}

#region IDisposable Members
Expand All @@ -60,24 +60,24 @@ public void Dispose() {
/// <summary>
/// Destructor.
/// </summary>
~NXCanvasNode() {
~NXBitmapNode() {
Dispose();
}

/// <summary>
/// Loads the canvas into memory.
/// Loads the bitmap into memory.
/// </summary>
/// <returns>
/// The canvas, as a <see cref="Bitmap" />
/// The bitmap, as a <see cref="Bitmap" />
/// </returns>
protected override unsafe Bitmap LoadValue() {
if (_file._canvasBlock == (ulong*)0 ||
(_file._flags & NXReadSelection.NeverParseCanvas) == NXReadSelection.NeverParseCanvas) return null;
if (_file._bitmapBlock == (ulong*)0 ||
(_file._flags & NXReadSelection.NeverParseBitmap) == NXReadSelection.NeverParseBitmap) return null;
var bdata = new byte[_nodeData->Type5Width*_nodeData->Type5Height*4];
_gcH = GCHandle.Alloc(bdata, GCHandleType.Pinned);
IntPtr outBuf = _gcH.AddrOfPinnedObject();

byte* ptr = _file._start + _file._canvasBlock[_nodeData->TypeIDData] + 4;
byte* ptr = _file._start + _file._bitmapBlock[_nodeData->TypeIDData] + 4;
if (Util._is64Bit) Util.EDecompressLZ464(ptr, outBuf, bdata.Length);
else Util.EDecompressLZ432(ptr, outBuf, bdata.Length);
return new Bitmap(_nodeData->Type5Width, _nodeData->Type5Height, 4*_nodeData->Type5Width,
Expand All @@ -86,17 +86,17 @@ protected override unsafe Bitmap LoadValue() {
}

/// <summary>
/// An optionally lazily-loaded canvas node, containing an MP3 file in a byte array.
/// An optionally lazily-loaded audio node, containing an audio file in a byte array.
/// </summary>
internal sealed class NXMP3Node : NXLazyValuedNode<byte[]> {
internal unsafe NXMP3Node(NodeData* ptr, NXFile file) : base(ptr, file) {
if ((_file._flags & NXReadSelection.EagerParseMP3) == NXReadSelection.EagerParseMP3) _value = LoadValue();
internal sealed class NXAudioNode : NXLazyValuedNode<byte[]> {
internal unsafe NXAudioNode(NodeData* ptr, NXFile file) : base(ptr, file) {
if ((_file._flags & NXReadSelection.EagerParseAudio) == NXReadSelection.EagerParseAudio) _value = LoadValue();
}

/// <summary>
/// Loads the MP3 into memory.
/// Loads the audio file into memory.
/// </summary>
/// <returns> The MP3, as a byte array. </returns>
/// <returns> The audio file, as a byte array. </returns>
protected override unsafe byte[] LoadValue() {
if (_file._mp3Block == (ulong*)0) return null;
var ret = new byte[_nodeData->Type4DataY];
Expand Down

0 comments on commit 8af6382

Please sign in to comment.