diff options
Diffstat (limited to 'ue2')
| -rw-r--r-- | ue2/imgsynth2/cbitmap.cpp | 22 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr24.cpp | 3 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr555.cpp | 3 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_indexed8.cpp | 6 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixmap.cpp | 6 | ||||
| -rw-r--r-- | ue2/imgsynth2/cwindowsbitmap.cpp | 2 |
6 files changed, 39 insertions, 3 deletions
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp index 3d206f5..3bff857 100644 --- a/ue2/imgsynth2/cbitmap.cpp +++ b/ue2/imgsynth2/cbitmap.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <algorithm> | 8 | #include <algorithm> |
| 9 | #include <boost/lexical_cast.hpp> | 9 | #include <boost/lexical_cast.hpp> |
| 10 | #include <boost/numeric/conversion/cast.hpp> | 10 | #include <boost/numeric/conversion/cast.hpp> |
| 11 | #include <assert.h> | ||
| 11 | #include "cbitmap.h" | 12 | #include "cbitmap.h" |
| 12 | 13 | ||
| 13 | using namespace std; | 14 | using namespace std; |
| @@ -28,7 +29,6 @@ CBitmap::~CBitmap() | |||
| 28 | m_pixelformat = NULL; | 29 | m_pixelformat = NULL; |
| 29 | 30 | ||
| 30 | /* delete colortable content */ | 31 | /* delete colortable content */ |
| 31 | //map<string, CPixelFormat::RGBPIXEL *>::iterator it2; | ||
| 32 | map<uint32_t, CPixelFormat::RGBPIXEL *>::iterator it2; | 32 | map<uint32_t, CPixelFormat::RGBPIXEL *>::iterator it2; |
| 33 | for(it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) | 33 | for(it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) |
| 34 | delete (*it2).second; | 34 | delete (*it2).second; |
| @@ -67,6 +67,10 @@ void CBitmap::fillrect(std::list<std::string> params) | |||
| 67 | if (m_pixeldata == NULL || m_pixelformat == NULL) | 67 | if (m_pixeldata == NULL || m_pixelformat == NULL) |
| 68 | return; | 68 | return; |
| 69 | 69 | ||
| 70 | assert(getHeight() > 0); | ||
| 71 | assert(getWidth() > 0); | ||
| 72 | assert(getPixelDataSize() > 0); | ||
| 73 | |||
| 70 | /* convert parameters */ | 74 | /* convert parameters */ |
| 71 | uint32_t pparams[7]; | 75 | uint32_t pparams[7]; |
| 72 | int i = 0; | 76 | int i = 0; |
| @@ -106,7 +110,7 @@ void CBitmap::fillrect(std::list<std::string> params) | |||
| 106 | pixel.blue = pparams[6]; | 110 | pixel.blue = pparams[6]; |
| 107 | 111 | ||
| 108 | /* call setPixel for every pixel in the rectangel */ | 112 | /* call setPixel for every pixel in the rectangel */ |
| 109 | /* NOTE: maybe use fill() here? */ | 113 | /* NOTE: maybe use std::fill() here? */ |
| 110 | for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) | 114 | for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) |
| 111 | { | 115 | { |
| 112 | for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++) | 116 | for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++) |
| @@ -139,6 +143,10 @@ void CBitmap::invert(std::list<std::string> params) | |||
| 139 | if (m_pixeldata == NULL || m_pixelformat == NULL) | 143 | if (m_pixeldata == NULL || m_pixelformat == NULL) |
| 140 | return; | 144 | return; |
| 141 | 145 | ||
| 146 | assert(getHeight() > 0); | ||
| 147 | assert(getWidth() > 0); | ||
| 148 | assert(getPixelDataSize() > 0); | ||
| 149 | |||
| 142 | CPixelFormat::RGBPIXEL pixel; | 150 | CPixelFormat::RGBPIXEL pixel; |
| 143 | CPixelFormat::RGBPIXEL max; | 151 | CPixelFormat::RGBPIXEL max; |
| 144 | m_pixelformat->getMaxColor(max); | 152 | m_pixelformat->getMaxColor(max); |
| @@ -261,6 +269,11 @@ void CBitmap::mirror_y(std::list<std::string> params) | |||
| 261 | if (m_pixeldata == NULL || m_pixelformat == NULL) | 269 | if (m_pixeldata == NULL || m_pixelformat == NULL) |
| 262 | return; | 270 | return; |
| 263 | 271 | ||
| 272 | assert(m_rowsize > 0); | ||
| 273 | assert(getHeight() > 0); | ||
| 274 | assert(getWidth() > 0); | ||
| 275 | assert(getPixelDataSize() > 0); | ||
| 276 | |||
| 264 | uint8_t *buf = new uint8_t[m_rowsize]; | 277 | uint8_t *buf = new uint8_t[m_rowsize]; |
| 265 | for(uint32_t i = 0; i < getHeight()/2; i++) | 278 | for(uint32_t i = 0; i < getHeight()/2; i++) |
| 266 | { | 279 | { |
| @@ -296,6 +309,11 @@ void CBitmap::mirror_x(std::list<std::string> params) | |||
| 296 | /* calc pixelwidth */ | 309 | /* calc pixelwidth */ |
| 297 | unsigned int pixelwidth = (hasColorTable()) ? sizeof(uint32_t) : m_pixelformat->getBitCount()/8; | 310 | unsigned int pixelwidth = (hasColorTable()) ? sizeof(uint32_t) : m_pixelformat->getBitCount()/8; |
| 298 | 311 | ||
| 312 | assert(m_rowsize > 0); | ||
| 313 | assert(getHeight() > 0); | ||
| 314 | assert(getWidth() > 0); | ||
| 315 | assert(getPixelDataSize() > 0); | ||
| 316 | |||
| 299 | uint8_t *buf = new uint8_t[pixelwidth]; | 317 | uint8_t *buf = new uint8_t[pixelwidth]; |
| 300 | for(uint32_t i = 0; i < getHeight(); i++) | 318 | for(uint32_t i = 0; i < getHeight(); i++) |
| 301 | { | 319 | { |
diff --git a/ue2/imgsynth2/cpixelformat_bgr24.cpp b/ue2/imgsynth2/cpixelformat_bgr24.cpp index bc95ab9..2332142 100644 --- a/ue2/imgsynth2/cpixelformat_bgr24.cpp +++ b/ue2/imgsynth2/cpixelformat_bgr24.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include <boost/numeric/conversion/cast.hpp> | 8 | #include <boost/numeric/conversion/cast.hpp> |
| 9 | #include <assert.h> | ||
| 9 | #include "cpixelformat_bgr24.h" | 10 | #include "cpixelformat_bgr24.h" |
| 10 | #include "cbitmap.h" | 11 | #include "cbitmap.h" |
| 11 | 12 | ||
| @@ -15,6 +16,7 @@ void CPixelFormat_BGR24::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y) | |||
| 15 | { | 16 | { |
| 16 | if (m_bitmap->getPixelData() == NULL) | 17 | if (m_bitmap->getPixelData() == NULL) |
| 17 | throw PixelFormatError("No pixelbuffer allocated."); | 18 | throw PixelFormatError("No pixelbuffer allocated."); |
| 19 | assert(m_bitmap->getPixelDataSize() > 0); | ||
| 18 | 20 | ||
| 19 | /* if the y-coordinates are mirrored */ | 21 | /* if the y-coordinates are mirrored */ |
| 20 | if (m_bitmap->isMirrored()) | 22 | if (m_bitmap->isMirrored()) |
| @@ -37,6 +39,7 @@ void CPixelFormat_BGR24::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y) | |||
| 37 | { | 39 | { |
| 38 | if (m_bitmap->getPixelData() == NULL) | 40 | if (m_bitmap->getPixelData() == NULL) |
| 39 | throw PixelFormatError("No pixelbuffer allocated."); | 41 | throw PixelFormatError("No pixelbuffer allocated."); |
| 42 | assert(m_bitmap->getPixelDataSize() > 0); | ||
| 40 | 43 | ||
| 41 | /* if the y-coordinates are mirrored */ | 44 | /* if the y-coordinates are mirrored */ |
| 42 | if (m_bitmap->isMirrored()) | 45 | if (m_bitmap->isMirrored()) |
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.cpp b/ue2/imgsynth2/cpixelformat_bgr555.cpp index 657c148..ba12cb5 100644 --- a/ue2/imgsynth2/cpixelformat_bgr555.cpp +++ b/ue2/imgsynth2/cpixelformat_bgr555.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include <boost/numeric/conversion/cast.hpp> | 9 | #include <boost/numeric/conversion/cast.hpp> |
| 10 | #include <assert.h> | ||
| 10 | #include "cpixelformat_bgr555.h" | 11 | #include "cpixelformat_bgr555.h" |
| 11 | #include "cbitmap.h" | 12 | #include "cbitmap.h" |
| 12 | 13 | ||
| @@ -16,6 +17,7 @@ void CPixelFormat_BGR555::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y) | |||
| 16 | { | 17 | { |
| 17 | if (m_bitmap->getPixelData() == NULL) | 18 | if (m_bitmap->getPixelData() == NULL) |
| 18 | throw PixelFormatError("No pixelbuffer allocated."); | 19 | throw PixelFormatError("No pixelbuffer allocated."); |
| 20 | assert(m_bitmap->getPixelDataSize() > 0); | ||
| 19 | 21 | ||
| 20 | /* if the y-coordinates are mirrored */ | 22 | /* if the y-coordinates are mirrored */ |
| 21 | if (m_bitmap->isMirrored()) | 23 | if (m_bitmap->isMirrored()) |
| @@ -39,6 +41,7 @@ void CPixelFormat_BGR555::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y | |||
| 39 | { | 41 | { |
| 40 | if (m_bitmap->getPixelData() == NULL) | 42 | if (m_bitmap->getPixelData() == NULL) |
| 41 | throw PixelFormatError("No pixelbuffer allocated."); | 43 | throw PixelFormatError("No pixelbuffer allocated."); |
| 44 | assert(m_bitmap->getPixelDataSize() > 0); | ||
| 42 | 45 | ||
| 43 | /* if the y-coordinates are mirrored */ | 46 | /* if the y-coordinates are mirrored */ |
| 44 | if (m_bitmap->isMirrored()) | 47 | if (m_bitmap->isMirrored()) |
diff --git a/ue2/imgsynth2/cpixelformat_indexed8.cpp b/ue2/imgsynth2/cpixelformat_indexed8.cpp index 21b0988..d92ae9f 100644 --- a/ue2/imgsynth2/cpixelformat_indexed8.cpp +++ b/ue2/imgsynth2/cpixelformat_indexed8.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include <boost/numeric/conversion/cast.hpp> | 8 | #include <boost/numeric/conversion/cast.hpp> |
| 9 | #include <assert.h> | ||
| 9 | #include "cpixelformat_indexed8.h" | 10 | #include "cpixelformat_indexed8.h" |
| 10 | 11 | ||
| 11 | using namespace std; | 12 | using namespace std; |
| @@ -16,6 +17,7 @@ void CPixelFormat_Indexed8::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y) | |||
| 16 | throw PixelFormatError("No pixelbuffer allocated."); | 17 | throw PixelFormatError("No pixelbuffer allocated."); |
| 17 | if (m_bitmap->getColorTable().size() == 0) | 18 | if (m_bitmap->getColorTable().size() == 0) |
| 18 | return; | 19 | return; |
| 20 | assert(m_bitmap->getPixelDataSize() > 0); | ||
| 19 | 21 | ||
| 20 | uint32_t offset = y * m_bitmap->getWidth() + x; | 22 | uint32_t offset = y * m_bitmap->getWidth() + x; |
| 21 | 23 | ||
| @@ -40,8 +42,10 @@ void CPixelFormat_Indexed8::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t | |||
| 40 | { | 42 | { |
| 41 | if (m_bitmap->getPixelData() == NULL) | 43 | if (m_bitmap->getPixelData() == NULL) |
| 42 | throw PixelFormatError("No pixelbuffer allocated."); | 44 | throw PixelFormatError("No pixelbuffer allocated."); |
| 45 | /* if colortable is empty there are no pixels */ | ||
| 43 | if (m_bitmap->getColorTable().size() == 0) | 46 | if (m_bitmap->getColorTable().size() == 0) |
| 44 | return; | 47 | return; |
| 48 | assert(m_bitmap->getPixelDataSize() > 0); | ||
| 45 | 49 | ||
| 46 | uint32_t offset = y * m_bitmap->getWidth() + x; | 50 | uint32_t offset = y * m_bitmap->getWidth() + x; |
| 47 | 51 | ||
| @@ -60,7 +64,7 @@ void CPixelFormat_Indexed8::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t | |||
| 60 | } | 64 | } |
| 61 | 65 | ||
| 62 | uint32_t index = (*it).first; | 66 | uint32_t index = (*it).first; |
| 63 | /* need to get a new character for our color */ | 67 | /* need to get a new entry for our color */ |
| 64 | if (it == m_bitmap->getColorTable().end()) | 68 | if (it == m_bitmap->getColorTable().end()) |
| 65 | { | 69 | { |
| 66 | index = (*it).first + 1; | 70 | index = (*it).first + 1; |
diff --git a/ue2/imgsynth2/cpixmap.cpp b/ue2/imgsynth2/cpixmap.cpp index 94f0310..52f9825 100644 --- a/ue2/imgsynth2/cpixmap.cpp +++ b/ue2/imgsynth2/cpixmap.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <boost/algorithm/string/split.hpp> | 11 | #include <boost/algorithm/string/split.hpp> |
| 12 | #include <boost/algorithm/string.hpp> | 12 | #include <boost/algorithm/string.hpp> |
| 13 | #include <boost/lexical_cast.hpp> | 13 | #include <boost/lexical_cast.hpp> |
| 14 | #include <assert.h> | ||
| 14 | #ifdef DEBUG | 15 | #ifdef DEBUG |
| 15 | # include <iostream> | 16 | # include <iostream> |
| 16 | #endif | 17 | #endif |
| @@ -123,6 +124,7 @@ void CPixmap::read(std::ifstream& in) | |||
| 123 | throw FileError("Pixmap has no imagename."); | 124 | throw FileError("Pixmap has no imagename."); |
| 124 | 125 | ||
| 125 | /* additional: check "{" exists */ | 126 | /* additional: check "{" exists */ |
| 127 | assert(!line.empty()); | ||
| 126 | if (line[line.length() - 1] != '{') | 128 | if (line[line.length() - 1] != '{') |
| 127 | throw FileError("Pixmap array has no opening bracket."); | 129 | throw FileError("Pixmap array has no opening bracket."); |
| 128 | 130 | ||
| @@ -236,6 +238,7 @@ void CPixmap::read(std::ifstream& in) | |||
| 236 | for(uint32_t x = 0; x < getWidth(); x++) | 238 | for(uint32_t x = 0; x < getWidth(); x++) |
| 237 | { | 239 | { |
| 238 | character = line.substr(x * m_fileheader.nChar, m_fileheader.nChar); | 240 | character = line.substr(x * m_fileheader.nChar, m_fileheader.nChar); |
| 241 | assert(!character.empty()); | ||
| 239 | if (colornr.find(character) == colornr.end()) | 242 | if (colornr.find(character) == colornr.end()) |
| 240 | throw FileError("Pixel has no reference in colortable."); | 243 | throw FileError("Pixel has no reference in colortable."); |
| 241 | 244 | ||
| @@ -265,6 +268,7 @@ void CPixmap::read(std::ifstream& in) | |||
| 265 | const std::string CPixmap::getXPMColorID(unsigned int index, unsigned int length) | 268 | const std::string CPixmap::getXPMColorID(unsigned int index, unsigned int length) |
| 266 | { | 269 | { |
| 267 | static const char code[] = PIXMAP_COLORCHARS; | 270 | static const char code[] = PIXMAP_COLORCHARS; |
| 271 | assert(strlen(code) > 0); | ||
| 268 | string str(""); | 272 | string str(""); |
| 269 | for(unsigned int i = length - 1; i > 0; i--) | 273 | for(unsigned int i = length - 1; i > 0; i--) |
| 270 | { | 274 | { |
| @@ -272,6 +276,7 @@ const std::string CPixmap::getXPMColorID(unsigned int index, unsigned int length | |||
| 272 | index /= strlen(code); | 276 | index /= strlen(code); |
| 273 | } | 277 | } |
| 274 | str += code[index]; | 278 | str += code[index]; |
| 279 | assert(!str.empty()); | ||
| 275 | return str; | 280 | return str; |
| 276 | } | 281 | } |
| 277 | 282 | ||
| @@ -286,6 +291,7 @@ void CPixmap::write(std::ofstream& out) | |||
| 286 | out << PIXMAP_IDENTIFIER << endl; | 291 | out << PIXMAP_IDENTIFIER << endl; |
| 287 | 292 | ||
| 288 | /* variables*/ | 293 | /* variables*/ |
| 294 | assert(!m_imagename.empty()); | ||
| 289 | out << "static char * " << m_imagename << "[] = {" << endl; | 295 | out << "static char * " << m_imagename << "[] = {" << endl; |
| 290 | out << "\"" << m_fileheader.width << " " << m_fileheader.height | 296 | out << "\"" << m_fileheader.width << " " << m_fileheader.height |
| 291 | << " " << m_fileheader.nColor << " " << m_fileheader.nChar; | 297 | << " " << m_fileheader.nColor << " " << m_fileheader.nChar; |
diff --git a/ue2/imgsynth2/cwindowsbitmap.cpp b/ue2/imgsynth2/cwindowsbitmap.cpp index d561465..83954b6 100644 --- a/ue2/imgsynth2/cwindowsbitmap.cpp +++ b/ue2/imgsynth2/cwindowsbitmap.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include <boost/lexical_cast.hpp> | 8 | #include <boost/lexical_cast.hpp> |
| 9 | #include <boost/numeric/conversion/cast.hpp> | 9 | #include <boost/numeric/conversion/cast.hpp> |
| 10 | #include <assert.h> | ||
| 10 | #ifdef DEBUG | 11 | #ifdef DEBUG |
| 11 | # include <iostream> | 12 | # include <iostream> |
| 12 | #endif | 13 | #endif |
| @@ -58,6 +59,7 @@ void CWindowsBitmap::read(std::ifstream& in) | |||
| 58 | if (m_pixeldata != NULL) | 59 | if (m_pixeldata != NULL) |
| 59 | delete[] m_pixeldata; | 60 | delete[] m_pixeldata; |
| 60 | m_pixeldata = new uint8_t[m_infoheader.biSizeImage]; | 61 | m_pixeldata = new uint8_t[m_infoheader.biSizeImage]; |
| 62 | assert(m_fileheader.bfOffBits > 0); | ||
| 61 | in.seekg(m_fileheader.bfOffBits); | 63 | in.seekg(m_fileheader.bfOffBits); |
| 62 | in.read(reinterpret_cast<char *>(m_pixeldata), m_infoheader.biSizeImage); | 64 | in.read(reinterpret_cast<char *>(m_pixeldata), m_infoheader.biSizeImage); |
| 63 | } | 65 | } |
