summaryrefslogtreecommitdiffstats
path: root/plugins/src/imageformats/png/main.cpp
blob: dcd579298a54d776707833f1210bab3392c8dcec (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_PNG
#undef QT_NO_IMAGEIO_PNG
#endif
#include "../../../../src/kernel/qpngio.cpp"

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

    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 & );
};

PNGFormat::PNGFormat()
{
}


QStringList PNGFormat::keys() const
{
    QStringList list;
    list << "PNG";

    return list;
}

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

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

    read_png_image( &io );

    return TRUE;
}

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

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

    write_png_image( &io );

    return TRUE;
}

bool PNGFormat::installIOHandler( const QString &name )
{
    if ( name != "PNG" ) 
	return FALSE;

    qInitPngIO();
    return TRUE;
}

Q_EXPORT_PLUGIN( PNGFormat )

#endif // QT_NO_IMAGEFORMATPLUGIN