1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/* Copyright (C) 2004 TightVNC Team. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// -=- PixelFormatList class
#include <rfbplayer/PixelFormatList.h>
using namespace rfb;
using namespace rfb::win32;
PixelFormatList::PixelFormatList() {
PixelFormatListElement PFElem;
// -=- Add the default pixel formats to list
// PF_BGR233
PFElem.setName("8-bits depth (BGR233)");
PFElem.setPF(&PixelFormat(8,8,0,1,7,7,3,0,3,6));
PFList.push_back(PFElem);
// PF_RGB555
PFElem.setName("15-bits depth (RGB555)");
PFElem.setPF(&PixelFormat(16,15,0,1,31,31,31,10,5,0));
PFList.push_back(PFElem);
// PF_BGR555
PFElem.setName("15-bits depth (BGR555)");
PFElem.setPF(&PixelFormat(16,15,0,1,31,31,31,0,5,10));
PFList.push_back(PFElem);
// PF_RGB565
PFElem.setName("16-bits depth (RGB565)");
PFElem.setPF(&PixelFormat(16,16,0,1,31,63,31,11,5,0));
PFList.push_back(PFElem);
// PF_BGR565
PFElem.setName("16-bits depth (BGR565)");
PFElem.setPF(&PixelFormat(16,16,0,1,31,63,31,0,5,11));
PFList.push_back(PFElem);
// PF_RGB888
PFElem.setName("24-bits depth (RGB888)");
PFElem.setPF(&PixelFormat(32,24,0,1,255,255,255,16,8,0));
PFList.push_back(PFElem);
// PF_BGR888
PFElem.setName("24-bits depth (BGR888)");
PFElem.setPF(&PixelFormat(32,24,0,1,255,255,255,0,8,16));
PFList.push_back(PFElem);
PF_DEFAULT_COUNT = PFList.size();
}
PixelFormatListElement PixelFormatList::operator[](int index) {
return *getIterator(index);
}
void PixelFormatList::add(char *format_name, PixelFormat PF) {
PixelFormatListElement PFElem;
PFElem.setName(format_name);
PFElem.setPF(&PF);
PFList.push_back(PFElem);
}
void PixelFormatList::insert(int index, char *format_name, PixelFormat PF) {
if (isDefaultPF(index))
rdr::Exception("PixelFormatList:can't insert to the default pixel format place");
PixelFormatListElement PFElem;
PFElem.setName(format_name);
PFElem.setPF(&PF);
PFList.insert(getIterator(index), PFElem);
}
void PixelFormatList::remove(int index) {
if (isDefaultPF(index))
rdr::Exception("PixelFormatList:can't remove the default pixel format");
PFList.erase(getIterator(index));
}
list <PixelFormatListElement>::iterator PixelFormatList::getIterator(int index) {
if ((index >= PFList.size()) || (index < 0))
rdr::Exception("PixelFormatList:out of range");
int i = 0;
list <PixelFormatListElement>::iterator iter;
for (iter = PFList.begin(); iter != PFList.end(); iter++) {
if (i++ == index) break;
}
return iter;
}
bool PixelFormatList::isDefaultPF(int index) {
if (index < PF_DEFAULT_COUNT) return true;
return false;
}
void PixelFormatList::readUserDefinedPF(HKEY root, const char *keypath) {
RegKey regKey;
regKey.createKey(root, keypath);
int count = regKey.getInt(_T("PixelFormatCount"), 0);
if (count > 0) {
// Erase all user defined pixel formats
int upf_count = getUserPFCount();
if (upf_count > 0) {
for(int i = 0; i < upf_count; i++) {
remove(PF_DEFAULT_COUNT);
}
}
// Add the user defined pixel formats from the registry
for(int i = 0; i < count; i++) {
char upf_name[20] = "\0";
sprintf(upf_name, "%s%i", "Upf", i);
int size = sizeof(PixelFormatListElement);
PixelFormatListElement *pPFElem = 0;// = &PFElem;
regKey.getBinary(upf_name, (void**)&pPFElem, &size);
PFList.push_back(*pPFElem);
if (pPFElem) delete pPFElem;
}
}
}
void PixelFormatList::writeUserDefinedPF(HKEY root, const char *keypath) {
RegKey regKey;
// Delete all user defined pixel formats from the regisry
regKey.createKey(root, keypath);//_T("Software\\TightVnc\\RfbPlayer\\UserDefinedPF"));
int count = regKey.getInt(_T("PixelFormatCount"), 0);
for (int i = 0; i < count; i++) {
char upf_name[20] = "\0";
sprintf(upf_name, "%s%i", "Upf", i);
regKey.deleteValue(upf_name);
}
regKey.setInt(_T("PixelFormatCount"), 0);
// Write new user defined pixel formats to the registry
regKey.setInt(_T("PixelFormatCount"), getUserPFCount());
for (i = 0; i < getUserPFCount(); i++) {
char upf_name[20] = "\0";
sprintf(upf_name, "%s%i", "Upf", i);
regKey.setBinary(upf_name, (void *)&operator[](i+getDefaultPFCount()),
sizeof(PixelFormatListElement));
}
}
int PixelFormatList::getIndexByPFName(const char *format_name) {
for (int i = 0; i < PixelFormatList::count(); i++) {
if (_stricmp(operator[](i).format_name, format_name) == 0) return i;
}
return -1;
}
|