summaryrefslogtreecommitdiffstats
path: root/ue1/imgsynth/cpixelformat_24.cpp
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-04-27 00:24:16 +0200
committermanuel <manuel@nc8430.lan>2009-04-27 00:24:16 +0200
commit384539f7cc9feaa7ef7cee385cce472c6966c843 (patch)
tree42d3cbc96d44087c0b6bbe8d41710e5c5f1efced /ue1/imgsynth/cpixelformat_24.cpp
downloadooprog-384539f7cc9feaa7ef7cee385cce472c6966c843.tar.gz
ooprog-384539f7cc9feaa7ef7cee385cce472c6966c843.tar.bz2
ooprog-384539f7cc9feaa7ef7cee385cce472c6966c843.zip
Adding ue1
Diffstat (limited to 'ue1/imgsynth/cpixelformat_24.cpp')
-rw-r--r--ue1/imgsynth/cpixelformat_24.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/ue1/imgsynth/cpixelformat_24.cpp b/ue1/imgsynth/cpixelformat_24.cpp
new file mode 100644
index 0000000..022b592
--- /dev/null
+++ b/ue1/imgsynth/cpixelformat_24.cpp
@@ -0,0 +1,47 @@
1/**
2 * @module cpixelformat_24
3 * @author Manuel Mausz, 0728348
4 * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps.
5 * @date 18.04.2009
6 */
7
8#include <boost/numeric/conversion/cast.hpp>
9#include "cpixelformat_24.h"
10
11using namespace std;
12
13void CPixelFormat_24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y)
14{
15 if (m_bitmap->getPixelData() == NULL)
16 throw PixelFormatError("No pixelbuffer allocated.");
17
18 uint32_t rowsize = 4 * static_cast<uint32_t>(
19 ((CPixelFormat_24::getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
20 );
21
22 /* if height is positive the y-coordinates are mirrored */
23 if (m_bitmap->getInfoHeader().biHeight > 0)
24 y = m_bitmap->getInfoHeader().biHeight - y - 1;
25 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
26
27 /* boundary check */
28 if (offset + 3 * sizeof(uint8_t) > m_bitmap->getInfoHeader().biSizeImage)
29 throw PixelFormatError("Pixel position is out of range.");
30
31 /* convert color values to correct types */
32 uint8_t data[3];
33 try
34 {
35 data[0] = boost::numeric_cast<uint8_t>(pixel[2]);
36 data[1] = boost::numeric_cast<uint8_t>(pixel[1]);
37 data[2] = boost::numeric_cast<uint8_t>(pixel[0]);
38 }
39 catch(boost::numeric::bad_numeric_cast& ex)
40 {
41 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
42 }
43
44 copy(data, data + 3, m_bitmap->getPixelData() + offset);
45}
46
47/* vim: set et sw=2 ts=2: */