-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc_measurement.cpp
1907 lines (1671 loc) · 60.3 KB
/
icc_measurement.cpp
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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ICC Examin ist eine ICC Profil Betrachter
*
* Copyright (C) 2004-2014 Kai-Uwe Behrmann
*
* Autor: Kai-Uwe Behrmann <[email protected]>
*
* This program 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 program 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 program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* -----------------------------------------------------------------------------
*
* qualtity check from measurements, possibly from inside profile itself
*
*/
// Date: 20. 08. 2004
#if 0
# ifndef DEBUG
# define DEBUG
# endif
# define DEBUG_ICCMEASUREMENT
# define DBG_MESS_START DBG_PROG_START
# define DBG_MESS_ENDE DBG_PROG_ENDE
# define DBG_MESS_V(t) DBG_NUM_V(t)
#else
# define DBG_MESS_START
# define DBG_MESS_ENDE
# define DBG_MESS_V(t)
#endif
#include "icc_utils.h"
#include "icc_profile.h"
#include "icc_oyranos.h"
#include "icc_examin_version.h"
#include "icc_helfer.h"
#include "icc_cgats_filter.h"
#include "icc_info.h"
using namespace icc_examin_ns;
/**
* @brief ICCmeasurement functions
*/
int icc_measurement_id_ = 0;
ICCmeasurement::ICCmeasurement (ICCprofile* profil)
{ DBG_PROG_START
id_ = icc_measurement_id_++;
DBG_MEM_V( id_ <<" "<< profil )
defaults();
profile_ = profil;
DBG_PROG_ENDE
}
ICCmeasurement::ICCmeasurement (ICCprofile* profil, ICCtag &tag)
{ DBG_PROG_START
id_ = icc_measurement_id_++;
DBG_MEM_V( id_ <<" "<< profil )
ICCmeasurement::load (profil, tag);
DBG_PROG_ENDE
}
ICCmeasurement::ICCmeasurement (const ICCmeasurement& m)
{
id_ = icc_measurement_id_++;
DBG_MEM_V( id_ <<" "<< profile_ )
DBG_PROG
copy (m);
}
ICCmeasurement::ICCmeasurement ()
{
DBG_PROG_START
WARN_S( "----------------------- dont use the default constructor --------------------------" )
id_ = icc_measurement_id_++;
DBG_MEM_V( id_ )
defaults();
DBG_PROG_ENDE
}
ICCmeasurement::~ICCmeasurement ()
{
DBG_PROG_S("::~ICCmeasurement")
clear();
DBG_MEM_S( "::~ICCmeasurement id_ "<< id_ <<" "<< profile_ )
}
void
ICCmeasurement::defaults ()
{
DBG_PROG_START
DBG_MEM_V( id_ <<" "<< profile_ )
sig_ = (icTagSignature)0xFFFFFFFF;
size_ = 0;
data_ = NULL;
nFelder_ = 0;
channels_ = 0;
isICCDisplay_ = 0;
profile_ = NULL;
XYZ_measurement_ = false;
LAB_measurement_ = false;
RGB_measurement_ = false;
CMYK_measurement_ = false;
Lab_Differenz_max_ = -1000;
Lab_Differenz_min_ = 1000;
Lab_Differenz_Durchschnitt_ = 0;
DE00_Differenz_max_ = -1000;
DE00_Differenz_min_ = 1000;
DE00_Differenz_Durchschnitt_ = 0;
export_farben = false;
int i;
for(i=0;i<6;i+=2) { range_XYZ[i] = 0.f; range_XYZ[i+1] = 100.f; }
range_Lab[0] = 0.f; range_Lab[1] = 100.f;
for(i=2;i<6;i+=2) { range_Lab[i] = -128.f; range_Lab[i+1] = 127.f; }
for(i=0;i<6;i+=2) { range_RGB[i] = 0.f; range_RGB[i+1] = 255.f; }
for(i=0;i<8;i+=2) { range_CMYK[i] = 0.f; range_CMYK[i+1] = 100.f; }
XYZmax[0] = XYZmax[1] = XYZmax[2] = -100000;
XYZmin[0] = XYZmin[1] = XYZmin[2] = 100000;
XYZWP[0] = X_D50;
XYZWP[1] = Y_D50;
XYZWP[2] = Z_D50;
XYZBP[0] = XYZBP[1] = XYZBP[2] = 0;
minFeld = -1;
maxFeld = -1;
cgats = 0;
options_ = 0;
DBG_PROG_ENDE
}
void
ICCmeasurement::copy (const ICCmeasurement& m)
{
DBG_PROG_START
DBG_MEM_V( id_ <<" "<< m.id_ <<" "<< m.profile_ )
sig_ = m.sig_;
size_ = m.size_;
if (size_ && m.data_) {
data_ = (char*)calloc(sizeof(char),size_+1);
memcpy (data_ , m.data_ , size_);
DBG_MEM_S((int*)m.data_ << " -> " << (int*)data_)
} else {
data_ = NULL;
size_ = 0;
}
nFelder_ = m.nFelder_;
channels_ = m.channels_;
isICCDisplay_ = m.isICCDisplay_;
profile_ = m.profile_;
LAB_measurement_ = m.LAB_measurement_;
XYZ_measurement_ = m.XYZ_measurement_;
RGB_measurement_ = m.RGB_measurement_;
CMYK_measurement_ = m.CMYK_measurement_;
// measurments
XYZ_Satz_ = m.XYZ_Satz_;
Lab_Satz_ = m.Lab_Satz_;
RGB_Satz_ = m.RGB_Satz_;
CMYK_Satz_ = m.CMYK_Satz_;
// profile values
Feldnamen_ = m.Feldnamen_;
XYZ_Ergebnis_ = m.XYZ_Ergebnis_;
Lab_Ergebnis_ = m.Lab_Ergebnis_;
RGB_MessFarben_ = m.RGB_MessFarben_;
RGB_ProfilFarben_ = m.RGB_ProfilFarben_;
patch_src_lines_ = m.patch_src_lines_;
// results
Lab_Differenz_ = m.Lab_Differenz_;
Lab_Differenz_max_ = m.Lab_Differenz_max_;
Lab_Differenz_min_ = m.Lab_Differenz_min_;
Lab_Differenz_Durchschnitt_ = m.Lab_Differenz_Durchschnitt_;
DE00_Differenz_ = m.DE00_Differenz_;
DE00_Differenz_max_ = m.DE00_Differenz_max_;
DE00_Differenz_min_ = m.DE00_Differenz_min_;
DE00_Differenz_Durchschnitt_ = m.DE00_Differenz_Durchschnitt_;
memcpy( range_XYZ, m.range_XYZ, 6*sizeof(double) );
memcpy( range_Lab, m.range_Lab, 6*sizeof(double) );
memcpy( range_RGB, m.range_RGB, 6*sizeof(double) );
memcpy( range_CMYK, m.range_CMYK, 8*sizeof(double) );
memcpy( XYZmax, m.XYZmax, 3*sizeof(double) );
memcpy( XYZmin, m.XYZmin, 3*sizeof(double) );
memcpy( XYZWP, m.XYZWP, 3*sizeof(double) );
memcpy( XYZBP, m.XYZBP, 3*sizeof(double) );
minFeld = m.minFeld;
maxFeld = m.maxFeld;
export_farben = m.export_farben;
if(m.cgats)
cgats = new CgatsFilter(*(m.cgats));
if(m.options_)
{
options_ = oyOptions_Copy( m.options_, m.options_->oy_ );
} else
options_ = 0;
DBG_PROG_ENDE
}
void
ICCmeasurement::clear (void)
{
DBG_PROG_START
DBG_MEM_V( id_ <<" "<< profile_ )
if (data_ != NULL) free(data_);
defaults();
XYZ_Satz_.clear();
Lab_Satz_.clear();
RGB_Satz_.clear();
CMYK_Satz_.clear();
Feldnamen_.clear();
XYZ_Ergebnis_.clear();
Lab_Ergebnis_.clear();
RGB_MessFarben_.clear();
RGB_ProfilFarben_.clear();
patch_src_lines_.clear();
Lab_Differenz_.clear();
DE00_Differenz_.clear();
reportTabelle_.clear();
layout.clear();
if(cgats) delete cgats;
oyOptions_Release( &options_ );
DBG_PROG_ENDE
}
ICCmeasurement &
ICCmeasurement::operator = (const ICCmeasurement& m)
{
DBG_PROG copy (m);
return *this;
}
void
ICCmeasurement::load ( ICCprofile *profil,
ICCtag& tag )
{ DBG_PROG_START
profile_ = profil;
if (!profile_) WARN_S( "cant initialise, profile referenz is missed" )
sig_ = tag._sig;
if(tag.size_)
size_ = tag.size_ - 8;
else
size_ = 0;
DBG_PROG_V( size_ )
// simply exchange
if (data_ != NULL) { free (data_); data_ = NULL; }
if(size_)
{
data_ = (char*) calloc ( size_+1 , sizeof (char) );
memcpy ( data_ , &(tag.data_)[8] , size_ );
}
DBG_PROG_ENDE
}
void
ICCmeasurement::load ( ICCprofile *profil,
const char *data,
size_t size )
{ DBG_PROG_START
profile_ = profil;
if (!profile_) WARN_S( "cant initialise, profile referenz is missed" )
if (sig_ != (icTagSignature)0xFFFFFFFF)
sig_ = icSigCharTargetTag;
size_ = size;
// simply exchange
if (!data_) free (data_);
data_ = (char*) calloc ( size_+1 , sizeof (char) );
memcpy ( data_ , data , size_ );
DBG_PROG_ENDE
}
void
ICCmeasurement::leseTag (void)
{ DBG_PROG_START
//DBG_PROG_V( data_ )
if(!data_ || !size_)
return;
cgats->lade( data_, size_ );
std::string data = cgats->lcms_gefiltert (); DBG_NUM_V( (int*)data_ <<" "<< size_ )
// locale - differentiate commas (Attention: CgatsFilter changes LC_NUMERIC)
doLocked_m( std::string loc_alt = setlocale(LC_NUMERIC, NULL);,NULL) //getenv("LANG");
if(loc_alt.size()) {
DBG_NUM_V( loc_alt )
} else {
DBG_NUM_S( "LANG variable not found" )
}
doLocked_m( setlocale(LC_NUMERIC,"C");,NULL);
if(data.size())
{
// correct CGATS data -> data_
if (data_ != NULL) { free (data_); data_ = NULL; }
data_ = (char*) calloc (sizeof(char), data.size()+1);
size_ = data.size();
memcpy (data_, data.c_str(), size_); DBG_NUM_V( (int*)data_ )
if(strstr(data.c_str(), "\nDESCRIPTOR \"Argyll Calibration Target chart"))
{
range_RGB[0] = range_RGB[2] = range_RGB[4] = 0.f;
range_RGB[1] = range_RGB[3] = range_RGB[5] = 100.f;
} else
if(strstr(data.c_str(), "ORIGINATOR \"Monaco Systems, Inc\""))
{
range_RGB[0] = range_RGB[2] = range_RGB[4] = 0.f;
range_RGB[1] = range_RGB[3] = range_RGB[5] = 1.f;
} else {
range_RGB[0] = range_RGB[2] = range_RGB[4] = 0.f;
range_RGB[1] = range_RGB[3] = range_RGB[5] = 255.f;
}
# if 0
// lcms liest ein
lcms_parse();
# else
//LCMSHANDLE _lcms_it8 = cmsIT8LoadFromMem ( data_, size_ ); DBG_MEM_V( (int*)data_)
int ps = patch_src_lines_.size();
patch_src_lines_.resize( ps + 1 );
patch_src_lines_[ps].first = getSigTagName( sig_ );
const char **SampleNames = 0;
int m = 0; // actual measurement
int m_n = cgats->messungen.size();
int _nKanaele = 0;
bool _sample_name = false;
bool _sample_id = false;
bool _id_vor_name = false;
if(cgats && cgats->messungen.size() && cgats->messungen[m].felder.size())
_nKanaele = (int)cgats->messungen[m].felder[0].size();
for(m = 0; m < m_n; ++m)
{
int n = cgats->messungen[m].block_zeilen,
start = nFelder_,
end = nFelder_ + n;
if(cgats->messungen[m].felder.size() != 1)
{
WARN_S( "There are unadequate field declarations: "
<< cgats->messungen[m].felder.size() )
}
// we want valid patchsets only
// heuristic: skip patches sets with fewer patches
if(m > 0 && n &&
_nKanaele > (int)cgats->messungen[m].felder[0].size())
continue;
// measurement spot number
if (nFelder_ == 0 ||
nFelder_ ||
(m_n > 1) )
{
nFelder_ += n;
patch_src_lines_[ps].second.resize( nFelder_ );
} else {
WARN_S( "number of measurements should correspond! " << nFelder_ << "|" << (int)cgats->messungen[m].block_zeilen )
clear();
goto finish;
}
if(cgats->messungen[m].felder.size())
{
_nKanaele = (int)cgats->messungen[m].felder[0].size();
SampleNames = (const char**) new const char* [_nKanaele];
for (int i = 0; i < _nKanaele; i++)
SampleNames[i] = cgats->messungen[m].felder[0][i].c_str();
}
// What is all here? Do we want do exchange the names later?
if(cgats->messungen[m].felder.size())
{
_sample_name = false;
_sample_id = false;
_id_vor_name = false;
for (int i = 0; i < _nKanaele; i++)
{
if (strstr(cgats->messungen[m].felder[0][i].c_str(),"SAMPLE_ID") != 0)
_sample_id = true;
if (strstr(cgats->messungen[m].felder[0][i].c_str(),"SAMPLE_NAME") != 0
&& _sample_id) {
_sample_name = true;
_id_vor_name = true;
}
# ifdef DEBUG_ICCMEASUREMENT
DBG_NUM_S( SampleNames[i] << " _sample_name " << _sample_name <<
" _sample_id" << _sample_id << " _id_vor_name " << _id_vor_name)
# endif
}
}
// reding and parsing
ICClist<std::string> farbkanaele;
// locals !
bool has_Lab = false;
bool has_XYZ = false;
bool has_CMYK = false;
bool has_RGB = false;
bool has_xyY = false;
for (int i = 0; i < _nKanaele; i++) {
if ((strstr (SampleNames[i], "LAB_L") != 0)
|| (strstr (SampleNames[i], "LAB_A") != 0)
|| (strstr (SampleNames[i], "LAB_B") != 0)) {
DBG_PROG_S( "Lab data " )
has_Lab = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "XYZ_X") != 0)
|| (strstr (SampleNames[i], "XYZ_Y") != 0)
|| (strstr (SampleNames[i], "XYZ_Z") != 0)) {
DBG_PROG_S( "XYZ data " )
has_XYZ = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "CMYK_C") != 0)
|| (strstr (SampleNames[i], "CMYK_M") != 0)
|| (strstr (SampleNames[i], "CMYK_Y") != 0)
|| (strstr (SampleNames[i], "CMYK_K") != 0)) {
DBG_PROG_S( "CMYK data " )
has_CMYK = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "RGB_R") != 0)
|| (strstr (SampleNames[i], "RGB_G") != 0)
|| (strstr (SampleNames[i], "RGB_B") != 0)) {
DBG_PROG_S( "RGB data " )
has_RGB = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "XYY_X") != 0)
|| (strstr (SampleNames[i], "XYY_Y") != 0)
|| (strstr (SampleNames[i], "XYY_CAPY") != 0)) {
DBG_PROG_S( "xyY data " )
has_xyY = true;
farbkanaele.push_back(SampleNames[i]);
} else {
farbkanaele.push_back(SampleNames[i]);
}
} DBG_PROG
// variables
int farben = 0;
if (has_Lab) {farben++; LAB_measurement_ = true; }
if (has_XYZ) {farben++; XYZ_measurement_ = true; }
if (has_RGB) {farben++; RGB_measurement_ = true; }
if (has_CMYK){farben++; CMYK_measurement_ = true; }
if (has_xyY) farben++;
// list lcms colour names
Feldnamen_.resize(end);
DBG_PROG_V( nFelder_ )
for (int k = 0; k < n; k++) {
if (_id_vor_name
&& (getTagName() != "DevD")) {// ignore names
char *text = (char*) calloc (sizeof(char), 12);
sprintf (text, "%d", start+k+1);
Feldnamen_[start+k] = text;
free(text);
} else if(_sample_id || _sample_name) {
const char *constr = cgats->messungen[m].block[k][0].c_str();
Feldnamen_[start+k] = constr;
} else {
char n[8];
snprintf(n,8,"%d",start+k+1);
Feldnamen_[start+k] = n;
}
patch_src_lines_[ps].second[start+k] = cgats->messungen[m].line[k];
}
if(nFelder_)
DBG_NUM_S (Feldnamen_[0] << " bis " << Feldnamen_[nFelder_-1])
DBG_NUM_V( has_XYZ << has_Lab << has_RGB << has_CMYK )
// read colours
int c = 0;
const char * d_text = 0;
if (has_XYZ)
{ DBG_PROG // no calculation required
XYZ_Satz_.resize(nFelder_);
for (int i = 0; i < n; i++)
{
if((int)cgats->messungen[m].block.size() > i)
for (int j = 0; j < _nKanaele; ++j)
{
if((int)cgats->messungen[m].block[i].size() <= j)
continue;
d_text = cgats->messungen[m].block[i][j].c_str();
c = 0;
if( strcmp(SampleNames[j], "XYZ_X") == 0 )
XYZ_Satz_[start+i].X = (atof(d_text) - range_XYZ[c]) /
(range_XYZ[c+1] - range_XYZ[c]);
c+=2;
if( strcmp(SampleNames[j], "XYZ_Y") == 0 )
XYZ_Satz_[start+i].Y = (atof(d_text) - range_XYZ[c]) /
(range_XYZ[c+1] - range_XYZ[c]);
c+=2;
if( strcmp(SampleNames[j], "XYZ_Z") == 0 )
XYZ_Satz_[start+i].Z = (atof(d_text) - range_XYZ[c]) /
(range_XYZ[c+1] - range_XYZ[c]);
}
}
}
if (has_Lab)
{
DBG_PROG // no calculation required
Lab_Satz_.resize(nFelder_);
for (int i = 0; i < n; i++)
{
if((int)cgats->messungen[m].block.size() > i)
for (int j = 0; j < _nKanaele; ++j)
{
if((int)cgats->messungen[m].block[i].size() <= j)
continue;
d_text = cgats->messungen[m].block[i][j].c_str();
c = 0;
if( strcmp(SampleNames[j], "LAB_L") == 0 )
Lab_Satz_[start+i].L = (atof(d_text) - range_Lab[c]) /
(range_Lab[c+1] - range_Lab[c]);
c+=2;
if( strcmp(SampleNames[j], "LAB_A") == 0 )
Lab_Satz_[start+i].a = (atof(d_text) - range_Lab[c]) /
(range_Lab[c+1] - range_Lab[c]);
c+=2;
if( strcmp(SampleNames[j], "LAB_B") == 0 )
Lab_Satz_[start+i].b = (atof(d_text) - range_Lab[c]) /
(range_Lab[c+1] - range_Lab[c]);
}
}
}
if (has_RGB) { DBG_PROG // no calculation required
RGB_Satz_.resize(nFelder_);
for (int i = 0; i < n; i++)
{
if((int)cgats->messungen[m].block.size() > i)
for (int j = 0; j < _nKanaele; ++j)
{
if((int)cgats->messungen[m].block[i].size() <= j)
continue;
d_text = cgats->messungen[m].block[i][j].c_str();
c = 0;
if( strcmp(SampleNames[j], "RGB_R") == 0 )
RGB_Satz_[start+i].R = (atof(d_text) - range_RGB[c]) /
(range_RGB[c+1] - range_RGB[c]);
c+=2;
if( strcmp(SampleNames[j], "RGB_G") == 0 )
RGB_Satz_[start+i].G = (atof(d_text) - range_RGB[c]) /
(range_RGB[c+1] - range_RGB[c]);
c+=2;
if( strcmp(SampleNames[j], "RGB_B") == 0 )
RGB_Satz_[start+i].B = (atof(d_text) - range_RGB[c]) /
(range_RGB[c+1] - range_RGB[c]);
}
}
}
if (has_CMYK) { DBG_PROG // no calculation required
CMYK_Satz_.resize(nFelder_);
for (int i = 0; i < n; i++)
{
if((int)cgats->messungen[m].block.size() > i)
for (int j = 0; j < _nKanaele; ++j)
{
if((int)cgats->messungen[m].block[i].size() <= j)
continue;
d_text = cgats->messungen[m].block[i][j].c_str();
c = 0;
if( strcmp(SampleNames[j], "CMYK_C") == 0 )
CMYK_Satz_[start+i].C = (atof(d_text) - range_CMYK[c]) /
(range_CMYK[c+1] - range_CMYK[c]);
c+=2;
if( strcmp(SampleNames[j], "CMYK_M") == 0 )
CMYK_Satz_[start+i].M = (atof(d_text) - range_CMYK[c]) /
(range_CMYK[c+1] - range_CMYK[c]);
c+=2;
if( strcmp(SampleNames[j], "CMYK_Y") == 0 )
CMYK_Satz_[start+i].Y = (atof(d_text) - range_CMYK[c]) /
(range_CMYK[c+1] - range_CMYK[c]);
c+=2;
if( strcmp(SampleNames[j], "CMYK_K") == 0 )
CMYK_Satz_[start+i].K = (atof(d_text) - range_CMYK[c]) /
(range_CMYK[c+1] - range_CMYK[c]);
}
} DBG_PROG
}
// colour names of taste
if (_id_vor_name) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < (int)cgats->messungen[m].block[i].size(); ++j) {
if( strcmp(SampleNames[j], "SAMPLE_NAME") == 0 )
Feldnamen_[start+i] = cgats->messungen[m].block[i][j].c_str();
}
} DBG_NUM_S (Feldnamen_[0] <<" to "<< Feldnamen_[nFelder_-1] <<" "<< nFelder_)
}
}
DBG_NUM_V( XYZ_Satz_.size() )
DBG_NUM_V( RGB_Satz_.size() )
DBG_NUM_V( CMYK_Satz_.size() )
# endif
}
finish:
if(loc_alt.size())
doLocked_m( setlocale(LC_NUMERIC,loc_alt.c_str()) , NULL);
DBG_PROG_ENDE
}
void
ICCmeasurement::init (void)
{ DBG_PROG_START DBG_MEM_V( (int*)data_ )
if (valid())
return;
if( profile_->data_type == ICCprofile::ICCcorruptedprofileDATA )
return;
if(!cgats)
cgats = new CgatsFilter;
if (!profile_) WARN_S( "cant initialise, profile referenz missed; id: "<<id_<<" profile: "<< (int*)profile_ )
if (profile_->hasTagName("targ")) {
load (profile_, profile_->getTag(profile_->getTagIDByName("targ")));
leseTag ();
}
else if (profile_->hasTagName("b015")) {
load (profile_, profile_->getTag(profile_->getTagIDByName("b015")));
leseTag ();
}
else if (profile_->hasTagName("TGL2")) {
load (profile_, profile_->getTag(profile_->getTagIDByName("TGL2")));
leseTag ();
}
else if (profile_->hasTagName("DevD") && (profile_->hasTagName("CIED"))) {
load (profile_, profile_->getTag(profile_->getTagIDByName("DevD")));
leseTag ();
// We start again at position zero.
nFelder_ = 0;
load (profile_, profile_->getTag(profile_->getTagIDByName("CIED")));
leseTag ();
}
if (RGB_MessFarben_.size() != 0)
DBG_NUM_V( RGB_MessFarben_.size() );
if (profile_ &&
profile_->data_type == ICCprofile::ICCprofileDATA )
{
channels_ = profile_->getColourChannelsCount();
isICCDisplay_ = /*!(profile_->hasCLUT()) &&*/
profile_->getHeader().deviceClass() == icSigDisplayClass;
}
init_umrechnen();
DBG_PROG_ENDE
}
#if 0
void
ICCmeasurement::lcms_parse (void)
{ DBG_PROG_START
LCMSHANDLE _lcms_it8 = cmsIT8LoadFromMem ( data_, size_ ); DBG_MEM_V( (int*)data_)
char **SampleNames; DBG_MEM
// Messfeldanzahl
if (nFelder_ == 0
|| nFelder_ == (int)cmsIT8GetPropertyDbl(_lcms_it8, "NUMBER_OF_SETS")) { DBG_NUM
nFelder_ = (int)cmsIT8GetPropertyDbl(_lcms_it8, "NUMBER_OF_SETS"); DBG_NUM
} else {
WARN_S( "Messfeldanzahl sollte schon uebereinstimmen! " << nFelder_ << "|" << (int)cmsIT8GetPropertyDbl(_lcms_it8, "NUMBER_OF_SETS") )
clear();
return;
}
int _nKanaele = cmsIT8EnumDataFormat(_lcms_it8, &SampleNames);
bool _sample_name = false;
bool _sample_id = false;
bool _id_vor_name = false;
// Was ist alles da? Wollen wir spaeter die Namen tauschen?
for (int i = 0; i < _nKanaele; i++) {
if (strstr((char*)SampleNames[i],"SAMPLE_ID") != 0)
_sample_id = true;
if (strstr((char*)SampleNames[i],"SAMPLE_NAME") != 0
&& _sample_id) {
_sample_name = true;
_id_vor_name = true;
}
# ifdef DEBUG_ICCMEASUREMENT
DBG_NUM_S( (char*)SampleNames[i] << " _sample_name " << _sample_name <<
" _sample_id" << _sample_id << " _id_vor_name " << _id_vor_name)
# endif
}
// Auslesen und Aufbereiten
ICClist<std::string> farbkanaele;
// muessen lokal bleiben !
bool has_Lab = false;
bool has_XYZ = false;
bool has_CMYK = false;
bool has_RGB = false;
bool has_xyY = false;
for (int i = 0; i < _nKanaele; i++) {
if ((strstr (SampleNames[i], "LAB_L") != 0)
|| (strstr (SampleNames[i], "LAB_A") != 0)
|| (strstr (SampleNames[i], "LAB_B") != 0)) {
cout << "Lab Daten ";
has_Lab = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "XYZ_X") != 0)
|| (strstr (SampleNames[i], "XYZ_Y") != 0)
|| (strstr (SampleNames[i], "XYZ_Z") != 0)) {
cout << "XYZ Daten ";
has_XYZ = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "CMYK_C") != 0)
|| (strstr (SampleNames[i], "CMYK_M") != 0)
|| (strstr (SampleNames[i], "CMYK_Y") != 0)
|| (strstr (SampleNames[i], "CMYK_K") != 0)) {
cout << "CMYK Daten ";
has_CMYK = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "RGB_R") != 0)
|| (strstr (SampleNames[i], "RGB_G") != 0)
|| (strstr (SampleNames[i], "RGB_B") != 0)) {
cout << "RGB Daten ";
has_RGB = true;
farbkanaele.push_back(SampleNames[i]);
} else if ((strstr (SampleNames[i], "XYY_X") != 0)
|| (strstr (SampleNames[i], "XYY_Y") != 0)
|| (strstr (SampleNames[i], "XYY_CAPY") != 0)) {
cout << "xyY Daten ";
has_xyY = true;
farbkanaele.push_back(SampleNames[i]);
} else {
farbkanaele.push_back(SampleNames[i]);
}
} DBG_PROG
// Variablen
int farben = 0;
if (has_Lab) farben++;
if (has_XYZ) {farben++; XYZ_measurement_ = true; }
if (has_RGB) {farben++; RGB_measurement_ = true; }
if (has_CMYK) {farben++; CMYK_measurement_ = true; }
if (has_xyY) farben++;
// vorlaeufige lcms Farbnamen listen
Feldnamen_.resize(nFelder_);
DBG_PROG_V( nFelder_ )
for (int k = 0; k < nFelder_; k++) {
if (_id_vor_name
&& (getTagName() != "DevD")) {// Name ignorieren
char *text = (char*) calloc (sizeof(char), 12);
sprintf (text, "%d", k+1);
Feldnamen_[k] = text;
free(text);
} else {
const char *constr = cmsIT8GetPatchName (_lcms_it8, k, NULL);
Feldnamen_[k] = constr;
}
}
if(nFelder_)
DBG_NUM_S (Feldnamen_[0] << " bis " << Feldnamen_[nFelder_-1])
DBG_NUM_V( has_XYZ << has_RGB << has_CMYK )
// Farben auslesen
if (has_XYZ) { DBG_PROG // keine Umrechnung noetig
XYZ_Satz_.resize(nFelder_);
for (int i = 0; i < nFelder_; i++) {
XYZ_Satz_[i].X = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"XYZ_X") / 100.0;
XYZ_Satz_[i].Y = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"XYZ_Y") / 100.0;
XYZ_Satz_[i].Z = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"XYZ_Z") / 100.0;
}
}
if (has_RGB) { DBG_PROG // keine Umrechnung noetig
RGB_Satz_.resize(nFelder_);
for (int i = 0; i < nFelder_; i++) {
RGB_Satz_[i].R = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"RGB_R") / 255.0;
RGB_Satz_[i].G = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"RGB_G") / 255.0;
RGB_Satz_[i].B = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"RGB_B") / 255.0;
}
}
if (has_CMYK) { DBG_PROG // keine Umrechnung noetig
CMYK_Satz_.resize(nFelder_);
for (int i = 0; i < nFelder_; i++) {
CMYK_Satz_[i].C = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"CMYK_C") /100.0;
CMYK_Satz_[i].M = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"CMYK_M") /100.0;
CMYK_Satz_[i].Y = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"CMYK_Y") /100.0;
CMYK_Satz_[i].K = cmsIT8GetDataDbl (_lcms_it8, Feldnamen_[i].c_str(),
"CMYK_K") /100.0;
} DBG_PROG
}
// Farbnamen nach Geschmack (unmittelbar vor cmsIT8Free !)
if (_id_vor_name) {
for (int i = 0; i < nFelder_; i++) {
Feldnamen_[i] = cmsIT8GetData (_lcms_it8, Feldnamen_[i].c_str(),
"SAMPLE_NAME");
} DBG_NUM_S (Feldnamen_[0] <<" bis "<< Feldnamen_[nFelder_-1] <<" "<< nFelder_)
}
// lcms's cgats Leser wird nicht mehr gebraucht
cmsIT8Free (_lcms_it8);
_lcms_it8 = NULL;
DBG_NUM_V( XYZ_Satz_.size() )
DBG_NUM_V( RGB_Satz_.size() )
DBG_NUM_V( CMYK_Satz_.size() )
DBG_PROG_ENDE
}
#endif
oyPixelAccess_s * oyPixelAccess_FromConversion( oyConversion_s * cc )
{
oyPixelAccess_s * pixel_access;
oyFilterNode_s * node = oyConversion_GetNode( cc, OY_OUTPUT );
oyFilterPlug_s * plug = oyFilterNode_GetPlug( node, 0 );
oyFilterNode_Release( &node );
pixel_access = oyPixelAccess_Create( 0,0, plug, oyPIXEL_ACCESS_IMAGE, 0 );
oyFilterPlug_Release( &plug );
return pixel_access;
}
void
ICCmeasurement::init_umrechnen (void)
{ DBG_PROG_START
if( profile_->data_type == ICCprofile::ICCcorruptedprofileDATA )
return;
Lab_Differenz_max_ = -1000.0;
Lab_Differenz_min_ = 1000.0;
Lab_Differenz_Durchschnitt_ = 0.0;
DE00_Differenz_max_ = -1000.0;
DE00_Differenz_min_ = 1000.0;
DE00_Differenz_Durchschnitt_ = 0.0;
# define PRECALC cmsFLAGS_NOTPRECALC // No memory overhead, VERY
// SLOW ON TRANSFORMING, very fast on creating transform.
// Maximum accurancy.
XYZmax[0] = XYZmax[1] = XYZmax[2] = -100000;
XYZmin[0] = XYZmin[1] = XYZmin[2] = 100000;
{
#ifdef DEBUG
int maxFeld=0, minFeld=0;
#endif
const char *maxFN=0, *minFN=0;
if (nFelder_ != (int)XYZ_Satz_.size()) {
DBG_PROG_S("divergine measurement count");
}
int m = nFelder_ < (int)XYZ_Satz_.size() ? nFelder_ : (int)XYZ_Satz_.size();
if(!m && isICCDisplay_)
WARN_S("No XYZ data available. Dont support this display profile?");
DBG_PROG_S( "fields: " << m )
for (int i = 0; i < m; i++)
{
if (XYZmax[1] < XYZ_Satz_[i].Y)
{ XYZmax[0] = XYZ_Satz_[i].X;
XYZmax[1] = XYZ_Satz_[i].Y;
XYZmax[2] = XYZ_Satz_[i].Z;
maxFeld = i;
maxFN = Feldnamen_[i].c_str();
}
if (XYZmin[1] > XYZ_Satz_[i].Y)
{ XYZmin[0] = XYZ_Satz_[i].X;
XYZmin[1] = XYZ_Satz_[i].Y;
XYZmin[2] = XYZ_Satz_[i].Z;
minFeld = i;
minFN = Feldnamen_[i].c_str();
}
}
if( maxFN ) {
DBG_PROG_S( maxFN << " Nr. " << maxFeld << endl << " X_max = "<< XYZmax[0] <<" Y_max = "<< XYZmax[1] <<" Z_max = "<< XYZmax[2] );
}
if( minFN ) {
DBG_PROG_S( minFN << " Nr. " << minFeld << endl << " X_min = "<< XYZmin[0] <<" Y_min = "<< XYZmin[1] <<" Z_min = "<< XYZmin[2] );
}
}
{
int bkpt_pos = -1;
ICClist<double> wp, bp;
if (profile_)
{
wp = profile_->getWhitePkt();
bkpt_pos = profile_->getTagIDByName("bkpt");
if(bkpt_pos >= 0)
bp = profile_->getTagCIEXYZ(bkpt_pos);
}
if (wp.size() == 3)
{ for (int i = 0; i < 3; i++)
XYZWP[i] = wp[i];
} else
{ XYZWP[0] = X_D50;
XYZWP[1] = Y_D50;
XYZWP[2] = Z_D50;
}
if (bp.size() == 3 &&
bp[0] != 0.0 && bp[1] != 0.0 && bp[2] != 0.0)
for (int i = 0; i < 3; i++)
XYZBP[i] = 0.0;
else
for (int i = 0; i < 3; i++)
XYZBP[i] = XYZmin[i];
}
if ((RGB_measurement_ ||
CMYK_measurement_) || (XYZ_measurement_ || LAB_measurement_))
{
double start = fortschritt();
if (getColorSpaceName(profile_->header.colorSpace()) != "Rgb"
&& getColorSpaceName(profile_->header.colorSpace()) != "Cmyk")
{
WARN_S("different mesurement- and profile colour space ")
DBG_PROG_V( getColorSpaceName(profile_->header.colorSpace()) )
}
oyProfile_s * profile = 0,
* profile_rgb = 0,
* profile_xyz = oyProfile_FromStd( oyEDITING_XYZ, icc_oyranos.icc_profile_flags, 0 ),
* profile_lab = oyProfile_FromStd( oyEDITING_LAB, icc_oyranos.icc_profile_flags, 0 );
// select a fitting monitor- / displayprofile
if(!export_farben)
{
profile_rgb = icc_oyranos.getEditingProfile(1);
} else
{
profile_rgb = oyProfile_FromStd( oyASSUMED_WEB, icc_oyranos.icc_profile_flags, 0 );
DBG_PROG_S( "Export colours" );
}