Skip to content

Commit

Permalink
Exposed SPNG version externally. Cleaned up the SPNG define. SPNG is …
Browse files Browse the repository at this point in the history
…currently enabled for loading/saving of (non-animated) PNG files, and LibPNG is still used for apngasm and apngdis (animated pngs).
  • Loading branch information
bluescan committed Feb 7, 2024
1 parent 92087aa commit 6b8e3f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Modules/Image/Inc/Image/tPicture.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ extern int Version_BCDec_Major;
extern int Version_BCDec_Minor;
extern int Version_ETCDec_Major;
extern int Version_ETCDec_Minor;
extern int Version_SPNG_Major;
extern int Version_SPNG_Minor;
extern int Version_SPNG_Patch;
extern int Version_TinyXML2_Major;
extern int Version_TinyXML2_Minor;
extern int Version_TinyXML2_Patch;
Expand Down
29 changes: 18 additions & 11 deletions Modules/Image/Src/tImagePNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
//
// The loading and saving code in here is roughly based on the example code from the LibPNG library. The licence may be
// found in the file Licence_LibPNG.txt.
// The loading and saving code in here is roughly based on the example code from the LibPNG and SPNG libraries. The
// licences may be found in Licence_LibPNG.txt and Licence_LibSPNG.txt.

#include <Foundation/tArray.h>
#include <System/tFile.h>

// This define chooses between using LibPNG (the original png library) or the slightly cleaner/newer LibSPNG. While the
// interface for SPNG isn't that much different, I did notice SPNG loads 16-bpc PNG files without multiplying the alpha
// channel into the colours -- this is the desired behaviour and so SPNG is enabled. Note that apngasm and apngdis
// depend on LibPNG, so we are keeping LibPNG around until SPNG supports animated PNGs. This is apparently work in
// progress as of 2024.02.06.
#define USE_SPNG_LIBRARY
#ifndef USE_SPNG_LIBRARY
#include "png.h"
#include "spng.h" // Testing the spng library.
#else
#include "spng.h"
#endif

#include "Image/tImagePNG.h"
#include "Image/tImageJPG.h" // Because some jpg/jfif files have a png extension in the wild. Scary but true.
#include "Image/tPicture.h"
Expand Down Expand Up @@ -48,8 +59,7 @@ bool tImagePNG::Load(const tString& pngFile, const LoadParams& params)
}


//#define USE_LIBPNG_LOAD
#ifdef USE_LIBPNG_LOAD
#ifndef USE_SPNG_LIBRARY
bool tImagePNG::Load(const uint8* pngFileInMemory, int numBytes, const LoadParams& paramsIn)
{
Clear();
Expand Down Expand Up @@ -212,8 +222,7 @@ bool tImagePNG::Load(const uint8* pngFileInMemory, int numBytes, const LoadParam
#endif


#define USE_SPNG_LOAD
#ifdef USE_SPNG_LOAD
#ifdef USE_SPNG_LIBRARY
bool tImagePNG::Load(const uint8* pngFileInMemory, int numBytes, const LoadParams& paramsIn)
{
Clear();
Expand Down Expand Up @@ -507,8 +516,7 @@ tImagePNG::tFormat tImagePNG::Save(const tString& pngFile, tFormat format) const
}


//#define USE_LIBPNG_SAVE
#ifdef USE_LIBPNG_SAVE
#ifndef USE_SPNG_LIBRARY
tImagePNG::tFormat tImagePNG::Save(const tString& pngFile, const SaveParams& params) const
{
if (!IsValid())
Expand Down Expand Up @@ -713,8 +721,7 @@ tImagePNG::tFormat tImagePNG::Save(const tString& pngFile, const SaveParams& par
#endif


#define USE_SPNG_SAVE
#ifdef USE_SPNG_SAVE
#ifdef USE_SPNG_LIBRARY
tImagePNG::tFormat tImagePNG::Save(const tString& pngFile, const SaveParams& params) const
{
if (!IsValid())
Expand Down
4 changes: 4 additions & 0 deletions Modules/Image/Src/tPicture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const char* ASTCENCODER_VERSION_STRING = VERSION_STRING;
#include "Math/tLinearAlgebra.h"
#include <OpenEXR/loadImage.h>
#include <zlib.h>
#include <spng.h>
#include <png.h>
#include <apngdis.h>
#include <apngasm.h>
Expand Down Expand Up @@ -68,6 +69,9 @@ int tImage::Version_BCDec_Major = BCDEC_VERSION_MAJOR;
int tImage::Version_BCDec_Minor = BCDEC_VERSION_MINOR;
int tImage::Version_ETCDec_Major = ETCDEC_VERSION_MAJOR;
int tImage::Version_ETCDec_Minor = ETCDEC_VERSION_MINOR;
int tImage::Version_SPNG_Major = SPNG_VERSION_MAJOR;
int tImage::Version_SPNG_Minor = SPNG_VERSION_MINOR;
int tImage::Version_SPNG_Patch = SPNG_VERSION_PATCH;
int tImage::Version_TinyXML2_Major = TINYXML2_MAJOR_VERSION;
int tImage::Version_TinyXML2_Minor = TINYXML2_MINOR_VERSION;
int tImage::Version_TinyXML2_Patch = TINYXML2_PATCH_VERSION;
Expand Down

0 comments on commit 6b8e3f7

Please sign in to comment.