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

View file

@ -740,7 +740,7 @@ bool GFont::read(Stream& io_rStream)
io_rStream.read(buffLen, inBuff);
// Decompress.
uLongf destLen = (maxGlyph-minGlyph+1)*sizeof(S32);
uLongf destLen = (static_cast<unsigned long long>(maxGlyph) - minGlyph + 1) * sizeof(S32);
uncompress((Bytef*)&mRemapTable[minGlyph], &destLen, (Bytef*)(S32*)inBuff, buffLen);
AssertISV(destLen == (maxGlyph-minGlyph+1)*sizeof(S32), "GFont::read - invalid remap table data!");
@ -787,8 +787,8 @@ bool GFont::write(Stream& stream)
stream.write(mTextureSheets.size());
for (i = 0; i < mTextureSheets.size(); i++)
{
String path = String::ToString("%s/%s %d %d (%s).png", Con::getVariable("$GUI::fontCacheDirectory"), mFaceName.c_str(), mSize, i, getCharSetName(mCharSet));
//mTextureSheets[i].getBitmap()->writeBitmap("png", path);
/*String path = String::ToString("%s/%s %d %d (%s).png", Con::getVariable("$GUI::fontCacheDirectory"), mFaceName.c_str(), mSize, i, getCharSetName(mCharSet));
mTextureSheets[i].getBitmap()->writeBitmap("png", path);*/
mTextureSheets[i].getBitmap()->writeBitmapStream("png", stream);
}
@ -824,7 +824,7 @@ bool GFont::write(Stream& stream)
const U32 buffSize = 128 * 1024;
FrameTemp<S32> outBuff(buffSize);
uLongf destLen = buffSize * sizeof(S32);
compress2((Bytef*)(S32*)outBuff, &destLen, (Bytef*)(S32*)&mRemapTable[minGlyph], (maxGlyph-minGlyph+1)*sizeof(S32), 9);
compress2((Bytef*)(S32*)outBuff, &destLen, (Bytef*)(S32*)&mRemapTable[minGlyph], (static_cast<unsigned long long>(maxGlyph) - minGlyph + 1) * sizeof(S32), 9);
// Write out.
stream.write((U32)destLen);
@ -1086,6 +1086,7 @@ DefineEngineFunction( populateFontCacheRange, void, ( const char *faceName, S32
}
// This has the side effect of generating character info, including the bitmaps.
Con::printf(" o Populating font '%s'", faceName);
for(U32 i=rangeStart; i<rangeEnd; i++)
{
if(f->isValidChar(i))

View file

@ -26,7 +26,7 @@
#include "math/util/frustum.h"
#include "core/stream/fileStream.h"
#include "gui/core/guiCanvas.h"
#include "gfx/bitmap/pngUtils.h"
#include "gfx/bitmap/imageUtils.h"
#include "console/engineAPI.h"
@ -126,6 +126,13 @@ void ScreenShot::capture( GuiCanvas *canvas )
// Open up the file on disk.
dSprintf( filename, 256, "%s.%s", mFilename, "png" );
FileStream fs;
if (!fs.open(filename, Torque::FS::File::Write))
Con::errorf("ScreenShot::capture() - Failed to open output file '%s'!", filename);
// Open a PNG stream for the final image
DeferredPNGWriter pngWriter;
pngWriter.begin(outBuffer->getFormat(), outBuffer->getWidth(), canvasSize.y * mTiles - overlapPixels.y * mTiles * 2, fs);
//// Render each tile to generate a huge screenshot.
for (U32 ty = 0; ty < mTiles; ty++)
@ -192,9 +199,20 @@ void ScreenShot::capture( GuiCanvas *canvas )
delete gb;
}
// Write the captured tile row into the PNG stream
pngWriter.append(outBuffer, outBuffer->getHeight() - overlapPixels.y);
}
outBuffer->writeBitmap("png", filename);
//Close the PNG stream
pngWriter.end();
fs.close();
if(mWriteJPG)
outBuffer->writeBitmap("jpg", filename);
else
outBuffer->writeBitmap("png", filename);
// We captured... clear the flag.
mPending = false;