forked from ambilight-4-mediaportal/AtmoWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtmoTools.cpp
More file actions
844 lines (692 loc) · 24.4 KB
/
Copy pathAtmoTools.cpp
File metadata and controls
844 lines (692 loc) · 24.4 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
/*
* AtmoTools.cpp: Collection of tool and helperfunction
*
* See the README.txt file for copyright information and how to reach the author(s).
*
* $Id: 45dfca6a1929a43f6514eceda43096061a929399 $
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "AtmoTools.h"
#include "AtmoDynData.h"
#include "AtmoLiveView.h"
#include "AtmoClassicConnection.h"
#include "AtmoDmxSerialConnection.h"
#include "AtmoEntecSerialConnection.h"
#include "AtmoMultiConnection.h"
#include "MoMoConnection.h"
#include "FnordlichtConnection.h"
#include "AtmoDuinoV2Connection.h"
#include "AtmoExternalCaptureInput.h"
#include <math.h>
#include "Language.h"
#if !defined(_ATMO_VLC_PLUGIN_)
# include "AtmoColorChanger.h"
# include "AtmoLeftRightColorChanger.h"
# include "AtmoDummyConnection.h"
# include "AtmoNulConnection.h"
# include "MondolightConnection.h"
# include "AtmoGdiDisplayCaptureInput.h"
# include "AtmoDesktopDuplicationCaptureInput.h"
#endif
CAtmoTools::CAtmoTools(void)
{
}
CAtmoTools::~CAtmoTools(void)
{
}
void CAtmoTools::ShowShutdownColor(CAtmoDynData *pDynData)
{
pDynData->LockCriticalSection();
CAtmoConnection *atmoConnection = pDynData->getAtmoConnection();
CAtmoConfig *atmoConfig = pDynData->getAtmoConfig();
if((atmoConnection != NULL) && (atmoConfig!=NULL) && atmoConfig->isSetShutdownColor())
{
int i;
pColorPacket packet;
AllocColorPacket(packet, atmoConfig->getZoneCount());
// set a special color? on shutdown of the software? mostly may use black or so ...
// if this function ist disabled ... atmo will continuing to show the last color...
for(i = 0; i < packet->numColors; i++)
{
packet->zone[i].r = atmoConfig->getShutdownColor_Red();
packet->zone[i].g = atmoConfig->getShutdownColor_Green();
packet->zone[i].b = atmoConfig->getShutdownColor_Blue();
}
packet = CAtmoTools::ApplyGamma(atmoConfig, packet);
if(atmoConfig->isUseSoftwareWhiteAdj())
packet = CAtmoTools::WhiteCalibration(atmoConfig, packet);
atmoConnection->SendData(packet);
delete (char *)packet;
}
pDynData->UnLockCriticalSection();
}
EffectMode CAtmoTools::SwitchEffect(CAtmoDynData *pDynData, EffectMode newEffectMode)
{
// may need a critical section??
if(pDynData == NULL)
{
return emUndefined;
}
pDynData->LockCriticalSection();
CAtmoConfig *atmoConfig = pDynData->getAtmoConfig();
if(atmoConfig == NULL)
{
pDynData->UnLockCriticalSection();
return emUndefined;
}
CAtmoConnection *atmoConnection = pDynData->getAtmoConnection();
EffectMode oldEffectMode = atmoConfig->getEffectMode();
CThread *currentEffect = pDynData->getEffectThread();
CAtmoInput *currentInput = pDynData->getLiveInput();
CAtmoPacketQueue *currentPacketQueue = pDynData->getLivePacketQueue();
if(oldEffectMode == emLivePicture)
{
/* in case of disabling the live mode
first we have to stop the input
then the effect thread!
*/
if(currentInput != NULL)
{
pDynData->setLiveInput( NULL );
currentInput->Close();
delete currentInput;
currentInput = NULL;
}
}
// stop and delete/cleanup current Effect Thread...
pDynData->setEffectThread( NULL );
if(currentEffect != NULL)
{
currentEffect->Terminate();
delete currentEffect;
currentEffect = NULL;
}
if(oldEffectMode == emLivePicture)
{
/*
and last we kill the PacketQueue used for communication between the threads
*/
pDynData->setLivePacketQueue( NULL );
delete currentPacketQueue;
currentPacketQueue = NULL;
}
if((atmoConnection!=NULL) && (atmoConnection->isOpen()==ATMO_TRUE))
{
// neuen EffectThread nur mit aktiver Connection starten...
switch(newEffectMode)
{
case emUndefined: // do nothing also in that case (avoid compiler warning)
break;
case emDisabled:
{
// get values from config - and put them to all channels?
pColorPacket packet;
AllocColorPacket(packet, atmoConfig->getZoneCount());
for(int i=0; i < packet->numColors; i++)
{
packet->zone[i].r = 0;
packet->zone[i].g = 0;
packet->zone[i].b = 0;
}
atmoConnection->SendData( packet );
atmoConnection->SendData( packet );
delete (char *)packet;
break;
}
case emStaticColor:
{
// get values from config - and put them to all channels?
pColorPacket packet;
AllocColorPacket(packet, atmoConfig->getZoneCount());
for(int i=0; i < packet->numColors; i++){
packet->zone[i].r = atmoConfig->getStaticColor_Red();
packet->zone[i].g = atmoConfig->getStaticColor_Green();
packet->zone[i].b = atmoConfig->getStaticColor_Blue();
}
packet = CAtmoTools::ApplyGamma( atmoConfig, packet );
if(atmoConfig->isUseSoftwareWhiteAdj())
packet = CAtmoTools::WhiteCalibration(atmoConfig, packet);
atmoConnection->SendData( packet );
atmoConnection->SendData( packet );
delete (char *)packet;
break;
}
case emLivePicture:
{
currentEffect = new CAtmoLiveView(pDynData);
#if !defined(_ATMO_VLC_PLUGIN_)
CAtmoPacketQueueStatus *packetMon = NULL;
if(atmoConfig->getShow_statistics())
{
packetMon = new CAtmoPacketQueueStatus(pDynData->getAppHinstance(), (HWND)NULL);
packetMon->createWindow();
packetMon->showWindow(SW_SHOW);
}
currentPacketQueue = new CAtmoPacketQueue(packetMon);
pDynData->setLivePictureSource(lpsScreenCapture);
//Atmo liveview option GDi <Win7 / DekstopDuplication >Win8
int AtmoSetup_Mode = atmoConfig->getLiveView_Mode();
if (AtmoSetup_Mode == 1)
{
currentInput = new CAtmoDesktopDuplicationCaptureInput( pDynData );
}
else
{
currentInput = new CAtmoGdiDisplayCaptureInput( pDynData );
}
#else
currentPacketQueue = new CAtmoPacketQueue();
pDynData->setLivePictureSource(lpsExtern);
currentInput = new CAtmoExternalCaptureInput( pDynData );
#endif
break;
}
#if !defined(_ATMO_VLC_PLUGIN_)
case emColorChange:
currentEffect = new CAtmoColorChanger(atmoConnection, atmoConfig);
break;
case emLrColorChange:
currentEffect = new CAtmoLeftRightColorChanger(atmoConnection, atmoConfig);
break;
#endif
}
}
atmoConfig->setEffectMode( newEffectMode );
pDynData->setLivePacketQueue( currentPacketQueue );
pDynData->setEffectThread( currentEffect );
pDynData->setLiveInput( currentInput );
if(currentEffect != NULL)
currentEffect->Run();
if(currentInput != NULL)
currentInput->Open();
pDynData->UnLockCriticalSection();
return oldEffectMode;
}
LivePictureSource CAtmoTools::SwitchLiveSource(CAtmoDynData *pDynData, LivePictureSource newLiveSource)
{
LivePictureSource oldSource;
pDynData->LockCriticalSection();
oldSource = pDynData->getLivePictureSource();
pDynData->setLivePictureSource( newLiveSource );
if ((pDynData->getAtmoConfig()->getEffectMode() == emLivePicture) &&
(pDynData->getEffectThread() != NULL) &&
(pDynData->getLivePacketQueue() != NULL))
{
CAtmoInput *input = pDynData->getLiveInput();
pDynData->setLiveInput( NULL );
if(input != NULL)
{
input->Close();
delete input;
input = NULL;
}
switch(pDynData->getLivePictureSource())
{
case lpsDisabled: // do nothing in that case - avoid compiler warning
break;
#if !defined(_ATMO_VLC_PLUGIN_)
case lpsScreenCapture:
input = new CAtmoGdiDisplayCaptureInput( pDynData );
break;
#endif
case lpsExtern:
input = new CAtmoExternalCaptureInput( pDynData );
break;
}
pDynData->setLiveInput( input );
if(input != NULL)
input->Open();
}
pDynData->UnLockCriticalSection();
return oldSource;
}
ATMO_BOOL CAtmoTools::RecreateConnection(CAtmoDynData *pDynData)
{
pDynData->LockCriticalSection();
CLanguage *Lng = new CLanguage;
CAtmoConnection *current = pDynData->getAtmoConnection();
CAtmoConfig *atmoConfig = pDynData->getAtmoConfig();
AtmoConnectionType act = atmoConfig->getConnectionType();
pDynData->setAtmoConnection(NULL);
if(current != NULL)
{
current->CloseConnection();
delete current;
}
switch(act)
{
case actClassicAtmo:
{
CAtmoClassicConnection *tempConnection = new CAtmoClassicConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
#if !defined(_ATMO_VLC_PLUGIN_)
if(atmoConfig->getIgnoreConnectionErrorOnStartup() == ATMO_FALSE)
{
char errorMsgBuf[200];
sprintf(errorMsgBuf,Lng->sMessagesText[26] + "com%d" + Lng->sMessagesText[26] + "%d (0x%x)",
pDynData->getAtmoConfig()->getArduComport(),
tempConnection->getLastError(),
tempConnection->getLastError()
);
MessageBox(0,errorMsgBuf,Lng->sMessagesText[3] ,MB_ICONERROR | MB_OK);
}
#endif
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));
CAtmoTools::SetChannelAssignment(pDynData,
atmoConfig->getCurrentChannelAssignment());
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
#if !defined(_ATMO_VLC_PLUGIN_)
case actDummy:
{
// actDummy8,actDummy12,actDummy16
CAtmoDummyConnection *tempConnection = new CAtmoDummyConnection(pDynData->getResHinstance(),
atmoConfig);
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));
CAtmoTools::SetChannelAssignment(pDynData, pDynData->getAtmoConfig()->getCurrentChannelAssignment());
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
#endif
case actDMX:
{
// create here your DMX connections... instead of the dummy....
CAtmoDmxSerialConnection *tempConnection = new CAtmoDmxSerialConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));
CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
#if !defined(_ATMO_VLC_PLUGIN_)
case actNUL:
{
CAtmoNulConnection *tempConnection = new CAtmoNulConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));
CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
#endif
case actMultiAtmo:
{
CAtmoMultiConnection *tempConnection = new CAtmoMultiConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));
CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
#if !defined(_ATMO_VLC_PLUGIN_)
case actMondolight:
{
CMondolightConnection *tempConnection = new CMondolightConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));
CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
#endif
case actMoMoLight:
{
CMoMoConnection *tempConnection = new CMoMoConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping( atmoConfig->getChannelAssignment(0) );
CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment() );
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
case actFnordlicht:
{
CFnordlichtConnection *tempConnection = new CFnordlichtConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping( atmoConfig->getChannelAssignment(0) );
CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment() );
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
case actEnttecDMX:
{
CAtmoEntecSerialConnection *tempConnection = new CAtmoEntecSerialConnection( atmoConfig );
if(tempConnection->OpenConnection() == ATMO_FALSE)
{
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping( atmoConfig->getChannelAssignment(0) );
CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment() );
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
case actAtmoDuinoV2: {
CAtmoDuinoV2Connection *tempConnection = new CAtmoDuinoV2Connection(atmoConfig);
if (tempConnection->OpenConnection() == ATMO_FALSE) {
#if !defined(_ATMO_VLC_PLUGIN_)
if (atmoConfig->getIgnoreConnectionErrorOnStartup() == ATMO_FALSE)
{
char errorMsgBuf[200];
sprintf(errorMsgBuf, "Failed to open serial port com%d with errorcode: %d (0x%x)",
pDynData->getAtmoConfig()->getComport(),
tempConnection->getLastError(),
tempConnection->getLastError()
);
MessageBox(0, errorMsgBuf, "Error", MB_ICONERROR | MB_OK);
}
#endif
pDynData->setAtmoConnection(tempConnection);
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
pDynData->setAtmoConnection(tempConnection);
pDynData->ReloadZoneDefinitionBitmaps();
tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));
CAtmoTools::SetChannelAssignment(pDynData,
atmoConfig->getCurrentChannelAssignment());
pDynData->UnLockCriticalSection();
return ATMO_TRUE;
}
default:
{
pDynData->UnLockCriticalSection();
return ATMO_FALSE;
}
}
}
pColorPacket CAtmoTools::WhiteCalibration(CAtmoConfig *pAtmoConfig, pColorPacket ColorPacket)
{
if (pAtmoConfig->isUseSoftware2WhiteAdj())
{
for (int i = 0; i < ColorPacket->numColors; i++)
{
ColorPacket->zone[i].r = (unsigned char)(pAtmoConfig->red_whiteAdj[(int)ColorPacket->zone[i].r]);
ColorPacket->zone[i].g = (unsigned char)(pAtmoConfig->green_whiteAdj[(int)ColorPacket->zone[i].g]);
ColorPacket->zone[i].b = (unsigned char)(pAtmoConfig->blue_whiteAdj[(int)ColorPacket->zone[i].b]);
}
}
else
{
int w_adj_red = pAtmoConfig->getWhiteAdjustment_Red();
int w_adj_green = pAtmoConfig->getWhiteAdjustment_Green();
int w_adj_blue = pAtmoConfig->getWhiteAdjustment_Blue();
for (int i = 0; i < ColorPacket->numColors; i++)
{
ColorPacket->zone[i].r = (unsigned char)(((int)w_adj_red * (int)ColorPacket->zone[i].r) / 255);
ColorPacket->zone[i].g = (unsigned char)(((int)w_adj_green * (int)ColorPacket->zone[i].g) / 255);
ColorPacket->zone[i].b = (unsigned char)(((int)w_adj_blue * (int)ColorPacket->zone[i].b) / 255);
}
}
return ColorPacket;
}
pColorPacket CAtmoTools::Applyinvert(CAtmoConfig *pAtmoConfig, pColorPacket ColorPacket)
{
for (int zoneIdx = 0; zoneIdx < ColorPacket->numColors; zoneIdx++)
{
ColorPacket->zone[zoneIdx].r = 255-ColorPacket->zone[zoneIdx].r;
ColorPacket->zone[zoneIdx].g = 255-ColorPacket->zone[zoneIdx].g;
ColorPacket->zone[zoneIdx].b = 255-ColorPacket->zone[zoneIdx].b;
}
return ColorPacket;
}
pColorPacket CAtmoTools::ApplyColorK(CAtmoConfig *pAtmoConfig, pColorPacket ColorPacket)
{
for (int zoneIdx = 0; zoneIdx < ColorPacket->numColors; zoneIdx++)
{
ColorPacket->zone[zoneIdx].r = trilinear(pAtmoConfig, ColorPacket->zone[zoneIdx].r,ColorPacket->zone[zoneIdx].g, ColorPacket->zone[zoneIdx].b,0);
ColorPacket->zone[zoneIdx].g = trilinear(pAtmoConfig, ColorPacket->zone[zoneIdx].r,ColorPacket->zone[zoneIdx].g, ColorPacket->zone[zoneIdx].b,1);
ColorPacket->zone[zoneIdx].b = trilinear(pAtmoConfig, ColorPacket->zone[zoneIdx].r,ColorPacket->zone[zoneIdx].g, ColorPacket->zone[zoneIdx].b,2);
}
return ColorPacket;
}
pColorPacket CAtmoTools::ApplySens(CAtmoConfig *pAtmoConfig, pColorPacket ColorPacket)
{
for (int zoneIdx = 0; zoneIdx < ColorPacket->numColors; zoneIdx++)
{
int sens = pAtmoConfig->getLiveView_Sensitivity();
if ((ColorPacket->zone[zoneIdx].r < sens ) &&(ColorPacket->zone[zoneIdx].g < sens)&&(ColorPacket->zone[zoneIdx].b < sens))
{
ColorPacket->zone[zoneIdx].r = 0;
ColorPacket->zone[zoneIdx].g = 0;
ColorPacket->zone[zoneIdx].b = 0;
}
}
return ColorPacket;
}
int CAtmoTools::trilinear(CAtmoConfig *pAtmoConfig, int x, int y, int z, int col)
{
double xd = x/256.0f;
double yd = y/256.0f;
double zd = z/256.0f;
double c00 = 0 + pAtmoConfig->ColorCube[1][0][0][col]*xd;
double c10 = pAtmoConfig->ColorCube[0][1][0][col]*(1-xd) + pAtmoConfig->ColorCube[1][1][0][col]*xd;
double c01 = pAtmoConfig->ColorCube[0][0][1][col]*(1-xd) + pAtmoConfig->ColorCube[1][0][1][col]*xd;
double c11 = pAtmoConfig->ColorCube[0][1][1][col]*(1-xd) + pAtmoConfig->ColorCube[1][1][1][col]*xd;
double c0 = c00*(1-yd) + c10*yd;
double c1 = c01*(1-yd) + c11*yd;
return static_cast<int>(c0*(1-zd) + c1*zd + 0.5f);
};
int CAtmoTools::trilinear3dl(CAtmoConfig *pAtmoConfig,int x, int y, int z, int col)
{
int x0 = (int)x/17;
int x1 = x0 + 1;
if (x1 > 16) {x1 = x0;}
int y0 = (int)y/17;
int y1 = y0 + 1;
if (y1 > 16) {y1 = y0;}
int z0 = (int)z/17;
int z1 = z0 + 1;
if (z1 > 16) {z1 = z0;}
double xd = (x-x0*17)/15.0f;
double yd = (y-y0*17)/15.0f;
double zd = (z-z0*17)/15.0f;
double c00 = pAtmoConfig->little_ColorCube[x0][y0][z0][col]*(1-xd) + pAtmoConfig->little_ColorCube[x1][y0][z0][col]*xd;
double c10 = pAtmoConfig->little_ColorCube[x0][y1][z0][col]*(1-xd) + pAtmoConfig->little_ColorCube[x1][y1][z0][col]*xd;
double c01 = pAtmoConfig->little_ColorCube[x0][y0][z1][col]*(1-xd) + pAtmoConfig->little_ColorCube[x1][y0][z1][col]*xd;
double c11 = pAtmoConfig->little_ColorCube[x0][y1][z1][col]*(1-xd) + pAtmoConfig->little_ColorCube[x1][y1][z1][col]*xd;
double c0 = c00*(1-yd) + c10*yd;
double c1 = c01*(1-yd) + c11*yd;
return static_cast<int>(c0*(1-zd) + c1*zd + 0.5f);
};
pColorPacket CAtmoTools::Apply3dlut(CAtmoConfig *pAtmoConfig, pColorPacket ColorPacket)
{
for (int zoneIdx = 0; zoneIdx < ColorPacket->numColors; zoneIdx++)
{
ColorPacket->zone[zoneIdx].r = trilinear3dl(pAtmoConfig, ColorPacket->zone[zoneIdx].r,ColorPacket->zone[zoneIdx].g, ColorPacket->zone[zoneIdx].b,0);
ColorPacket->zone[zoneIdx].g = trilinear3dl(pAtmoConfig, ColorPacket->zone[zoneIdx].r,ColorPacket->zone[zoneIdx].g, ColorPacket->zone[zoneIdx].b,1);
ColorPacket->zone[zoneIdx].b = trilinear3dl(pAtmoConfig, ColorPacket->zone[zoneIdx].r,ColorPacket->zone[zoneIdx].g, ColorPacket->zone[zoneIdx].b,2);
}
return ColorPacket;
}
pColorPacket CAtmoTools::ApplyGamma(CAtmoConfig *pAtmoConfig, pColorPacket ColorPacket)
{
double v;
switch(pAtmoConfig->getSoftware_gamma_mode())
{
case agcNone: break;
case agcPerColor:
{
double GammaRed = 100.0 / ((double)pAtmoConfig->getSoftware_gamma_red());
double GammaGreen = 100.0 / ((double)pAtmoConfig->getSoftware_gamma_green());
double GammaBlue = 100.0 / ((double)pAtmoConfig->getSoftware_gamma_blue());
for (int i = 0; i < ColorPacket->numColors; i++)
{
v = ColorPacket->zone[i].r;
v = (pow( v / 255.0f, 1.0f/GammaRed ) * 255.0f);
ColorPacket->zone[i].r = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].g;
v = (pow( v / 255.0f, 1.0f/GammaGreen ) * 255.0f);
ColorPacket->zone[i].g = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].b;
v = (pow( v / 255.0f, 1.0f/GammaBlue ) * 255.0f);
ColorPacket->zone[i].b = ATMO_MIN((int)v, 255);
}
break;
}
case agcGlobal:
{
double Gamma = 100.0 / ((double)pAtmoConfig->getSoftware_gamma_global());
for (int i = 0; i < ColorPacket->numColors; i++)
{
v = ColorPacket->zone[i].r;
v = (pow( v / 255.0f, 1.0f/Gamma ) * 255.0f);
ColorPacket->zone[i].r = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].g;
v = (pow( v / 255.0f, 1.0f/Gamma ) * 255.0f);
ColorPacket->zone[i].g = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].b;
v = (pow( v / 255.0f, 1.0f/Gamma ) * 255.0f);
ColorPacket->zone[i].b = ATMO_MIN((int)v, 255);
}
break;
}
}
return ColorPacket;
}
pColorPacket CAtmoTools::ApplyGamma2(AtmoGammaCorrect Software_gamma_mode, int red, int green, int blue, int global, pColorPacket ColorPacket)
{
double v;
switch(Software_gamma_mode)
{
case agcNone: break;
case agcPerColor:
{
double GammaRed = 100.0 / ((double)red);
double GammaGreen = 100.0 / ((double)green);
double GammaBlue = 100.0 / ((double)blue);
for (int i = 0; i < ColorPacket->numColors; i++)
{
v = ColorPacket->zone[i].r;
v = (pow( v / 255.0f, 1.0f/GammaRed ) * 255.0f);
ColorPacket->zone[i].r = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].g;
v = (pow( v / 255.0f, 1.0f/GammaGreen ) * 255.0f);
ColorPacket->zone[i].g = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].b;
v = (pow( v / 255.0f, 1.0f/GammaBlue ) * 255.0f);
ColorPacket->zone[i].b = ATMO_MIN((int)v, 255);
}
break;
}
case agcGlobal:
{
double Gamma = 100.0 / ((double)global);
for (int i = 0; i < ColorPacket->numColors; i++)
{
v = ColorPacket->zone[i].r;
v = (pow( v / 255.0f, 1.0f/Gamma ) * 255.0f);
ColorPacket->zone[i].r = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].g;
v = (pow( v / 255.0f, 1.0f/Gamma ) * 255.0f);
ColorPacket->zone[i].g = ATMO_MIN((int)v, 255);
v = ColorPacket->zone[i].b;
v = (pow( v / 255.0f, 1.0f/Gamma ) * 255.0f);
ColorPacket->zone[i].b = ATMO_MIN((int)v, 255);
}
break;
}
}
return ColorPacket;
}
int CAtmoTools::SetChannelAssignment(CAtmoDynData *pDynData, int index)
{
CAtmoConfig *pAtmoConfig = pDynData->getAtmoConfig();
CAtmoConnection *pAtmoConnection = pDynData->getAtmoConnection();
int oldIndex = pAtmoConfig->getCurrentChannelAssignment();
CAtmoChannelAssignment *ca = pAtmoConfig->getChannelAssignment(index);
if((ca!=NULL) && (pAtmoConnection!=NULL))
{
pAtmoConnection->SetChannelAssignment(ca);
pAtmoConfig->setCurrentChannelAssignment(index);
}
return oldIndex;
}
#if !defined(_ATMO_VLC_PLUGIN_)
void CAtmoTools::SaveBitmap(HDC hdc,HBITMAP hBmp,char *fileName)
{
BITMAPINFO bmpInfo;
BITMAPFILEHEADER bmpFileHeader;
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
GetDIBits(hdc,hBmp,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
if(bmpInfo.bmiHeader.biSizeImage<=0)
bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth * abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
void *pBuf = malloc(bmpInfo.bmiHeader.biSizeImage);
bmpInfo.bmiHeader.biCompression=BI_RGB;
GetDIBits(hdc,hBmp,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);
bmpFileHeader.bfReserved1=0;
bmpFileHeader.bfReserved2=0;
bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
bmpFileHeader.bfType = MakeIntelWord('M','B');
bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
FILE *fp = NULL;
fp = fopen(fileName,"wb");
fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
fclose(fp);
}
#endif