-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc_fenster.cpp
448 lines (379 loc) · 11.6 KB
/
icc_fenster.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
/*
* ICC Examin ist eine ICC Profil Betrachter
*
* Copyright (C) 2004-2016 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.
*
* -----------------------------------------------------------------------------
*
* file selection
*
*/
//#include "icc_utils.h"
//#include "icc_kette.h"
#include "icc_betrachter.h"
#include "icc_examin.h"
#include "icc_gl.h"
#include "icc_dateiwahl.h"
#include "icc_fenster.h"
#include "icc_helfer_fltk.h"
#include <string>
#include <FL/Fl.H>
#if HAVE_X && !defined(__APPLE__)
#include <FL/x.H>
#include <X11/Xutil.h>
#endif
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Return_Button.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Scroll.H>
#include <FL/Enumerations.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_Shared_Image.H>
namespace icc_examin_ns {
#ifdef HAVE_FLTK
MyFl_File_Chooser *dateiwahl_ = 0;
Fl_Image* iccImageCheck( const char* fname, uchar *header ICC_UNUSED, int len ICC_UNUSED )
{
const char *home; // Home directory
char preview[1024], // Preview filename
command[2048]; // Command
int stat;
const char *endung = strrchr(fname,'.');
if( !endung ) return NULL;
ICCprofile::ICCDataType file_type = guessFileType( fname );
if(profile.size())
file_type = guessFileType( profile.profil()->filename() );
if(strcmp(endung+1,"jpg") == 0) return NULL;
home = getenv("HOME");
sprintf(preview, "%s/.preview.ppm", home ? home : "");
remove(preview);
if (file_type == ICCprofile::ICCimageDATA)
{
oyProfile_s * p;
if(dateiwahl_)
{
icc_examin_ns::MyFl_Double_Window *w = dateiwahl()->window;
p = icc_oyranos.oyMoni(w->x()+w->w()/2, w->y()+w->h()/2, 0);
} else
p = icc_oyranos.oyMoni(0,0,0);
oyImage_s * image = NULL;
oyImage_FromFile(fname, icc_oyranos.icc_profile_flags, &image, NULL);
oyConversion_s * cc = oyConversion_CreateFromImage (
image, 0,
p, oyUINT8, oyOPTIONATTRIBUTE_ADVANCED, 0 );
oyConversion_RunPixels( cc, 0 );
oyImage_Release( &image );
image = oyConversion_GetImage( cc, OY_OUTPUT );
oyImage_WritePPM( image, preview, fname );
WARN_S("wrote file:" << fname <<" to "<<preview);
return new Fl_PNM_Image( preview );
} else if(file_type == ICCprofile::ICCprofileDATA)
{
std::string t = "oyranos-profile-graph -w 512 -b";
if(!icc_examin->icc_betrachter->DD_farbraum->spectral_line)
t += " -n";
t += " -o ";
t += preview;
if(profile.size())
{
for(int i = 0; i < profile.size(); ++i)
{
t += " '";
t += profile.name(i);
t += "'";
}
} else
{
t += " '";
t += fname;
t += "'";
}
DBG_NUM_V( t.c_str() )
stat = system (t.c_str());
return new Fl_PNG_Image( preview );
} else
{
sprintf (command, "dcraw -i '%s'\n", fname);
DBG_NUM_V( command )
stat = system (command);
if(stat) {
if (file_type != ICCprofile::ICCimageDATA && stat) {
if (stat > 0x200)
WARN_S (_("The \"rawphoto\" plugin won't work because "
"there is no \"dcraw\" executable in your path."));
}
return NULL;
}
sprintf(command,
"dcraw -e -v -c"
" \'%s\' > \'%s\' ", fname, preview);
if (system(command)) return NULL;
}
return new Fl_JPEG_Image( preview );
}
MyFl_File_Chooser * dateiwahl()
{
if(!dateiwahl_)
{
my_fl_translate_file_chooser();
const char* ptr = NULL;
if (profile.size())
ptr = profile.name().c_str();
dateiwahl_ = new MyFl_File_Chooser(ptr, _("All Formats (*.{ICC,ICM,txt,it8,IT8,RGB,CMYK,ti*,cgats,CIE,cie,nCIE,oRPT,DLY,LAB,Q60,wrl,vrml,wrl.gz,vrml.gz,png,ppm,pnm,pgm,pfm}) ICC colour profiles (*.{I,i}{C,c}{M,m,C,c}) Measurement (*.{txt,it8,IT8,RGB,CMYK,ti*,cgats,CIE,cie,nCIE,oRPT,DLY,LAB,Q60}) Argyll Gamuts (*.{wrl,vrml,wrl.gz,vrml.gz} Images (*.png,ppm,pnm,pgm,pfm)"), MyFl_File_Chooser::MULTI, _("Which ICC profile?"));
dateiwahl_->callback(dateiwahl_cb);
dateiwahl_->preview(true);
icc_examin_ns::MyFl_Double_Window *w = dateiwahl_->window;
w->use_escape_hide = true;
}
return dateiwahl_;
}
void
dateiwahl_cb (MyFl_File_Chooser *f, void *data, int finish ICC_UNUSED)
{ DBG_PROG_START
const char *filename;
MyFl_File_Chooser* fl = (MyFl_File_Chooser*)f;
DBG_NUM_V( data )
filename = fl->value();
static ICCThreadList<std::string> file_vect;
file_vect.frei(false);
if (filename && fl->count() && dateiwahl()->preview()) {
ICClist<std::string> profilnamen;
profilnamen.resize(fl->count());
for (int i = 0; i < fl->count(); i++) {
if(strchr(fl->value(i), '/') == 0) {
profilnamen[i] = fl->directory();
profilnamen[i].append("/");
profilnamen[i].append(fl->value(i));
} else
profilnamen[i] = fl->value(i);
DBG_PROG_V( i <<":"<< profilnamen[i] )
}
// add new files
int file_in_list;
for(int i = 0; i < (int)profilnamen.size(); ++i)
{
file_in_list = 0;
for( int j = 0; j < (int)file_vect.size(); ++j )
if(profilnamen[i] == file_vect[j])
{
file_in_list = 1;
break;
}
if(!file_in_list)
file_vect.push_back( profilnamen[i] );
}
// remove unseen files
int run = 1;
while(run)
{
run = 0;
for(int i = 0; i < (int)file_vect.size(); ++i)
{
file_in_list = 0;
for(int j = 0; j < (int)profilnamen.size(); ++j)
if(profilnamen[j] == file_vect[i])
{
file_in_list = 1;
break;
}
if(!file_in_list)
{
file_vect.erase( &file_vect[i] );
run = 1;
break;
}
}
}
if(profilnamen.size() != file_vect.size())
WARN_S("Something went wrong here.");
DBG_PROG_V( file_vect.size() << filename )
icc_examin->oeffnen( file_vect );
}
file_vect.frei(true);
DBG_PROG_ENDE
}
MyFl_Double_Window* nachricht_ (std::string text);
MyFl_Double_Window* log_ (std::string text, int code);
#if 1
MyFl_Double_Window*
nachricht (std::string text) {
// for Fl_Scroll no vtable created:
// icc_fenster.cpp:162: undefined reference to `icc_examin_ns::Fl_Scroll::Fl_Scroll[in-charge](int, int, int, int, char const*)'
// Now the funtion is outside of icc_examin_ns::
return nachricht_(text);
}
struct log_cb_struct {
std::string text;
int code;
};
void log_cb(void * data)
{
struct log_cb_struct * a = (struct log_cb_struct *)data;
log_(a->text, a->code);
delete a;
}
iccThreadMutex_m icc_log_mutex_;
MyFl_Double_Window*
log (std::string text, int code)
{
/* let FLTK call the main thread */
struct log_cb_struct * a = new struct log_cb_struct;
a->text = text;
a->code = code;
#if ((FL_MAJOR_VERSION * 10000 + FL_MINOR_VERSION * 100 + FL_PATCH_VERSION) > 10108)
Fl::awake( log_cb, a );
#else
Fl::awake( );
#endif
return 0;
}
void log_show(void)
{
if(!log_window)
log_("", 0);
log_window->show();
}
#else
MyFl_Double_Window*
nachricht(std::string text)
{ DBG_PROG_START
fl_message_icon()->resize(1,1,1,1);
fl_message_icon()->hide();
DBG_PROG
fl_message(text.c_str());
DBG_PROG_ENDE
}
#endif
#endif
static void cb_Gut(Fl_Return_Button*, void* v) {
((MyFl_Double_Window*)v)->hide();
}
static Fl_Text_Display *display_info=(Fl_Text_Display*)0;
static Fl_Text_Display *display_log=(Fl_Text_Display*)0;
static Fl_Text_Buffer *buffer_log=(Fl_Text_Buffer*)0;
MyFl_Double_Window *log_window=(MyFl_Double_Window*)0;
int log_window_poped = 0;
static ICCThreadList<int> icc_log_lock_;
int iccCLIMessage( const char * text, int code ICC_UNUSED )
{
cout << text << endl;
return 0;
}
MyFl_Double_Window*
log_ (std::string text, int code)
{
int log_window_new = 0;
int dbg_id = wandelThreadId ( iccThreadSelf() );
/* do not go over expensive log window in case we want explicitely debug */
if(icc_debug ||
(dbg_id != THREAD_HAUPT &&!log_window))
iccCLIMessage( text.c_str(), code );
/* avoid to create a FLTK window from outside the main thread */
if(dbg_id != THREAD_HAUPT && !log_window)
return 0;
icc_log_lock_.frei(false);
if(icc_examin && icc_examin->laeuft() && !log_window)
{
MyFl_Double_Window* w = log_window = new MyFl_Double_Window(SCALE(600), SCALE(226), _("Log:"));
w->hotspot(w);
{ Fl_Return_Button* o = new Fl_Return_Button(SCALE(220), SCALE(195), SCALE(160), SCALE(25), _("Yes"));
o->shortcut(0xff0d);
o->callback((Fl_Callback*)cb_Gut, (void*)(w));
o->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
w->hotspot(o);
}
{ Fl_Text_Display* o = display_log = new Fl_Text_Display(0, 0, SCALE(600), SCALE(190));
//o->type(12);
//o->color((Fl_Color)53);
o->textfont( FL_COURIER );
o->box( FL_FLAT_BOX );
o->color(FL_BACKGROUND_COLOR);
Fl_Group::current()->resizable(o);
}
//w->show();
w->end();
w->use_escape_hide = true;
log_window_new = 1;
}
if(!buffer_log)
buffer_log = new Fl_Text_Buffer(0);
if(display_log && buffer_log && !display_log->buffer())
display_log->buffer(buffer_log);
if(buffer_log)
{
int l = buffer_log->length();
int ip = -1;
if(display_log)
ip = display_log->insert_position();
buffer_log->append( text.c_str() );
if((display_log && l == ip) || log_window_new)
{
ip = buffer_log->length();
display_log->insert_position( ip );
display_log->show_insert_position();
}
if(code == ICC_MSG_ERROR &&
log_window &&
icc_examin &&
icc_examin->icc_betrachter &&
!log_window_poped)
{
log_window_poped = 1;
while(!icc_examin->frei())
icc_examin_ns::sleep(0.01);
log_window->show();
}
}
icc_log_lock_.frei(true);
return log_window;
}
MyFl_Double_Window*
nachricht_ (std::string text) {
MyFl_Double_Window* w;
{ MyFl_Double_Window* o = new MyFl_Double_Window(SCALE(275), SCALE(326), _("Information:"));
w = o;
w->hotspot(o);
{ Fl_Return_Button* o = new Fl_Return_Button(SCALE(60), SCALE(295), SCALE(160), SCALE(25), _("Yes"));
o->shortcut(0xff0d);
o->callback((Fl_Callback*)cb_Gut, (void*)(w));
o->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
w->hotspot(o);
}
{ Fl_Text_Display* o = display_info = new Fl_Text_Display(0, 0, SCALE(275), SCALE(290));
//o->type(12);
//o->color((Fl_Color)53);
Fl_Text_Buffer * buffer = new Fl_Text_Buffer(0);
buffer->append( text.c_str() );
o->buffer( buffer );
o->textfont( FL_COURIER );
o->box( FL_FLAT_BOX );
o->color(FL_BACKGROUND_COLOR);
Fl_Group::current()->resizable(o);
}
o->show();
o->end();
o->use_escape_hide = true;
}
//output_info->value(text.c_str());
return w;
}
}