2016-03-01 15:47:10 +00:00
|
|
|
#ifndef __M_PNG_H
|
|
|
|
#define __M_PNG_H
|
|
|
|
/*
|
|
|
|
** m_png.h
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2002-2005 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
|
2017-03-09 22:30:42 +00:00
|
|
|
class FileReader;
|
|
|
|
class FileWriter;
|
2016-03-01 15:47:10 +00:00
|
|
|
// PNG Writing --------------------------------------------------------------
|
|
|
|
|
|
|
|
// Start writing an 8-bit palettized PNG file.
|
|
|
|
// The passed file should be a newly created file.
|
|
|
|
// This function writes the PNG signature and the IHDR, gAMA, PLTE, and IDAT
|
|
|
|
// chunks.
|
2017-03-08 17:47:52 +00:00
|
|
|
bool M_CreatePNG (FileWriter *file, const uint8_t *buffer, const PalEntry *pal,
|
2016-03-01 15:47:10 +00:00
|
|
|
ESSType color_type, int width, int height, int pitch);
|
|
|
|
|
|
|
|
// Creates a grayscale 1x1 PNG file. Used for savegames without savepics.
|
2016-09-21 07:01:12 +00:00
|
|
|
bool M_CreateDummyPNG (FileWriter *file);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Appends any chunk to a PNG file started with M_CreatePNG.
|
2017-03-08 17:47:52 +00:00
|
|
|
bool M_AppendPNGChunk (FileWriter *file, uint32_t chunkID, const uint8_t *chunkData, uint32_t len);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Adds a tEXt chunk to a PNG file started with M_CreatePNG.
|
2016-09-21 07:01:12 +00:00
|
|
|
bool M_AppendPNGText (FileWriter *file, const char *keyword, const char *text);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Appends the IEND chunk to a PNG file.
|
2016-09-21 07:01:12 +00:00
|
|
|
bool M_FinishPNG (FileWriter *file);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-03-08 17:47:52 +00:00
|
|
|
bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height, int pitch, FileWriter *file);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// PNG Reading --------------------------------------------------------------
|
|
|
|
|
|
|
|
class FileReader;
|
|
|
|
struct PNGHandle
|
|
|
|
{
|
|
|
|
struct Chunk
|
|
|
|
{
|
2017-03-08 17:47:52 +00:00
|
|
|
uint32_t ID;
|
|
|
|
uint32_t Offset;
|
|
|
|
uint32_t Size;
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
FileReader *File;
|
|
|
|
bool bDeleteFilePtr;
|
|
|
|
TArray<Chunk> Chunks;
|
|
|
|
TArray<char *> TextChunks;
|
|
|
|
unsigned int ChunkPt;
|
|
|
|
|
|
|
|
PNGHandle(FILE *file);
|
2016-09-21 19:57:24 +00:00
|
|
|
PNGHandle(FileReader *file, bool takereader = false);
|
2016-03-01 15:47:10 +00:00
|
|
|
~PNGHandle();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that a file really is a PNG file. This includes not only checking
|
|
|
|
// the signature, but also checking for the IEND chunk. CRC checking of
|
|
|
|
// each chunk is not done. If it is valid, you get a PNGHandle to pass to
|
|
|
|
// the following functions.
|
2016-09-21 19:57:24 +00:00
|
|
|
PNGHandle *M_VerifyPNG (FileReader *file, bool takereader = false);
|
2016-03-01 15:47:10 +00:00
|
|
|
PNGHandle *M_VerifyPNG (FILE *file);
|
|
|
|
|
|
|
|
// Finds a chunk in a PNG file. The file pointer will be positioned at the
|
|
|
|
// beginning of the chunk data, and its length will be returned. A return
|
|
|
|
// value of 0 indicates the chunk was either not present or had 0 length.
|
2017-03-08 17:47:52 +00:00
|
|
|
unsigned int M_FindPNGChunk (PNGHandle *png, uint32_t chunkID);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Finds a chunk in the PNG file, starting its search at whatever chunk
|
|
|
|
// the file pointer is currently positioned at.
|
2017-03-08 17:47:52 +00:00
|
|
|
unsigned int M_NextPNGChunk (PNGHandle *png, uint32_t chunkID);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Finds a PNG text chunk with the given signature and returns a pointer
|
|
|
|
// to a NULL-terminated string if present. Returns NULL on failure.
|
|
|
|
// (Note: tEXt, not zTXt.)
|
|
|
|
char *M_GetPNGText (PNGHandle *png, const char *keyword);
|
|
|
|
bool M_GetPNGText (PNGHandle *png, const char *keyword, char *buffer, size_t buffsize);
|
|
|
|
|
|
|
|
// The file must be positioned at the start of the first IDAT. It reads
|
|
|
|
// image data into the provided buffer. Returns true on success.
|
2017-03-08 17:47:52 +00:00
|
|
|
bool M_ReadIDAT (FileReader *file, uint8_t *buffer, int width, int height, int pitch,
|
|
|
|
uint8_t bitdepth, uint8_t colortype, uint8_t interlace, unsigned int idatlen);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FTexture;
|
|
|
|
|
|
|
|
FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename);
|
|
|
|
|
|
|
|
#endif
|