Subversion Repositories Scribus

Rev

Rev 14681 | Rev 14705 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13669 pierre 1
/*****************************************************************
2
* Copyright (C) 2009  Pierre Marchand
3
 
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
8
 
9
* This program 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
12
* GNU General Public License for more details.
13
 
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
*
17
******************************************************************/
18
 
19
 
20
#include "loadimage.h"
21
#include "previewimage.h"
22
#include "picturebrowser.h"
23
 
14681 fschmid 24
#include "fileloader.h"
25
#include "loadsaveplugin.h"
26
#include "../../plugins/formatidlist.h"
27
#include "scimagecachemanager.h"
28
 
13669 pierre 29
#include <QMetaType>
30
 
31
loadImagesThread::loadImagesThread ( PictureBrowser *parent, PreviewImagesModel *parentModel )
32
{
33
        pictureBrowser = parent;
34
        pModel = parentModel;
35
}
36
 
37
 
38
void loadImagesThread::run()
39
{
40
        loadImagesThreadInstance help;
41
 
42
        help.pictureBrowser = pictureBrowser;
43
        help.pModel = pModel;
44
 
45
//register types for slots and signals
46
        qRegisterMetaType<previewImage *> ( "previewImage*" );
47
        qRegisterMetaType<ImageInformation *> ( "ImageInformation*" );
48
        qRegisterMetaType<QImage> ( "QImage" );
49
 
14691 fschmid 50
        connect(&help, SIGNAL(imageLoaded(int, const QImage, ImageInformation*, int) ), pModel, SLOT(processLoadedImage(int, const QImage, ImageInformation*, int)), Qt::QueuedConnection);
51
        connect(&help, SIGNAL(imageLoadError(int, int, int)), pModel, SLOT(processImageLoadError(int, int, int)), Qt::QueuedConnection);
52
        connect(pictureBrowser, SIGNAL(loadImageJob(int, QString, int, int)), &help, SLOT(processLoadImageJob(int, QString, int, int)), Qt::QueuedConnection);
13669 pierre 53
 
54
        exec();
55
}
56
 
57
 
58
loadImagesThreadInstance::loadImagesThreadInstance()
59
{
60
}
61
 
62
void loadImagesThreadInstance::processLoadImageJob ( int row, QString path, int size, int tpId )
63
{
14681 fschmid 64
        ScImageCacheManager & icm = ScImageCacheManager::instance();
65
        bool cacheEnabled = icm.enabled();
66
        icm.setEnabled(false);
13669 pierre 67
        //check if list of files has changed and this job is obsolete
68
        if ( pModel->pId != tpId )
69
        {
70
                return;
71
        }
72
 
73
        if ( qAbs ( row - pictureBrowser->currentRow ) > 2* ( pictureBrowser->previewIconsVisible ) )
74
        {
75
                emit imageLoadError ( row, tpId, 0 );
76
                return;
77
        }
78
 
14681 fschmid 79
        QFileInfo fi = QFileInfo(path);
80
        QString ext = fi.suffix().toLower();
81
        QStringList allFormatsV = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
82
        if (allFormatsV.contains(ext.toUtf8()))
83
        {
84
                FileLoader *fileLoader = new FileLoader(path);
85
                int testResult = fileLoader->TestFile();
86
                delete fileLoader;
87
                if ((testResult != -1) && (testResult >= FORMATID_ODGIMPORT))
88
                {
89
                        const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
90
                        if( fmt )
91
                        {
92
                                QImage im = fmt->readThumbnail(path);
93
                                if (!im.isNull())
94
                                {
95
                                        ImageInformation *imgInfo = new ImageInformation;
96
                                        ( *imgInfo ).width = im.text("XSize").toDouble();
97
                                        ( *imgInfo ).height = im.text("YSize").toDouble();
98
                                        ( *imgInfo ).type = 6;
99
                                        ( *imgInfo ).colorspace = 0;
100
                                        ( *imgInfo ).xdpi = 72;
101
                                        ( *imgInfo ).ydpi = 72;
102
                                        ( *imgInfo ).layers = 0;
103
                                        ( *imgInfo ).embedded = false;
104
                                        ( *imgInfo ).profileName = "";
105
                                        ( *imgInfo ).valid = true;
106
 
107
                                        if ( ( im.width() > ( size-2 ) ) || ( im.height() > ( size-2 ) ) )
108
                                        {
109
                                                emit imageLoaded ( row, im.scaled ( ( size-2 ), ( size-2 ), Qt::KeepAspectRatio, Qt::SmoothTransformation ), imgInfo, tpId );
110
                                        }
111
                                        //image is <= our icon -> put it in as it is
112
                                        else
113
                                        {
114
                                                emit imageLoaded ( row, im.copy(), imgInfo, tpId );
115
                                        }
116
                                }
117
                        }
118
                }
119
                icm.setEnabled(cacheEnabled);
120
                return;
121
        }
122
 
13669 pierre 123
        ScImage image;
124
//no realCMYK
125
        bool mode=false;
126
//no document needs to be assigned to this
14170 jghali 127
        CMSettings cms ( 0, "", Intent_Perceptual);
14467 jghali 128
        cms.allowColorManagement(false);
129
        cms.setUseEmbeddedProfile(true);
13669 pierre 130
 
131
        ImageInformation *imgInfo = new ImageInformation;
132
 
133
        //load previewimage
14467 jghali 134
        if ( image.loadPicture ( path, 1, cms, ScImage::Thumbnail, 72, &mode ) )
13669 pierre 135
        {
136
                int ix,iy;
137
                if ( ( image.imgInfo.exifDataValid ) && ( !image.imgInfo.exifInfo.thumbnail.isNull() ) )
138
                {
139
                        ix = image.imgInfo.exifInfo.width;
140
                        iy = image.imgInfo.exifInfo.height;
141
                }
142
                else
143
                {
144
                        ix = image.width();
145
                        iy = image.height();
146
                }
147
                ( *imgInfo ).width = ix;
148
                ( *imgInfo ).height = iy;
149
                ( *imgInfo ).type = image.imgInfo.type;
150
                ( *imgInfo ).colorspace = image.imgInfo.colorspace;
151
                ( *imgInfo ).xdpi = qRound ( image.imgInfo.xres );
152
                ( *imgInfo ).ydpi = qRound ( image.imgInfo.yres );
153
                ( *imgInfo ).layers = image.imgInfo.layerInfo.size();
154
                ( *imgInfo ).embedded = image.imgInfo.isEmbedded;
155
                ( *imgInfo ).profileName = image.imgInfo.profileName;
156
                ( *imgInfo ).valid = true;
157
 
158
                //image is bigger than our icon -> resize
159
                if ( ( image.width() > ( size-2 ) ) || ( image.height() > ( size-2 ) ) )
160
                {
161
                        emit imageLoaded ( row, image.scaled ( ( size-2 ), ( size-2 ), Qt::KeepAspectRatio, Qt::SmoothTransformation ), imgInfo, tpId );
162
                }
163
                //image is <= our icon -> put it in as it is
164
                else
165
                {
166
                        emit imageLoaded ( row, image.qImage().copy(), imgInfo, tpId );
167
                }
168
        }
169
        else
170
        {
171
                //emit some errorsignal here
172
                ( *imgInfo ).valid = false;
173
                emit imageLoaded ( row, QImage(), imgInfo, tpId );
174
        }
14681 fschmid 175
        icm.setEnabled(cacheEnabled);
13669 pierre 176
}
177