1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : A QImage loader for DImg framework.
9
* Copyright (C) 2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
10
* Copyright (C) 2006-2007 by Caulier Gilles <caulier dot gilles at gmail dot com>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option)
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* ============================================================ */
33
#include "dimgloaderobserver.h"
34
#include "qimageloader.h"
39
QImageLoader::QImageLoader(DImg* image)
44
bool QImageLoader::load(const QString& filePath, DImgLoaderObserver *observer)
46
// Loading is opaque to us. No support for stopping from observer,
47
// progress info are only pseudo values
48
QImage image(filePath);
51
observer->progressInfo(m_image, 0.9);
55
DDebug() << "Cannot loading \"" << filePath << "\" using DImg::QImageLoader!" << endl;
59
m_hasAlpha = image.hasAlphaBuffer();
60
QImage target = image.convertDepth(32);
62
uint w = target.width();
63
uint h = target.height();
64
uchar* data = new uchar[w*h*4];
65
uint* sptr = (uint*)target.bits();
68
for (uint i = 0 ; i < w*h ; i++)
70
dptr[0] = qBlue(*sptr);
71
dptr[1] = qGreen(*sptr);
72
dptr[2] = qRed(*sptr);
73
dptr[3] = qAlpha(*sptr);
80
observer->progressInfo(m_image, 1.0);
86
// We considering that PNG is the most representative format of an image loaded by Qt
87
imageSetAttribute("format", "PNG");
92
bool QImageLoader::save(const QString& filePath, DImgLoaderObserver *observer)
94
QVariant qualityAttr = imageGetAttribute("quality");
95
int quality = qualityAttr.isValid() ? qualityAttr.toInt() : 90;
102
QVariant formatAttr = imageGetAttribute("format");
103
QCString format = formatAttr.toCString();
105
QImage image = m_image->copyQImage();
108
observer->progressInfo(m_image, 0.1);
110
// Saving is opaque to us. No support for stopping from observer,
111
// progress info are only pseudo values
112
bool success = image.save(filePath, format.upper(), quality);
113
if (observer && success)
114
observer->progressInfo(m_image, 1.0);
116
imageSetAttribute("format", format.upper());
121
bool QImageLoader::hasAlpha() const
126
} // NameSpace Digikam