Browse Source

Cleaned up and unified error and assertion messages.

pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
e55b4b80c6
  1. 20
      src/Plugins/MagnumFont/MagnumFont.cpp
  2. 4
      src/Plugins/TgaImageConverter/TgaImageConverter.cpp
  3. 12
      src/Plugins/TgaImporter/TgaImporter.cpp

20
src/Plugins/MagnumFont/MagnumFont.cpp

@ -68,7 +68,7 @@ bool MagnumFont::doIsOpened() const { return _opened; }
void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, const Float) {
/* We need just the configuration file and image file */
if(data.size() != 2) {
Error() << "Magnum::Text::MagnumFont::openData(): wanted two files, got" << data.size();
Error() << "Text::MagnumFont::openData(): wanted two files, got" << data.size();
return;
}
@ -76,20 +76,20 @@ void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers:
std::istringstream in({reinterpret_cast<const char*>(data[0].second.begin()), data[0].second.size()});
Utility::Configuration conf(in, Utility::Configuration::Flag::SkipComments);
if(!conf.isValid() || conf.isEmpty()) {
Error() << "Magnum::Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid();
Error() << "Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid();
return;
}
/* Check version */
if(conf.value<UnsignedInt>("version") != 1) {
Error() << "Magnum::Text::MagnumFont::openData(): unsupported file version, expected 1 but got"
Error() << "Text::MagnumFont::openData(): unsupported file version, expected 1 but got"
<< conf.value<UnsignedInt>("version");
return;
}
/* Check that we have also the image file */
if(conf.value("image") != data[1].first) {
Error() << "Magnum::Text::MagnumFont::openData(): expected file"
Error() << "Text::MagnumFont::openData(): expected file"
<< conf.value("image") << "but got" << data[1].first;
return;
}
@ -97,12 +97,12 @@ void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers:
/* Open and load image file */
Trade::TgaImporter importer;
if(!importer.openData(data[1].second)) {
Error() << "Magnum::Text::MagnumFont::openData(): cannot open image file";
Error() << "Text::MagnumFont::openData(): cannot open image file";
return;
}
Trade::ImageData2D* image = importer.image2D(0);
if(!image) {
Error() << "Magnum::Text::MagnumFont::openData(): cannot load image file";
Error() << "Text::MagnumFont::openData(): cannot load image file";
return;
}
@ -114,13 +114,13 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) {
/* Open the configuration file */
Utility::Configuration conf(filename, Utility::Configuration::Flag::ReadOnly|Utility::Configuration::Flag::SkipComments);
if(!conf.isValid() || conf.isEmpty()) {
Error() << "Magnum::Text::MagnumFont::openFile(): cannot open file" << filename << conf.isValid();
Error() << "Text::MagnumFont::openFile(): cannot open file" << filename << conf.isValid();
return;
}
/* Check version */
if(conf.value<UnsignedInt>("version") != 1) {
Error() << "Magnum::Text::MagnumFont::openFile(): unsupported file version, expected 1 but got"
Error() << "Text::MagnumFont::openFile(): unsupported file version, expected 1 but got"
<< conf.value<UnsignedInt>("version");
return;
}
@ -129,12 +129,12 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) {
const std::string imageFilename = Utility::Directory::join(Utility::Directory::path(filename), conf.value("image"));
Trade::TgaImporter importer;
if(!importer.openFile(imageFilename)) {
Error() << "Magnum::Text::MagnumFont::openFile(): cannot open image file" << imageFilename;
Error() << "Text::MagnumFont::openFile(): cannot open image file" << imageFilename;
return;
}
Trade::ImageData2D* image = importer.image2D(0);
if(!image) {
Error() << "Magnum::Text::MagnumFont::openFile(): cannot load image file";
Error() << "Text::MagnumFont::openFile(): cannot load image file";
return;
}

4
src/Plugins/TgaImageConverter/TgaImageConverter.cpp

@ -57,12 +57,12 @@ Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageRe
image.format() != ImageFormat::Red)
#endif
{
Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image.format();
Error() << "Trade::TgaImageConverter::convertToData(): unsupported image format" << image.format();
return nullptr;
}
if(image.type() != ImageType::UnsignedByte) {
Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image.type();
Error() << "Trade::TgaImageConverter::convertToData(): unsupported image type" << image.type();
return nullptr;
}

12
src/Plugins/TgaImporter/TgaImporter.cpp

@ -60,7 +60,7 @@ void TgaImporter::doOpenFile(const std::string& filename) {
in = new std::ifstream(filename.c_str());
if(in->good()) return;
Error() << "Trade::TgaImporter::TgaImporter::openFile(): cannot open file" << filename;
Error() << "Trade::TgaImporter::openFile(): cannot open file" << filename;
close();
}
@ -77,7 +77,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
std::streampos filesize = in->tellg();
in->seekg(0, std::istream::beg);
if(filesize < std::streampos(sizeof(TgaHeader))) {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): the file is too short:" << filesize << "bytes";
Error() << "Trade::TgaImporter::image2D(): the file is too short:" << filesize << "bytes";
return nullptr;
}
@ -91,7 +91,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
/* Image format */
ImageFormat format;
if(header.colorMapType != 0) {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): paletted files are not supported";
Error() << "Trade::TgaImporter::image2D(): paletted files are not supported";
return nullptr;
}
@ -113,7 +113,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
#endif
break;
default:
Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp;
Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp;
return nullptr;
}
@ -126,13 +126,13 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
format = ImageFormat::Red;
#endif
if(header.bpp != 8) {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp;
Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp;
return nullptr;
}
/* Compressed files */
} else {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType;
Error() << "Trade::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType;
return nullptr;
}

Loading…
Cancel
Save