summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cpixelformat_bgr24.cpp
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-04-27 00:25:16 +0200
committermanuel <manuel@nc8430.lan>2009-04-27 00:25:16 +0200
commitaa139a7d2b3f26af7590edbf413df67195c5d900 (patch)
treeba99ea3b2af9aa191386550f025520117f18f4f8 /ue2/imgsynth2/cpixelformat_bgr24.cpp
parent384539f7cc9feaa7ef7cee385cce472c6966c843 (diff)
downloadooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.tar.gz
ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.tar.bz2
ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.zip
Adding ue2
Diffstat (limited to 'ue2/imgsynth2/cpixelformat_bgr24.cpp')
-rw-r--r--ue2/imgsynth2/cpixelformat_bgr24.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/ue2/imgsynth2/cpixelformat_bgr24.cpp b/ue2/imgsynth2/cpixelformat_bgr24.cpp
new file mode 100644
index 0000000..cc02dcc
--- /dev/null
+++ b/ue2/imgsynth2/cpixelformat_bgr24.cpp
@@ -0,0 +1,90 @@
1/**
2 * @module cpixelformat_BGR24
3 * @author Guenther Neuwirth (0626638), 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_bgr24.h"
10
11using namespace std;
12
13void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y)
14{
15 /*
16 * pixel[0] ... red
17 * pixel[1] ... green
18 * pixel[2] ... blue
19 */
20 if (m_bitmap->getPixelData() == NULL)
21 throw PixelFormatError("No pixelbuffer allocated.");
22
23 /* calc rowsize - boundary is 32 */
24 uint32_t rowsize = 4 * static_cast<uint32_t>(
25 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
26 );
27
28 /* if height is positive the y-coordinates are mirrored */
29 if (m_bitmap->getInfoHeader().biHeight > 0)
30 y = m_bitmap->getInfoHeader().biHeight - y - 1;
31 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
32
33 /* boundary check */
34 if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage)
35 throw PixelFormatError("Pixel position is out of range.");
36
37 /* get pixel */
38 try
39 {
40 pixel[0] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 2));
41 pixel[1] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 1));
42 pixel[2] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset));
43 }
44 catch(boost::numeric::bad_numeric_cast& ex)
45 {
46 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
47 }
48}
49
50void CPixelFormat_BGR24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y)
51{
52 /*
53 * pixel[0] ... red
54 * pixel[1] ... green
55 * pixel[2] ... blue
56 */
57 if (m_bitmap->getPixelData() == NULL)
58 throw PixelFormatError("No pixelbuffer allocated.");
59
60 /* calc rowsize - boundary is 32 */
61 uint32_t rowsize = 4 * static_cast<uint32_t>(
62 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
63 );
64
65 /* if height is positive the y-coordinates are mirrored */
66 if (m_bitmap->getInfoHeader().biHeight > 0)
67 y = m_bitmap->getInfoHeader().biHeight - y - 1;
68 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
69
70 /* boundary check */
71 if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage)
72 throw PixelFormatError("Pixel position is out of range.");
73
74 /* convert color values to correct types */
75 uint8_t data[3];
76 try
77 {
78 data[0] = boost::numeric_cast<uint8_t>(pixel[2]);
79 data[1] = boost::numeric_cast<uint8_t>(pixel[1]);
80 data[2] = boost::numeric_cast<uint8_t>(pixel[0]);
81 }
82 catch(boost::numeric::bad_numeric_cast& ex)
83 {
84 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
85 }
86
87 copy(data, data + 3, m_bitmap->getPixelData() + offset);
88}
89
90/* vim: set et sw=2 ts=2: */