source/Graphics/ImageLoader.cpp: use the new File API
This commit is contained in:
parent
dc04a12922
commit
1a43bcd77a
1 changed files with 8 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
#include <Spectre/System/File.h>
|
||||
#include <Spectre/System/Path.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
#include <Spectre/Graphics/Image.h>
|
||||
|
|
@ -18,22 +19,17 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
bool ImageLoader::loadFromFile(const char *filename, Image& img)
|
||||
{
|
||||
FILE *fd = fopen(filename, "rb");
|
||||
File file(filename);
|
||||
|
||||
if (fd) {
|
||||
if (file.isOpen()) {
|
||||
std::vector<unsigned char> buf;
|
||||
fseek(fd, 0, SEEK_END);
|
||||
buf.resize(ftell(fd));
|
||||
rewind(fd);
|
||||
fread(&buf[0], 1, buf.size(), fd);
|
||||
fclose(fd);
|
||||
file.read(buf);
|
||||
|
||||
// loaded into memory. now decode.
|
||||
if (decode((const char*)&buf[0], buf.size(), img) == false) {
|
||||
|
|
@ -45,7 +41,7 @@ bool ImageLoader::loadFromFile(const char *filename, Image& img)
|
|||
}
|
||||
|
||||
Log::warn("ImageLoader: could not open file '%s'. Reason: %s",
|
||||
filename, strerror(errno));
|
||||
filename, file.getErrorMessage().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -78,10 +74,9 @@ bool ImageLoader::saveToFile(const Image& img, const char *filename)
|
|||
|
||||
if (encoded_data.size() > 0) {
|
||||
|
||||
FILE *fd = fopen(filename, "wb");
|
||||
if (fd) {
|
||||
fwrite(&encoded_data[0], 1, encoded_data.size(), fd);
|
||||
fclose(fd);
|
||||
File file(filename, File::Access::WRITE);
|
||||
if (file.isOpen()) {
|
||||
file.write(encoded_data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue