Skip to content

Commit

Permalink
Address reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
colinator27 committed Aug 18, 2024
1 parent 90834d8 commit e8e036f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
6 changes: 4 additions & 2 deletions UndertaleModLib/Models/UndertaleEmbeddedTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,11 @@ public GMImage Image
public bool FormatBZ2 => _image.Format is GMImage.ImageFormat.Bz2Qoi;

/// <summary>
/// If located within a data file, this is the maximum end position of the image data (or start of the next texture blob).
/// All data between the actual end position and this maximum end position should be padding.
/// If located within a data file, this is the upper bound on the end position of the image data (or start of the next texture blob).
/// </summary>
/// <remarks>
/// All data between the actual end position and this maximum end position should be 0x00 byte padding.
/// </remarks>
private int _maxEndOfStreamPosition { get; set; } = -1;

/// <inheritdoc />
Expand Down
11 changes: 5 additions & 6 deletions UndertaleModLib/UndertaleChunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,13 +1654,12 @@ internal override void UnserializeChunk(UndertaleReader reader)
{
// Skip this texture, as it's external
searchIndex++;
continue;
}
else
{
// Use start address of this blob
maxEndOfStreamPosition = (int)reader.GetOffsetMapRev()[searchObj.TextureData];
break;
}

// Use start address of this blob
maxEndOfStreamPosition = (int)reader.GetOffsetMapRev()[searchObj.TextureData];
break;
}

if (maxEndOfStreamPosition == -1)
Expand Down
24 changes: 12 additions & 12 deletions UndertaleModLib/Util/GMImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public GMImage(int width, int height)
_data = new byte[width * height * 4];
}

// Constructor for use by other creation methods
/// <summary>
/// Basic private constructor for use by other creation methods; just initializes the given fields.
/// </summary>
private GMImage(ImageFormat format, int width, int height, byte[] data)
{
Format = format;
Expand Down Expand Up @@ -195,15 +197,13 @@ private static long FindEndOfBZ2Search(IBinaryReader reader, long endDataPositio
// Return position relative to the start of the data we read
return (endDataPosition - data.Length) + endOfBZ2StreamPosition;
}
else

// Current search failed to make a full match, so progress to next bit, to search starting from there
searchStartBitPosition++;
if (searchStartBitPosition >= 8)
{
// Current search failed to do a full match, so progress to next bit, to search starting from there
searchStartBitPosition++;
if (searchStartBitPosition >= 8)
{
searchStartBitPosition = 0;
searchStartPosition--;
}
searchStartBitPosition = 0;
searchStartPosition--;
}
}

Expand Down Expand Up @@ -259,7 +259,7 @@ private static long FindEndOfBZ2Stream(IBinaryReader reader, long startOfStreamP
/// <param name="reader">Binary reader to read the image data from.</param>
/// <param name="maxEndOfStreamPosition">
/// Location where the image stream must end at or before, from within the <see cref="IBinaryReader"/>.
/// There should only be 0 bytes (AKA padding), between the end of the image data and this position.
/// There should only be 0x00 bytes (AKA padding), between the end of the image data and this position.
/// </param>
/// <param name="gm2022_5">Whether using GameMaker version 2022.5 or above. Relevant only for BZ2 + QOI format images.</param>
/// <exception cref="IOException">If no supported texture format is found</exception>
Expand All @@ -275,8 +275,8 @@ public static GMImage FromBinaryReader(IBinaryReader reader, long maxEndOfStream
// PNG
if (header.SequenceEqual(MagicPng))
{
// There's no overall PNG image length, so we parse image
// chunks until we find the end
// There's no overall PNG image length, so we parse image chunks,
// which do have their own length, until we find the end
while (true)
{
// PNG is big endian, so swap endianness here manually
Expand Down
1 change: 1 addition & 0 deletions UndertaleModLib/Util/TextureWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public IMagickImage<byte> GetTextureFor(UndertaleTexturePageItem texPageItem, st
/// <remarks>
/// Image color format will always be converted to BGRA, with no compression.
/// </remarks>
/// <param name="filePath">File path to read the image from.</param>
/// <returns>An image, in uncompressed BGRA format, containing the contents of the image file at the given path.</returns>
public static MagickImage ReadBGRAImageFromFile(string filePath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ private void ReloadTextureImage(object sender, PropertyChangedEventArgs e)
if (texture is null)
return;

if (e.PropertyName != nameof(UndertaleEmbeddedTexture.TexData.Image))
return;

// If the texture's image was updated, reload it
if (e.PropertyName == nameof(UndertaleEmbeddedTexture.TexData.Image))
{
UpdateImage(texture);
}
UpdateImage(texture);
}

private void UnloadTexture(object sender, RoutedEventArgs e)
Expand Down
28 changes: 14 additions & 14 deletions UndertaleModTool/Editors/UndertaleTexturePageItemEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ private void ReloadTexturePage(object sender, PropertyChangedEventArgs e)
if (item is null)
return;

if (e.PropertyName == nameof(UndertaleTexturePageItem.TexturePage))
{
UpdateImages(item);
if (e.PropertyName != nameof(UndertaleTexturePageItem.TexturePage))
return;

// Start listening for (new) texture image updates
if (_textureDataContext is not null)
{
_textureDataContext.PropertyChanged -= ReloadTextureImage;
}
_textureDataContext = item.TexturePage.TextureData;
_textureDataContext.PropertyChanged += ReloadTextureImage;
UpdateImages(item);

// Start listening for (new) texture image updates
if (_textureDataContext is not null)
{
_textureDataContext.PropertyChanged -= ReloadTextureImage;
}
_textureDataContext = item.TexturePage.TextureData;
_textureDataContext.PropertyChanged += ReloadTextureImage;
}

private void ReloadTextureImage(object sender, PropertyChangedEventArgs e)
Expand All @@ -98,11 +98,11 @@ private void ReloadTextureImage(object sender, PropertyChangedEventArgs e)
if (item is null)
return;

if (e.PropertyName != nameof(UndertaleEmbeddedTexture.TexData.Image))
return;

// If the texture's image was updated, reload it
if (e.PropertyName == nameof(UndertaleEmbeddedTexture.TexData.Image))
{
UpdateImages(item);
}
UpdateImages(item);
}

private void UnloadTexture(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit e8e036f

Please sign in to comment.