~ubuntu-branches/ubuntu/edgy/digikam/edgy-proposed

« back to all changes in this revision

Viewing changes to digikam/utilities/imageeditor/imlibinterface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Achim Bohnet
  • Date: 2006-05-15 01:15:02 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515011502-kpyuz7766hpbuia8
Tags: 0.8.2~rc1-0ubuntu1
* sync with debian (UVF see #44102)
  0.8.2~rc1-0ubuntu1 is identical to debian's 0.8.1+0.8.2-rc1-1.
  Version was changed due to latest 0.8.1.ubuntu-0ubuntu1 upload.
  This version is unfortunately bigger than debian's 0.8.1+0.8.2-rc1-1
* Merge in ubuntu changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
// KDE includes.
50
50
 
 
51
#include <kfilemetainfo.h>
51
52
#include <kdebug.h>
52
53
#include <kprocess.h>
53
54
#include <libkexif/kexifdata.h>
63
64
#include "undomanager.h"
64
65
#include "undoaction.h"
65
66
#include "imlibinterface.h"
 
67
#include "dcrawbinary.h"
66
68
 
67
69
namespace Digikam
68
70
{
69
71
 
70
72
#define MaxRGB 255L
71
73
 
72
 
class ImlibInterfacePrivate {
 
74
class ImlibInterfacePrivate
 
75
{
73
76
 
74
77
public:
75
78
 
170
173
 
171
174
int ImlibInterface::fileFormat(const QString& filePath)
172
175
{
 
176
    if ( filePath == QString::null )
 
177
        return NONE_IMAGE;
 
178
 
 
179
    // In first we trying to check the file extension. This is mandatory because
 
180
    // some tiff files are detected like RAW files by dcraw::parse method.
 
181
 
 
182
    QFileInfo fileInfo(filePath);
 
183
    if (!fileInfo.exists())
 
184
    {
 
185
        kdDebug() << k_funcinfo << "Failed to open file" << endl;
 
186
        return NONE_IMAGE;
 
187
    }
 
188
    
 
189
    QString ext = fileInfo.extension().upper();
 
190
 
 
191
    if (ext == QString("JPEG") || ext == QString("JPG"))
 
192
        return JPEG_IMAGE;
 
193
    else if (ext == QString("PNG"))
 
194
        return PNG_IMAGE;
 
195
    else if (ext == QString("TIFF") || ext == QString("TIF"))
 
196
        return TIFF_IMAGE;
 
197
 
 
198
    // In second, we trying to parse file header.
 
199
        
173
200
    FILE* f = fopen(QFile::encodeName(filePath), "rb");
 
201
    
174
202
    if (!f)
175
203
    {
176
204
        kdWarning() << "Failed to open file" << endl;
189
217
 
190
218
    fclose(f);
191
219
    
192
 
    DcrawParse     rawFileParser;
193
 
    unsigned short jpegID    = 0xD8FF;
194
 
    unsigned short tiffBigID = 0x4d4d;
195
 
    unsigned short tiffLilID = 0x4949;
196
 
    unsigned char  pngID[8]  = {'\211', 'P', 'N', 'G', '\r', '\n', '\032', '\n'};
197
 
    
 
220
    DcrawParse rawFileParser;
 
221
    uchar jpegID[2]    = { 0xFF, 0xD8 };   
 
222
    uchar tiffBigID[2] = { 0x4D, 0x4D };
 
223
    uchar tiffLilID[2] = { 0x49, 0x49 };
 
224
    uchar pngID[8]     = {'\211', 'P', 'N', 'G', '\r', '\n', '\032', '\n'};
 
225
 
198
226
    if (memcmp(&header, &jpegID, 2) == 0)            // JPEG file ?
199
227
    {
200
228
        return JPEG_IMAGE;
215
243
    {
216
244
        return TIFF_IMAGE;
217
245
    }
 
246
    
 
247
    // In others cases, QImage will be used to try to open file.
 
248
    return QIMAGE_IMAGE;
218
249
 
219
 
    // In others cases, QImage will be used to open file.
220
 
    return QIMAGE_IMAGE;      
221
250
}
222
251
 
223
252
bool ImlibInterface::load(const QString& filename, bool *isReadOnly)
265
294
        }    
266
295
        
267
296
        case JPEG_IMAGE:
268
 
        case TIFF_IMAGE:
269
297
        case PNG_IMAGE:
270
298
        {
271
299
            // Try to load image using imlib2.
293
321
            // -2 : 8bit ppm output
294
322
            // -w : Use camera white balance, if possible  
295
323
            // -a : Use automatic white balance
296
 
            command  = "dcraw -c -2 -w -a -q 0 ";
 
324
            command  = DcrawBinary::instance()->path();
 
325
            command += " -c -2 -w -a -q 0 ";
297
326
            command += QFile::encodeName( KProcess::quote( filename ) );
298
327
            kdWarning() << "Running dcraw command : " << command << endl;
299
328
        
1171
1200
    // file saved. now preserve the permissions
1172
1201
    if (d->filePermissions != 0)
1173
1202
    {
1174
 
        ::chmod(QFile::encodeName(saveFile), d->filePermissions);
 
1203
        // Add the user write permission.
 
1204
        // There is a problem with lost Exif info on read only files,
 
1205
        // and there won't be sophisticated handling for this in the 0.8 branch any more.
 
1206
        ::chmod(QFile::encodeName(saveFile), d->filePermissions | S_IWRITE);
1175
1207
    }
1176
1208
 
1177
1209
    return true;