Final Cleanup

-Removed LPNG
-Removed LJPEG
-Re-Added DefferredPNGWriter from rextimmy stb work

Commented out lines about file saving and reading in gfont, these are good for debugging font saves.
This commit is contained in:
marauder2k7 2024-01-23 08:47:26 +00:00
parent 68a7dadd2b
commit d87199f5da
635 changed files with 134 additions and 227025 deletions

View file

@ -64,4 +64,23 @@ namespace ImageUtil
U32 getMaxMipCount(const U32 width, const U32 height);
};
#endif
struct DeferredPNGWriterData;
class Stream;
class GBitmap;
class DeferredPNGWriter
{
protected:
DeferredPNGWriterData* mData;
bool mActive;
public:
DeferredPNGWriter();
~DeferredPNGWriter();
bool begin(GFXFormat format, S32 width, S32 height, Stream& stream);
void append(GBitmap* bitmap, U32 rows);
void end();
};
#endif

View file

@ -27,6 +27,7 @@
#include "core/stream/memStream.h"
#include "core/strings/stringFunctions.h"
#include "gfx/bitmap/gBitmap.h"
#include "gfx/bitmap/imageUtils.h"
#ifdef __clang__
#define STBIWDEF static inline
@ -380,3 +381,89 @@ bool sWriteStreamSTB(const String& bmType, Stream& stream, GBitmap* bitmap, U32
return false;
}
struct DeferredPNGWriterData
{
S32 width = 0;
S32 height = 0;
S32 channels = 0;
dsize_t offset = 0;
U8* pPixelData = NULL;
GFXFormat format;
Stream* pStream = NULL;
};
DeferredPNGWriter::DeferredPNGWriter() :
mData(NULL),
mActive(false)
{
mData = new DeferredPNGWriterData();
}
DeferredPNGWriter::~DeferredPNGWriter()
{
if (mData)
{
SAFE_DELETE_ARRAY(mData->pPixelData);
}
SAFE_DELETE(mData);
}
bool DeferredPNGWriter::begin(GFXFormat format, S32 width, S32 height, Stream& stream)
{
// ONLY RGB bitmap writing supported at this time!
AssertFatal(format == GFXFormatR8G8B8 ||
format == GFXFormatR8G8B8A8 ||
format == GFXFormatR8G8B8X8 ||
format == GFXFormatA8 ||
format == GFXFormatR5G6B5, "DeferredPNGWriter::begin: ONLY RGB bitmap writing supported at this time.");
if (format != GFXFormatR8G8B8 &&
format != GFXFormatR8G8B8A8 &&
format != GFXFormatR8G8B8X8 &&
format != GFXFormatA8 &&
format != GFXFormatR5G6B5)
{
return false;
}
mData->pStream = &stream;
mData->width = width;
mData->height = height;
mData->format = format;
const size_t dataSize = GFXFormat_getByteSize(format) * width * height;
mData->pPixelData = new U8[dataSize];
mActive = true;
return true;
}
void DeferredPNGWriter::append(GBitmap* bitmap, U32 rows)
{
AssertFatal(mActive, "Cannot append to an inactive DeferredPNGWriter!");
if (mData->channels == 0)
{
mData->channels = bitmap->getBytesPerPixel();
}
const U32 height = getMin(bitmap->getHeight(), rows);
const dsize_t dataChuckSize = bitmap->getByteSize();
const U8* pSrcData = bitmap->getBits();
U8* pDstData = mData->pPixelData + mData->offset;
dMemcpy(pDstData, pSrcData, dataChuckSize);
mData->offset += dataChuckSize;
}
void DeferredPNGWriter::end()
{
AssertFatal(mActive, "Cannot end an inactive DeferredPNGWriter!");
stbi_write_png_to_func(stbiWriteFunc, mData->pStream, mData->width, mData->height, mData->channels, mData->pPixelData, mData->width * mData->channels);
mActive = false;
}

View file

@ -1,49 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _PNG_UTILS_H_
#define _PNG_UTILS_H_
#ifndef _GFXENUMS_H_
#include "gfx/gfxEnums.h"
#endif
struct DeferredPNGWriterData; // This is used to avoid including png.h in this header
class GBitmap;
class Stream;
/// This class is used to write PNGs in row batches
class DeferredPNGWriter {
protected:
DeferredPNGWriterData *mData;
bool mActive;
public:
DeferredPNGWriter();
~DeferredPNGWriter();
bool begin( GFXFormat format, S32 width, S32 height, Stream &stream, U32 compressionLevel );
void append( GBitmap* bitmap, U32 rows );
void end();
};
#endif