summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cbitmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ue2/imgsynth2/cbitmap.cpp')
-rw-r--r--ue2/imgsynth2/cbitmap.cpp41
1 files changed, 16 insertions, 25 deletions
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp
index 2e135db..3d206f5 100644
--- a/ue2/imgsynth2/cbitmap.cpp
+++ b/ue2/imgsynth2/cbitmap.cpp
@@ -28,7 +28,8 @@ CBitmap::~CBitmap()
28 m_pixelformat = NULL; 28 m_pixelformat = NULL;
29 29
30 /* delete colortable content */ 30 /* delete colortable content */
31 map<string, CPixelFormat::RGBPIXEL *>::iterator it2; 31 //map<string, CPixelFormat::RGBPIXEL *>::iterator it2;
32 map<uint32_t, CPixelFormat::RGBPIXEL *>::iterator it2;
32 for(it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) 33 for(it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++)
33 delete (*it2).second; 34 delete (*it2).second;
34} 35}
@@ -144,7 +145,7 @@ void CBitmap::invert(std::list<std::string> params)
144 if (hasColorTable()) 145 if (hasColorTable())
145 { 146 {
146 /* invert every entry in the colortable */ 147 /* invert every entry in the colortable */
147 map<string, CPixelFormat::RGBPIXEL *>::iterator it; 148 map<uint32_t, CPixelFormat::RGBPIXEL *>::iterator it;
148 for (it = m_colortable.begin(); it != m_colortable.end(); it++) 149 for (it = m_colortable.begin(); it != m_colortable.end(); it++)
149 { 150 {
150 (*it).second->red = max.red - (*it).second->red; 151 (*it).second->red = max.red - (*it).second->red;
@@ -212,8 +213,8 @@ void CBitmap::brightness(std::list<std::string> params)
212 m_pixelformat->getMaxColor(max); 213 m_pixelformat->getMaxColor(max);
213 if (hasColorTable()) 214 if (hasColorTable())
214 { 215 {
215 /* invert every entry in the colortable */ 216 /* change every entry in the colortable */
216 map<string, CPixelFormat::RGBPIXEL *>::iterator it; 217 map<uint32_t, CPixelFormat::RGBPIXEL *>::iterator it;
217 for (it = m_colortable.begin(); it != m_colortable.end(); it++) 218 for (it = m_colortable.begin(); it != m_colortable.end(); it++)
218 { 219 {
219 (*it).second->red = min(max.red, static_cast<uint32_t>((*it).second->red * factor)); 220 (*it).second->red = min(max.red, static_cast<uint32_t>((*it).second->red * factor));
@@ -223,7 +224,7 @@ void CBitmap::brightness(std::list<std::string> params)
223 } 224 }
224 else 225 else
225 { 226 {
226 /* invert per pixel */ 227 /* change per pixel */
227 for(uint32_t y = 0; y < getHeight(); y++) 228 for(uint32_t y = 0; y < getHeight(); y++)
228 { 229 {
229 for(uint32_t x = 0; x < getWidth(); x++) 230 for(uint32_t x = 0; x < getWidth(); x++)
@@ -260,27 +261,22 @@ void CBitmap::mirror_y(std::list<std::string> params)
260 if (m_pixeldata == NULL || m_pixelformat == NULL) 261 if (m_pixeldata == NULL || m_pixelformat == NULL)
261 return; 262 return;
262 263
263 /* calc rowsize - boundary is 32 */ 264 uint8_t *buf = new uint8_t[m_rowsize];
264 uint32_t rowsize = 4 * static_cast<uint32_t>(
265 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32
266 );
267
268 uint8_t *buf = new uint8_t[rowsize];
269 for(uint32_t i = 0; i < getHeight()/2; i++) 265 for(uint32_t i = 0; i < getHeight()/2; i++)
270 { 266 {
271 uint32_t j = getHeight() - i - 1; 267 uint32_t j = getHeight() - i - 1;
272 uint32_t offset = i * rowsize; 268 uint32_t offset = i * m_rowsize;
273 uint32_t backset = j * rowsize; 269 uint32_t backset = j * m_rowsize;
274 270
275 /* boundary check */ 271 /* boundary check */
276 if (offset + rowsize > getPixelDataSize() 272 if (offset + m_rowsize > getPixelDataSize()
277 || backset + rowsize > getPixelDataSize()) 273 || backset + m_rowsize > getPixelDataSize())
278 throw FileError("Mirrored pixel position is out of range."); 274 throw FileError("Mirrored pixel position is out of range.");
279 275
280 /* mirroring, backup lower data first */ 276 /* mirroring, backup lower data first */
281 copy(m_pixeldata + backset, m_pixeldata + backset + rowsize, buf); 277 copy(m_pixeldata + backset, m_pixeldata + backset + m_rowsize, buf);
282 copy(m_pixeldata + offset, m_pixeldata + offset + rowsize, m_pixeldata + backset); 278 copy(m_pixeldata + offset, m_pixeldata + offset + m_rowsize, m_pixeldata + backset);
283 copy(buf, buf + rowsize, m_pixeldata + offset); 279 copy(buf, buf + m_rowsize, m_pixeldata + offset);
284 } 280 }
285 delete[] buf; 281 delete[] buf;
286} 282}
@@ -297,18 +293,13 @@ void CBitmap::mirror_x(std::list<std::string> params)
297 if (m_pixeldata == NULL || m_pixelformat == NULL) 293 if (m_pixeldata == NULL || m_pixelformat == NULL)
298 return; 294 return;
299 295
300 /* calc rowsize - boundary is 32 */
301 uint32_t rowsize = 4 * static_cast<uint32_t>(
302 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32
303 );
304
305 /* calc pixelwidth */ 296 /* calc pixelwidth */
306 unsigned int pixelwidth = m_pixelformat->getBitCount()/8; 297 unsigned int pixelwidth = (hasColorTable()) ? sizeof(uint32_t) : m_pixelformat->getBitCount()/8;
307 298
308 uint8_t *buf = new uint8_t[pixelwidth]; 299 uint8_t *buf = new uint8_t[pixelwidth];
309 for(uint32_t i = 0; i < getHeight(); i++) 300 for(uint32_t i = 0; i < getHeight(); i++)
310 { 301 {
311 uint32_t offset = i * rowsize; 302 uint32_t offset = i * m_rowsize;
312 303
313 for(uint32_t j = 0; j <= getWidth()/2; j++) 304 for(uint32_t j = 0; j <= getWidth()/2; j++)
314 { 305 {