2
* psipng.cpp - QImageFormat for loading Psi PNG animations
3
* Copyright (C) 2003 Michail Pishchagin
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#include <qasyncimageio.h>
26
class PsiPNGFormat : public QImageFormat {
36
static const int framePeriod;
47
int decode(QImage &img, QImageConsumer *consumer, const uchar *buffer, int length)
52
if ( image.isNull() ) { // cache our image for speedup
53
if ( image.loadFromData( buffer, length ) ) {
58
frameBytes = length / numFrames;
59
frameW = w / numFrames;
62
consumer->setLooping( numFrames > 1 ? 0 : 1 );
63
consumer->setFramePeriod(framePeriod);
64
consumer->setSize(frameW, h);
70
if ( !image.isNull() )
71
qWarning("PsiPNGFormat::decode: WARNING: QImage is not loaded and is NOT null!!!");
76
if ( frame < numFrames ) {
77
img = image.copy(frame++ * frameW, 0, frameW, h);
78
consumer->frameDone(QPoint(0, 0), QRect(0, 0, frameW, h));
80
if ( frame >= numFrames ) {
82
frameBytes = maxLen - curLen;
85
consumer->setFramePeriod(framePeriod);
93
const int PsiPNGFormat::framePeriod = 120;
95
class PsiPNGFormatType : public QImageFormatType
97
QImageFormat *decoderFor(const uchar *buffer, int length)
110
return new PsiPNGFormat;
115
const char *formatName() const
121
PsiPNGFormatType *globalPsiPngFormatTypeObject = 0;
123
void cleanupPsiPngIO()
125
if ( globalPsiPngFormatTypeObject ) {
126
delete globalPsiPngFormatTypeObject;
127
globalPsiPngFormatTypeObject = 0;
132
Call this function to register PsiPNG animation format.
134
In this format, all animation frames are stored in one .png file.
135
<tt>Frame width = Frame height</tt>, and
136
<tt>total .png width = tatal .png height * numFrames</tt>.
140
static bool done = FALSE;
143
globalPsiPngFormatTypeObject = new PsiPNGFormatType;
144
qAddPostRoutine( cleanupPsiPngIO );