delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kioslave / thumbnail / exrcreator.cpp
bloba788ec3da6e2b3e643311b81b481e47c683bbf8b
1 /* This file is part of the KDE libraries
2 Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "exrcreator.h"
22 #include <QImage>
24 #include <kdebug.h>
25 #include <ksharedconfig.h>
26 #include <kglobal.h>
27 #include <QFile>
29 #include <ImfInputFile.h>
30 #include <ImfPreviewImage.h>
32 #include <kconfiggroup.h>
34 extern "C"
36 KDE_EXPORT ThumbCreator *new_creator()
38 return new EXRCreator;
42 bool EXRCreator::create(const QString &path, int, int, QImage &img)
44 Imf::InputFile in ( path.toAscii() );
45 const Imf::Header &h = in.header();
47 if ( h.hasPreviewImage() ) {
48 kDebug() << "EXRcreator - using preview";
49 const Imf::PreviewImage &preview = in.header().previewImage();
50 QImage qpreview(preview.width(), preview.height(), QImage::Format_RGB32);
51 for ( unsigned int y=0; y < preview.height(); y++ ) {
52 for ( unsigned int x=0; x < preview.width(); x++ ) {
53 const Imf::PreviewRgba &q = preview.pixels()[x+(y*preview.width())];
54 qpreview.setPixel( x, y, qRgba(q.r, q.g, q.b, q.a) );
57 img = qpreview;
58 return true;
59 } else {
60 // do it the hard way
61 // We ignore maximum size when just extracting the thumnail
62 // from the header, but it is very expensive to render large
63 // EXR images just to turn it into an icon, so we go back
64 // to honoring it in here.
65 kDebug() << "EXRcreator - using original image";
66 KSharedConfig::Ptr config = KGlobal::config();
67 KConfigGroup configGroup( config, "PreviewSettings" );
68 unsigned long long maxSize = configGroup.readEntry( "MaximumSize", 1024*1024 /* 1MB */ );
69 unsigned long long fileSize = QFile( path ).size();
70 if ( (fileSize > 0) && (fileSize < maxSize) ) {
71 if (!img.load( path )) {
72 return false;
74 if (img.depth() != 32)
75 img = img.convertToFormat( QImage::Format_RGB32 );
76 return true;
77 } else {
78 return false;
83 ThumbCreator::Flags EXRCreator::flags() const
85 return None;