summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cbitmap.cpp
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-05-02 17:28:21 +0200
committermanuel <manuel@nc8430.lan>2009-05-02 17:28:21 +0200
commit5c4506a8c5ee1a82268146007619b09e980a7a57 (patch)
treec21bb83bdf7c87b7c9f9693cd4fcd43212ae4be2 /ue2/imgsynth2/cbitmap.cpp
parentbcadfa267f976fe9f29afa50a635cbe3ea174e38 (diff)
downloadooprog-5c4506a8c5ee1a82268146007619b09e980a7a57.tar.gz
ooprog-5c4506a8c5ee1a82268146007619b09e980a7a57.tar.bz2
ooprog-5c4506a8c5ee1a82268146007619b09e980a7a57.zip
add some assert() to make tutor happy
Diffstat (limited to 'ue2/imgsynth2/cbitmap.cpp')
-rw-r--r--ue2/imgsynth2/cbitmap.cpp22
1 files changed, 20 insertions, 2 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
13using namespace std; 14using 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 {