~ubuntu-branches/ubuntu/saucy/gwenview/saucy-proposed

« back to all changes in this revision

Viewing changes to lib/documentview/rasterimageview.cpp

  • Committer: Package Import Robot
  • Author(s): Michał Zając
  • Date: 2013-06-28 17:58:23 UTC
  • mfrom: (1.1.29)
  • Revision ID: package-import@ubuntu.com-20130628175823-jw1lr549kc7nz057
Tags: 4:4.10.90-0ubuntu1
New upstream bet release

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 
68
68
    QWeakPointer<AbstractRasterImageViewTool> mTool;
69
69
 
 
70
    bool mApplyDisplayTransform; // Defaults to true. Can be set to false if there is no need or no way to apply color profile
70
71
    cmsHTRANSFORM mDisplayTransform;
71
72
 
72
 
    void updateDisplayTransform()
 
73
    void updateDisplayTransform(QImage::Format format)
73
74
    {
 
75
        GV_RETURN_IF_FAIL(format != QImage::Format_Invalid);
 
76
        mApplyDisplayTransform = false;
74
77
        if (mDisplayTransform) {
75
78
            cmsDeleteTransform(mDisplayTransform);
76
79
        }
77
80
        mDisplayTransform = 0;
 
81
 
78
82
        Cms::Profile::Ptr profile = q->document()->cmsProfile();
79
83
        if (!profile) {
80
84
            return;
81
85
        }
82
86
        Cms::Profile::Ptr monitorProfile = Cms::Profile::getMonitorProfile();
83
87
        if (!monitorProfile) {
 
88
            kWarning() << "Could not get monitor color profile";
84
89
            return;
85
90
        }
86
91
 
87
92
        cmsUInt32Number cmsFormat = 0;
88
 
        switch (q->document()->image().format()) {
 
93
        switch (format) {
89
94
        case QImage::Format_RGB32:
90
95
        case QImage::Format_ARGB32:
91
96
            cmsFormat = TYPE_BGRA_8;
92
97
            break;
93
98
        default:
 
99
            kWarning() << "This image has a color profile, but Gwenview can only apply color profile on RGB32 or ARGB32 images";
94
100
            return;
95
101
        }
96
 
        // FIXME: Wrap cmsHTRANSFORM type?
97
102
        mDisplayTransform = cmsCreateTransform(profile->handle(), cmsFormat,
98
103
                                               monitorProfile->handle(), cmsFormat,
99
104
                                               INTENT_PERCEPTUAL, cmsFLAGS_BLACKPOINTCOMPENSATION);
 
105
        mApplyDisplayTransform = true;
100
106
    }
101
107
 
102
108
    void createBackgroundTexture()
185
191
{
186
192
    d->q = this;
187
193
    d->mEmittedCompleted = false;
 
194
    d->mApplyDisplayTransform = true;
188
195
    d->mDisplayTransform = 0;
189
196
 
190
197
    d->mAlphaBackgroundMode = AlphaBackgroundCheckBoard;
260
267
void RasterImageView::finishSetDocument()
261
268
{
262
269
    GV_RETURN_IF_FAIL(document()->size().isValid());
263
 
    d->updateDisplayTransform();
264
270
 
265
271
    d->mScaler->setDocument(document());
266
272
    d->resizeBuffer();
302
308
 
303
309
void RasterImageView::updateFromScaler(int zoomedImageLeft, int zoomedImageTop, const QImage& image)
304
310
{
305
 
    if (d->mDisplayTransform) {
306
 
        quint8 *bytes = const_cast<quint8*>(image.bits());
307
 
        cmsDoTransform(d->mDisplayTransform, bytes, bytes, image.width() * image.height());
 
311
    if (d->mApplyDisplayTransform) {
 
312
        if (!d->mDisplayTransform) {
 
313
            d->updateDisplayTransform(image.format());
 
314
        }
 
315
        if (d->mDisplayTransform) {
 
316
            quint8 *bytes = const_cast<quint8*>(image.bits());
 
317
            cmsDoTransform(d->mDisplayTransform, bytes, bytes, image.width() * image.height());
 
318
        }
308
319
    }
309
320
 
310
321
    d->resizeBuffer();