Repository navigation
Expand file tree
/
Copy pathconversionopts.cpp
More file actions
323 lines (256 loc) · 7.78 KB
/
Copy pathconversionopts.cpp
File metadata and controls
323 lines (256 loc) · 7.78 KB
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
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "debug.h"
#include "util.h"
#include "pathsupport.h"
#include "configdb.h"
#include "conversionopts.h"
#include "imagesource_promote.h"
#include "imagesource_cms.h"
#include "imagesource_deflatten.h"
#include "imagesource_mask.h"
#include "imagesource_montage.h"
#include "imagesource_flatten.h"
#include "naivetransforms.h"
using namespace std;
#define DEFAULTCMYK "coated_FOGRA39L_argl.icc"
ConfigTemplate CMYKConversionPreset::Template[]=
{
// ConfigTemplate("PresetID",PRESET_PREVIOUS_ESCAPE),
ConfigTemplate("DisplayName","unnamed preset"),
ConfigTemplate("InRGBProfile",BUILTINSRGB_ESCAPESTRING),
ConfigTemplate("InCMYKProfile",DEFAULTCMYK),
ConfigTemplate("OutProfile",DEFAULTCMYK),
ConfigTemplate("IgnoreEmbedded",int(0)),
ConfigTemplate("UseDevicelink",int(0)),
ConfigTemplate("Devicelink",""),
ConfigTemplate("Intent",int(0)),
ConfigTemplate("Mode",int(1)),
ConfigTemplate("Width",int(10)),
ConfigTemplate()
};
CMYKConversionOptions::CMYKConversionOptions(ProfileManager &pm)
: profilemanager(pm), inrgbprofile("sRGB Color Space Profile.icm"), incmykprofile(DEFAULTCMYK),
outprofile(DEFAULTCMYK), intent(LCMSWRAPPER_INTENT_DEFAULT), mode(CMYKCONVERSIONMODE_NORMAL),
ignoreembedded(false), usedevicelink(false), width(0)
{
}
CMYKConversionOptions::CMYKConversionOptions(const CMYKConversionOptions &other)
: profilemanager(other.profilemanager), inrgbprofile(other.inrgbprofile), incmykprofile(other.incmykprofile),
outprofile(other.outprofile), devicelink(other.devicelink), intent(other.intent), mode(other.mode),
ignoreembedded(other.ignoreembedded), usedevicelink(other.usedevicelink)
{
Debug[TRACE] << "*** Copy constructor sees usedevicelink flag as " << usedevicelink << std::endl;
}
CMYKConversionOptions::~CMYKConversionOptions()
{
}
CMYKConversionOptions &CMYKConversionOptions::operator=(const CMYKConversionOptions &other)
{
mode=other.mode;
intent=other.intent;
inrgbprofile=other.inrgbprofile;
incmykprofile=other.incmykprofile;
outprofile=other.outprofile;
devicelink=other.devicelink;
ignoreembedded=other.ignoreembedded;
usedevicelink=other.usedevicelink;
Debug[TRACE] << "*** Assignment operator sees usedevicelink flag as " << usedevicelink << std::endl;
return(*this);
}
LCMSWrapper_Intent CMYKConversionOptions::GetIntent()
{
return(intent);
}
CMYKConversionMode CMYKConversionOptions::GetMode()
{
return(mode);
}
bool CMYKConversionOptions::GetIgnoreEmbedded()
{
return(ignoreembedded);
}
const char *CMYKConversionOptions::GetInRGBProfile()
{
return(inrgbprofile.c_str());
}
const char *CMYKConversionOptions::GetInCMYKProfile()
{
return(incmykprofile.c_str());
}
const char *CMYKConversionOptions::GetOutProfile()
{
return(outprofile.c_str());
}
int CMYKConversionOptions::GetWidth()
{
return(width);
}
bool CMYKConversionOptions::GetUseDeviceLink()
{
Debug[TRACE] << std::endl << "Getting usedl flag : " << usedevicelink << endl;
return(usedevicelink);
}
const char *CMYKConversionOptions::GetDeviceLink()
{
Debug[TRACE] << std::endl << "Getting devicelink name " << devicelink << endl;
return(devicelink.c_str());
}
void CMYKConversionOptions::SetIntent(LCMSWrapper_Intent intent)
{
this->intent=intent;
}
void CMYKConversionOptions::SetMode(CMYKConversionMode mode)
{
this->mode=mode;
}
void CMYKConversionOptions::SetIgnoreEmbedded(bool ignore)
{
ignoreembedded=ignore;
}
void CMYKConversionOptions::SetInRGBProfile(const char *in)
{
if(in)
inrgbprofile=string(in);
}
void CMYKConversionOptions::SetInCMYKProfile(const char *in)
{
if(in)
incmykprofile=string(in);
}
void CMYKConversionOptions::SetOutProfile(const char *out)
{
if(out)
outprofile=string(out);
}
void CMYKConversionOptions::SetWidth(int w)
{
width=w;
}
void CMYKConversionOptions::SetUseDeviceLink(bool usedl)
{
Debug[TRACE] << "Setting usedl flag to " << usedl << std::endl;
usedevicelink=usedl;
}
void CMYKConversionOptions::SetDeviceLink(const char *dl)
{
if(dl)
Debug[TRACE] << "Setting dl to " << dl << std::endl;
else
Debug[WARN] << "WARNING: Setting dl but no filename!" << std::endl;
devicelink=dl;
}
//void CMYKConversionOptions::Save(const char *presetname)
//{
//}
IS_TYPE CMYKConversionOptions::GetOutputType(IS_TYPE type)
{
if(GetMode()==CMYKCONVERSIONMODE_NONE)
return(type);
// If the user's chosen no output profile we want to use a naive RGB -> CMYK conversion...
if(outprofile==NOPROFILE_ESCAPESTRING)
return(IS_TYPE_CMYK);
CMSProfile *p=profilemanager.GetProfile(outprofile.c_str());
if(p)
{
if(p->IsDeviceLink())
type=p->GetDeviceLinkOutputSpace();
else
type=p->GetColourSpace();
delete p;
}
return(type);
}
ImageSource *CMYKConversionOptions::Apply(ImageSource *src,ImageSource *mask,CMTransformFactory *factory)
{
if(mode==CMYKCONVERSIONMODE_NONE)
return(src);
bool freeinprof=false;
CMSProfile *inprof=NULL;
if(!ignoreembedded)
inprof=&*src->GetEmbeddedProfile();
if(!inprof)
{
// Promote to RGB only if there's no embedded grey profile.
// FIXME - support for default grey profile.
if(STRIP_ALPHA(src->type)==IS_TYPE_GREY)
src=new ImageSource_Promote(src,IS_TYPE_RGB);
freeinprof=true;
switch(STRIP_ALPHA(src->type))
{
case IS_TYPE_RGB:
inprof=profilemanager.GetProfile(inrgbprofile.c_str());
break;
case IS_TYPE_CMYK:
inprof=profilemanager.GetProfile(incmykprofile.c_str());
break;
default:
throw "Image type not (yet) supported";
break;
}
if(!inprof)
throw "Can't open input profile";
}
CMSProfile *outprof=NULL;
CMSProfile *dlprof=NULL;
Debug[TRACE] << "Opening profile: " << outprofile << endl;
if(outprofile!=NOPROFILE_ESCAPESTRING)
outprof=profilemanager.GetProfile(outprofile.c_str());
if(GetUseDeviceLink())
dlprof=profilemanager.GetProfile(GetDeviceLink());
if(outprof && outprof->IsDeviceLink() && !dlprof)
{
dlprof=outprof;
outprof=NULL;
}
// If we have a devicelink profile, we embed the output profile.
if(dlprof)
{
Debug[TRACE] << "Using DeviceLink profile" << endl;
if(factory)
{
Debug[TRACE] << "Getting transform from factory" << endl;
RefCountPtr<CMSTransform> trans=factory->GetTransform(dlprof,NULL,intent);
if(trans)
src=new ImageSource_Deflatten(src,trans,mode==CMYKCONVERSIONMODE_HOLDBLACK,
mode==CMYKCONVERSIONMODE_OVERPRINT,mode==CMYKCONVERSIONMODE_HOLDGREY,width);
}
else
src=new ImageSource_Deflatten(src,dlprof,NULL,mode==CMYKCONVERSIONMODE_HOLDBLACK,
mode==CMYKCONVERSIONMODE_OVERPRINT,mode==CMYKCONVERSIONMODE_HOLDGREY,width);
Debug[TRACE] << "Setting embedded output profile... (DL)" << std::endl;
src->SetEmbeddedProfile(outprof);
}
else if(outprof)
{
Debug[TRACE] << "Not using DeviceLink profile" << endl;
if(factory)
{
RefCountPtr<CMSTransform> trans=factory->GetTransform(outprof,inprof,intent);
if(trans)
src=new ImageSource_Deflatten(src,trans,mode==CMYKCONVERSIONMODE_HOLDBLACK,
mode==CMYKCONVERSIONMODE_OVERPRINT,mode==CMYKCONVERSIONMODE_HOLDGREY,width);
}
else
src=new ImageSource_Deflatten(src,inprof,outprof,mode==CMYKCONVERSIONMODE_HOLDBLACK,
mode==CMYKCONVERSIONMODE_OVERPRINT,mode==CMYKCONVERSIONMODE_HOLDGREY,width);
Debug[TRACE] << "Setting embedded output profile to " << long(outprof) << std::endl;
src->SetEmbeddedProfile(outprof);
Debug[TRACE] << "Verifying embedded output profile: " << long(&*src->GetEmbeddedProfile()) << std::endl;
}
else
{
// No output profile - use a naive conversion instead.
RefCountPtr<CMSTransform> trans;
trans=new NaiveRGBToCMYKCMSTransform(src);
src=new ImageSource_Deflatten(src,trans,mode==CMYKCONVERSIONMODE_HOLDBLACK,
mode==CMYKCONVERSIONMODE_OVERPRINT,mode==CMYKCONVERSIONMODE_HOLDGREY,width);
}
if(freeinprof)
delete inprof;
// We don't free the output profile - the ImageSource assumes ownership of it.
if(dlprof)
delete dlprof;
return(src);
}