mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-03 04:20:30 +00:00
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:
parent
68a7dadd2b
commit
d87199f5da
635 changed files with 134 additions and 227025 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue