|
@@ -5,16 +5,19 @@
|
|
#include "images/PNGReader.h"
|
|
#include "images/PNGReader.h"
|
|
|
|
|
|
PNGReader::PNGReader(const char* path)
|
|
PNGReader::PNGReader(const char* path)
|
|
- : path(path), width(0), height(0), channels(0), bitDepth(0), rowBytes(0), file(fopen(path, "r")), read(nullptr),
|
|
|
|
- info(nullptr), rowPointers(nullptr) {
|
|
|
|
|
|
+ : path(path), width(0), height(0), channels(0), bitDepth(0), rowBytes(0),
|
|
|
|
+ file(fopen(path, "r")), read(nullptr), info(nullptr),
|
|
|
|
+ rowPointers(nullptr) {
|
|
if(file == nullptr) {
|
|
if(file == nullptr) {
|
|
- std::cout << "file '" << path << "' cannot be read: " << strerror(errno) << "\n";
|
|
|
|
|
|
+ std::cout << "file '" << path << "' cannot be read: " << strerror(errno)
|
|
|
|
+ << "\n";
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if(checkSignature()) {
|
|
if(checkSignature()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- read = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
|
|
|
|
|
+ read = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr,
|
|
|
|
+ nullptr);
|
|
if(read == nullptr) {
|
|
if(read == nullptr) {
|
|
std::cout << "cannot create png read data structure\n";
|
|
std::cout << "cannot create png read data structure\n";
|
|
return;
|
|
return;
|
|
@@ -67,12 +70,14 @@ int PNGReader::getChannels() const {
|
|
}
|
|
}
|
|
|
|
|
|
int PNGReader::getBufferSize() const {
|
|
int PNGReader::getBufferSize() const {
|
|
- return width * height;
|
|
|
|
|
|
+ return width * height * channels;
|
|
}
|
|
}
|
|
|
|
|
|
bool PNGReader::hasError() const {
|
|
bool PNGReader::hasError() const {
|
|
if(channels < 1 || channels > 4) {
|
|
if(channels < 1 || channels > 4) {
|
|
- std::cout << "'" << path << "' has unsupported number of channels: " << channels << "\n";
|
|
|
|
|
|
+ std::cout << "'" << path
|
|
|
|
+ << "' has unsupported number of channels: " << channels
|
|
|
|
+ << "\n";
|
|
return true;
|
|
return true;
|
|
} else if(width < 1 || width > 2048 || height < 1 || height > 2048) {
|
|
} else if(width < 1 || width > 2048 || height < 1 || height > 2048) {
|
|
std::cout << "width and height of '" << path << "' are too big\n";
|
|
std::cout << "width and height of '" << path << "' are too big\n";
|
|
@@ -80,7 +85,7 @@ bool PNGReader::hasError() const {
|
|
} else if(bitDepth != 8 && bitDepth != 16) {
|
|
} else if(bitDepth != 8 && bitDepth != 16) {
|
|
std::cout << "bit depth of '" << path << "' is neither 8 or 16\n";
|
|
std::cout << "bit depth of '" << path << "' is neither 8 or 16\n";
|
|
return true;
|
|
return true;
|
|
- } else if(getBufferSize() * channels != (rowBytes * height * 8 / bitDepth)) {
|
|
|
|
|
|
+ } else if(getBufferSize() != (rowBytes * height * 8 / bitDepth)) {
|
|
std::cout << "'" << path << "' needs an unexpected buffer size\n";
|
|
std::cout << "'" << path << "' needs an unexpected buffer size\n";
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -105,7 +110,8 @@ bool PNGReader::readData(ColorChannel* buffer) {
|
|
std::cout << "png file '" << path << "' has used error callback\n";
|
|
std::cout << "png file '" << path << "' has used error callback\n";
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- rowPointers = static_cast<ColorChannel**>(png_malloc(read, height * sizeof(ColorChannel*)));
|
|
|
|
|
|
+ rowPointers = static_cast<ColorChannel**>(
|
|
|
|
+ png_malloc(read, height * sizeof(ColorChannel*)));
|
|
for(int i = 0; i < height; i++) {
|
|
for(int i = 0; i < height; i++) {
|
|
rowPointers[i] = (buffer + i * width * channels);
|
|
rowPointers[i] = (buffer + i * width * channels);
|
|
}
|
|
}
|