Skip to content

Commit

Permalink
encoding type check
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeG621 committed Dec 17, 2023
1 parent 2262a27 commit ac11b80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Library for reading LucasArts *.DAT backdrop files
==========
Version History

- BC7 format detection, currently unsupported and returns a blank image

v2.4 - 27 Feb 2022
- Added Format 25C capability
- Image isn't decompressed until first accessed
Expand Down
14 changes: 11 additions & 3 deletions Sub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* Licensed under the GPL v2.0 or later
*
* Full notice in DatFile.cs
* VERSION: 2.4
* VERSION: 2.4+
*/

/* CHANGE LOG
* [NEW] BC7 detection, format currently unsupported and returns a blank image
* v2.4, 220227
* [UPD] _rows set to null for Full32bpp images since there's no processing
* [NEW] Format "25C", 32bpp LZMA compressed
Expand Down Expand Up @@ -293,9 +294,11 @@ public static Bitmap DecodeImage(byte[] rawData, int width, int height, Color[]
/// <param name="trimmedImage"><paramref name="image"/> with unused color indexes removed, or simply the original <paramref name="image"/> as <see cref="PixelFormat.Format32bppArgb"/> if <paramref name="type"/> is <see cref="ImageType.Full32bppArgb"/> or <see cref="ImageType.Compressed32bppArgb"/>.</param>
/// <param name="trimmedColors"><paramref name="colors"/> with unused color indexes removed, or <b>null</b> if <paramref name="type"/> is <see cref="ImageType.Full32bppArgb"/> or <see cref="ImageType.Compressed32bppArgb"/>.</param>
/// <remarks>Unused color indexes are removed from both <paramref name="colors"/> and <paramref name="image"/>, the returned array reflects the trimmed parameters. <paramref name="colors"/> is ignored and can be <b>null</b> if <paramref name="type"/> is <see cref="ImageType.Full32bppArgb"/> or <see cref="ImageType.Compressed32bppArgb"/>.<br/>
/// If <paramref name="type"/> is <see cref="ImageType.Compressed32bppArgb"/>, then instead of being row data the array is the compressed LZMA data.</remarks>
/// If <paramref name="type"/> is <see cref="ImageType.Compressed32bppArgb"/>, then instead of being row data the array is the compressed LZMA data.<br/>
/// **<see cref="ImageType.BC7Compressed"/> is not supported!**</remarks>
/// <returns>Encoded byte data of <paramref name="trimmedImage"/></returns>
/// <exception cref="ArgumentNullException"><paramref name="colors"/> is null and <paramref name="type"/> is not <see cref="ImageType.Full32bppArgb"/> or <see cref="ImageType.Compressed32bppArgb"/>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="colors"/> is <b>null</b> and <paramref name="type"/> is not <see cref="ImageType.Full32bppArgb"/> or <see cref="ImageType.Compressed32bppArgb"/>.</exception>
/// <exception cref="NotImplementedException"><paramref name="type"/> is <see cref="ImageType.BC7Compressed"/></exception>
public static byte[] EncodeImage(Bitmap image, ImageType type, Color[] colors, out Bitmap trimmedImage, out Color[] trimmedColors)
{
if (type == ImageType.Full32bppArgb || type == ImageType.Compressed32bppArgb)
Expand All @@ -321,6 +324,11 @@ public static byte[] EncodeImage(Bitmap image, ImageType type, Color[] colors, o
return rawData;
}

if (type == ImageType.BC7Compressed)
{
throw new NotImplementedException("BC7 encoding is not supported, choose another format.");
}

byte[] mask = null;
if (colors == null)
throw new ArgumentNullException("colors", "Colors is required for all types except Full32bppArgb");
Expand Down

0 comments on commit ac11b80

Please sign in to comment.