blob: 5384c6edce825cd394696e832428866ba10c79ba [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2004 TightVNC Team. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- PlayerOptions class
20
21#include <rfbplayer/PlayerOptions.h>
22
23using namespace rfb::win32;
24
25PlayerOptions::PlayerOptions() {
26 writeDefaults();
27};
28
29void PlayerOptions::readFromRegistry() {
30 try {
31 PixelFormat *pPF = 0;
32 int pfSize = sizeof(PixelFormat);
33 RegKey regKey;
34 regKey.createKey(HKEY_CURRENT_USER, _T("Software\\TightVnc\\RfbPlayer"));
35 autoPlay = regKey.getBool(_T("AutoPlay"), DEFAULT_AUTOPLAY);
36 autoDetectPF = regKey.getBool(_T("AutoDetectPixelFormat"), DEFAULT_AUTOPF);
37 bigEndianFlag = regKey.getBool(_T("BigEndianFlag"), DEFAULT_BIG_ENDIAN);
38 pixelFormatIndex = regKey.getInt(_T("PixelFormatIndex"), DEFAULT_PF_INDEX);
39 regKey.getBinary(_T("PixelFormat"), (void**)&pPF, &pfSize,
40 &PixelFormat(32,24,0,1,255,255,255,16,8,0), sizeof(PixelFormat));
41 setPF(pPF);
42 acceptBell = regKey.getBool(_T("AcceptBell"), DEFAULT_ACCEPT_BELL);
43 acceptCutText = regKey.getBool(_T("AcceptCutText"), DEFAULT_ACCEPT_CUT_TEXT);
44 autoPlay = regKey.getBool(_T("AutoPlay"), DEFAULT_AUTOPLAY);
45 askPixelFormat = regKey.getBool(_T("AskPixelFormat"), DEFAULT_ASK_PF);
46 if (pPF) delete pPF;
47 } catch (rdr::Exception e) {
48 MessageBox(0, e.str(), "RFB Player", MB_OK | MB_ICONERROR);
49 }
50}
51
52void PlayerOptions::writeToRegistry() {
53 try {
54 RegKey regKey;
55 regKey.createKey(HKEY_CURRENT_USER, _T("Software\\TightVnc\\RfbPlayer"));
56 regKey.setBool(_T("AutoPlay"), autoPlay);
57 regKey.setBool(_T("AutoDetectPixelFormat"), autoDetectPF);
58 regKey.setBool(_T("BigEndianFlag"), bigEndianFlag);
59 regKey.setInt(_T("PixelFormatIndex"), pixelFormatIndex);
60 regKey.setBinary(_T("PixelFormat"), &pixelFormat, sizeof(PixelFormat));
61 regKey.setBool(_T("AcceptBell"), acceptBell);
62 regKey.setBool(_T("AcceptCutText"), acceptCutText);
63 regKey.setBool(_T("AutoPlay"), autoPlay);
64 regKey.setBool(_T("AskPixelFormat"), askPixelFormat);
65 } catch (rdr::Exception e) {
66 MessageBox(0, e.str(), "RFB Player", MB_OK | MB_ICONERROR);
67 }
68}
69
70void PlayerOptions::writeDefaults() {
71 initTime = DEFAULT_INIT_TIME;
72 playbackSpeed = DEFAULT_SPEED;
73 autoDetectPF = DEFAULT_AUTOPF;
74 bigEndianFlag = DEFAULT_BIG_ENDIAN;
75 pixelFormatIndex = DEFAULT_PF_INDEX;
76 pixelFormat = PixelFormat(32,24,0,1,255,255,255,16,8,0);
77 frameScale = DEFAULT_FRAME_SCALE;
78 autoPlay = DEFAULT_AUTOPLAY;
79 fullScreen = DEFAULT_FULL_SCREEN;
80 acceptBell = DEFAULT_ACCEPT_BELL;
81 acceptCutText = DEFAULT_ACCEPT_CUT_TEXT;
82 loopPlayback = DEFAULT_LOOP_PLAYBACK;
83 askPixelFormat = DEFAULT_ASK_PF;
84 commandLineParam = false;
85}
86
87void PlayerOptions::setPF(PixelFormat *newPF) {
88 memcpy(&pixelFormat, newPF, sizeof(PixelFormat));
89}
90
91bool PlayerOptions::setPF(int rgb_order, int rm, int gm, int bm, bool big_endian) {
92 PixelFormat newPF;
93
94 // Calculate the colour bits per pixel
95 int bpp = rm + gm + bm;
96 if (bpp < 0) {
97 return false;
98 } else if (bpp <= 8 ) {
99 newPF.bpp = 8;
100 } else if (bpp <= 16) {
101 newPF.bpp = 16;
102 } else if (bpp <= 32) {
103 newPF.bpp = 32;
104 } else {
105 return false;
106 }
107 newPF.depth = bpp;
108
109 // Calculate the r, g and b bits shifts
110 switch (rgb_order) {
111 case RGB_ORDER:
112 newPF.redShift = gm + bm;
113 newPF.greenShift = bm;
114 newPF.blueShift = 0;
115 break;
116 case RBG_ORDER:
117 newPF.redShift = bm + gm;
118 newPF.blueShift = gm;
119 newPF.greenShift = 0;
120 break;
121 case GRB_ORDER:
122 newPF.greenShift = rm + bm;
123 newPF.redShift = bm;
124 newPF.blueShift = 0;
125 break;
126 case GBR_ORDER:
127 newPF.greenShift = bm + rm;
128 newPF.blueShift = rm;
129 newPF.redShift = 0;
130 break;
131 case BGR_ORDER:
132 newPF.blueShift = gm + rm;
133 newPF.greenShift = rm;
134 newPF.redShift = 0;
135 break;
136 case BRG_ORDER:
137 newPF.blueShift = rm + gm;
138 newPF.redShift = gm;
139 newPF.greenShift = 0;
140 break;
141 default:
142 return false;
143 }
144
145 newPF.trueColour = true;
146 newPF.bigEndian = big_endian;
147 newPF.redMax = (1 << rm) - 1;
148 newPF.greenMax = (1 << gm) - 1;
149 newPF.blueMax = (1 << bm) - 1;
150 setPF(&newPF);
151 return true;
152}