]> git.sesse.net Git - vlc/blob - modules/video_filter/atmo/AtmoConfig.cpp
cosmetic: remove nullity test on free() and delete
[vlc] / modules / video_filter / atmo / AtmoConfig.cpp
1 /*
2  * AtmoConfig.cpp: Class for holding all configuration values of AtmoWin - stores
3  * the values and retrieves its values from registry
4  *
5  * See the README.txt file for copyright information and how to reach the author(s).
6  *
7  * $Id$
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12
13 #include "AtmoConfig.h"
14
15 /* Import Hint
16
17    if somebody Adds new config option this has to be done in the following
18    files and includes!
19
20    AtmoConfig.h  -- extend class definition!, and add get... and set... Methods!
21                     so that the real variables are still hidden inside the class!
22    AtmoConfigRegistry.cpp --> SaveToRegistry();
23    AtmoConfigRegistry.cpp --> LoadFromRegistry();
24    AtmoConfig.cpp --> Assign( ... );
25
26 */
27
28 CAtmoConfig::CAtmoConfig()
29 {
30   // setup basic configruation structures...
31   m_IsShowConfigDialog = 0;
32   m_eAtmoConnectionType = actSerialPort;
33   for(int i=0;i<10;i++)
34       m_ChannelAssignments[i] = NULL;
35 #if defined (_ATMO_VLC_PLUGIN_)
36   m_devicename = NULL;
37 #endif
38   // load all config values with there defaults
39   LoadDefaults();
40
41   //   CAtmoZoneDefinition *m_ZoneDefinitions[ATMO_NUM_CHANNELS];
42   // generate default channel parameters which may be loaded later from .bmp files
43   for(int i=0;i<ATMO_NUM_CHANNELS;i++) {
44       m_ZoneDefinitions[i] = new CAtmoZoneDefinition();
45       m_ZoneDefinitions[i]->setZoneNumber(i);
46       switch(i) {
47           case 0:  // summary channel
48               m_ZoneDefinitions[i]->Fill(255);
49               break;
50           case 1: // left channel
51               m_ZoneDefinitions[i]->FillGradientFromLeft();
52               break;
53           case 2: // right channel
54               m_ZoneDefinitions[i]->FillGradientFromRight();
55               break;
56           case 3: // top channel
57               m_ZoneDefinitions[i]->FillGradientFromTop();
58               break;
59           case 4: // bottom channel
60               m_ZoneDefinitions[i]->FillGradientFromBottom();
61               break;
62       }
63   }
64 }
65
66 CAtmoConfig::~CAtmoConfig() {
67     // and finally cleanup...
68     clearAllChannelMappings();
69 #if !defined (WIN32)
70     free( m_devicename );
71 #endif
72 }
73
74 void CAtmoConfig::LoadDefaults() {
75     //    m_eAtmoConnectionType = actSerialPort;
76     //    m_Comport
77
78     m_eEffectMode = emDisabled;
79
80     m_WhiteAdjustment_Red    = 255;
81     m_WhiteAdjustment_Green  = 255;
82     m_WhiteAdjustment_Blue   = 255;
83         m_UseSoftwareWhiteAdj    = 1;
84
85         m_ColorChanger_iSteps    = 50;
86         m_ColorChanger_iDelay    = 25;
87
88         m_LrColorChanger_iSteps  = 50;
89         m_LrColorChanger_iDelay  = 25;
90
91     m_IsSetShutdownColor     = 1;
92         m_ShutdownColor_Red      = 0;
93         m_ShutdownColor_Green    = 0;
94         m_ShutdownColor_Blue     = 0;
95
96     m_StaticColor_Red        = 127; // ??
97     m_StaticColor_Green      = 192;
98     m_StaticColor_Blue       = 255;
99
100     m_LiveViewFilterMode         = afmCombined;
101     m_LiveViewFilter_PercentNew  = 50;
102     m_LiveViewFilter_MeanLength  = 300;
103     m_LiveViewFilter_MeanThreshold   = 40;
104
105     m_LiveView_EdgeWeighting  = 8;
106     m_LiveView_BrightCorrect  = 100;
107     m_LiveView_DarknessLimit  = 5;
108     m_LiveView_HueWinSize     = 3;
109     m_LiveView_SatWinSize     = 3;
110     m_LiveView_WidescreenMode = 0;
111
112     m_LiveView_HOverscanBorder  = 0;
113     m_LiveView_VOverscanBorder  = 0;
114     m_LiveView_DisplayNr        = 0;
115     m_LiveView_FrameDelay       = 0;
116
117
118     m_Hardware_global_gamma    = 128;
119     m_Hardware_global_contrast = 100;
120     m_Hardware_contrast_red    = 100;
121     m_Hardware_contrast_green  = 100;
122     m_Hardware_contrast_blue   = 100;
123
124     m_Hardware_gamma_red       = 22;
125     m_Hardware_gamma_green     = 22;
126     m_Hardware_gamma_blue      = 22;
127
128     clearAllChannelMappings();
129     m_CurrentChannelAssignment = 0;
130     tChannelAssignment* temp = new tChannelAssignment;
131     temp->system = true;
132     for(int i=0;i<ATMO_NUM_CHANNELS;i++)
133         temp->mappings[i] = i;
134     strcpy(temp->name,"Standard");
135     this->m_ChannelAssignments[0] =  temp;
136 }
137
138 void CAtmoConfig::Assign(CAtmoConfig *pAtmoConfigSrc) {
139
140 #if defined(_ATMO_VLC_PLUGIN_)
141     this->setSerialDevice(pAtmoConfigSrc->getSerialDevice());
142 #else
143     this->m_Comport                  = pAtmoConfigSrc->m_Comport;
144 #endif
145
146     this->m_eAtmoConnectionType      = pAtmoConfigSrc->m_eAtmoConnectionType;
147     this->m_eEffectMode              = pAtmoConfigSrc->m_eEffectMode;
148
149     this->m_WhiteAdjustment_Red      = pAtmoConfigSrc->m_WhiteAdjustment_Red;
150     this->m_WhiteAdjustment_Green    = pAtmoConfigSrc->m_WhiteAdjustment_Green;
151     this->m_WhiteAdjustment_Blue     = pAtmoConfigSrc->m_WhiteAdjustment_Blue;
152     this->m_UseSoftwareWhiteAdj      = pAtmoConfigSrc->m_UseSoftwareWhiteAdj;
153
154     this->m_IsSetShutdownColor       = pAtmoConfigSrc->m_IsSetShutdownColor;
155     this->m_ShutdownColor_Red        = pAtmoConfigSrc->m_ShutdownColor_Red;
156     this->m_ShutdownColor_Green      = pAtmoConfigSrc->m_ShutdownColor_Green;
157     this->m_ShutdownColor_Blue       = pAtmoConfigSrc->m_ShutdownColor_Blue;
158
159     this->m_ColorChanger_iSteps      = pAtmoConfigSrc->m_ColorChanger_iSteps;
160     this->m_ColorChanger_iDelay      = pAtmoConfigSrc->m_ColorChanger_iDelay;
161
162     this->m_LrColorChanger_iSteps    = pAtmoConfigSrc->m_LrColorChanger_iSteps;
163     this->m_LrColorChanger_iDelay    = pAtmoConfigSrc->m_LrColorChanger_iDelay;
164
165     this->m_StaticColor_Red          = pAtmoConfigSrc->m_StaticColor_Red;
166     this->m_StaticColor_Green        = pAtmoConfigSrc->m_StaticColor_Green;
167     this->m_StaticColor_Blue         = pAtmoConfigSrc->m_StaticColor_Blue;
168
169     this->m_LiveViewFilterMode             = pAtmoConfigSrc->m_LiveViewFilterMode;
170     this->m_LiveViewFilter_PercentNew      = pAtmoConfigSrc->m_LiveViewFilter_PercentNew;
171     this->m_LiveViewFilter_MeanLength      = pAtmoConfigSrc->m_LiveViewFilter_MeanLength;
172     this->m_LiveViewFilter_MeanThreshold   = pAtmoConfigSrc->m_LiveViewFilter_MeanThreshold;
173
174
175     this->m_LiveView_EdgeWeighting  =  pAtmoConfigSrc->m_LiveView_EdgeWeighting;
176     this->m_LiveView_BrightCorrect  =  pAtmoConfigSrc->m_LiveView_BrightCorrect;
177     this->m_LiveView_DarknessLimit  =  pAtmoConfigSrc->m_LiveView_DarknessLimit;
178     this->m_LiveView_HueWinSize     =  pAtmoConfigSrc->m_LiveView_HueWinSize;
179     this->m_LiveView_SatWinSize     =  pAtmoConfigSrc->m_LiveView_SatWinSize;
180     this->m_LiveView_WidescreenMode =  pAtmoConfigSrc->m_LiveView_WidescreenMode;
181
182     this->m_LiveView_HOverscanBorder  = pAtmoConfigSrc->m_LiveView_HOverscanBorder;
183     this->m_LiveView_VOverscanBorder  = pAtmoConfigSrc->m_LiveView_VOverscanBorder;
184     this->m_LiveView_DisplayNr        = pAtmoConfigSrc->m_LiveView_DisplayNr;
185     this->m_LiveView_FrameDelay       = pAtmoConfigSrc->m_LiveView_FrameDelay;
186
187     clearChannelMappings();
188     for(int i=1;i<pAtmoConfigSrc->getNumChannelAssignments();i++) {
189         tChannelAssignment *ta = pAtmoConfigSrc->m_ChannelAssignments[i];
190         if(ta!=NULL) {
191             tChannelAssignment *dest = this->m_ChannelAssignments[i];
192             if(dest == NULL) {
193                dest = new tChannelAssignment;
194                this->m_ChannelAssignments[i] = dest;
195             }
196             memcpy(dest, ta, sizeof(tChannelAssignment));
197         }
198     }
199 }
200
201
202
203 int CAtmoConfig::getNumChannelAssignments() {
204     int z=0;
205     for(int i=0;i<10;i++)
206         if(this->m_ChannelAssignments[i]!=NULL) z++;
207     return z;
208 }
209
210 void CAtmoConfig::clearChannelMappings() {
211     for(int i=1;i<10;i++) {
212         tChannelAssignment *ca = m_ChannelAssignments[i];
213         delete ca;
214         m_ChannelAssignments[i] = NULL;
215     }
216 }
217
218 void CAtmoConfig::clearAllChannelMappings() {
219     for(int i=0;i<10;i++) {
220         tChannelAssignment *ca = m_ChannelAssignments[i];
221         delete ca;
222         m_ChannelAssignments[i] = NULL;
223     }
224 }
225
226 void CAtmoConfig::AddChannelAssignment(tChannelAssignment *ta) {
227     for(int i=0;i<10;i++) {
228         if(m_ChannelAssignments[i] == NULL) {
229            m_ChannelAssignments[i] = ta;
230            break;
231         }
232     }
233 }
234
235 void CAtmoConfig::SetChannelAssignment(int index, tChannelAssignment *ta) {
236     delete m_ChannelAssignments[index];
237     m_ChannelAssignments[index] = ta;
238 }
239
240 CAtmoZoneDefinition *CAtmoConfig::getZoneDefinition(int zoneIndex) {
241     if(zoneIndex < 0)
242        return NULL;
243     if(zoneIndex >= ATMO_NUM_CHANNELS)
244        return NULL;
245     return m_ZoneDefinitions[zoneIndex];
246
247 }
248