Files
UnrealEngineUWP/Engine/Source/Runtime/ImageWrapper/Private/Formats/PngImageWrapper.h
charles bloom 04ffabc485 ImageWrapper and import/export refactor
FImage is now the standard preferred type for a bag of pixels
FImageView can point at pixels without owning an allocation
ERawImageFormat (FImage) converts to ETextureSourceFormat
FImageUtils provides generic load/save and get/set from FImage
major cleanup in the ImageWrappers
new preferred API is through ImageWrapperModule Compress/Decompress
SetRaw/GetRaw functions cleaned up to not have undefined behavior on unexpected formats
ImageWrapper output added for HDR,BMP,TGA
RGBA32F format added and supported throughout import/export
EditorFactories import/export made more generic, most image types handled the same way using FImage now
Deprecate old TSF RGBA order pixel formats
Fix many crashes or bad handling of unusual pixel formats
Pixel access functions should be used instead of switches on pixel type

#preflight 6230ade7e65a7e65d68a187c
#rb julien.stjean,martins.mozeiko,dan.thompson,fabian.giesen

[CL 19397199 by charles bloom in ue5-main branch]
2022-03-15 18:29:37 -04:00

106 lines
3.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreTypes.h"
#include "ImageWrapperBase.h"
#if WITH_UNREALPNG
THIRD_PARTY_INCLUDES_START
#include "ThirdParty/zlib/zlib-1.2.5/Inc/zlib.h"
// make sure no other versions of libpng headers are picked up
#if WITH_LIBPNG_1_6
#include "ThirdParty/libPNG/libPNG-1.6.37/png.h"
#include "ThirdParty/libPNG/libPNG-1.6.37/pngstruct.h"
#include "ThirdParty/libPNG/libPNG-1.6.37/pnginfo.h"
#else
#include "ThirdParty/libPNG/libPNG-1.5.2/png.h"
#include "ThirdParty/libPNG/libPNG-1.5.2/pnginfo.h"
#endif
#include <setjmp.h>
THIRD_PARTY_INCLUDES_END
/**
* PNG implementation of the helper class.
*
* The implementation of this class is almost entirely based on the sample from the libPNG documentation.
* See http://www.libpng.org/pub/png/libpng-1.2.5-manual.html for details.
*
* InitCompressed and InitRaw will set initial state and you will then be able to fill in Raw or
* CompressedData by calling Uncompress or Compress respectively.
*/
class FPngImageWrapper
: public FImageWrapperBase
{
public:
/** Default Constructor. */
FPngImageWrapper();
public:
//~ FImageWrapper interface
virtual void Compress(int32 Quality) override;
virtual void Reset() override;
virtual bool SetCompressed(const void* InCompressedData, int64 InCompressedSize) override;
virtual void Uncompress(const ERGBFormat InFormat, int32 InBitDepth) override;
virtual bool CanSetRawFormat(const ERGBFormat InFormat, const int32 InBitDepth) const override;
virtual ERawImageFormat::Type GetSupportedRawFormat(const ERawImageFormat::Type InFormat) const override;
public:
/**
* Query whether this is a valid PNG type.
*
* @return true if data a PNG
*/
bool IsPNG() const;
/**
* Load the header information, returns true if successful.
*
* @return true if successful
*/
bool LoadPNGHeader();
/** Helper function used to uncompress PNG data from a buffer */
void UncompressPNGData(const ERGBFormat InFormat, const int32 InBitDepth);
protected:
// Callbacks for the pnglibs
static void user_read_compressed(png_structp png_ptr, png_bytep data, png_size_t length);
static void user_write_compressed(png_structp png_ptr, png_bytep data, png_size_t length);
static void user_flush_data(png_structp png_ptr);
static void user_error_fn(png_structp png_ptr, png_const_charp error_msg);
static void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg);
static void* user_malloc(png_structp png_ptr, png_size_t size);
static void user_free(png_structp png_ptr, png_voidp struct_ptr);
private:
/** The read offset into our array. */
int64 ReadOffset;
/** The color type as defined in the header. */
int32 ColorType;
/** The number of channels. */
uint8 Channels;
#if PLATFORM_ANDROID
//Other platforms rely on libPNG internal mechanism to achieve concurrent compression\decompression on multiple threads
/** setjmp buffer for error recovery. */
jmp_buf SetjmpBuffer;
#endif
};
#endif //WITH_UNREALPNG