~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to utilities/imageeditor/canvas/iccmanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
{
47
47
public:
48
48
 
49
 
    IccManagerPriv()
 
49
    IccManagerPriv() :
 
50
        profileMismatch(false),
 
51
        observer(0)
50
52
    {
51
 
        profileMismatch = false;
52
 
        observer        = 0;
53
53
    }
54
54
 
55
55
    DImg                 image;
58
58
    IccProfile           workspaceProfile;
59
59
    bool                 profileMismatch;
60
60
    ICCSettingsContainer settings;
61
 
    DImgLoaderObserver  *observer;
 
61
    DImgLoaderObserver*  observer;
62
62
};
63
63
 
64
64
IccManager::IccManager(DImg& image, const QString& filePath, const ICCSettingsContainer& settings)
65
 
            : d(new IccManagerPriv)
 
65
    : d(new IccManagerPriv)
66
66
{
67
67
    d->image = image;
68
68
    d->filePath = filePath;
69
69
    d->settings = settings;
70
70
 
71
71
    if (d->image.isNull())
 
72
    {
72
73
        return;
 
74
    }
73
75
 
74
76
    if (!d->settings.enableCM)
 
77
    {
75
78
        return;
 
79
    }
76
80
 
77
81
    d->embeddedProfile  = d->image.getIccProfile();
78
82
    d->workspaceProfile = d->settings.workspaceProfile;
91
95
    }
92
96
 
93
97
    if (!d->embeddedProfile.isNull())
 
98
    {
94
99
        d->profileMismatch = !d->embeddedProfile.isSameProfileAs(d->workspaceProfile);
 
100
    }
95
101
}
96
102
 
97
103
IccManager::~IccManager()
99
105
    delete d;
100
106
}
101
107
 
102
 
void IccManager::setObserver(DImgLoaderObserver *observer)
 
108
void IccManager::setObserver(DImgLoaderObserver* observer)
103
109
{
104
110
    d->observer = observer;
105
111
}
112
118
void IccManager::transformDefault()
113
119
{
114
120
    if (d->image.isNull())
 
121
    {
115
122
        return;
 
123
    }
116
124
 
117
125
    if (!d->settings.enableCM)
 
126
    {
118
127
        return;
 
128
    }
119
129
 
120
130
    if (isUncalibratedColor())
 
131
    {
121
132
        transform(d->settings.defaultUncalibratedBehavior);
 
133
    }
122
134
    else if (isMissingProfile())
 
135
    {
123
136
        transform(d->settings.defaultMissingProfileBehavior);
 
137
    }
124
138
    else if (isProfileMismatch())
 
139
    {
125
140
        transform(d->settings.defaultMismatchBehavior);
 
141
    }
126
142
}
127
143
 
128
144
bool IccManager::isUncalibratedColor() const
164
180
void IccManager::transform(ICCSettingsContainer::Behavior behavior, IccProfile specifiedProfile)
165
181
{
166
182
    if (d->image.isNull())
 
183
    {
167
184
        return;
 
185
    }
168
186
 
169
187
    if (!d->settings.enableCM)
 
188
    {
170
189
        return;
 
190
    }
171
191
 
172
192
    if (behavior == ICCSettingsContainer::AskUser)
173
193
    {
193
213
 
194
214
    IccTransform trans;
195
215
    getTransform(trans, behavior, specifiedProfile);
 
216
 
196
217
    if (trans.willHaveEffect())
197
218
    {
198
219
        trans.apply(d->image, d->observer);
211
232
            img.hasAttribute("uncalibratedColorAskUser"));
212
233
}
213
234
 
214
 
IccTransform IccManager::postLoadingManage(QWidget *parent)
 
235
IccTransform IccManager::postLoadingManage(QWidget* parent)
215
236
{
216
237
    if (d->image.hasAttribute("missingProfileAskUser"))
217
238
    {
218
239
        d->image.removeAttribute("missingProfileAskUser");
219
240
        DImg preview = d->image.smoothScale(240, 180, Qt::KeepAspectRatio);
220
241
        QPointer<ColorCorrectionDlg> dlg = new ColorCorrectionDlg(ColorCorrectionDlg::MissingProfile, preview,
221
 
                                                                  d->filePath, parent);
 
242
                d->filePath, parent);
222
243
        dlg->exec();
223
244
 
224
245
        IccTransform trans;
231
252
        d->image.removeAttribute("profileMismatchAskUser");
232
253
        DImg preview = d->image.smoothScale(240, 180, Qt::KeepAspectRatio);
233
254
        QPointer<ColorCorrectionDlg> dlg = new ColorCorrectionDlg(ColorCorrectionDlg::ProfileMismatch, preview,
234
 
                                                                  d->filePath, parent);
 
255
                d->filePath, parent);
235
256
        dlg->exec();
236
257
 
237
258
        IccTransform trans;
244
265
        d->image.removeAttribute("uncalibratedColorAskUser");
245
266
        DImg preview = d->image.smoothScale(240, 180, Qt::KeepAspectRatio);
246
267
        QPointer<ColorCorrectionDlg> dlg = new ColorCorrectionDlg(ColorCorrectionDlg::UncalibratedColor, preview,
247
 
                                                                  d->filePath, parent);
 
268
                d->filePath, parent);
248
269
        dlg->exec();
249
270
 
250
271
        IccTransform trans;
263
284
IccProfile IccManager::imageProfile(ICCSettingsContainer::Behavior behavior, IccProfile specifiedProfile)
264
285
{
265
286
    if (behavior & ICCSettingsContainer::UseEmbeddedProfile)
 
287
    {
266
288
        return d->embeddedProfile;
 
289
    }
267
290
    else if (behavior & ICCSettingsContainer::UseWorkspace)
 
291
    {
268
292
        return d->workspaceProfile;
 
293
    }
269
294
    else if (behavior & ICCSettingsContainer::UseSRGB)
 
295
    {
270
296
        return IccProfile::sRGB();
 
297
    }
271
298
    else if (behavior & ICCSettingsContainer::UseDefaultInputProfile)
 
299
    {
272
300
        return d->settings.defaultInputProfile;
 
301
    }
273
302
    else if (behavior & ICCSettingsContainer::UseSpecifiedProfile)
 
303
    {
274
304
        return specifiedProfile;
 
305
    }
275
306
    else if (behavior & ICCSettingsContainer::AutomaticColors)
276
307
    {
277
308
        kError() << "Let the RAW loader do automatic color conversion";
278
309
        return IccProfile();
279
310
    }
280
311
    else if (behavior & ICCSettingsContainer::DoNotInterpret)
 
312
    {
281
313
        return IccProfile();
 
314
    }
282
315
 
283
316
    kError() << "No input profile: invalid Behavior flags" << (int)behavior;
284
317
    return IccProfile();
294
327
 
295
328
    // Output
296
329
    if (behavior & ICCSettingsContainer::ConvertToWorkspace)
 
330
    {
297
331
        outputProfile = d->workspaceProfile;
 
332
    }
298
333
 
299
334
    if (inputProfile.isNull())
 
335
    {
300
336
        return;
 
337
    }
301
338
 
302
339
    // Assigning the _input_ profile, if necessary. If output profile is not null, it needs to be assigned later.
303
340
    if (inputProfile != d->embeddedProfile && !(behavior & ICCSettingsContainer::LeaveFileUntagged))
 
341
    {
304
342
        setIccProfile(inputProfile);
 
343
    }
305
344
 
306
345
    if (!outputProfile.isNull())
307
346
    {
314
353
{
315
354
    d->image.setIccProfile(profile);
316
355
    d->embeddedProfile = profile;
 
356
 
317
357
    if (!d->embeddedProfile.isNull())
 
358
    {
318
359
        d->profileMismatch = !d->embeddedProfile.isSameProfileAs(d->workspaceProfile);
 
360
    }
319
361
}
320
362
 
321
363
 
327
369
    transformForDisplay(displayProfile());
328
370
}
329
371
 
330
 
void IccManager::transformForDisplay(QWidget *widget)
 
372
void IccManager::transformForDisplay(QWidget* widget)
331
373
{
332
374
    transformForDisplay(displayProfile(widget));
333
375
}
335
377
void IccManager::transformForDisplay(const IccProfile& profile)
336
378
{
337
379
    if (d->image.isNull())
 
380
    {
338
381
        return;
 
382
    }
339
383
 
340
384
    if (!d->settings.enableCM)
 
385
    {
341
386
        return;
 
387
    }
342
388
 
343
389
    IccProfile outputProfile = profile;
 
390
 
344
391
    if (outputProfile.isNull())
 
392
    {
345
393
        outputProfile = displayProfile();
 
394
    }
346
395
 
347
396
    if (isUncalibratedColor())
348
397
    {
349
398
        // set appropriate outputColorSpace in RawLoadingSettings
350
399
        kError() << "Do not use transformForDisplay for uncalibrated data "
351
 
                         "but let the RAW loader do the conversion to sRGB";
 
400
                 "but let the RAW loader do the conversion to sRGB";
352
401
    }
353
402
 
354
403
    IccTransform trans = displayTransform(outputProfile);
 
404
 
355
405
    if (trans.willHaveEffect())
356
406
    {
357
407
        trans.apply(d->image, d->observer);
359
409
    }
360
410
}
361
411
 
362
 
IccProfile IccManager::displayProfile(QWidget *displayingWidget)
 
412
IccProfile IccManager::displayProfile(QWidget* displayingWidget)
363
413
{
364
414
    IccProfile profile = IccSettings::instance()->monitorProfile(displayingWidget);
 
415
 
365
416
    if (profile.open())
 
417
    {
366
418
        return profile;
 
419
    }
367
420
 
368
421
    return IccProfile::sRGB();
369
422
}
370
423
 
371
 
IccTransform IccManager::displayTransform(QWidget *displayingWidget)
 
424
IccTransform IccManager::displayTransform(QWidget* displayingWidget)
372
425
{
373
426
    return displayTransform(displayProfile(displayingWidget));
374
427
}
376
429
IccTransform IccManager::displayTransform(const IccProfile& displayProfile)
377
430
{
378
431
    if (d->image.isNull())
 
432
    {
379
433
        return IccTransform();
 
434
    }
380
435
 
381
436
    if (!d->settings.enableCM)
 
437
    {
382
438
        return IccTransform();
 
439
    }
383
440
 
384
441
    IccTransform trans;
385
442
    trans.setIntent(d->settings.renderingIntent);
389
446
    {
390
447
        // set appropriate outputColorSpace in RawLoadingSettings
391
448
        kError() << "Do not use transformForDisplay for uncalibrated data "
392
 
                         "but let the RAW loader do the conversion to sRGB";
 
449
                 "but let the RAW loader do the conversion to sRGB";
393
450
    }
394
451
    else if (isMissingProfile())
395
452
    {
396
453
        ICCSettingsContainer::Behavior missingProfileBehavior = d->settings.defaultMissingProfileBehavior;
 
454
 
397
455
        if (missingProfileBehavior == ICCSettingsContainer::AskUser ||
398
456
            missingProfileBehavior == ICCSettingsContainer::SafestBestAction)
 
457
        {
399
458
            missingProfileBehavior = safestBestBehavior();
 
459
        }
 
460
 
400
461
        IccProfile assumedImageProfile = imageProfile(missingProfileBehavior, IccProfile());
401
462
        IccProfile outputProfile(displayProfile);
 
463
 
402
464
        if (!assumedImageProfile.isSameProfileAs(outputProfile))
403
465
        {
404
466
            trans.setInputProfile(d->embeddedProfile);
408
470
    else
409
471
    {
410
472
        IccProfile outputProfile(displayProfile);
 
473
 
411
474
        if (!d->embeddedProfile.isSameProfileAs(outputProfile))
412
475
        {
413
476
            trans.setInputProfile(d->embeddedProfile);
418
481
    return trans;
419
482
}
420
483
 
421
 
IccTransform IccManager::displaySoftProofingTransform(const IccProfile &deviceProfile, QWidget *displayingWidget)
 
484
IccTransform IccManager::displaySoftProofingTransform(const IccProfile& deviceProfile, QWidget* displayingWidget)
422
485
{
423
486
    return displaySoftProofingTransform(deviceProfile, displayProfile(displayingWidget));
424
487
}
425
488
 
426
 
IccTransform IccManager::displaySoftProofingTransform(const IccProfile &deviceProfile, const IccProfile& displayProfile)
 
489
IccTransform IccManager::displaySoftProofingTransform(const IccProfile& deviceProfile, const IccProfile& displayProfile)
427
490
{
428
491
    IccTransform transform = displayTransform(displayProfile);
429
492
    transform.setProofProfile(deviceProfile);
438
501
void IccManager::transformToSRGB()
439
502
{
440
503
    if (d->image.isNull())
 
504
    {
441
505
        return;
 
506
    }
442
507
 
443
508
    if (!d->settings.enableCM)
 
509
    {
444
510
        return;
 
511
    }
445
512
 
446
513
    if (isUncalibratedColor())
447
514
    {
448
515
        // set appropriate outputColorSpace in RawLoadingSettings
449
516
        kError() << "Do not use transformForDisplay for uncalibrated data "
450
 
                         "but let the RAW loader do the conversion to sRGB";
 
517
                 "but let the RAW loader do the conversion to sRGB";
451
518
    }
452
519
    else if (isMissingProfile())
453
520
    {
471
538
    }
472
539
}
473
540
 
474
 
void IccManager::transformToSRGB(QImage &qimage, const IccProfile& input)
 
541
void IccManager::transformToSRGB(QImage& qimage, const IccProfile& input)
475
542
{
476
543
    if (qimage.isNull())
 
544
    {
477
545
        return;
 
546
    }
478
547
 
479
548
    if (input.isNull())
 
549
    {
480
550
        return;
 
551
    }
481
552
 
482
553
    IccProfile inputProfile(input);
483
554
    IccProfile outputProfile = IccProfile::sRGB();
492
563
    }
493
564
}
494
565
 
495
 
void IccManager::transformForDisplay(QImage &qimage, const IccProfile& displayProfile)
 
566
void IccManager::transformForDisplay(QImage& qimage, const IccProfile& displayProfile)
496
567
{
497
568
    if (qimage.isNull())
 
569
    {
498
570
        return;
 
571
    }
499
572
 
500
573
    if (displayProfile.isNull())
 
574
    {
501
575
        return;
 
576
    }
502
577
 
503
578
    IccProfile inputProfile = IccProfile::sRGB();
504
579
    IccProfile outputProfile(displayProfile);
516
591
void IccManager::transformForOutput(const IccProfile& prof)
517
592
{
518
593
    if (d->image.isNull())
 
594
    {
519
595
        return;
 
596
    }
520
597
 
521
598
    if (!d->settings.enableCM)
 
599
    {
522
600
        return;
 
601
    }
523
602
 
524
603
    IccProfile inputProfile;
525
604
    IccProfile outputProfile = prof;
528
607
    {
529
608
        // set appropriate outputColorSpace in RawLoadingSettings
530
609
        kError() << "Do not use transformForOutput for uncalibrated data "
531
 
                         "but let the RAW loader do the conversion to sRGB";
 
610
                 "but let the RAW loader do the conversion to sRGB";
532
611
    }
533
612
    else if (isMissingProfile())
534
613
    {
538
617
    else
539
618
    {
540
619
        if (!d->embeddedProfile.isSameProfileAs(outputProfile))
 
620
        {
541
621
            inputProfile = d->embeddedProfile;
 
622
        }
542
623
    }
543
624
 
544
625
    if (!inputProfile.isNull())