-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc_cinepaint_intern.cpp
1709 lines (1439 loc) · 49.5 KB
/
icc_cinepaint_intern.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 plug-in for cinepaint.
*
* Copyright (C) 2004-2014 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* copies an assigned ICC profil to $TMP_DIR and calls the dialog
*
* internal linking of iccexamin in the icc_examin_cp plug-in
* 2006(?)
* add writing of image samples out to an profile - name: plug_in_icc_watch
* 2005-02-28
* bugfixes
* query only with found iccexamin executable
* 2005-04-28
* reorder functions, doxygenise, more variable checks
* 2005-10-13
* colour == farbkanaele
* 2005-10-21
* added imagename to written profile name
* 2005-10-30
*/
/*** includes ***/
#include "icc_utils.h"
#include "config.h"
#include "icc_helfer.h"
#include "icc_examin.h"
#include "icc_kette.h"
#include "icc_examin_version.h"
#include <oyProfiles_s.h>
#ifdef HAVE_X11
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
#ifdef DEBUG
#define DBG_PLUG_V(x) DBG_PROG_V(x)
#define DBG_PLUG_S(x) DBG_PROG_S(x)
#else
#define DBG_PLUG_V(x)
#define DBG_PLUG_S(x)
#endif
/*** local macros ***/
/** \addtogroup plug_in_api Externe Plug-in API
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
struct Bvals {
int ein_Argument;
} bvals;
#ifdef __cplusplus
} /* extern "C" */
#endif
/** @} */
/** alle Variablen -> icc_examin_cp */
namespace icc_examin_cp {
/** @brief Typ der benötigten Änderung */
typedef int ChanModE;
#define LAYOUT_NEU(b) ((b) << 0) //!< +- Ebene
#define GET_LAYOUT(b) (((b)>> 0)&1) //!< +- Ebene
#define GEOMETRY_NEU(b) ((b) << 1) //!< Versatz, Skalierung
#define GET_GEOMETRY(b) (((b)>> 1)&1) //!< Versatz, Skalierung
#define BITDEPTH_NEU(b) ((b) << 2) //!< Farbtiefe
#define GET_BITDEPTH(b) (((b)>> 2)&1) //!< Farbtiefe
#define CHANNELS_NEU(b) ((b) << 3) //!< alpha Kanal, Rgb<->SW
#define GET_CHANNELS(b) (((b)>> 3)&1) //!< alpha Kanal, Rgb<->SW
#define TRANSFORM_NEU(b) ((b) << 4) //!< Übertragung
#define GET_TRANSFORM(b) (((b)>> 4)&1) //!< Übertragung
#define PROFIL_NEU(b) ((b) << 5) //!< Farbprofil
#define GET_PROFIL(b) (((b)>> 5)&1) //!< Farbprofil
/*** struct definitions ***/
/** alle Layer relevanten Informationen */
struct Channel {
gint32 display_ID; //!< view
gint32 ID; //!< drawable_ID
GimpDrawable *drawable;
GDrawableType/*GimpDrawableType*/ drawable_type;
GimpPixelRgn srcRgn; //!< start image
//GimpPixelRgn dstRgn; //!< shadow image
// guchar *pixels, //!< raw pixel buffer for colors
// *pixel; //!< pointer to actual position in pixels
int precision, //!< precision gimp_drawable_precision (layer->ID);
samplesperpixel, //!< channels per pixel
alpha; //!< existence
int width, height; //!< total dimensions
int offx, offy; //!< layer offsets
gint sel_x1, sel_y1, sel_x2, sel_y2; //!< selection mask
gint sel_w, sel_h; //!< dimension of mask
icUInt32Number intent; //!< CinePaint rendering intent
icUInt32Number intent_proof; //!< CinePaint simulation intent
int flags; //!< CinePaint CMM switches
ChanModE status; //!< tasks to do later
Channel() {
display_ID = 0;
ID = 0;
drawable = 0;
drawable_type = RGB_IMAGE;
//srcRgn = 0;
precision = samplesperpixel = alpha = 0;
width = height = 0;
offx = offy = 0;
sel_x1 = sel_y1 = sel_x2 = sel_y2 = 0;
sel_w = sel_h = 0;
intent = 0;
intent_proof = 0;
flags = 0;
status = 256;
}
~Channel() {
if(drawable) gimp_drawable_detach(drawable);
}
};
typedef Channel channel;
/** ncl2 profilbody */
signed char icc_base_data[320] =
{
0,0,1,64,108,99,109,115,
2,48,0,0,110,109,99,108,
82,71,66,32,76,97,98,32,
0,0,0,0,0,0,0,0,
0,0,0,0,97,99,115,112,
83,71,73,32,0,0,0,0,
110,111,110,101,110,111,110,101,
-64,48,11,8,-40,-41,-1,-65,
0,0,0,0,0,0,-10,-42,
0,1,0,0,0,0,-45,45,
67,80,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,3,100,101,115,99,
0,0,0,-88,0,0,0,33,
99,112,114,116,0,0,0,-52,
0,0,0,29,110,99,108,50,
0,0,0,-20,0,0,0,84,
116,101,120,116,0,0,0,0,
67,105,110,101,80,97,105,110,
116,32,99,111,108,111,117,114,
32,115,97,109,112,108,101,115,
0,0,0,0,116,101,120,116,
0,0,0,0,110,111,116,32,
99,111,112,121,114,105,103,104,
116,101,100,32,100,97,116,97,
0,0,0,0,110,99,108,50,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,3,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
/** ncl2 snipet - one colour */
struct Ncl2Farbe {
char name[32];
icUInt16Number pcsfarbe[3]; // PCS Lab or XYZ
icUInt16Number geraetefarbe[16];
};
/** ncl2 profiletag */
struct Ncl2 {
char vendor_flag[4];
icUInt32Number anzahl;
icUInt32Number koord;
char vorname[32];
char nachname[32];
Ncl2Farbe *farben;
};
/** global variables */
oyProfile_s * hl = NULL; //!< CIE*Lab profile
oyProfile_s * hp = NULL; //!< image profile
oyProfile_s * hs = NULL; //!< simulation profile
oyConversion_s * transf = NULL;//!< device link
oyPixel_t format; //!< colour layout
int farb_kanaele; //!< colour channels as in image profile
double *colour = 0; //!< measured colours : 0.0 -> 1.0 ==farb_kanaele
double *outbuf = 0; //!< colours converted to Lab
char* colour_profile = 0; //!< measurement colours profile (named colours)
char *image_profile = NULL; //!< image profile
char *proof_profile = NULL; //!< simulation profile
ICClist<double> pcsfarbe; //!< -> CIE*Lab
ICClist<double> geraetefarbe; //!< image colours
ICClist<std::string> name; //!< colour names
std::string an, //!< image profile name
bn, //!< colour profile
pn, //!< proof profile
mn; //!< monitor profile
size_t tag_size; //!< ncl2 tag size
int x_num; //!< number of measurement points in x/y
int y_num;
int l = 30; //!< raster points in one dimension
double x_diff; //!< raster distance
double y_diff;
int x_start; //!< start point of measurement raster
int y_start;
int min_x, min_y, max_x, max_y;//!< intensity Max and Min
gint32 nlayers = 0; //!< layer count
int n_points; //!< measurement point count
gint32 image_ID; //!< CinePaint image number
bool farben_sind_gleich = true;//!< test switch
int intent_alt = -12; //!< test for changed intent
int intent_alt_proof = -12; //!< test for changed proof intent
int flags_alt = -12; //!< test for bpc ...
static bool erstes_mal = true; //!< identify programm thread
static bool farbe_pruefen_laeuft = false; //!< veto switch
}
using namespace icc_examin_cp;
/*** declaration of local functions ***/
/** \addtogroup internal_plug_in_api Interne Plug-in Funktions
* @{ */
static int doExamin (gint32 image_ID, CMSProfileType typ);
static int doWatch (gint32 image_ID);
static int dialog_ (gint32 image_ID);
int holeLayerInfo( channel & layer);
void aufraeumen(channel *layer);
int setzeRaster(channel*layer);
int reserviereSpeicher(channel & layer);
const char* dateiName(const char* name);
/** @} */
/** \addtogroup colour_api Colour Information API
* @{ */
static void minMax (gint32 image_ID, int & min_x, int & min_y,
int & max_x, int & max_y );
static std::string holeFarbPunkt ( channel* layers, int & x, int & y,
unsigned char *buf, int &n,
int &colour_x);
static void getColour (channel* layers, int n,
const unsigned char* data, double *colour,
const int & x, const int & y );
/** @} */
/** \addtogroup profil_api ICC Profile API
* The terms ncl2 and named colour are considered synonym.
* @{ */
void schreibeProfil (icUInt32Number intent);
void setzeRenderingIntent (char *header, icUInt32Number intent);
size_t berechneTagGroesse (int farben_n, int farb_kanaele);
int bearbeiteEingebetteteProfile( channel *layers );
void transformAnlegen( channel & layer );
gint drawableColourLayoutToOy ( channel & layer,
oyProfile_s * p );
/** @} */
/** \addtogroup thread_api Thread API
* @{ */
void* waechter (void* zeiger);
void pthreatFehler (int fehler);
/** @} */
/** \addtogroup io_api File API
* @{ */
void schreibeDatei(const void *data, gint groesse, std::string name);
/** @} */
/*** functions ***/
/** @brief not used */
static int
dialog_ (gint32 image_ID ICC_UNUSED)
{
return true;
}
/** @brief start ICC Exmain GUI */
static void
startWithArgs( int argc, char **argv )
{
# if HAVE_PTHREAD_H
registerThreadId( pthread_self(), THREAD_HAUPT );
# ifdef CWDEBUG
Debug(myproject::debug::init_thread()); // This is a custom function defined
// in example-project/debug.cc.
# endif
# endif
if(getenv("ICCEXAMIN_DEBUG") && atoi(getenv("ICCEXAMIN_DEBUG"))>0)
icc_debug = atoi(getenv("ICCEXAMIN_DEBUG"));
else
icc_debug = 0;
DBG_PROG_START
setI18N( argv[0] );
ICCexamin hauptprogramm;
icc_examin = &hauptprogramm;
icc_examin->scheme("gtk+");
hauptprogramm.start(argc, argv);
}
/** @brief watch colour profile in ICC Examin
* needs ICC Examin
* @param image_ID CinePaint image number
* @param typ CinePaint profile typ (image/simulation)
*/
static gint32
doExamin (gint32 image_ID, CMSProfileType typ)
{
DBG_PROG_S( "image: " << image_ID )
char *mem_profile=NULL;
gint size;
if(gimp_image_has_icc_profile(image_ID, typ)) {
mem_profile = gimp_image_get_icc_profile_by_mem(image_ID, &size, typ);
} else {
g_message ("%s",_("No profil assigned to image."));
return -1;
}
DBG_PROG_S( (int*)mem_profile << " " << size )
if (size && mem_profile) {
char *ptr = gimp_image_get_filename(image_ID);
const char *dateiname = dateiName(ptr);
std::stringstream profil_temp_name;
if(getenv("TMPDIR"))
profil_temp_name << getenv("TMPDIR") << "/icc_examin_temp_" << dateiname << "_" << typ << ".icc";
else
profil_temp_name << "/tmp/icc_examin_temp_" << dateiname << "_" << typ << ".icc";
std::string tname = profil_temp_name.str();
schreibeDatei(mem_profile, size, tname.c_str());
const char *args_c[2];
args_c[0] = argv[0];
args_c[1] = tname.c_str();
startWithArgs(2, (char**)args_c);
remove( tname.c_str() );
} else
g_message ("%s",_("Profil not written."));
return image_ID;
}
/** @brief write rendering intent in profile header
* @param header of profile
* @param intent of profile
*/
void
setzeRenderingIntent (char *header, icUInt32Number intent)
{
icProfile *p = (icProfile *)header;
p->header.renderingIntent = icValue( intent );
}
/** @brief preparation for ncl2 - compute size
* @param farben_n count of colours
* @param farb_kanaele number of colour channels
*/
size_t
berechneTagGroesse (int farben_n, int farb_kanaele)
{
size_t groesse = 8 + 76 +
(38 + farb_kanaele * sizeof(icUInt16Number)) * farben_n;
return groesse;
}
/** @brief write ncl2 colours in a block
* @param pcsfarbe colours in PCS colour space
* @param geraetefarbe colours in device colour space
* @param farb_kanaele count of colour channels
* @param vorname sur name for all colours
* @param name individual colour name
* @param nachname common family name for all colours
*/
char*
schreibeNcl2Tag ( ICClist<double> pcsfarbe,
ICClist<double> geraetefarbe,
int farb_kanaele,
const char* vorname,
ICClist<std::string> name,
const char* nachname)
{
int farben_n = pcsfarbe.size() / 3;
size_t groesse = berechneTagGroesse( farben_n, farb_kanaele );
DBG_PROG_S( "farb_kanaele: " << farb_kanaele <<" farben_n: "<< farben_n )
char* tag_block = (char*) new char [groesse];
DBG_PROG_S( "tag_block: " << (int*)tag_block <<" groesse: "<< groesse )
for(size_t i = 0; i < groesse; ++i)
tag_block[i] = 0;
// 0: count of colours
// 1...n: CIE*Lab colour values
// n = 3 * FarbAnzahl
Ncl2 *ncl2 = (Ncl2*) &tag_block[8];
ncl2->anzahl = icValue((icUInt32Number)farben_n);
ncl2->koord = icValue((icUInt32Number)farb_kanaele);
if(vorname && strlen(vorname) < 32)
sprintf(ncl2->vorname, "%s",vorname);
if(nachname && strlen(nachname) < 32)
sprintf(ncl2->nachname, "%s",nachname);
DBG_PROG_S( farben_n <<" "<< pcsfarbe.size() )
for (int i = 0; i < farben_n; ++i)
{
Ncl2Farbe *f = (Ncl2Farbe*) ((char*)ncl2 + 76 + // base size of Ncl2
(i * (38 + // base size of Ncl2Farbe
farb_kanaele // number of device colours
* sizeof(icUInt16Number))));//Ncl2Farbe::geraetefarbe
f->pcsfarbe[0] = icValue((icUInt16Number)(pcsfarbe[3*i+0]*65280.0));
f->pcsfarbe[1] = icValue((icUInt16Number)(pcsfarbe[3*i+1]*65535.0));
f->pcsfarbe[2] = icValue((icUInt16Number)(pcsfarbe[3*i+2]*65535.0));
for(int j=0; j < farb_kanaele; ++j)
f->geraetefarbe[j] = icValue((icUInt16Number)
(geraetefarbe[farb_kanaele*i+j]*65535.0));
// TODO mark pointer here
if (name.size() && name[i].size() < 32)
sprintf(f->name, "%s", name[i].c_str());
#ifdef DEBUG_
if( 10 < i && i < 20 )
DBG_PLG_S( icValue(f->pcsfarbe[0]) << "," << pcsfarbe[3*i+0] <<" "<<
icValue(f->pcsfarbe[1]) << "," << pcsfarbe[3*i+1] <<" "<<
f->pcsfarbe[2] << " " << pcsfarbe[3*i+2] <<" "<<
f->geraetefarbe[0] << " " <<
f->geraetefarbe[1] << " " <<
f->geraetefarbe[2] );
#endif
}
icTag ic_tag;
ic_tag.size = icValue ((icUInt32Number)groesse);
ic_tag.offset = 0;
memcpy(&ic_tag.sig, "ncl2", 4);
char sig[] = "ncl2";
memcpy (&tag_block[0], &sig, 4);
return tag_block;
}
/** @brief create device link
* @param layer informations
*/
void
transformAnlegen( channel & layer )
{
oyOptions_s * options = 0;
char num[12];
drawableColourLayoutToOy( layer, hp );
DBG_PROG_S( transf )
oyConversion_Release ( &transf );
DBG_PROG_S( transf <<" "<< layer.intent )
sprintf(num,"%d", layer.intent);
oyOptions_SetFromString( &options, OY_DEFAULT_RENDERING_INTENT, num,
OY_CREATE_NEW );
if(layer.intent_proof == 3)
sprintf(num,"%d", 1);
else
sprintf(num,"%d", 0);
oyOptions_SetFromString( &options, OY_DEFAULT_RENDERING_INTENT_PROOF,
num, OY_CREATE_NEW );
if(layer.flags & 0x2000) /* BPC */
oyOptions_SetFromString( &options, OY_DEFAULT_RENDERING_BPC,
"1", OY_CREATE_NEW );
if(layer.flags & 0x1000) /* gamut warning */
oyOptions_SetFromString( &options, OY_DEFAULT_RENDERING_GAMUT_WARNING,
"1", OY_CREATE_NEW );
if(layer.flags & 0x4000) /* proofing */
{
oyProfiles_s * proofs = oyProfiles_New(0);
oyProfile_s * proof = oyProfile_Copy( hs, 0 );
oyOptions_SetFromString( &options, OY_DEFAULT_PROOF_SOFT,
"1", OY_CREATE_NEW );
oyProfiles_MoveIn( proofs, &proof, -1 );
oyOptions_MoveInStruct( &options,
OY_TOP_SHARED OY_SLASH OY_DOMAIN_STD OY_SLASH OY_TYPE_STD "/icc/profiles_simulation",
(oyStruct_s**) &proofs, OY_CREATE_NEW );
}
transf = oyConversion_CreateBasicPixelsFromBuffers(
hp, colour, oyDataType_m(oyDOUBLE),
hl, outbuf, oyDataType_m(oyDOUBLE),
options, n_points );
if(!transf)
WARN_S( "no conversion context created: " <<
oyOptions_GetText(options, oyNAME_NAME));
oyOptions_Release( &options );
DBG_PLUG_S( transf <<" "<< hp <<" "<< hl <<" "<< hs <<" channels: "<<
oyToChannels_m(format) << " depth "<< oyToDataType_m(format) <<" i"<<
layer.intent <<" ip"<< layer.intent_proof <<" f"<< layer.flags );
/*DBG_PLUG_S( out[0]<<" "<<out[1]<<" "<<out[2]<<" "<<
out2[0]<<" "<<out2[1]<<" "<<out2[2] )*/
}
/** @brief search for changing colours
* as there is no information about changing in image,
* the image is polled for changes, and a new ncl2 will be generated.
* @param zeiger layer stack
*/
bool
vergleicheFarben(void* zeiger)
{
farbe_pruefen_laeuft = true;
channel* layer = 0;
if(zeiger)
layer = (channel*) zeiger;
DBG_PLUG_S( "layer "<< (int*)layer )
// colour memory - static is perhaps dangerous?
static ICClist<double> vorherige_farben;
DBG_PLUG_S( "zeiger " << (int*)zeiger )
if(!layer) {
farbe_pruefen_laeuft = false;
return true;
}
pcsfarbe.clear(); // -> unchanged colours: CIE*Lab
geraetefarbe.clear(); // image colours
name.clear(); // colour names
// ask the image in raster distance
guchar buf[128]; // point cache
int colour_x = 0; // counter
int x_punkt = 0 , y_punkt = 0;
int n = 0;
layer->status = 0;
holeLayerInfo( *layer );
// save of the embeded image profile -> a
if (bearbeiteEingebetteteProfile( layer ))
return -1;
if( GET_LAYOUT(layer->status)) {
}
if( GET_GEOMETRY(layer->status)) {
setzeRaster( layer );
DBG_PROG_S("raster")
}
if( GET_GEOMETRY(layer->status) ||
GET_PROFIL(layer->status) ||
GET_CHANNELS(layer->status) ||
GET_BITDEPTH(layer->status)) {
reserviereSpeicher( *layer );
DBG_PROG_S("reserved")
}
// create device link
if( GET_TRANSFORM(layer->status) ||
GET_PROFIL(layer->status) ||
GET_CHANNELS(layer->status) ||
GET_BITDEPTH(layer->status) ) {
transformAnlegen( *layer );
}
DBG_PLUG_S( "nlayers: " << nlayers )
name.resize(x_num*y_num+2);
if(nlayers)
{
for( int x = 0; x < x_num; ++x )
for( int y = 0; y < y_num; ++y )
{
x_punkt = (int)(x_start + x*x_diff);
y_punkt = (int)(y_start + y*y_diff);
name[colour_x] = holeFarbPunkt(layer, x_punkt, y_punkt,
buf, n, colour_x);
++colour_x;
}
}
// Maximalwerte
int x = MAX(MIN(min_x, layer->sel_w + layer->sel_x1), layer->sel_x1);
int y = MAX(MIN(min_y, layer->sel_h + layer->sel_y1), layer->sel_y1);
name[colour_x] = holeFarbPunkt(layer, x, y, buf, n, colour_x);
++colour_x;
x = MAX(MIN(max_x, layer->sel_w + layer->sel_x1), layer->sel_x1);
y = MAX(MIN(max_y, layer->sel_h + layer->sel_y1), layer->sel_y1);
name[colour_x] = holeFarbPunkt(layer, x, y, buf, n, colour_x);
{
// Vergleich der vorherigen Auslese
if( GET_TRANSFORM(layer->status) ||
GET_PROFIL(layer->status) )
farben_sind_gleich = false;
else
farben_sind_gleich = true;
int gleichviele = true;
if( (int)vorherige_farben.size() != n_points*farb_kanaele )
{
gleichviele = false;
farben_sind_gleich = false;
vorherige_farben.clear();
DBG_PROG_S( "n_points: " << n_points <<
" vorherige_farben.size(): " << vorherige_farben.size() )
}
{ // aktuelle Farben merken
for(int i = 0; i < n_points*farb_kanaele; ++i)
{
//DBG_PROG_S( i << " " << n_points*farb_kanaele )
if(gleichviele)
if(colour[i] != vorherige_farben[i])
farben_sind_gleich = false;
if(i < (int)vorherige_farben.size())
vorherige_farben[i] = colour[i];
else
vorherige_farben.push_back(colour[i]);
}
}
DBG_PLUG_S( colour_x << " " << n_points )
// Wir koennen das weitere auslassen
if(farben_sind_gleich &&
!layer->status)
{
farbe_pruefen_laeuft = false;
DBG_PLUG_S("colours are equal")
return false;
} else
DBG_PLUG_S("colours are not equal");
}
# ifdef DEBUG_
DBG_PROG_S( farb_kanaele <<" "<< oyToChannels_m(format) <<" "<< oyToDataType_m(format) )
cout <<
oyToSwapColourChannels_m(format) <<" "<<
oyToFlavor_m(format) <<" "<<
oyToPlanar_m(format) <<" "<<
oyToByteswap_m(format) <<" "<<
oyToColourOffset_m(format) <<" "; DBG
# endif
oyConversion_RunPixels( transf, NULL );
// Berechnung Auswerten ...
for(int i = 0; i < n_points; ++i)
{
pcsfarbe.push_back( outbuf[3*i+0]);
pcsfarbe.push_back( outbuf[3*i+1]);
pcsfarbe.push_back( outbuf[3*i+2]);
//DBG_PROG_S( pcsfarbe[farb_kanaele*i+0] << "," << pcsfarbe[farb_kanaele*i+1] << "," << pcsfarbe[farb_kanaele*i+2] )
for(int j = 0; j < farb_kanaele; ++j)
{
geraetefarbe.push_back( colour[farb_kanaele*i+j]/100.0 );
//DBG_PROG_S( colour[farb_kanaele*i+j] )
}
}
// ... und das ncl2 Profil vervollstaendigen
memcpy(colour_profile, icc_base_data, 320);
// Profilegroesse
char zahl[4];
*((icUInt32Number*)zahl) = icValue(236 + (icUInt32Number)tag_size);
memcpy(colour_profile, zahl, 4);
// Abschnittsgroesse
*((icUInt32Number*)zahl) = icValue((icUInt32Number)tag_size);
memcpy(&colour_profile[164], zahl, 4);
// Farbraum
*((icUInt32Number*)zahl) = icValue((icUInt32Number)
oyProfile_GetSignature( hp, oySIGNATURE_COLOR_SPACE ));
memcpy(&colour_profile[16], zahl, 4);
DBG_PROG_S( (int*)image_profile << " " << tag_size )
schreibeProfil( layer->intent );
farbe_pruefen_laeuft = false;
return false;
}
#include <unistd.h>
#include <pthread.h>
/** @brief Bild beobachten
* und gleichzeitig nach ICC Examin schauen
* @param zeiger Ebenenstapel
*/
void*
waechter (void* zeiger)
{
bool bin_erste = false;
if(erstes_mal)
{
bin_erste = true;
erstes_mal = false;
}
channel* layer = 0;
if(zeiger)
layer = (channel*) zeiger;
DBG_PROG_S( (int*)layer )
int fehler = false;
DBG_PROG_S( "bin_erste: " << bin_erste )
static bool freilauf = true;
// observe image
if(bin_erste)
{
int sl = 1000000;
while(!fehler && freilauf)
{
double rz = icc_examin_ns::zeitSekunden();
if(!fehler)
fehler = vergleicheFarben( layer );
rz = icc_examin_ns::zeitSekunden() - rz;
if(farben_sind_gleich) {
sl = max(sl,500000);
usleep(sl*2);
} else {
sl = (int)(rz*1000000.0)*4;
sl = max(sl,50000);
usleep(sl);
DBG_PROG_S( "rz: " << rz*1000000 << " sl " << sl )
}
}
DBG_PROG_S( "bin_erste: " << bin_erste )
sleep(10);
DBG_PROG_S( "bin_erste: " << bin_erste )
}
// start ICC Examin
if(!bin_erste)
{
const char *args_c[5];
int argc_c = 4;
args_c[0] = argv[0];
args_c[1] = bn.c_str();
args_c[2] = an.c_str();
args_c[3] = pn.c_str();
args_c[4] = mn.c_str();
// get the main screens net color spec ICC profile as supported by CinePaint
#ifdef HAVE_X
Display * display = XOpenDisplay(NULL);;
int screen = DefaultScreen( display );
Window root = RootWindow( display, screen );
Atom atom = XInternAtom( display, "_ICC_DEVICE_PROFILE", False ),
a;
int actual_format_return;
unsigned long nitems_return=0, bytes_after_return=0;
unsigned char* prop_return=0;
XGetWindowProperty( display, root, atom, 0, INT_MAX, 0, XA_CARDINAL, &a,
&actual_format_return, &nitems_return, &bytes_after_return,
&prop_return );
if(nitems_return)
{
schreibeDatei( prop_return, nitems_return, mn.c_str() );
++argc_c;
}
#endif
startWithArgs(argc_c, (char**)args_c);
DBG_PROG_S( "bin_erste: " << bin_erste )
freilauf = false;
while(farbe_pruefen_laeuft)
{
DBG_PROG_S( "bin_erste: " << bin_erste )
icc_examin_ns::sleep( 0.1 );
DBG_PROG_S( "bin_erste: " << bin_erste )
}
freilauf = true;
DBG_PROG_S( "bin_erste: " << bin_erste )
}
if(freilauf)
{
freilauf = false;
aufraeumen( layer );
DBG_PROG_S( "bin_erste: " << bin_erste )
} else
DBG_PROG_S( "bin_erste: " << bin_erste );
return layer;
}
#ifndef EAGAIN
#define EAGAIN 11
#endif
#ifndef PTHREAD_THREADS_MAX
#define PTHREAD_THREADS_MAX 16384
#endif
/** @brief Programmzweigfehler entschlüsseln */
void
pthreatFehler (int fehler)
{
if( fehler == EAGAIN)
{
WARN_S( "observer thread not started Error: " << fehler );
} else
if( fehler == 64/*PTHREAD_THREADS_MAX -- linux*/ )
{
WARN_S( "too many observer threads Error: " << fehler );
} else
if( fehler != 0 )
{
WARN_S( "unknown error at start of observer thread: " << fehler );
}
}
/** @brief clean layers
* @param layer stack
*/
void
aufraeumen(channel *layer ICC_UNUSED)
{
{
while(farbe_pruefen_laeuft) {
DBG_PROG_S( "farbe_pruefen_laeuft " << farbe_pruefen_laeuft )
sleep(1);
}
// clean
remove(an.c_str());
remove(bn.c_str());
remove(pn.c_str());
remove(mn.c_str());
if(colour_profile) delete [] colour_profile;
if(image_profile) free( image_profile);
if(proof_profile) free (proof_profile);
image_profile = 0;
proof_profile = 0;
if(colour) delete [] colour;
if(outbuf) delete [] outbuf;
oyConversion_Release( &transf );
oyProfile_Release( &hl);
oyProfile_Release( &hp);
if(hs) oyProfile_Release( &hs);
}
}
/** @brief memory block -> file
* @param data memory block
* @param groesse size
* @param name file name
*/
void
schreibeDatei(const void *data, gint groesse, std::string name)
{
DBG_PROG_S( (int*)data <<": "<< groesse <<" "<< name )
if(data && groesse && name.size())
{
std::ofstream f;
f.clear();
f.open ( name.c_str(), std::ios::out );
if(f.good())
{
f.write ( (char*)data, groesse );
DBG_MEM_S( "Profile %s written " << name.c_str() )
}
f.close();
DBG_PROG_S("Profile written")
} else
g_print ("Profile %s not written.", name.c_str());
}
/** @brief layer layout -> lcms colour layout
* following cariables are to handle:\n
T_COLORSPACE(s) \n
T_SWAPFIRST(s) \n
T_FLAVOR(s) \n
T_PLANAR(p) \n
T_ENDIAN16(e) \n
T_DOSWAP(e) \n
T_EXTRA(e) \n
oyToChannels_m(c) \n
oyToDataType_m(b) - always 0, as we convert to float.\n
* @param layer layers
* @param p lcms colour profile
*/
gint
drawableColourLayoutToOy ( channel & layer,
oyProfile_s * p ICC_UNUSED )
{
//GDrawableType/*GimpDrawableType*/ drawable_type;
gint success = GIMP_PDB_SUCCESS;
oyDATATYPE_e data_type = oyUINT8;
format = 0;
DBG_PROG_S( farb_kanaele <<" "<< format )
switch (layer.precision) {
case 1: // uint8
data_type = oyUINT8;
break;
case 2: // uint16
data_type = oyUINT16;
break;