mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-27 22:14:16 +01:00
Fix our threadsafe streambuf to accept a sink that receives all of the proper output...
This commit is contained in:
parent
f1924bd221
commit
c3cb8403b5
@ -41,14 +41,17 @@
|
||||
* <http://gamma.cs.unc.edu/FasTC/>
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "BlockStats.h"
|
||||
#include "TexComp.h"
|
||||
#include "ImageFile.h"
|
||||
#include "Image.h"
|
||||
#include "ImageFile.h"
|
||||
#include "TexComp.h"
|
||||
#include "ThreadSafeStreambuf.h"
|
||||
|
||||
void PrintUsage() {
|
||||
fprintf(stderr, "Usage: tc [OPTIONS] imagefile\n");
|
||||
@ -210,10 +213,13 @@ int main(int argc, char **argv) {
|
||||
img.SetBlockStreamOrder(false);
|
||||
}
|
||||
|
||||
int numBlocks = (img.GetWidth() * img.GetHeight())/16;
|
||||
BlockStatManager *statManager = NULL;
|
||||
std::ofstream logFile;
|
||||
ThreadSafeStreambuf streamBuf(std::cout);
|
||||
std::ostream logStream(&streamBuf);
|
||||
if(bSaveLog) {
|
||||
statManager = new BlockStatManager(numBlocks);
|
||||
char logname[256];
|
||||
sprintf(logname, "%s.log", basename);
|
||||
logFile.open(logname);
|
||||
}
|
||||
|
||||
SCompressionSettings settings;
|
||||
@ -224,7 +230,7 @@ int main(int argc, char **argv) {
|
||||
settings.iQuality = quality;
|
||||
settings.iNumCompressions = numCompressions;
|
||||
settings.iJobSize = numJobs;
|
||||
settings.pStatManager = statManager;
|
||||
settings.logStream = &logStream;
|
||||
|
||||
CompressedImage *ci = CompressImage(&img, settings);
|
||||
if(NULL == ci) {
|
||||
@ -240,12 +246,6 @@ int main(int argc, char **argv) {
|
||||
fprintf(stderr, "Error computing PSNR\n");
|
||||
}
|
||||
|
||||
if(bSaveLog) {
|
||||
char logname[256];
|
||||
sprintf(logname, "%s.log", basename);
|
||||
statManager->ToFile(logname);
|
||||
}
|
||||
|
||||
if(format == eCompressionFormat_BPTC) {
|
||||
strcat(basename, "-bc7.png");
|
||||
} else if(format == eCompressionFormat_PVRTC) {
|
||||
@ -257,8 +257,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Cleanup
|
||||
delete ci;
|
||||
if(statManager)
|
||||
delete statManager;
|
||||
|
||||
if(bSaveLog) {
|
||||
logFile.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -57,18 +57,20 @@
|
||||
class TCMutex;
|
||||
|
||||
#include <streambuf>
|
||||
#include <iosfwd>
|
||||
|
||||
class ThreadSafeStreambuf : public ::std::streambuf {
|
||||
public:
|
||||
ThreadSafeStreambuf();
|
||||
ThreadSafeStreambuf(std::ostream &sink);
|
||||
virtual ~ThreadSafeStreambuf();
|
||||
|
||||
protected:
|
||||
virtual std::streamsize xsputn(const char_type *s, std::streamsize count);
|
||||
|
||||
private:
|
||||
// Not implemented -- not allowed...
|
||||
ThreadSafeStreambuf(const ThreadSafeStreambuf &);
|
||||
ThreadSafeStreambuf &operator=(const ThreadSafeStreambuf &);
|
||||
std::ostream &m_Sink;
|
||||
TCMutex *m_Mutex;
|
||||
};
|
||||
|
||||
|
@ -53,14 +53,19 @@
|
||||
#include "ThreadSafeStreambuf.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "Thread.h"
|
||||
|
||||
ThreadSafeStreambuf::ThreadSafeStreambuf()
|
||||
ThreadSafeStreambuf::ThreadSafeStreambuf(std::ostream &sink)
|
||||
: ::std::streambuf()
|
||||
, m_Sink(sink)
|
||||
, m_Mutex(new TCMutex)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
ThreadSafeStreambuf::~ThreadSafeStreambuf() {
|
||||
if(m_Mutex) {
|
||||
@ -72,7 +77,6 @@ ThreadSafeStreambuf::~ThreadSafeStreambuf() {
|
||||
::std::streamsize count) {
|
||||
// Lock it.
|
||||
TCLock lock(*m_Mutex);
|
||||
// then just do what you would have done...
|
||||
return ::std::streambuf::xsputn(s, count);
|
||||
::std::streambuf *sinkStream = m_Sink.rdbuf();
|
||||
return sinkStream->sputn(s, count);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user