mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 19:08:17 +02:00
Add logging category to TGAReader
This commit is contained in:
parent
c55811ced5
commit
2af9dc886a
1 changed files with 20 additions and 18 deletions
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include "TGAReader.h"
|
||||
|
||||
#include "ImageLogging.h"
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -57,12 +59,12 @@ QImage image::readTGA(QIODevice& content) {
|
|||
TGAHeader header;
|
||||
|
||||
if (content.isSequential()) {
|
||||
qWarning() << "TGA - Sequential devices are not supported for reading";
|
||||
qWarning(imagelogging) << "TGA - Sequential devices are not supported for reading";
|
||||
return QImage();
|
||||
}
|
||||
|
||||
if (content.bytesAvailable() < TGA_HEADER_SIZE_BYTES) {
|
||||
qWarning() << "TGA - Unexpectedly reached end of file";
|
||||
qWarning(imagelogging) << "TGA - Unexpectedly reached end of file";
|
||||
return QImage();
|
||||
}
|
||||
|
||||
|
@ -78,28 +80,28 @@ QImage image::readTGA(QIODevice& content) {
|
|||
content.read((char*)&header.imageDescriptor, 1);
|
||||
|
||||
if (WANT_DEBUG) {
|
||||
qDebug() << "Id Length: " << (int)header.idLength;
|
||||
qDebug() << "Color map: " << (int)header.colorMap.firstEntryIndex << header.colorMap.length << header.colorMap.entrySize;
|
||||
qDebug() << "Color map type: " << (int)header.colorMapType;
|
||||
qDebug() << "Image type: " << (int)header.imageType;
|
||||
qDebug() << "Origin: " << header.xOrigin << header.yOrigin;
|
||||
qDebug() << "Size: " << header.width << header.height;
|
||||
qDebug() << "Depth: " << header.pixelDepth;
|
||||
qDebug() << "Image desc: " << header.imageDescriptor.attributeBitsPerPixel << (int)header.imageDescriptor.orientation;
|
||||
qDebug(imagelogging) << "Id Length: " << (int)header.idLength;
|
||||
qDebug(imagelogging) << "Color map: " << (int)header.colorMap.firstEntryIndex << header.colorMap.length << header.colorMap.entrySize;
|
||||
qDebug(imagelogging) << "Color map type: " << (int)header.colorMapType;
|
||||
qDebug(imagelogging) << "Image type: " << (int)header.imageType;
|
||||
qDebug(imagelogging) << "Origin: " << header.xOrigin << header.yOrigin;
|
||||
qDebug(imagelogging) << "Size: " << header.width << header.height;
|
||||
qDebug(imagelogging) << "Depth: " << header.pixelDepth;
|
||||
qDebug(imagelogging) << "Image desc: " << header.imageDescriptor.attributeBitsPerPixel << (int)header.imageDescriptor.orientation;
|
||||
}
|
||||
|
||||
if (header.xOrigin != 0 || header.yOrigin != 0) {
|
||||
qWarning() << "TGA - origin not supporter";
|
||||
qWarning(imagelogging) << "TGA - origin not supporter";
|
||||
return QImage();
|
||||
}
|
||||
|
||||
if (!(header.pixelDepth == 24 && header.imageDescriptor.attributeBitsPerPixel == 0) && header.pixelDepth != 32) {
|
||||
qWarning() << "TGA - Only pixel depths of 24 (with no alpha) and 32 bits are supported";
|
||||
qWarning(imagelogging) << "TGA - Only pixel depths of 24 (with no alpha) and 32 bits are supported";
|
||||
return QImage();
|
||||
}
|
||||
|
||||
if (header.imageDescriptor.attributeBitsPerPixel != 0 && header.imageDescriptor.attributeBitsPerPixel != 8) {
|
||||
qWarning() << "TGA - Only 0 or 8 bits for the alpha channel is supported";
|
||||
qWarning(imagelogging) << "TGA - Only 0 or 8 bits for the alpha channel is supported";
|
||||
return QImage();
|
||||
}
|
||||
|
||||
|
@ -110,7 +112,7 @@ QImage image::readTGA(QIODevice& content) {
|
|||
if (header.imageType == TGAImageType::UncompressedTrueColor) {
|
||||
qint64 minimumSize = header.width * header.height * bytesPerPixel;
|
||||
if (content.bytesAvailable() < minimumSize) {
|
||||
qWarning() << "TGA - Unexpectedly reached end of file";
|
||||
qWarning(imagelogging) << "TGA - Unexpectedly reached end of file";
|
||||
return QImage();
|
||||
}
|
||||
|
||||
|
@ -146,7 +148,7 @@ QImage image::readTGA(QIODevice& content) {
|
|||
constexpr char LENGTH_MASK{ (char)0x7f };
|
||||
char repetition;
|
||||
if (content.read(&repetition, 1) != 1) {
|
||||
qWarning() << "TGA - Unexpectedly reached end of file";
|
||||
qWarning(imagelogging) << "TGA - Unexpectedly reached end of file";
|
||||
return QImage();
|
||||
}
|
||||
bool isRepetition = repetition & IS_REPETITION_MASK;
|
||||
|
@ -159,7 +161,7 @@ QImage image::readTGA(QIODevice& content) {
|
|||
// Read into temporary buffer
|
||||
char color[4];
|
||||
if (content.read(color, bytesPerPixel) != bytesPerPixel) {
|
||||
qWarning() << "TGA - Unexpectedly reached end of file";
|
||||
qWarning(imagelogging) << "TGA - Unexpectedly reached end of file";
|
||||
return QImage();
|
||||
}
|
||||
color[3] |= alphaMask;
|
||||
|
@ -177,7 +179,7 @@ QImage image::readTGA(QIODevice& content) {
|
|||
} else {
|
||||
qint64 minimumSize = length * bytesPerPixel;
|
||||
if (content.bytesAvailable() < minimumSize) {
|
||||
qWarning() << "TGA - Unexpectedly reached end of file";
|
||||
qWarning(imagelogging) << "TGA - Unexpectedly reached end of file";
|
||||
return QImage();
|
||||
}
|
||||
|
||||
|
@ -194,7 +196,7 @@ QImage image::readTGA(QIODevice& content) {
|
|||
}
|
||||
return image;
|
||||
} else {
|
||||
qWarning() << "TGA - Unsupported image type: " << (int)header.imageType;
|
||||
qWarning(imagelogging) << "TGA - Unsupported image type: " << (int)header.imageType;
|
||||
}
|
||||
|
||||
return QImage();
|
||||
|
|
Loading…
Reference in a new issue