-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc_oyranos.cpp
1786 lines (1480 loc) · 50.4 KB
/
icc_oyranos.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.
*
* -----------------------------------------------------------------------------
*
* The CMS sorter.
*
*/
// Date: 25. 11. 2004
#include "icc_formeln.h"
#include "icc_oyranos.h"
#include "icc_profile.h"
#include "icc_utils.h"
#include "icc_fenster.h"
#include "icc_info.h"
#include "config.h"
using namespace icc_examin_ns;
#include <oyranos.h>
#include <oyranos_devices.h>
#include "oyranos_display_helpers.c"
#if defined(__APPLE__)
#include <Carbon/Carbon.h>
#include <IOKit/Graphics/IOGraphicsLib.h>
#endif
#if defined(HAVE_X) && !defined(__APPLE__)
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include <X11/Xcm/Xcm.h>
# ifdef HAVE_FLTK
# include <FL/x.H>
# endif
#endif
Oyranos icc_oyranos;
/* concepts:
* o - oyInit() initialisiert die Bibliothek und erlaubt das lesen von
* Zeigern
* - oyQuit() beraeumt all diese
* o one object per profile (void* cmsOpen(...) ; cmsClose(void*))
* this will wait until a CMM architecture is ready
* o a C++ wrapper for liboyranos as with Oyranos oyranos
* export oyranos with a C++ header
* o leave all to the user (C free())
* in prototyp here
* o sich auf reine Namensnennung beschraenken --
*/
Oyranos::Oyranos()
{
DBG_PROG_START
oy_profile_from_flags = OY_NO_REPAIR;
DBG_PROG_ENDE
}
Oyranos::~Oyranos()
{
DBG_PROG_START
DBG_PROG_ENDE
}
// local types in icc_oyranos.cpp
typedef std::map<std::string,Speicher> Prof_map;
typedef std::map<std::string,Speicher>::iterator Prof_mapIt;
typedef std::pair<std::string,Speicher> Prof_Map_elem;
typedef std::pair<Prof_map::const_iterator,bool> Prof_mapIt_bool;
void
Oyranos::clear()
{
lab_.clear();
moni_.clear();
moni_native_.clear();
rgb_.clear();
cmyk_.clear();
proof_.clear();
}
bool
Oyranos::profil_test_ (const char* profil_name)
{
DBG_PROG_START
bool fehler = false;
if(profil_name && strlen(profil_name))
{
Prof_mapIt cmp = pspeicher_.find( profil_name );
if( cmp == pspeicher_.end() )
{
fehler = oyCheckProfile( profil_name, 0 );
if( !fehler )
{
// insert empty block
Prof_Map_elem teil (profil_name, Speicher());
Prof_mapIt_bool erg = pspeicher_ .insert( teil );
if( erg.second == true )
{
// get referenz to block
Speicher *v_block = &pspeicher_[profil_name];
*v_block = profil_name;
size_t size;
char* block = (char*)oyGetProfileBlock( profil_name, &size, malloc);
DBG_PROG_V( (int*)block <<"|"<< size )
v_block->ladeUndFreePtr(&block, size);
}
}
} else // profile in list
{
//Speicher *v_block = &pspeicher_[profil_name];
// ...
}
}
DBG_NUM_S( "Standard " OY_DEFAULT_ASSUMED_LAB_PROFILE " Profil = "<< *lab_ <<" "<< lab_.size() <<"\n" )
return fehler;
DBG_PROG_ENDE
}
void
Oyranos::lab_test_ ()
{
DBG_PROG_START
Speicher *v_block = &lab_;
if( !v_block->size() )
{ DBG_PROG_V( v_block->size() )
char* profil_name = oyGetDefaultProfileName( oyASSUMED_LAB, myAllocFunc );
if(profil_name)
DBG_PROG_V( (int*)profil_name << profil_name );
if( profil_name &&
*v_block != profil_name )
{
*v_block = profil_name;
size_t size = oyGetProfileSize ( profil_name );
DBG_PROG_V( size )
if (size)
{ char *block = (char*)oyGetProfileBlock( profil_name, &size, malloc);
if( oyCheckProfileMem( block, size, 0 ) )
WARN_S ( _("WARNING: Could not load corrupt or damaged profile.") )
else {
DBG_PROG_V( (intptr_t)block <<"|"<< size )
v_block->ladeUndFreePtr(&block, size);
}
} else
WARN_S(_("WARNING: Could not load profile."));
}
}
DBG_NUM_S( "Standard " OY_DEFAULT_ASSUMED_LAB_PROFILE " Profil = "<< *lab_ <<" "<< lab_.size() <<"\n" )
DBG_PROG_ENDE
}
#if defined(__APPLE__) && 0
typedef struct {
char *data;
SInt32 size;
} refcon;
OSErr
MyFlattenProfileProc (
SInt32 command,
SInt32 *size,
void *data,
void *refCon)
{
// collect all parts
if(*size)
{
refcon *ref = (refcon*) refCon;
char* block = (char*)malloc(ref->size+*size);
// old data
if(ref->data && ref->size) {
memcpy(block, ref->data, ref->size);
free(ref->data);
}
// new data
memcpy( &block[ref->size], data, *size );
ref->data = block;
ref->size += *size;
}
DBG_PROG_V(command<<" "<<*size)
return 0;
}
OSErr
MyFlattenProfileProcSize (
SInt32 command,
SInt32 *size,
void *data,
void *refCon)
{
// collect all parts
if(*size)
{
refcon *ref = (refcon*) refCon;
ref->size += *size;
}
DBG_PROG_V(command<<" "<<*size)
return 0;
}
int
oyGetProfileBlockOSX (CMProfileRef prof, char *block, size_t *size, oyAlloc_f allocateFunc)
{
DBG_PROG_START
CMProfileLocation loc;
UInt32 locationSize = sizeof(CMProfileLocation);
//CMError err = CMGetProfileLocation( prof, &loc );
NCMGetProfileLocation(prof, &loc, &locationSize);
switch(loc.locType)
{
case cmNoProfileBase:
DBG_PROG_S("Das Monitorprofil ist ein temporaeres Profil.")
break;
#if !__LP64__ && !TARGET_OS_WIN32
case cmFileBasedProfile:
DBG_PROG_S("Das Monitorprofil ist ein Datei Profil.")
break;
case cmHandleBasedProfile:
DBG_PROG_S("Das Monitorprofil ist ein Haendling Profil.")
break;
case cmPtrBasedProfile:
DBG_PROG_S("Das Monitorprofil ist ein Zeiger Profil.")
break;
case cmProcedureBasedProfile:
DBG_PROG_S("Das Monitorprofil ist ein prozedurales Profil.")
break;
#endif
case cmPathBasedProfile:
DBG_PROG_S("Das Monitorprofil ist ein Pfad Profil.")
break;
case cmBufferBasedProfile:
DBG_PROG_S("Das Monitorprofil ist ein Speicherblock Profil.")
break;
default:
DBG_PROG_S("kein Profil gefunden?")
break;
}
#if !__LP64__ && !TARGET_OS_WIN32
refcon ref = {0,0};
Boolean bol;
// only the size
if(*size == 0) {
CMError err = CMFlattenProfile ( prof, 0, MyFlattenProfileProcSize, &ref, &bol);
*size = ref.size;
return err;
}
CMError err = CMFlattenProfile ( prof, 0, MyFlattenProfileProc, &ref, &bol);
err = 0;
Str255 str;
ScriptCode code;
CMGetScriptProfileDescription(prof, str, &code);
DBG_PROG_V( (int)str[0] )
if (prof) CMCloseProfile(prof);
const unsigned char *profil_name = str; ++profil_name;
if(ref.size && ref.data)
{
*size = ref.size;
block = (char*) allocateFunc( *size );
memcpy(block, ref.data, ref.size);
DBG_MEM_V( size )
} else
#endif
if(loc.locType == cmBufferBasedProfile)
{
*size = loc.u.bufferLoc.size;
block = (char*) allocateFunc( *size );
memcpy(block, loc.u.bufferLoc.buffer, *size);
DBG_PROG_V( *size )
}
DBG_PROG_ENDE
return 0;
}
#endif
char*
changeScreenName_( const char *display_name, int screen )
{
char *new_display_name = 0;
if(!display_name)
return NULL;
if( (new_display_name = (char*) new char [strlen(display_name) +24]) == 0)
return NULL;
sprintf( new_display_name, "%s", display_name );
char *ptr = strchr( new_display_name, ':' );
char *ptr2 = 0;
if( ptr )
{
ptr2 = strchr( ptr, '.' );
if(ptr2)
sprintf( ptr2, ".%d", screen );
else
sprintf( &ptr[strlen(ptr)], ".%d", screen );
} else
sprintf( &ptr[strlen(ptr)], ".%d", screen );
return new_display_name;
}
void
Oyranos::moni_native_test_ (int x, int y)
{
DBG_PROG_START
size_t size = 0;
Speicher v_block = moni_native_;
oyProfile_s * oy_moni = 0;
if(icc_examin_ns::zeitSekunden() > v_block.zeit() + 1.0)
{
oy_moni = oyMoni(x,y, 1);
char* block = (char*) oyProfile_GetMem ( oy_moni, &size, 0, malloc );
/* monitor name is expensive for non cached profiles */
const char * vb = v_block;
if(v_block.size() != size ||
memcmp( vb, block, size ) != 0 )
{
if(block && size)
v_block.ladeUndFreePtr(&block, size);
else
v_block.zeit( icc_examin_ns::zeitSekunden() );
const char* oy_moni_name = oyProfile_GetFileName( oy_moni, 0 );
if(oy_moni_name)
v_block = oy_moni_name;
}
if(block && size) {
free( block ); block = 0; size = 0;
}
oyProfile_Release( &oy_moni );
}
DBG_PROG_ENDE
return;
}
void
Oyranos::moni_test_ (int x, int y)
{
DBG_PROG_START
size_t size = 0;
Speicher v_block = moni_;
oyProfile_s * oy_moni = 0;
if(icc_examin_ns::zeitSekunden() > v_block.zeit() + 1.0)
{
oy_moni = oyMoni(x,y);
char* block = (char*) oyProfile_GetMem ( oy_moni, &size, 0, malloc );
/* monitor name is expensive for non cached profiles */
const char * vb = v_block;
if(v_block.size() != size ||
memcmp( vb, block, size ) != 0 )
{
if(block && size)
v_block.ladeUndFreePtr(&block, size);
else
v_block.zeit( icc_examin_ns::zeitSekunden() );
const char* oy_moni_name = oyProfile_GetFileName( oy_moni, 0 );
if(oy_moni_name)
v_block = oy_moni_name;
}
if(block && size) {
free( block ); block = 0; size = 0;
}
oyProfile_Release( &oy_moni );
}
DBG_PROG_ENDE
return;
}
void
Oyranos::rgb_test_ ()
{
DBG_PROG_START
Speicher *v_block = &rgb_;
if( !v_block->size() )
{ DBG_PROG_V( v_block->size() )
const char* profil_name = oyGetDefaultProfileName( oyASSUMED_RGB, myAllocFunc );
if(profil_name)
DBG_PROG_V( (intptr_t)profil_name << profil_name );
if( profil_name &&
*v_block != profil_name )
{
*v_block = profil_name;
size_t size = oyGetProfileSize ( profil_name );
DBG_PROG_V( size )
if (size)
{ char *block = (char*)oyGetProfileBlock( profil_name, &size, malloc);
if( oyCheckProfileMem( block, size, 0 ) )
WARN_S(_("WARNING: Could not load profile."))
else {
DBG_PROG_V( (int*)block <<"|"<< size )
v_block->ladeUndFreePtr(&block, size);
}
} else
WARN_S(_("WARNING: Could not load profile."))
}
}
if(rgb_.size())
DBG_NUM_S( "Standard " OY_DEFAULT_ASSUMED_RGB_PROFILE " Profil = "<< *rgb_ <<" "<< rgb_.size() <<"\n" );
DBG_PROG_ENDE
}
void
Oyranos::cmyk_test_ ()
{
DBG_PROG_START
Speicher *v_block = &cmyk_;
if( !v_block->size() )
{ DBG_PROG_V( v_block->size() )
char* profil_name = oyGetDefaultProfileName( oyASSUMED_CMYK, myAllocFunc );
if(profil_name) {DBG_PROG_V( profil_name );
} else { DBG_PROG_V( (intptr_t)profil_name );}
if( profil_name &&
*v_block != profil_name )
{
*v_block = profil_name;
size_t size = oyGetProfileSize ( profil_name );
DBG_PROG_V( size )
if (size)
{ char *block = (char*)oyGetProfileBlock( profil_name, &size, malloc);
if( oyCheckProfileMem( block, size, 0 ) )
WARN_S(_("WARNING: Could not load profile."))
else {
DBG_PROG_V( (int*)block <<"|"<< size )
v_block->ladeUndFreePtr(&block, size);
}
} else
WARN_S(_("WARNING: Could not load profile."));
}
}
if(cmyk_.size())
DBG_NUM_S( "Standard " OY_DEFAULT_ASSUMED_CMYK_PROFILE " Profil = "<< *cmyk_ <<" "<< cmyk_.size() <<"\n" );
//oy_debug = 0;
DBG_PROG_ENDE
}
void
Oyranos::proof_test_ ()
{
DBG_PROG_START
Speicher *v_block = &proof_;
char* profil_name = NULL;
profil_name = oyGetDefaultProfileName( oyPROFILE_PROOF, myAllocFunc);
if( !v_block->size() )
{ DBG_PROG_V( v_block->size() )
if(profil_name) {DBG_PROG_V( profil_name );
} else { DBG_PROG_V( (intptr_t)profil_name );}
if( profil_name &&
*v_block != profil_name )
{
*v_block = profil_name;
size_t size = oyGetProfileSize ( profil_name );
DBG_PROG_V( size )
if (size)
{ char *block = (char*)oyGetProfileBlock( profil_name, &size, malloc);
if( oyCheckProfileMem( block, size, 0 ) )
WARN_S(_("WARNING: Could not load profile."))
else {
DBG_PROG_V( (int*)block <<"|"<< size )
v_block->ladeUndFreePtr(&block, size);
}
} else
WARN_S(_("WARNING: Could not load profile."));
}
}
if(cmyk_.size())
DBG_NUM_S( "Standard " OY_DEFAULT_PROOF_PROFILE " Profil = "<< *proof_ <<" "<< proof_.size() <<"\n" );
//oy_debug = 0;
DBG_PROG_ENDE
}
#if 0
char*
Oyranos::holeMonitorProfil (const char* display_name, size_t* size )
{
DBG_PROG_START
char* moni_profil = 0;
*size = 0;
# if defined(HAVE_X) && !defined(__APPLE__)
static Display *display=0;
if(display_name)
display = XOpenDisplay(display_name);
# ifdef HAVE_FLTK
if( !display )
display = fl_display;
# endif
if( !display )
display = XOpenDisplay(0);
display_name = XDisplayString( display ); // gehoert X
DBG_PROG_V( display_name <<" "<< strlen(display_name) )
# ifndef HAVE_FLTK
XCloseDisplay( display ); DBG_PROG
# endif
# endif
moni_profil = oyGetMonitorProfile( display_name, size );
DBG_PROG_V( *size <<" "<< (int*)moni_profil )
DBG_PROG_ENDE
return moni_profil;
}
#endif
int
Oyranos::setzeMonitorProfil (const char* profil_name , int x, int y )
{
DBG_PROG_START
int fehler = false;
DBG_PROG_V( profil_name )
const char *display_name=0;
# if defined(HAVE_X) && !defined(__APPLE__)
display_name = XDisplayString( fl_display ); // belongs to X
DBG_PROG_V( display_name <<" "<< strlen(display_name) )
# endif
int screen = oyGetScreenFromPosition( display_name, x,y );
char *new_display_name = changeScreenName_( display_name, screen );
if(new_display_name)
fehler = oySetMonitorProfile( new_display_name, profil_name );
char *neues_profil = oyGetMonitorProfileNameFromDB( display_name,myAllocFunc);
if(new_display_name) { delete [] new_display_name; new_display_name = 0; }
DBG_PROG_V( neues_profil )
if (neues_profil) free (neues_profil);
DBG_PROG_ENDE
return fehler;
}
char**
Oyranos::moniInfo (int x, int y, int * num)
{
DBG_PROG_START
*num = 0;
char **infos = 0;
char *display_name=0;
#if defined(HAVE_X) && !defined(__APPLE__)
display_name = oyGetDisplayNameFromPosition( 0, x,y, malloc );
#else
display_name = oyGetDisplayNameFromPosition2( OY_TYPE_STD, "monitor.qarz", 0, x,y, malloc );
#endif
infos = (char**) new char* [10];
static char *manufacturer = 0;
static char *model = 0;
static char *serial = 0;
static char *geometry = 0;
static char *system_port = 0;
static char * old_screen_name = 0;
//int fehler =
# if OYRANOS_VERSION > 300
oyConfig_s * device = 0;
oyOptions_s * options = 0;
const char * t;
if(display_name &&
(!old_screen_name ||
strcmp(display_name, old_screen_name) != 0))
{
oyOptions_SetFromString( &options,
"//" OY_TYPE_STD "/config/command",
"properties", OY_CREATE_NEW );
oyDeviceGet( OY_TYPE_STD, "monitor", display_name, options, &device );
oyOptions_Release( &options );
t = oyConfig_FindString( device, "manufacturer", 0 );
if(t) manufacturer = strdup( t );
t = oyConfig_FindString( device, "model", 0 );
if(t) model = strdup( t );
t = oyConfig_FindString( device, "serial", 0 );
if(t) serial = strdup( t );
t = oyConfig_FindString( device, "geometry", 0 );
if(t) geometry = strdup( t );
t = oyConfig_FindString( device, "system_port", 0 );
if(t) system_port = strdup( t );
oyConfig_Release( &device );
old_screen_name = strdup(display_name);
} else if(!display_name)
{
infos[2 * *num] = icc_strdup_m(_("Screen:"));
infos[2 * *num + 1] = icc_strdup_m(_("none"));
*num += 1;
return infos;
}
# elif OYRANOS_VERSION > 109
oyGetMonitorInfo( display_name,
&manufacturer, &model, &serial,
&system_port, &geometry, 0,
myAllocFunc );
# else
oyGetMonitorInfo( display_name,
&manufacturer, &model, &serial,
myAllocFunc );
# endif
if( manufacturer && strlen( manufacturer ) )
{
infos[2 * *num] = icc_strdup_m(_("Manufacturer:"));
infos[2 * *num + 1] = icc_strdup_m( manufacturer );
*num += 1;
}
if( model && strlen( model ) )
{
infos[2 * *num] = icc_strdup_m(_("Model:"));
infos[2 * *num + 1] = icc_strdup_m( model );
*num += 1;
}
if( serial && strlen( serial ) )
{
infos[2 * *num] = icc_strdup_m(_("Serial:"));
infos[2 * *num + 1] = icc_strdup_m( serial );
*num += 1;
}
if( geometry && strlen( geometry ) )
{
infos[2 * *num] = icc_strdup_m(_("Geometry:"));
infos[2 * *num + 1] = icc_strdup_m( geometry );
*num += 1;
}
if( system_port && strlen( system_port ) )
{
infos[2 * *num] = icc_strdup_m(_("Port:"));
infos[2 * *num + 1] = icc_strdup_m( system_port );
*num += 1;
}
if(display_name) { free(display_name); display_name = 0; }
DBG_PROG_ENDE
return infos;
}
/** generates a gamut hull */
std::string
Oyranos::netzVonProfil_ (ICCnetz & netz,
Speicher & profil,
oyOptions_s * options)
{
DBG_PROG_START
// a cubus from six squares with the range of the Lab cube
// will be transformed to a profile colour space and converted to a mesh
int a = 12; // resolution : 10 - more quick; 20 - more precise
size_t size = 4*a*(a+1) + 2*(a-1)*(a-1);
int channels_n = 3;
double *lab = new double [size*channels_n];
double min = 0.01, max = 0.99;
// side quares
for(int y = 0; y <= a; ++y)
for(int x = 0; x < 4 * a; ++x)
{
int b = 0; // area
int pos = (y * 4 * a + x) * channels_n;
// see http://www.oyranos.org/2008/01/gamut-mapping/
lab[pos + 0] = pow(.9999 - (double)y/(double)a, 2.0) + 0.0001;
if (b * a <= x && x < ++b * a) {
lab[pos + 1] = min + (x - (b - 1) * a)/(double)a * (max-min);
lab[pos + 2] = min;
} else if(b * a <= x && x < ++b * a) {
lab[pos + 1] = max;
lab[pos + 2] = min + (x - (b - 1) * a)/(double)a * (max-min);
} else if(b * a <= x && x < ++b * a) {
lab[pos + 1] = max - (x - (b - 1) * a)/(double)a * (max-min);
lab[pos + 2] = max;
} else if(b * a <= x && x < ++b * a) {
lab[pos + 1] = min;
lab[pos + 2] = max - (x - (b - 1) * a)/(double)a * (max-min);
}
}
// buttom and top square
for(int y = 0; y < (a - 1); ++y)
for(int x = 0; x < 2 * (a - 1); ++x)
{
int pos = (4 * a * (a + 1) + y * 2 * (a - 1) + x) * channels_n;
int b = 1; // area
int x_pos = x + 1, y_pos = y + 1;
double val = (double)y_pos/(double)a * (max-min);
if (0 <= x && x < a - 1) {
lab[pos + 0] = 1.0;
lab[pos + 1] = min + (x_pos - (b - 1) * (a - 1))/(double)a * (max-min);
lab[pos + 2] = min + val;
} else if(a - 1 <= x && x < 2 * a - 2) {
++b;
lab[pos + 1] = min + (x_pos - (b - 1) * (a - 1))/(double)a * (max-min);
lab[pos + 2] = min + val;
// see http://www.oyranos.org/2008/01/gamut-mapping/
lab[pos + 0] = HYP( lab[pos + 1] - 0.5, lab[pos + 2] - 0.5)/100.;//0.0
}
}
if(wandelLabNachProfilUndZurueck( lab, size, options,
profil ))
return std::string("oyranos");
//double * rgb = wandelLabNachBildschirmFarben( 0,0, lab, size, 0, 0 );
// collect colour points
netz.punkte. resize( size );
for(size_t i = 0; i < size; ++i)
{
for(int k = 0; k < channels_n; ++k)
{
netz.punkte[i].koord[k] = lab [i*channels_n+k];
netz.punkte[i].farbe[k] = 0;//rgb [i*channels_n+k];
}
netz.punkte[i].farbe[channels_n] = 1.0;
}
// build mesh
char *liste = new char [size];
memset( liste, 1, size );
std::pair<double,DreiecksIndexe> index_p;
for(int y = 0; y < a; ++y)
for(int x = 0; x < 4 * a; ++x)
{
int x_ = (x == 4 * a - 1) ? -1 : x;
index_p.second.i[0] = y * 4*a+x; index_p.second.i[1] = y * 4*a+x_+1;
index_p.second.i[2] = (y+1)*4*a+x;
netz.indexe. insert( index_p );
index_p.second.i[0] = y * 4*a+x_+1;
index_p.second.i[2] = (y+1)*4*a+x; index_p.second.i[1] = (y+1)*4*a+x_+1;
netz.indexe. insert( index_p );
}
int off = 4 * a * (a + 1);
// 1 0 0 (L a b)
index_p.second.i[0] = 4*a-1; index_p.second.i[1] = off;
index_p.second.i[2] = 0;
netz.indexe. insert( index_p );
index_p.second.i[0] = off;
index_p.second.i[2] = 0; index_p.second.i[1] = 1;
netz.indexe. insert( index_p );
// 0 0 0
index_p.second.i[1] = off-1; index_p.second.i[0] = off+a-1;
index_p.second.i[2] = off-4*a;
netz.indexe. insert( index_p );
index_p.second.i[1] = off+a-1;
index_p.second.i[2] = off-4*a; index_p.second.i[0] = off - 4*a+1;
netz.indexe. insert( index_p );
// 0 0 1
index_p.second.i[2] = off-a; index_p.second.i[1] = off-a-1;
index_p.second.i[0] = off+2*(a-1)*(a-1)-a+1;
netz.indexe. insert( index_p );
index_p.second.i[0] = off-a;
index_p.second.i[1] = off-a+1; index_p.second.i[2] = off+2*(a-1)*(a-1)-a+1;
netz.indexe. insert( index_p );
// 0 1 1
index_p.second.i[0] = off-2*a+1; index_p.second.i[2] = off-2*a;
index_p.second.i[1] = off+2*(a-1)*(a-1)-1;
netz.indexe. insert( index_p );
index_p.second.i[1] = off-2*a;
index_p.second.i[2] = off+2*(a-1)*(a-1)-1; index_p.second.i[0] = off-2*a-1;
netz.indexe. insert( index_p );
// 1 1 1
index_p.second.i[0] = 2*a-1; index_p.second.i[2] = 2*a;
index_p.second.i[1] = off+2*(a-1)*(a-1)-a;
netz.indexe. insert( index_p );
index_p.second.i[1] = 2*a;
index_p.second.i[2] = off+2*(a-1)*(a-1)-a; index_p.second.i[0] = 2*a+1;
netz.indexe. insert( index_p );
// 1 0 1
index_p.second.i[2] = 3*a; index_p.second.i[0] = 3*a-1;
index_p.second.i[1] = off+2*(a-1)*(a-1)-2*a+2;
netz.indexe. insert( index_p );
index_p.second.i[2] = 3*a;
index_p.second.i[1] = 3*a+1; index_p.second.i[0] = off+2*(a-1)*(a-1)-2*a+2;
netz.indexe. insert( index_p );
// 1 1 0
index_p.second.i[0] = off+a-2; index_p.second.i[1] = a + 1;
index_p.second.i[2] = a - 1;
netz.indexe. insert( index_p );
index_p.second.i[0] = a + 1;
index_p.second.i[2] = a - 1; index_p.second.i[1] = a;
netz.indexe. insert( index_p );
// 0 1 0
index_p.second.i[0] = off+2*(a-1)-1;
index_p.second.i[1] = off-3*a-1; index_p.second.i[2] = off-3*a;
netz.indexe. insert( index_p );
index_p.second.i[1] = off+2*(a-1)-1; index_p.second.i[0] = off-3*a+1;
index_p.second.i[2] = off-3*a+0;
netz.indexe. insert( index_p );
for(int y = 0; y < a; ++y)
{
if(0 < y && y < a - 1)
{
// 0 0 .
index_p.second.i[2] = off-y; index_p.second.i[0] = off+(y+1)*2*(a-1)-a+1;
index_p.second.i[1] = off-y-1;
netz.indexe. insert( index_p );
index_p.second.i[0] = off+(y+0)*2*(a-1)-a+1;
index_p.second.i[2] = off-y; index_p.second.i[1] = off+(y+1)*2*(a-1)-a+1;
netz.indexe. insert( index_p );
// 0 1 .
index_p.second.i[1] = off+(y+1)*2*(a-1)-1; index_p.second.i[0] =off-3*a+y+1;
index_p.second.i[2] = off+(y)*2*(a-1)-1;
netz.indexe. insert( index_p );
index_p.second.i[1] =off-3*a+y+1;
index_p.second.i[2] = off+(y)*2*(a-1)-1; index_p.second.i[0] = off-3*a+y;
netz.indexe. insert( index_p );
// 1 0 .
index_p.second.i[0] = off+2*(a-1)*(a-1)-(y+1)*2*(a-1);
index_p.second.i[1] = 3*a+y+1; index_p.second.i[2] = off+2*(a-1)*(a-1)-y*2*(a-1);
netz.indexe. insert( index_p );
index_p.second.i[0] = 3*a+y+1; index_p.second.i[2] = off+2*(a-1)*(a-1)-y*2*(a-1);
index_p.second.i[1] = 3*a+y;
netz.indexe. insert( index_p );
// 1 1 .
index_p.second.i[0] = off+2*(a-1)*(a-1)-(y+1)*2*(a-1)+a-2;
index_p.second.i[1] = off+2*(a-1)*(a-1)-(y+0)*2*(a-1)+a-2; index_p.second.i[2] = 2*a-y;
netz.indexe. insert( index_p );
index_p.second.i[0] = 2*a-y-1;
index_p.second.i[1] = off+2*(a-1)*(a-1)-(y+1)*2*(a-1)+a-2; index_p.second.i[2] = 2*a-y;
netz.indexe. insert( index_p );
}
for(int x = 0; x < 2 * a; ++x)
{
int x_ = x + off;
// lower border
if( y == 0 )
{
if(x == 0) {
} else if(x == a - 1) {
} else if(x < a - 1) {
// 1 . 0
index_p.second.i[0] = off + x - 1; index_p.second.i[1] = off + x;
index_p.second.i[2] = x;
netz.indexe. insert( index_p );
index_p.second.i[0] = off + x;
index_p.second.i[2] = x; index_p.second.i[1] = x + 1;
netz.indexe. insert( index_p );
// 0 . 1
index_p.second.i[0] = off-a-x; index_p.second.i[2] = off-a-x-1;
index_p.second.i[1] = off+2*(a-1)*(a-1)-a+x;
netz.indexe. insert( index_p );
index_p.second.i[2] = off-a-x-1;
index_p.second.i[0] = off+2*(a-1)*(a-1)-a+x; index_p.second.i[1] = off+2*(a-1)*(a-1)-a+x+1;
netz.indexe. insert( index_p );
// 1 . 1
index_p.second.i[0] = 3*a - x; index_p.second.i[1] = 3*a - x-1;
index_p.second.i[2] = off+2*(a-1)*(a-1)-2*(a-1)+x-1;
netz.indexe. insert( index_p );
index_p.second.i[0] = 3*a - x-1;
index_p.second.i[2] = off+2*(a-1)*(a-1)-2*(a-1)+x-1; index_p.second.i[1] = off+2*(a-1)*(a-1)-2*(a-1)+x;
netz.indexe. insert( index_p );
} else if (x > a + 1) {
// 0 . 0
index_p.second.i[0] = off+x-3; index_p.second.i[2] = off+x-3+1;
index_p.second.i[1] = 4*a*(a+1)-4*a + x-a-1;
netz.indexe. insert( index_p );
index_p.second.i[1] = off+x-3+1;
index_p.second.i[2] = 4*a*(a+1)-4*a + x-a-1; index_p.second.i[0] = 4*a*(a+1)-4*a + x-a;
netz.indexe. insert( index_p );
}
// upper border
} else if( y == a - 1 )
{
if(x == 0) {
}
} else if(0 <= x && x < a - 1 - 1) {
// upper middle field (*L=0.0)
index_p.second.i[0] = (y-1) * 2*(a-1)+x_; index_p.second.i[2] = (y-1)*2*(a-1)+x_+1;
index_p.second.i[1] = (y+0)*2*(a-1)+x_;
netz.indexe. insert( index_p );
index_p.second.i[2] = (y-1)*2*(a-1)+x_+1;
index_p.second.i[0] = (y+0)*2*(a-1)+x_; index_p.second.i[1] = (y+0)*2*(a-1)+x_+1;
netz.indexe. insert( index_p );
} else if(a - 1 <= x && x < 2 * a - 2 - 1) {
// lower middle field (*L=1.0)
index_p.second.i[0] = (y-1) * 2*(a-1)+x_; index_p.second.i[1] = (y-1)*2*(a-1)+x_+1;
index_p.second.i[2] = (y+0)*2*(a-1)+x_;
netz.indexe. insert( index_p );
index_p.second.i[0] = (y-1)*2*(a-1)+x_+1;
index_p.second.i[2] = (y+0)*2*(a-1)+x_; index_p.second.i[1] = (y+0)*2*(a-1)+x_+1;
netz.indexe. insert( index_p );
}
}
}
netz.kubus = 1;
//delete [] rgb;