]> git.sesse.net Git - vlc/blob - modules/video_filter/atmo/AtmoConfig.cpp
android_window: check subtitles bounds
[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 #ifdef HAVE_CONFIG_H
11 # include "config.h"
12 #endif
13
14 #include <stdio.h>
15 #include <string.h>
16
17 #include "AtmoConfig.h"
18
19 /* Import Hint
20
21    if somebody Adds new config option this has to be done in the following
22    files and includes!
23
24    AtmoConfig.h  -- extend class definition!, and add get... and set... Methods!
25                     so that the real variables are still hidden inside the class!
26    AtmoConfigRegistry.cpp --> SaveToRegistry();
27    AtmoConfigRegistry.cpp --> LoadFromRegistry();
28    AtmoConfig.cpp --> Assign( ... );
29
30 */
31
32 CAtmoConfig::CAtmoConfig()
33 {
34   // setup basic configruation structures...
35   m_IsShowConfigDialog = 0;
36   m_eAtmoConnectionType = actClassicAtmo;
37   for(int i=0;i<10;i++)
38       m_ChannelAssignments[i] = NULL;
39
40 #if defined (_ATMO_VLC_PLUGIN_)
41   m_devicename = NULL;
42   m_devicenames[0] = NULL;
43   m_devicenames[1] = NULL;
44   m_devicenames[2] = NULL;
45 #endif
46   // load all config values with there defaults
47   m_ZoneDefinitions  = NULL;
48   m_AtmoZoneDefCount = -1;
49   m_DMX_BaseChannels = NULL;
50
51   m_chWhiteAdj_Red   = NULL;
52   m_chWhiteAdj_Green = NULL;
53   m_chWhiteAdj_Blue  = NULL;
54
55   LoadDefaults();
56 }
57
58 CAtmoConfig::~CAtmoConfig() {
59    // and finally cleanup...
60    clearAllChannelMappings();
61
62    if(m_ZoneDefinitions)
63    {
64      for(int zone=0; zone<m_AtmoZoneDefCount; zone++)
65          delete m_ZoneDefinitions[zone];
66      delete[] m_ZoneDefinitions;
67      m_ZoneDefinitions = NULL;
68    }
69
70    delete []m_chWhiteAdj_Red;
71    delete []m_chWhiteAdj_Green;
72    delete []m_chWhiteAdj_Blue;
73
74    free( m_DMX_BaseChannels );
75
76 #if defined (_ATMO_VLC_PLUGIN_)
77     free( m_devicename );
78     free( m_devicenames[0] );
79     free( m_devicenames[1] );
80     free( m_devicenames[2] );
81 #endif
82 }
83
84 void CAtmoConfig::LoadDefaults() {
85     //    m_eAtmoConnectionType = actSerialPort;
86     //    m_Comport
87 #if defined (_ATMO_VLC_PLUGIN_)
88
89     free( m_devicename );
90     free( m_devicenames[0] );
91     free( m_devicenames[1] );
92     free( m_devicenames[2] );
93
94     m_devicename = NULL;
95     m_devicenames[0] = NULL;
96     m_devicenames[1] = NULL;
97     m_devicenames[2] = NULL;
98
99 #else
100
101     m_Comport     = -1;
102     m_Comports[0] = -1;
103     m_Comports[1] = -1;
104     m_Comports[2] = -1;
105
106 #endif
107
108     m_eEffectMode = emDisabled;
109
110     m_IgnoreConnectionErrorOnStartup = ATMO_FALSE;
111
112     m_UpdateEdgeWeightningFlag = 0;
113
114     m_Software_gamma_mode = agcNone;
115     m_Software_gamma_red    = 10;
116     m_Software_gamma_green  = 10;
117     m_Software_gamma_blue   = 10;
118     m_Software_gamma_global = 10;
119
120     m_WhiteAdjustment_Red    = 255;
121     m_WhiteAdjustment_Green  = 255;
122     m_WhiteAdjustment_Blue   = 255;
123     m_UseSoftwareWhiteAdj    = 1;
124
125     m_WhiteAdjPerChannel = ATMO_FALSE;
126     m_chWhiteAdj_Count = 0;
127
128     delete []m_chWhiteAdj_Red;
129     delete []m_chWhiteAdj_Green;
130     delete []m_chWhiteAdj_Blue;
131
132     m_chWhiteAdj_Red   = NULL;
133     m_chWhiteAdj_Green = NULL;
134     m_chWhiteAdj_Blue  = NULL;
135
136     m_ColorChanger_iSteps    = 50;
137     m_ColorChanger_iDelay    = 25;
138
139     m_LrColorChanger_iSteps  = 50;
140     m_LrColorChanger_iDelay  = 25;
141
142     m_IsSetShutdownColor     = 1;
143     m_ShutdownColor_Red      = 0;
144     m_ShutdownColor_Green    = 0;
145     m_ShutdownColor_Blue     = 0;
146
147     m_StaticColor_Red        = 127; // ??
148     m_StaticColor_Green      = 192;
149     m_StaticColor_Blue       = 255;
150
151     m_LiveViewFilterMode         = afmCombined;
152     m_LiveViewFilter_PercentNew  = 50;
153     m_LiveViewFilter_MeanLength  = 300;
154     m_LiveViewFilter_MeanThreshold   = 40;
155     m_show_statistics = ATMO_FALSE;
156
157     m_LiveView_EdgeWeighting  = 8;
158     m_LiveView_BrightCorrect  = 100;
159     m_LiveView_DarknessLimit  = 5;
160     m_LiveView_HueWinSize     = 3;
161     m_LiveView_SatWinSize     = 3;
162     m_LiveView_WidescreenMode = 0;
163
164     m_LiveView_HOverscanBorder  = 0;
165     m_LiveView_VOverscanBorder  = 0;
166     m_LiveView_DisplayNr        = 0;
167     m_LiveView_FrameDelay       = 30;
168     m_LiveView_GDI_FrameRate    = 25;
169     m_LiveView_RowsPerFrame     = 0;
170
171
172     m_Hardware_global_gamma    = 128;
173     m_Hardware_global_contrast = 100;
174     m_Hardware_contrast_red    = 100;
175     m_Hardware_contrast_green  = 100;
176     m_Hardware_contrast_blue   = 100;
177
178     m_Hardware_gamma_red       = 22;
179     m_Hardware_gamma_green     = 22;
180     m_Hardware_gamma_blue      = 22;
181
182     m_DMX_BaseChannels         = strdup("0");
183     m_DMX_RGB_Channels        = 5; // so wie atmolight
184
185     m_MoMo_Channels           = 3; // default momo, there exists also a 4 ch version!
186     m_Fnordlicht_Amount       = 2; // default fnordlicht, there are 2 fnordlicht's!
187
188     m_ZonesTopCount            = 1;
189     m_ZonesBottomCount         = 1;
190     m_ZonesLRCount             = 1;
191     m_ZoneSummary              = ATMO_FALSE;
192     UpdateZoneCount();
193
194     clearAllChannelMappings();
195     m_CurrentChannelAssignment = 0;
196     CAtmoChannelAssignment *temp = new CAtmoChannelAssignment();
197     temp->system = true;
198     temp->setName( "Standard" );
199     this->m_ChannelAssignments[0] =  temp;
200
201     UpdateZoneDefinitionCount();
202 }
203
204 void CAtmoConfig::Assign(CAtmoConfig *pAtmoConfigSrc) {
205
206 #if defined(_ATMO_VLC_PLUGIN_)
207     this->setSerialDevice(0, pAtmoConfigSrc->getSerialDevice(0));
208     this->setSerialDevice(1, pAtmoConfigSrc->getSerialDevice(1));
209     this->setSerialDevice(2, pAtmoConfigSrc->getSerialDevice(2));
210     this->setSerialDevice(3, pAtmoConfigSrc->getSerialDevice(3));
211 #else
212     this->m_Comport                  = pAtmoConfigSrc->m_Comport;
213     this->m_Comports[0]              = pAtmoConfigSrc->m_Comports[0];
214     this->m_Comports[1]              = pAtmoConfigSrc->m_Comports[1];
215     this->m_Comports[2]              = pAtmoConfigSrc->m_Comports[2];
216 #endif
217
218     this->m_eAtmoConnectionType      = pAtmoConfigSrc->m_eAtmoConnectionType;
219     this->m_eEffectMode              = pAtmoConfigSrc->m_eEffectMode;
220
221     this->m_WhiteAdjustment_Red      = pAtmoConfigSrc->m_WhiteAdjustment_Red;
222     this->m_WhiteAdjustment_Green    = pAtmoConfigSrc->m_WhiteAdjustment_Green;
223     this->m_WhiteAdjustment_Blue     = pAtmoConfigSrc->m_WhiteAdjustment_Blue;
224     this->m_UseSoftwareWhiteAdj      = pAtmoConfigSrc->m_UseSoftwareWhiteAdj;
225
226     this->m_WhiteAdjPerChannel       = pAtmoConfigSrc->m_WhiteAdjPerChannel;
227     this->m_chWhiteAdj_Count         = pAtmoConfigSrc->m_chWhiteAdj_Count;
228     delete []m_chWhiteAdj_Red;
229     delete []m_chWhiteAdj_Green;
230     delete []m_chWhiteAdj_Blue;
231     if(m_chWhiteAdj_Count > 0)
232     {
233        m_chWhiteAdj_Red   = new int[ m_chWhiteAdj_Count ];
234        m_chWhiteAdj_Green = new int[ m_chWhiteAdj_Count ];
235        m_chWhiteAdj_Blue  = new int[ m_chWhiteAdj_Count ];
236        memcpy(m_chWhiteAdj_Red, pAtmoConfigSrc->m_chWhiteAdj_Red, sizeof(int) * m_chWhiteAdj_Count);
237        memcpy(m_chWhiteAdj_Green, pAtmoConfigSrc->m_chWhiteAdj_Green, sizeof(int) * m_chWhiteAdj_Count);
238        memcpy(m_chWhiteAdj_Blue, pAtmoConfigSrc->m_chWhiteAdj_Blue, sizeof(int) * m_chWhiteAdj_Count);
239     } else {
240        m_chWhiteAdj_Red   = NULL;
241        m_chWhiteAdj_Green = NULL;
242        m_chWhiteAdj_Blue  = NULL;
243     }
244
245     this->m_IsSetShutdownColor       = pAtmoConfigSrc->m_IsSetShutdownColor;
246     this->m_ShutdownColor_Red        = pAtmoConfigSrc->m_ShutdownColor_Red;
247     this->m_ShutdownColor_Green      = pAtmoConfigSrc->m_ShutdownColor_Green;
248     this->m_ShutdownColor_Blue       = pAtmoConfigSrc->m_ShutdownColor_Blue;
249
250     this->m_ColorChanger_iSteps      = pAtmoConfigSrc->m_ColorChanger_iSteps;
251     this->m_ColorChanger_iDelay      = pAtmoConfigSrc->m_ColorChanger_iDelay;
252
253     this->m_LrColorChanger_iSteps    = pAtmoConfigSrc->m_LrColorChanger_iSteps;
254     this->m_LrColorChanger_iDelay    = pAtmoConfigSrc->m_LrColorChanger_iDelay;
255
256     this->m_StaticColor_Red          = pAtmoConfigSrc->m_StaticColor_Red;
257     this->m_StaticColor_Green        = pAtmoConfigSrc->m_StaticColor_Green;
258     this->m_StaticColor_Blue         = pAtmoConfigSrc->m_StaticColor_Blue;
259
260     this->m_LiveViewFilterMode             = pAtmoConfigSrc->m_LiveViewFilterMode;
261     this->m_LiveViewFilter_PercentNew      = pAtmoConfigSrc->m_LiveViewFilter_PercentNew;
262     this->m_LiveViewFilter_MeanLength      = pAtmoConfigSrc->m_LiveViewFilter_MeanLength;
263     this->m_LiveViewFilter_MeanThreshold   = pAtmoConfigSrc->m_LiveViewFilter_MeanThreshold;
264
265     this->m_show_statistics               = pAtmoConfigSrc->m_show_statistics;
266
267     this->m_LiveView_EdgeWeighting  =  pAtmoConfigSrc->m_LiveView_EdgeWeighting;
268     this->m_LiveView_BrightCorrect  =  pAtmoConfigSrc->m_LiveView_BrightCorrect;
269     this->m_LiveView_DarknessLimit  =  pAtmoConfigSrc->m_LiveView_DarknessLimit;
270     this->m_LiveView_HueWinSize     =  pAtmoConfigSrc->m_LiveView_HueWinSize;
271     this->m_LiveView_SatWinSize     =  pAtmoConfigSrc->m_LiveView_SatWinSize;
272     this->m_LiveView_WidescreenMode =  pAtmoConfigSrc->m_LiveView_WidescreenMode;
273
274     this->m_LiveView_HOverscanBorder  = pAtmoConfigSrc->m_LiveView_HOverscanBorder;
275     this->m_LiveView_VOverscanBorder  = pAtmoConfigSrc->m_LiveView_VOverscanBorder;
276     this->m_LiveView_DisplayNr        = pAtmoConfigSrc->m_LiveView_DisplayNr;
277     this->m_LiveView_FrameDelay       = pAtmoConfigSrc->m_LiveView_FrameDelay;
278     this->m_LiveView_GDI_FrameRate    = pAtmoConfigSrc->m_LiveView_GDI_FrameRate;
279     this->m_LiveView_RowsPerFrame   =  pAtmoConfigSrc->m_LiveView_RowsPerFrame;
280
281     this->m_ZonesTopCount             = pAtmoConfigSrc->m_ZonesTopCount;
282     this->m_ZonesBottomCount          = pAtmoConfigSrc->m_ZonesBottomCount;
283     this->m_ZonesLRCount              = pAtmoConfigSrc->m_ZonesLRCount;
284     this->m_ZoneSummary               = pAtmoConfigSrc->m_ZoneSummary;
285     UpdateZoneCount();
286
287     this->m_Software_gamma_mode      =  pAtmoConfigSrc->m_Software_gamma_mode;
288     this->m_Software_gamma_red       =  pAtmoConfigSrc->m_Software_gamma_red;
289     this->m_Software_gamma_green     =  pAtmoConfigSrc->m_Software_gamma_green;
290     this->m_Software_gamma_blue      =  pAtmoConfigSrc->m_Software_gamma_blue;
291     this->m_Software_gamma_global    =  pAtmoConfigSrc->m_Software_gamma_global;
292
293     this->setDMX_BaseChannels( pAtmoConfigSrc->getDMX_BaseChannels() );
294
295     this->m_DMX_RGB_Channels         = pAtmoConfigSrc->m_DMX_RGB_Channels;
296
297     this->m_MoMo_Channels            = pAtmoConfigSrc->m_MoMo_Channels;
298
299     this->m_Fnordlicht_Amount        = pAtmoConfigSrc->m_Fnordlicht_Amount;
300
301     this->m_CurrentChannelAssignment = pAtmoConfigSrc->m_CurrentChannelAssignment;
302
303     clearChannelMappings();
304     for(int i=1;i<pAtmoConfigSrc->getNumChannelAssignments();i++) {
305         CAtmoChannelAssignment *ta = pAtmoConfigSrc->m_ChannelAssignments[i];
306         if(ta!=NULL) {
307             CAtmoChannelAssignment *dest = this->m_ChannelAssignments[i];
308             if(dest == NULL) {
309                dest = new CAtmoChannelAssignment();
310                this->m_ChannelAssignments[i] = dest;
311             }
312             // memcpy(dest, ta, sizeof(tChannelAssignment));
313             dest->setSize(ta->getSize());
314             dest->setName(ta->getName());
315             dest->system = ta->system;
316             for(int c=0;c<dest->getSize();c++)
317                 dest->setZoneIndex(c, ta->getZoneIndex(c));
318         }
319     }
320
321     UpdateZoneDefinitionCount();
322 }
323
324 int CAtmoConfig::getNumChannelAssignments() {
325     int z=0;
326     for(int i=0;i<10;i++)
327         if(this->m_ChannelAssignments[i]!=NULL) z++;
328     return z;
329 }
330
331 void CAtmoConfig::clearChannelMappings() {
332     for(int i=1;i<10;i++) {
333         CAtmoChannelAssignment *ca = m_ChannelAssignments[i];
334         if(ca!=NULL)
335            delete ca;
336         m_ChannelAssignments[i] = NULL;
337     }
338 }
339
340 void CAtmoConfig::clearAllChannelMappings() {
341     for(int i=0;i<10;i++) {
342         CAtmoChannelAssignment *ca = m_ChannelAssignments[i];
343         if(ca!=NULL)
344            delete ca;
345         m_ChannelAssignments[i] = NULL;
346     }
347 }
348
349 void CAtmoConfig::AddChannelAssignment(CAtmoChannelAssignment *ta) {
350     for(int i=0;i<10;i++) {
351         if(m_ChannelAssignments[i] == NULL) {
352            m_ChannelAssignments[i] = ta;
353            break;
354         }
355     }
356 }
357
358 void CAtmoConfig::SetChannelAssignment(int index, CAtmoChannelAssignment *ta) {
359      if(m_ChannelAssignments[index]!=NULL)
360         delete m_ChannelAssignments[index];
361      m_ChannelAssignments[index] = ta;
362 }
363
364 CAtmoZoneDefinition *CAtmoConfig::getZoneDefinition(int zoneIndex) {
365     if(zoneIndex < 0)
366        return NULL;
367     if(zoneIndex >= m_AtmoZoneDefCount)
368        return NULL;
369     return m_ZoneDefinitions[zoneIndex];
370
371 }
372
373 void CAtmoConfig::UpdateZoneCount()
374 {
375   m_computed_zones_count = m_ZonesTopCount + m_ZonesBottomCount + 2 * m_ZonesLRCount;
376   if(m_ZoneSummary)
377      m_computed_zones_count++;
378 }
379
380 int CAtmoConfig::getZoneCount()
381 {
382     return(m_computed_zones_count);
383 }
384
385 void CAtmoConfig::UpdateZoneDefinitionCount()
386 {
387    if( getZoneCount() != m_AtmoZoneDefCount)
388    {
389       // okay zonen anzahl hat sich geändert - wir müssen neu rechnen
390       // und allokieren!
391       if(m_ZoneDefinitions)
392       {
393         for(int zone=0; zone<m_AtmoZoneDefCount; zone++)
394             delete m_ZoneDefinitions[zone];
395         delete[] m_ZoneDefinitions;
396         m_ZoneDefinitions = NULL;
397       }
398       m_AtmoZoneDefCount = getZoneCount();
399       if(m_AtmoZoneDefCount > 0)
400       {
401          m_ZoneDefinitions = new CAtmoZoneDefinition*[m_AtmoZoneDefCount];
402          for(int zone=0; zone< m_AtmoZoneDefCount; zone++) {
403              m_ZoneDefinitions[zone] = new CAtmoZoneDefinition();
404              m_ZoneDefinitions[zone]->Fill(255);
405          }
406       }
407    }
408 }
409
410 #if defined(_ATMO_VLC_PLUGIN_)
411
412 char *CAtmoConfig::getSerialDevice(int i)
413 {
414    if(i == 0)
415       return m_devicename;
416    else  {
417        i--;
418        return m_devicenames[i];
419    }
420 }
421
422 void CAtmoConfig::setSerialDevice(int i,const char *pszNewDevice)
423 {
424     if(i == 0)
425        setSerialDevice(pszNewDevice);
426     else {
427        i--;
428        free( m_devicenames[i] );
429        if(pszNewDevice)
430           m_devicenames[i] = strdup(pszNewDevice);
431        else
432           m_devicenames[i] = NULL;
433     }
434 }
435
436 #else
437
438 int CAtmoConfig::getComport(int i)
439 {
440   if(i == 0)
441      return this->m_Comport;
442   else {
443      i--;
444      return this->m_Comports[i];
445   }
446 }
447
448 void CAtmoConfig::setComport(int i, int nr)
449 {
450   if(i == 0)
451       this->m_Comport = nr;
452   else {
453     this->m_Comports[i-1] = nr;
454   }
455 }
456
457 #endif
458
459 void CAtmoConfig::setDMX_BaseChannels(char *channels)
460 {
461      free(m_DMX_BaseChannels);
462      m_DMX_BaseChannels = strdup(channels);
463 }
464
465 void CAtmoConfig::getChannelWhiteAdj(int channel,int &red,int &green,int &blue)
466 {
467   if(channel >= m_chWhiteAdj_Count)
468   {
469      red = 256;
470      green = 256;
471      blue = 256;
472
473   } else {
474
475     red   = m_chWhiteAdj_Red[ channel ];
476     green = m_chWhiteAdj_Green[ channel ];
477     blue  = m_chWhiteAdj_Blue[ channel ];
478
479   }
480 }
481
482 void CAtmoConfig::setChannelWhiteAdj(int channel,int red,int green,int blue)
483 {
484     if(channel >= m_chWhiteAdj_Count)
485     {
486        int *tmp = new int[channel+1];
487        if(m_chWhiteAdj_Red)
488           memcpy( tmp, m_chWhiteAdj_Red, m_chWhiteAdj_Count * sizeof(int) );
489        delete []m_chWhiteAdj_Red;
490        m_chWhiteAdj_Red = tmp;
491
492        tmp = new int[channel + 1];
493        if(m_chWhiteAdj_Green)
494           memcpy( tmp, m_chWhiteAdj_Green, m_chWhiteAdj_Count * sizeof(int) );
495        delete []m_chWhiteAdj_Green;
496        m_chWhiteAdj_Green = tmp;
497
498        tmp = new int[channel + 1];
499        if(m_chWhiteAdj_Blue)
500           memcpy( tmp, m_chWhiteAdj_Blue, m_chWhiteAdj_Count * sizeof(int) );
501        delete []m_chWhiteAdj_Blue;
502        m_chWhiteAdj_Blue = tmp;
503
504        m_chWhiteAdj_Count = channel + 1;
505    }
506
507    m_chWhiteAdj_Red[channel]   = red;
508    m_chWhiteAdj_Green[channel] = green;
509    m_chWhiteAdj_Blue[channel]  = blue;
510
511 }