summaryrefslogtreecommitdiffstats
path: root/plugins/src/imageformats/jpeg/main.cpp
blob: d2fa377de5d136e2d3c96009a34b9f2157a089fd (plain)
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
#ifndef QT_CLEAN_NAMESPACE
#define QT_CLEAN_NAMESPACE
#endif
#include <qimageformatplugin.h>

#ifndef QT_NO_IMAGEFORMATPLUGIN

#ifdef QT_NO_IMAGEIO_JPEG
#undef QT_NO_IMAGEIO_JPEG
#endif
#include "../../../../src/kernel/qjpegio.cpp"

class JPEGFormat : public QImageFormatPlugin
{
public:
    JPEGFormat();

    QStringList keys() const;
    bool loadImage( const QString &format, const QString &filename, QImage * );
    bool saveImage( const QString &format, const QString &filename, const QImage & );
    bool installIOHandler( const QString & );
};

JPEGFormat::JPEGFormat()
{
}


QStringList JPEGFormat::keys() const
{
    QStringList list;
    list << "JPEG";

    return list;
}

bool JPEGFormat::loadImage( const QString &format, const QString &filename, QImage *image )
{
    if ( format != "JPEG" )
	return FALSE;

    QImageIO io;
    io.setFileName( filename );
    io.setImage( *image );

    read_jpeg_image( &io );

    return TRUE;
}

bool JPEGFormat::saveImage( const QString &format, const QString &filename, const QImage &image )
{
    if ( format != "JPEG" )
	return FALSE;

    QImageIO io;
    io.setFileName( filename );
    io.setImage( image );

    write_jpeg_image( &io );

    return TRUE;
}

bool JPEGFormat::installIOHandler( const QString &name )
{
    if ( name.upper() != "JPEG" )
	return FALSE;

    qInitJpegIO();
    return TRUE;
}

Q_EXPORT_PLUGIN( JPEGFormat )

#endif // QT_NO_IMAGEFORMATPLUGIN