-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc_examin_farbraum.cpp
624 lines (514 loc) · 16.2 KB
/
icc_examin_farbraum.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
/*
* ICC Examin ist eine ICC Profil Betrachter
*
* Copyright (C) 2004-2013 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.
*
* -----------------------------------------------------------------------------
*
* the central class. colour space parts
*
*/
#include "icc_examin.h"
#include "icc_betrachter.h"
#include "icc_gl.h"
#include <oyranos_color.h>
using namespace icc_examin_ns;
//#define DEBUG_EXAMIN
#ifdef DEBUG_EXAMIN
#define DBG_EXAMIN_START DBG_PROG_START
#define DBG_EXAMIN_ENDE DBG_PROG_ENDE
#define DBG_EXAMIN_V( texte ) DBG_NUM_V( texte )
#define DBG_EXAMIN_S( texte ) DBG_NUM_S( texte )
#else
#define DBG_EXAMIN_START
#define DBG_EXAMIN_ENDE
#define DBG_EXAMIN_V( texte )
#define DBG_EXAMIN_S( texte )
#endif
#ifdef DEBUG_
#define MARK(x) DBG_S( #x ) x
#else
#define MARK(x) x
#endif
void
ICCexamin::messwertLese (int n,
oyNamedColors_s ** list)
{
DBG_PROG_START
if(profile.size() > n &&
profile[n]->hasMeasurement() )
{ DBG_NUM_S( "nutze Messdaten" )
ICCmeasurement messung = profile[n]->getMeasurement();
if(messung.validHalf() && profile[n]->size())
icc_betrachter->DD_farbraum->show_points_as_pairs = true;
else
icc_betrachter->DD_farbraum->show_points_as_pairs = false;
DBG_NUM_V( icc_betrachter->DD_farbraum->show_points_as_pairs )
icc_betrachter->DD_farbraum->show_points_as_measurements = true;
DBG_NUM_V( icc_betrachter->DD_farbraum->show_points_as_measurements )
if(profile.profil()->data_type == ICCprofile::ICCmeasurementDATA ||
profile.profil()->hasTagName("ncl2") )
icc_betrachter->DD_farbraum->show_points_as_measurements = true;
else
icc_betrachter->DD_farbraum->show_points_as_measurements = false;
DBG_NUM_V( icc_betrachter->DD_farbraum->show_points_as_measurements )
unsigned int j;
unsigned int n_farben = messung.getPatchCount(); DBG_PROG_V( messung.getPatchCount() )
oyNamedColor_s * c = 0;
oyNamedColors_s * nl = oyNamedColors_New(0);
if(messung.validHalf())
{
for (j = 0; j < n_farben; ++j)
{ // first the measurments ...
if(messung.hasXYZ() || messung.hasLab())
c = messung.getMessColour(j);
else
c = messung.getCmmColour(j);
if (c)
oyNamedColors_MoveIn( nl, &c, -1 );
}
unsigned int n_old = oyNamedColors_Count( *list );
if(n_old != n_farben * 2)
oyNamedColors_Release( list );
if(icc_betrachter->DD_farbraum->show_points_as_pairs)
{
if(n_old == n_farben * 2 && *list)
{
for(unsigned int i = 0; i < n_farben; ++i)
{
if(profile[n]->data_type == ICCprofile::ICCmeasurementDATA)
c = oyNamedColors_Get( *list, i );
else
c = messung.getCmmColour(i);
if(c)
oyNamedColors_MoveIn( nl, &c, -1 );
}
}
else
{
for(unsigned int i = 0; i < n_farben; ++i)
{
if(profile[n]->data_type == ICCprofile::ICCmeasurementDATA)
c = oyNamedColors_Get( nl, i );
else
c = messung.getCmmColour(i);
if(c)
oyNamedColors_MoveIn( nl, &c, -1 );
}
}
}
oyNamedColors_Release( list );
*list = nl; nl = 0;
}
}
DBG_PROG_ENDE
}
void
ICCexamin::netzLese (int n,
icc_examin_ns::ICCThreadList<ICCnetz> *netz)
{
DBG_PROG_START
if( profile.size() == 0 && farbraumModus()) {
netz->resize(1);
return;
}
ICCnetz & netz_temp = (*netz)[n];
{
int intent = intentGet(NULL);
oyOptions_s * opts = oyOptions_FromBoolean( options(), NULL,
oyBOOLEAN_UNION, NULL );
if(farbraumModus())
intent = profile[n]->intent();
if( intent < 0 || 3 < intent ) /* check range */
intent = 3;
char num[4];
sprintf(num, "%d", intent);
oyOptions_SetFromString( &opts, "rendering_intent", num, OY_CREATE_NEW );
if(profile[n]->data_type == ICCprofile::ICCprofileDATA)
icc_oyranos.netzVonProfil( *(profile[n]), opts, nativeGamut(),
netz_temp );
oyOptions_Release( &opts );
if(netz_temp.punkte.size())
{
netz_temp.name = profile[n]->filename();
// extract the file name
std::string & dateiname = netz_temp.name;
if( dateiname.find_last_of(ICC_DIR_SEPARATOR) != std::string::npos)
dateiname = dateiname.substr( dateiname.find_last_of(ICC_DIR_SEPARATOR)+1,
dateiname.size() );
DBG_NUM_V( netz_temp.undurchsicht <<" "<< netz_temp.umriss.size() )
}
}
/*for(int i = 0; i < (int)netz->size(); ++i)
DBG_PROG_V( (*netz)[n].aktiv <<" "<< (*netz)[i].undurchsicht <<" "<< (*netz)[i].umriss.size() );*/
DBG_PROG_ENDE
}
/**
@param[in] n < 0 - single patch; >= 0 all patches from profile n
@param[out] p lab positions
@param[out] f colour
@param[out] names according names
@return nothing
*/
void
ICCexamin::farbenLese ( int n,
ICClist<double> & p,
ICClist<double> & f,
ICClist<std::string> & names )
{
DBG_PROG_START
// show named colours
ICCprofile * pr = NULL;
int single = (n < 0);
int patch = single ? -n - 1 : -1;
int s;
if( single )
pr = profile.profil();
else
pr = profile[n];
if( (n >= 0 && profile.size() > n) ||
single )
{
DBG_PROG
int item = pr->getTagIDByName("ncl2");
ICClist<double> p_neu = pr->getTagNumbers (item, ICCtag::MATRIX);
int channels_n = p_neu[1]+0.5;
unsigned int n_farben = p_neu.size()/(3+channels_n);
if(n_farben != p_neu[0])
WARN_S( "wrong patch count" << n_farben<<">"<< p_neu[0] )
names = pr->getTag(item).getText("ncl2_names");
int mult = 1;
int neu = 0;
if( single )
{
if( patch > (int)p_neu.size() )
WARN_S( "inadequate patch requested" << patch<<">"<< p_neu.size() )
n_farben = 1;
}
if(n_farben != p.size() / 3 / mult)
{
DBG_PROG_S( "resize " << n_farben <<" "<<
(p_neu.size()-2) / 3 <<" "<< p.size() / 3 / mult )
p.resize( n_farben * 3 * mult );
f.resize( n_farben * channels_n * mult );
neu = 1;
}
if( single )
{
p[0] = p_neu[patch*3+2+0];
p[1] = p_neu[patch*3+2+1];
p[2] = p_neu[patch*3+2+2];
names[0] = names[patch];
names.resize(1);
} else {
for(size_t i = 0; i < n_farben; ++i)
{
s = i*mult*3;
if(mult == 2 && !neu)
{
// copy old colours
p[s+3] = p[s+0];
p[s+4] = p[s+1];
p[s+5] = p[s+2];
}
p[s+0] = p_neu[i*3+2+0];
p[s+1] = p_neu[i*3+2+1];
p[s+2] = p_neu[i*3+2+2];
if(mult == 2 && neu)
{
// double of new colours
p[s+3] = p[s+0];
p[s+4] = p[s+1];
p[s+5] = p[s+2];
}
}
}
if(channels_n && mult &&
n_farben != f.size() / channels_n / mult)
neu = 1;
else
neu = 0;
DBG_NUM_V( f.size() )
for(unsigned i = 0; i < n_farben; ++i)
{
s = i*mult*channels_n;
if(mult == 2 && !neu)
for(int j = 0; j < channels_n; ++j)
f[s+channels_n + j] = f[s + j];
for(int j = 0; j < channels_n; ++j)
f[s + j] = p_neu[3*n_farben + i*channels_n +2+ j];
if(mult == 2 && neu)
for(int j = 0; j < channels_n; ++j)
f[s + channels_n + j] = f[i + j];
}
}
DBG_PROG_ENDE
}
void
ICCexamin::farbenLese ( int n,
oyNamedColors_s ** list )
{
DBG_PROG_START
int single = (n < 0);
oyNamedColors_s * nl = oyNamedColors_New(0);
ICClist<double> p;
ICClist<double> f; // colour
ICClist<std::string> names;
oyNamedColor_s * c = 0;
oyProfile_s * prof = oyProfile_FromFile( profile[n]->filename(), icc_oyranos.icc_profile_flags, 0 );
int channels_n = oyProfile_GetChannelsCount( prof );
farbenLese(n, p, f, names);
unsigned int n_farben = p.size()/3;
unsigned int n_old = oyNamedColors_Count( *list );
if(n_old != n_farben * 2)
oyNamedColors_Release( list );
if( !single )
{
icc_betrachter->DD_farbraum->show_points_as_measurements = true;
icc_betrachter->DD_farbraum->show_points_as_pairs = true;
} else {
n_farben = 1;
}
for (unsigned int i = 0; i < n_farben; ++i)
{
double XYZ[3];
double cielab[3];
const char * name = 0;
unsigned int names_n = names.size();
double * channels = NULL;
if(channels_n*i < f.size())
channels = &f[channels_n*i];
if(i >= names_n)
{
if(names_n*2 == n_farben)
name = names[i-names_n].c_str();
} else
name = names[i].c_str();
LabToCIELab( &p[3*i], cielab, 1 );
oyLab2XYZ( cielab, XYZ );
c = oyNamedColor_CreateWithName( name,0,0, channels, XYZ, 0,0, prof, 0 );
if(c)
oyNamedColors_MoveIn( nl, &c, -1 );
}
oyProfile_Release( &prof );
if(n_old == n_farben * 2 && *list)
for(unsigned int i = 0; i < n_farben; ++i)
{
c = oyNamedColors_Get( *list, i );
if(c)
oyNamedColors_MoveIn( nl, &c, -1 );
}
else
for(unsigned int i = 0; i < n_farben; ++i)
{
c = oyNamedColors_Get( nl, i );
if(c)
oyNamedColors_MoveIn( nl, &c, -1 );
}
oyNamedColors_Release( list );
*list = nl;
DBG_PROG_ENDE
}
void
ICCexamin::farbraum (int n)
{
DBG_PROG_START
ICClist<std::string> texte, namen;
texte.push_back(_("CIE *L"));
texte.push_back(_("CIE *a"));
texte.push_back(_("CIE *b"));
oyStructList_s * namedColours = icc_betrachter->DD_farbraum->namedColours();
oyNamedColors_s * ncl = 0;
if(oyStructList_Count( namedColours ) > n)
ncl = (oyNamedColors_s*) oyStructList_GetRefType( namedColours, n,
oyOBJECT_NAMED_COLORS_S );
DBG_PROG_V( n <<" "<< profile.size()<<" "<<profile.aktuell() )
DBG_PROG_V( profile[n]->filename() )
// measurements
int messwerte=false;
bool has_mess = profile[n]->hasMeasurement();
MARK( frei(false); )
if(profile.size() > n &&
has_mess &&
!(profile[n]->data_type == ICCprofile::ICCprofileDATA &&
profile.aktuell() != n))
{
DBG_PROG
messwertLese(n, &ncl);
messwerte = true;
}
MARK( frei(true); )
int ncl2_profil = profile[n]->hasTagName("ncl2");
// open
if(lade())
farbraumModus( profile.aktuell() );
// show named colours
if( profile.size() > n && ncl2_profil )
{
DBG_PROG
farbenLese(n, &ncl );
}
bool neues_netz = false;
if( n >= (int)icc_betrachter->DD_farbraum->triangle_nets.size() )
neues_netz = true;
//if((int)icc_betrachter->DD_farbraum->triangle_nets.size() > n)
//icc_betrachter->DD_farbraum->triangle_nets[n].undurchsicht = 1.0;
if(oyStructList_Count( namedColours ) > n && !collect_changing_points)
oyStructList_ReleaseAt( namedColours, n );
if(ncl)
{
if(!namedColours)
namedColours = oyStructList_New(0);
oyStructList_MoveIn( namedColours, (oyStruct_s**)&ncl, n, 0 );
}
icc_betrachter->DD_farbraum->namedColours( namedColours );
oyStructList_Release( &namedColours );
do {
icc_examin_ns::sleep(0.05);
} while(!icc_betrachter->DD_farbraum->frei());
if(profile[0]->data_type != ICCprofile::ICCvrmlDATA)
{
//MARK( icc_betrachter->DD_farbraum->frei(false); )
icc_betrachter->DD_farbraum->triangle_nets.frei(false);
if((int)icc_betrachter->DD_farbraum->triangle_nets .size() <= n)
icc_betrachter->DD_farbraum->triangle_nets .resize( n + 1 );
icc_examin_ns::ICCThreadList<ICCnetz> *netze = &icc_betrachter->DD_farbraum->triangle_nets;
DBG_PROG_V( icc_betrachter->DD_farbraum->triangle_nets.size() <<" "<< n )
if( profile.size() > n && !ncl2_profil )
{
//icc_betrachter->DD_farbraum->frei(true);
netzLese(n, netze);
//icc_betrachter->DD_farbraum->frei(false);
}
DBG_PROG_V( n <<" "<< netze->size() <<" "<< ncl2_profil )
// set some standard values
if(netze->size() && neues_netz)
{
if((messwerte || ncl2_profil) && !(*netze)[n].punkte.size())
{
(*netze)[n].undurchsicht = 1.0;
if(n == 0)
(*netze)[n].grau = false;
else
(*netze)[n].grau = true;
}
else
if((n == 0 && ncl2_profil) &&
!messwerte )
{
(*netze)[n].undurchsicht = 0.15;
(*netze)[n].grau = false;
}
else
if ( farbraumModus() && !messwerte )
{
if(n == 1)
(*netze)[n].undurchsicht = 0.15;
else
(*netze)[n].undurchsicht = 0.10;
(*netze)[n].grau = true;
}
else
if ( n == 0 )
{
(*netze)[n].undurchsicht = 0.25;
(*netze)[n].grau = false;
}
else
{
(*netze)[n].undurchsicht = 0.3;
(*netze)[n].grau = true;
}
if(profile[n]->filename() == icc_examin->moniName() &&
netze->size() > 1)
{
profile.passiv(n);
(*netze)[n].active( false );
}
icc_betrachter->DD_farbraum->achsNamen( texte );
DBG_PROG_V( n <<" "<< profile.aktiv(n) )
}
if(icc_betrachter->DD_farbraum->triangle_nets[n].name == "")
{
icc_betrachter->DD_farbraum->triangle_nets[n].name =
profile[n]->filename();
// extract file name
std::string & dateiname = icc_betrachter->DD_farbraum->triangle_nets[n].name;
if( dateiname.find_last_of("/") != std::string::npos)
dateiname = dateiname.substr( dateiname.find_last_of("/")+1,
dateiname.size() );
DBG_PROG_V( icc_betrachter->DD_farbraum->triangle_nets[n].name )
}
#if 0
if( profile.size() > n && !ncl2_profil )
icc_betrachter->DD_farbraum->hineinNetze(
icc_betrachter->DD_farbraum->triangle_nets );
#endif
icc_betrachter->DD_farbraum->triangle_nets.frei(true);
//MARK( icc_betrachter->DD_farbraum->frei(true); )
}
DBG_PROG_ENDE
}
void
ICCexamin::farbraum ()
{
DBG_PROG_START
MARK( frei(false); )
MARK( icc_betrachter->DD_farbraum->triangle_nets.frei(false); )
if((int)icc_betrachter->DD_farbraum->triangle_nets.size() > profile.size())
icc_betrachter->DD_farbraum->triangle_nets.resize(profile.size());
MARK( icc_betrachter->DD_farbraum->triangle_nets.frei(true); )
DBG_PROG_V( icc_betrachter->DD_farbraum->triangle_nets.size() )
MARK( frei(true); )
for(int i = 0; i < profile.size(); ++i)
{
while(!profile[i] || profile[i]->changing())
icc_examin_ns::sleep(0.05);
farbraum(i);
}
icc_betrachter->DD_farbraum->clearNet();
/*if(icc_betrachter->DD_farbraum -> triangle_nets.size())
icc_betrachter->DD_farbraum ->
triangle_nets [icc_betrachter->DD_farbraum->triangle_nets.size()-1]
. undurchsicht = 0.7;*/
DBG_PROG_V( profile.size() )
DBG_PROG_ENDE
}
void
ICCexamin::farbraumModus (int profil ICC_UNUSED)
{
DBG_PROG_START
MARK( frei(false); )
farbraum_modus_ = false;
if(profile.size() && profile.profil()->hasTagName("ncl2"))
{
farbraum_modus_ = true;
static int test = 1;
if(lade() && test)
intentNoUpdate( profile.profil()->intent() );
else
intent( -1, 0 );
DBG_PROG_S( "set colour space mode" )
} else if(!profile.size()) {
WARN_S( "too early with " << profile.size() << " profiles" )
}
DBG_PROG_V( farbraum_modus_ )
MARK( frei(true); )
DBG_PROG_ENDE
}