mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-23 19:51:19 +00:00
More formatting fixes.
This commit is contained in:
parent
9d4f412f65
commit
081866907f
|
@ -91,21 +91,21 @@ ImageFile::ImageFile(const CHAR *filename)
|
||||||
: m_FileFormat( DetectFileFormat(filename) )
|
: m_FileFormat( DetectFileFormat(filename) )
|
||||||
, m_Image(NULL)
|
, m_Image(NULL)
|
||||||
{
|
{
|
||||||
strncpy(m_Filename, filename, kMaxFilenameSz);
|
strncpy(m_Filename, filename, kMaxFilenameSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageFile::ImageFile(const CHAR *filename, EImageFileFormat format)
|
ImageFile::ImageFile(const CHAR *filename, EImageFileFormat format)
|
||||||
: m_FileFormat(format)
|
: m_FileFormat(format)
|
||||||
, m_Image(NULL)
|
, m_Image(NULL)
|
||||||
{
|
{
|
||||||
strncpy(m_Filename, filename, kMaxFilenameSz);
|
strncpy(m_Filename, filename, kMaxFilenameSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageFile::ImageFile(const char *filename, EImageFileFormat format, const Image &image)
|
ImageFile::ImageFile(const char *filename, EImageFileFormat format, const Image &image)
|
||||||
: m_FileFormat(format)
|
: m_FileFormat(format)
|
||||||
, m_Image(new Image(image))
|
, m_Image(new Image(image))
|
||||||
{
|
{
|
||||||
strncpy(m_Filename, filename, kMaxFilenameSz);
|
strncpy(m_Filename, filename, kMaxFilenameSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageFile::~ImageFile() {
|
ImageFile::~ImageFile() {
|
||||||
|
@ -117,50 +117,48 @@ ImageFile::~ImageFile() {
|
||||||
|
|
||||||
bool ImageFile::Load() {
|
bool ImageFile::Load() {
|
||||||
|
|
||||||
if(m_Image) {
|
if(m_Image) {
|
||||||
delete m_Image;
|
delete m_Image;
|
||||||
m_Image = NULL;
|
m_Image = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *rawData = ReadFileData(m_Filename);
|
unsigned char *rawData = ReadFileData(m_Filename);
|
||||||
if(rawData) {
|
if(rawData) {
|
||||||
m_Image = LoadImage(rawData);
|
m_Image = LoadImage(rawData);
|
||||||
delete [] rawData;
|
delete [] rawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_Image != NULL;
|
return m_Image != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageFile::Write() {
|
bool ImageFile::Write() {
|
||||||
|
|
||||||
ImageWriter *writer = NULL;
|
ImageWriter *writer = NULL;
|
||||||
switch(m_FileFormat) {
|
switch(m_FileFormat) {
|
||||||
|
|
||||||
#ifdef PNG_FOUND
|
#ifdef PNG_FOUND
|
||||||
case eFileFormat_PNG:
|
case eFileFormat_PNG:
|
||||||
{
|
writer = new ImageWriterPNG(*m_Image);
|
||||||
writer = new ImageWriterPNG(*m_Image);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
#endif // PNG_FOUND
|
#endif // PNG_FOUND
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unable to write image: unknown file format.\n");
|
fprintf(stderr, "Unable to write image: unknown file format.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == writer)
|
if(NULL == writer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!writer->WriteImage()) {
|
if(!writer->WriteImage()) {
|
||||||
delete writer;
|
delete writer;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteImageDataToFile(writer->GetRawFileData(), uint32(writer->GetRawFileDataSz()), m_Filename);
|
WriteImageDataToFile(writer->GetRawFileData(), uint32(writer->GetRawFileDataSz()), m_Filename);
|
||||||
|
|
||||||
delete writer;
|
delete writer;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image *ImageFile::LoadImage(const unsigned char *rawImageData) const {
|
Image *ImageFile::LoadImage(const unsigned char *rawImageData) const {
|
||||||
|
@ -170,9 +168,7 @@ Image *ImageFile::LoadImage(const unsigned char *rawImageData) const {
|
||||||
|
|
||||||
#ifdef PNG_FOUND
|
#ifdef PNG_FOUND
|
||||||
case eFileFormat_PNG:
|
case eFileFormat_PNG:
|
||||||
{
|
loader = new ImageLoaderPNG(rawImageData);
|
||||||
loader = new ImageLoaderPNG(rawImageData);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
#endif // PNG_FOUND
|
#endif // PNG_FOUND
|
||||||
|
|
||||||
|
@ -245,8 +241,8 @@ unsigned char *ImageFile::ReadFileData(const CHAR *filename) {
|
||||||
uint64 totalBytesLeft = fileSize;
|
uint64 totalBytesLeft = fileSize;
|
||||||
int32 bytesRead;
|
int32 bytesRead;
|
||||||
while((bytesRead = fstr.Read(rawData, uint32(fileSize))) > 0) {
|
while((bytesRead = fstr.Read(rawData, uint32(fileSize))) > 0) {
|
||||||
totalBytesRead += bytesRead;
|
totalBytesRead += bytesRead;
|
||||||
totalBytesLeft -= bytesRead;
|
totalBytesLeft -= bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(totalBytesRead != fileSize) {
|
if(totalBytesRead != fileSize) {
|
||||||
|
@ -259,16 +255,18 @@ unsigned char *ImageFile::ReadFileData(const CHAR *filename) {
|
||||||
return rawData;
|
return rawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageFile::WriteImageDataToFile(const uint8 *data, const uint32 dataSz, const CHAR *filename) {
|
bool ImageFile::WriteImageDataToFile(const uint8 *data,
|
||||||
|
const uint32 dataSz,
|
||||||
|
const CHAR *filename) {
|
||||||
|
|
||||||
// Open a file stream and write out the data...
|
// Open a file stream and write out the data...
|
||||||
FileStream fstr (filename, eFileMode_WriteBinary);
|
FileStream fstr (filename, eFileMode_WriteBinary);
|
||||||
if(fstr.Tell() < 0) {
|
if(fstr.Tell() < 0) {
|
||||||
fprintf(stderr, "Error opening file for reading: %s\n", filename);
|
fprintf(stderr, "Error opening file for reading: %s\n", filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fstr.Write(data, dataSz);
|
fstr.Write(data, dataSz);
|
||||||
fstr.Flush();
|
fstr.Flush();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue