File: exrcreator.cpp

package info (click to toggle)
kio-extras 4%3A18.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,364 kB
  • sloc: cpp: 25,948; ansic: 4,443; perl: 1,056; xml: 460; python: 28; sh: 20; makefile: 6
file content (84 lines) | stat: -rw-r--r-- 2,708 bytes parent folder | download | duplicates (2)
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
/*  This file is part of the KDE libraries
    Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "exrcreator.h"

#include <QImage>
#include <QDebug>
#include <QFile>

#include <ImfInputFile.h>
#include <ImfPreviewImage.h>

#include <ksharedconfig.h>
#include <kconfiggroup.h>

extern "C"
{
    Q_DECL_EXPORT ThumbCreator *new_creator()
    {
        return new EXRCreator;
    }
}

bool EXRCreator::create(const QString &path, int, int, QImage &img)
{
    Imf::InputFile in ( QFile::encodeName( path ) );
    const Imf::Header &h = in.header();

    if ( h.hasPreviewImage() ) {
	qDebug() << "EXRcreator - using preview";
	const Imf::PreviewImage &preview = in.header().previewImage();
	QImage qpreview(preview.width(), preview.height(), QImage::Format_RGB32);
	for ( unsigned int y=0; y < preview.height(); y++ ) {
	    for ( unsigned int x=0; x < preview.width(); x++ ) {
		const Imf::PreviewRgba &q = preview.pixels()[x+(y*preview.width())];
		qpreview.setPixel( x, y, qRgba(q.r, q.g, q.b, q.a) );
	    }
	}
	img = qpreview;
	return true;
    } else {
        // do it the hard way
	// We ignore maximum size when just extracting the thumnail
	// from the header, but it is very expensive to render large
	// EXR images just to turn it into an icon, so we go back
	// to honoring it in here.
	qDebug() << "EXRcreator - using original image";
	KSharedConfig::Ptr config = KSharedConfig::openConfig();
	KConfigGroup configGroup( config, "PreviewSettings" );
	unsigned long long maxSize = configGroup.readEntry( "MaximumSize", 1024*1024 /* 1MB */ );
	unsigned long long fileSize = QFile( path ).size();
	if ( (fileSize > 0) && (fileSize < maxSize) ) {
	    if (!img.load( path )) {
		return false;
	    }
	    if (img.depth() != 32)
		img = img.convertToFormat( QImage::Format_RGB32 );
	    return true;
	} else {
	    return false;
	}
    }
}

ThumbCreator::Flags EXRCreator::flags() const
{
    return None;
}