App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

ColorConvertor.cpp
Go to the documentation of this file.
1
6 #include "ColorConvertor.hpp"
7
8 namespace app {
9
10 ColorConvertor::~ColorConvertor() {}
11
12 int ColorConvertor::convert(rgba_8bit_bitmap &bitmap, ColorMode mode) {
13 ColorMode srcMode = bitmap.getType();
14 if (srcMode == mode) { return 0; }
15 int err = 0;
16 if (srcMode != RGBA && mode != RGBA) {
17 err = convert(bitmap, RGBA);
18 if (err) { return 100 + err; }
19 err = convert(bitmap, mode);
20 if (err) { return 200 + err; }
21 return 0;
22 } else if (srcMode == RGBA) {
23 switch (mode) {
24 case HSVA: return RGB_HSV<px_4x8bit, px_1x8bit>(bitmap); break;
25 case HLSA: return RGB_HLS<px_4x8bit, px_1x8bit>(bitmap); break;
26 default: return 30; break;
27 }
28 } else {
29 switch (srcMode) {
30 case HSVA: return HSV_RGB<px_4x8bit, px_1x8bit>(bitmap); break;
31 case HLSA: return HLS_RGB<px_4x8bit, px_1x8bit>(bitmap); break;
32 default: return 40; break;
33 }
34 }
35 return 0;
36 }
37
38 template <typename TPIXEL, typename TCHANNEL>
39 int ColorConvertor::RGB_HSV(TBitmap<TPIXEL, TCHANNEL> &src) {
40 if (src.getType() != RGBA) { return 1; }
41 TPIXEL * ptr = src.getData(); if (ptr == NULL) { return 2; } // Nemelo by nastat, ale pro jistotu.
42 TPIXEL * ptrEnd = ptr + src.getWidth() * src.getHeight();
43 TPixel<TPIXEL, TCHANNEL> px;
44 while (ptr < ptrEnd) {
45 px.value = *ptr;
46 px.RGB_HSV();
47 *ptr = px.value;
48 ptr++;
49 }
50 src.setType(HSVA);
51 return 0;
52 }
53
54 template <typename TPIXEL, typename TCHANNEL>
55 int ColorConvertor::HSV_RGB(TBitmap<TPIXEL, TCHANNEL> &src) {
56 if (src.getType() != HSVA) { return 1; }
57 TPIXEL * ptr = src.getData(); if (ptr == NULL) { return 2; } // Nemelo by nastat, ale pro jistotu.
58 TPIXEL * ptrEnd = ptr + src.getWidth() * src.getHeight();
59 TPixel<TPIXEL, TCHANNEL> px;
60 while (ptr < ptrEnd) {
61 px.value = *ptr;
62 px.HSV_RGB();
63 *ptr = px.value;
64 ptr++;
65 }
66 src.setType(RGBA);
67 return 0;
68 }
69
70 template <typename TPIXEL, typename TCHANNEL>
71 int ColorConvertor::HLS_RGB(TBitmap<TPIXEL, TCHANNEL> &src) {
72 if (src.getType() != HLSA) { return 1; }
73 TPIXEL * ptr = src.getData(); if (ptr == NULL) { return 2; } // Nemelo by nastat, ale pro jistotu.
74 TPIXEL * ptrEnd = ptr + src.getWidth() * src.getHeight();
75 TPixel<TPIXEL, TCHANNEL> px;
76 while (ptr < ptrEnd) {
77 px.value = *ptr;
78 px.HLS_RGB();
79 *ptr = px.value;
80 ptr++;
81 }
82 src.setType(RGBA);
83 return 0;
84 }
85
86 template <typename TPIXEL, typename TCHANNEL>
87 int ColorConvertor::RGB_HLS(TBitmap<TPIXEL, TCHANNEL> &src) {
88 if (src.getType() != RGBA) { return 1; }
89 TPIXEL * ptr = src.getData(); if (ptr == NULL) { return 2; } // Nemelo by nastat, ale pro jistotu.
90 TPIXEL * ptrEnd = ptr + src.getWidth() * src.getHeight();
91 TPixel<TPIXEL, TCHANNEL> px;
92 while (ptr < ptrEnd) {
93 px.value = *ptr;
94 px.RGB_HLS();
95 *ptr = px.value;
96 ptr++;
97 }
98 src.setType(HLSA);
99 return 0;
100 }
101
102
103 } /* namespace app */