Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::FilePNG Class Reference

Reads and writes PNG files. More...

Collaboration diagram for Burger::FilePNG:

Public Types

enum  {
  PNG_GREYSCALE =0 , PNG_RGB =2 , PNG_INDEXED =3 , PNG_GREYSCALEALPHA =4 ,
  PNG_RGBA =6
}
 

Public Member Functions

const char * SeekPNGChunk (InputMemoryStream *pInput, uint32_t uID)
 Scan a PNG file in memory and return pointer to a chunk.
 
const char * SeekNextPNGChunk (InputMemoryStream *pInput, uint32_t uID)
 Scan a PNG file in memory starting AFTER the previously found chunk and return pointer to a chunk.
 
 FilePNG ()
 Default constructor.
 
uint_t Load (Image *pOutput, InputMemoryStream *pInput)
 Parses a PNG file.
 
const RGBAWord8_tGetPalette (void) const
 Get the file image's palette.
 
RGBAWord8_tGetPalette (void)
 Get the file image's palette.
 
void SetPalette (const RGBWord8_t *pInput, uint_t uStartIndex=0, uint_t uPaletteSize=256)
 Set the file image's palette (RGB)
 
void SetPalette (const RGBAWord8_t *pInput, uint_t uStartIndex=0, uint_t uPaletteSize=256)
 Set the file image's palette (RGBA)
 

Static Public Attributes

static const uint32_t FILETYPE = 0x504E4720
 'PNG ' Mac File type for PNG files (Byte swapped on little endian machines)
 
static const uint32_t AUXTYPE = 0x6F676C65
 'ogle' Mac creator code for PNG files (Byte swapped on little endian machines)
 

Protected Member Functions

const char * SeekChunk (InputMemoryStream *pInput, uint32_t uID, uintptr_t uStartOffset)
 Scan a PNG file in memory and return pointer to a chunk.
 

Private Attributes

RGBAWord8_t m_Palette [256]
 Palette found in the image.
 
uintptr_t m_uStartOffset
 PNG file image chunk start offset.
 
uintptr_t m_uNextOffset
 Offset to the next chunk.
 
uint32_t m_uChunkSize
 Size of the current chunk in bytes.
 
uint32_t m_uPNGID
 Untouched ID of the current PNG chunk.
 

Detailed Description

Reads and writes PNG files.


This class will read and write out PNG files and use Burger::Image class instances as data transporters

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
PNG_GREYSCALE 

Each pixel is a grayscale sample.

PNG_RGB 

Each pixel is an R,G,B triple.

PNG_INDEXED 

Each pixel is a palette index;.

PNG_GREYSCALEALPHA 

Each pixel is a grayscale sample,.

PNG_RGBA 

Each pixel is an R,G,B,A quad,.

Constructor & Destructor Documentation

◆ FilePNG()

Burger::FilePNG::FilePNG ( )

Default constructor.


Initializes all extra file data to defaults

Member Function Documentation

◆ GetPalette() [1/2]

RGBAWord8_t * Burger::FilePNG::GetPalette ( void )
inline

Get the file image's palette.


Obtain a pointer to the 256 entry RGBA color palette found in the PNG file

Returns
Pointer to the 256 entry RGBAWord8_t palette
See also
Burger::FilePNG::GetPalette(void) const

◆ GetPalette() [2/2]

const RGBAWord8_t * Burger::FilePNG::GetPalette ( void ) const
inline

Get the file image's palette.


Obtain a constant pointer to the 256 entry RGBA color palette found in the PNG file

Returns
Constant pointer to the 256 entry RGBAWord8_t palette
See also
Burger::FilePNG::GetPalette(void)

◆ Load()

uint_t BURGER_API Burger::FilePNG::Load ( Image * pOutput,
InputMemoryStream * pInput )

Parses a PNG file.


Read in a PNG file and set the extra variables

Will parse 8, 16, 24 and 32 bit compressed PNG files only. Other formats are not supported

Note
A descriptive error message is passed to Debug::Warning()
Parameters
pOutputPointer to an Image record to store the new image into
pInputPointer to a memory stream that has a PNG file image
Returns
Zero for success or non-zero on failure

◆ SeekChunk()

const char * Burger::FilePNG::SeekChunk ( InputMemoryStream * pInput,
uint32_t uID,
uintptr_t uStartOffset )
protected

Scan a PNG file in memory and return pointer to a chunk.


Parameters
pInputData stream to read compressed data from
uIDPNG token to scan for (Must be upper case)
uStartOffsetOffset into the stream to begin the scan
Returns
NULL if success or a pointer to a string describing the error

◆ SeekNextPNGChunk()

const char * Burger::FilePNG::SeekNextPNGChunk ( InputMemoryStream * pInput,
uint32_t uID )

Scan a PNG file in memory starting AFTER the previously found chunk and return pointer to a chunk.


Parameters
pInputData stream to read compressed data from
uIDPNG token to scan for (Must be upper case)
Returns
NULL if success or a pointer to a string describing the error

◆ SeekPNGChunk()

const char * Burger::FilePNG::SeekPNGChunk ( InputMemoryStream * pInput,
uint32_t uID )

Scan a PNG file in memory and return pointer to a chunk.


Parameters
pInputData stream to read compressed data from
uIDPNG token to scan for (Must be upper case)
Returns
NULL if success or a pointer to a string describing the error

◆ SetPalette() [1/2]

void Burger::FilePNG::SetPalette ( const RGBAWord8_t * pInput,
uint_t uStartIndex = 0,
uint_t uPaletteSize = 256 )
inline

Set the file image's palette (RGBA)


Given a pointer to a palette, copy the colors into this class for writing to an 8 bit PNG file.

If the starting index is greater than 255, this function does nothing. If the color entry count exceeds 256 colors, the remaining colors are ignored to prevent buffer overruns

Parameters
pInputPointer to the palette to copy
uStartIndexColor index of the 256 color internal palette to start modification
uPaletteSizeNumber of color entries in the palette (Maximum 256)
See also
SetPalette(const RGBWord8_t *,uint_t,uint_t)

◆ SetPalette() [2/2]

void Burger::FilePNG::SetPalette ( const RGBWord8_t * pInput,
uint_t uStartIndex = 0,
uint_t uPaletteSize = 256 )
inline

Set the file image's palette (RGB)


Given a pointer to a palette, copy the colors into this class for writing to an 8 bit PNG file. Since the Alpha is missing from the input, each entry set will have the alpha set to zero.

If the starting index is greater than 255, this function does nothing. If the color entry count exceeds 256 colors, the remaining colors are ignored to prevent buffer overruns

Parameters
pInputPointer to the palette to copy
uStartIndexColor index of the 256 color internal palette to start modification
uPaletteSizeNumber of color entries in the palette (Maximum 256)
See also
SetPalette(const RGBAWord8_t *,uint_t,uint_t)

Member Data Documentation

◆ AUXTYPE

const uint32_t Burger::FilePNG::AUXTYPE = 0x6F676C65
static

'ogle' Mac creator code for PNG files (Byte swapped on little endian machines)

◆ FILETYPE

const uint32_t Burger::FilePNG::FILETYPE = 0x504E4720
static

'PNG ' Mac File type for PNG files (Byte swapped on little endian machines)

◆ m_Palette

RGBAWord8_t Burger::FilePNG::m_Palette[256]
private

Palette found in the image.

◆ m_uChunkSize

uint32_t Burger::FilePNG::m_uChunkSize
private

Size of the current chunk in bytes.

◆ m_uNextOffset

uintptr_t Burger::FilePNG::m_uNextOffset
private

Offset to the next chunk.

◆ m_uPNGID

uint32_t Burger::FilePNG::m_uPNGID
private

Untouched ID of the current PNG chunk.

◆ m_uStartOffset

uintptr_t Burger::FilePNG::m_uStartOffset
private

PNG file image chunk start offset.