Qt 4.8
Public Functions | Public Variables | List of all members
QMngHandlerPrivate Class Reference

Public Functions

QColor backgroundColor () const
 
int currentImageNumber () const
 
bool getNextImage (QImage *result)
 
int imageCount () const
 
bool jumpToImage (int imageNumber)
 
bool jumpToNextImage ()
 
int nextImageDelay () const
 
mng_bool processHeader (mng_uint32 iWidth, mng_uint32 iHeight)
 
 QMngHandlerPrivate (QMngHandler *q_ptr)
 
mng_bool readData (mng_ptr pBuf, mng_uint32 iSize, mng_uint32p pRead)
 
bool setBackgroundColor (const QColor &color)
 
mng_bool writeData (mng_ptr pBuf, mng_uint32 iSize, mng_uint32p pWritten)
 
bool writeImage (const QImage &image)
 
 ~QMngHandlerPrivate ()
 

Public Variables

int elapsed
 
int frameCount
 
int frameIndex
 
bool haveReadAll
 
bool haveReadNone
 
mng_handle hMNG
 
QImage image
 
mng_uint32 iStyle
 
int iterCount
 
int nextDelay
 
int nextIndex
 
QMngHandlerq_ptr
 

Detailed Description

Definition at line 53 of file qmnghandler.cpp.

Constructors and Destructors

◆ QMngHandlerPrivate()

QMngHandlerPrivate::QMngHandlerPrivate ( QMngHandler q_ptr)

Definition at line 210 of file qmnghandler.cpp.

211  : haveReadNone(true), haveReadAll(false), elapsed(0), nextDelay(0), iterCount(1),
212  frameIndex(-1), nextIndex(0), frameCount(0), q_ptr(q_ptr)
213 {
214  iStyle = (QSysInfo::ByteOrder == QSysInfo::LittleEndian) ? MNG_CANVAS_BGRA8 : MNG_CANVAS_ARGB8;
215  // Initialize libmng
216  hMNG = mng_initialize((mng_ptr)this, myalloc, myfree, mytrace);
217  if (hMNG) {
218  // Set callback functions
219  mng_setcb_errorproc(hMNG, myerror);
220  mng_setcb_openstream(hMNG, myopenstream);
221  mng_setcb_closestream(hMNG, myclosestream);
222  mng_setcb_readdata(hMNG, myreaddata);
223  mng_setcb_writedata(hMNG, mywritedata);
224  mng_setcb_processheader(hMNG, myprocessheader);
225  mng_setcb_getcanvasline(hMNG, mygetcanvasline);
226  mng_setcb_refresh(hMNG, myrefresh);
227  mng_setcb_gettickcount(hMNG, mygettickcount);
228  mng_setcb_settimer(hMNG, mysettimer);
229  mng_setcb_processterm(hMNG, myprocessterm);
230  mng_set_doprogressive(hMNG, MNG_FALSE);
231  mng_set_suspensionmode(hMNG, MNG_TRUE);
232  }
233 }
static mng_ptr myalloc(mng_size_t iSize)
static mng_bool myopenstream(mng_handle)
static mng_bool myrefresh(mng_handle, mng_uint32, mng_uint32, mng_uint32, mng_uint32)
static mng_bool mywritedata(mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize, mng_uint32p pWritten)
static mng_uint32 mygettickcount(mng_handle hMNG)
static mng_ptr mygetcanvasline(mng_handle hMNG, mng_uint32 iLinenr)
static mng_bool myclosestream(mng_handle hMNG)
static mng_bool myreaddata(mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize, mng_uint32p pRead)
static mng_bool myerror(mng_handle, mng_int32 iErrorcode, mng_int8, mng_chunkid iChunkname, mng_uint32, mng_int32 iExtra1, mng_int32 iExtra2, mng_pchar zErrortext)
Definition: qmnghandler.cpp:85
static mng_bool mytrace(mng_handle, mng_int32 iFuncnr, mng_int32 iFuncseq, mng_pchar zFuncname)
static mng_bool mysettimer(mng_handle hMNG, mng_uint32 iMsecs)
QMngHandler * q_ptr
Definition: qmnghandler.cpp:82
static mng_bool myprocessheader(mng_handle hMNG, mng_uint32 iWidth, mng_uint32 iHeight)
static mng_bool myprocessterm(mng_handle hMNG, mng_uint8 iTermaction, mng_uint8, mng_uint32, mng_uint32 iItermax)
static void myfree(mng_ptr pPtr, mng_size_t)

◆ ~QMngHandlerPrivate()

QMngHandlerPrivate::~QMngHandlerPrivate ( )

Definition at line 235 of file qmnghandler.cpp.

236 {
237  mng_cleanup(&hMNG);
238 }

Functions

◆ backgroundColor()

QColor QMngHandlerPrivate::backgroundColor ( ) const

Definition at line 368 of file qmnghandler.cpp.

369 {
370  mng_uint16 iRed;
371  mng_uint16 iBlue;
372  mng_uint16 iGreen;
373  if (mng_get_bgcolor(hMNG, &iRed, &iBlue, &iGreen) == MNG_NOERROR)
374  return QColor((iRed >> 8) & 0xFF, (iGreen >> 8) & 0xFF, (iBlue >> 8) & 0xFF);
375  return QColor();
376 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67

◆ currentImageNumber()

int QMngHandlerPrivate::currentImageNumber ( ) const

Definition at line 317 of file qmnghandler.cpp.

Referenced by jumpToNextImage().

318 {
319 // return mng_get_currentframe(hMNG) % imageCount(); not implemented, apparently
320  return frameIndex;
321 }

◆ getNextImage()

bool QMngHandlerPrivate::getNextImage ( QImage result)

Definition at line 263 of file qmnghandler.cpp.

264 {
265  mng_retcode ret;
266  const bool savedHaveReadAll = haveReadAll;
267  if (haveReadNone) {
268  haveReadNone = false;
269  ret = mng_readdisplay(hMNG);
270  } else {
271  ret = mng_display_resume(hMNG);
272  }
273  if ((MNG_NOERROR == ret) || (MNG_NEEDTIMERWAIT == ret)) {
274  *result = image;
275 
276  // QTBUG-28894 -- libmng produces an extra frame at the end
277  // of the animation on the first loop only.
278  if (nextDelay == 1 && (!savedHaveReadAll && haveReadAll)) {
279  ret = mng_display_resume(hMNG);
280  }
281 
282  frameIndex = nextIndex++;
283  if (haveReadAll && (frameCount == 0))
285  return true;
286  }
287  return false;
288 }

◆ imageCount()

int QMngHandlerPrivate::imageCount ( ) const

Definition at line 323 of file qmnghandler.cpp.

Referenced by jumpToNextImage().

324 {
325 // return mng_get_totalframes(hMNG); not implemented, apparently
326  if (haveReadAll)
327  return frameCount;
328  return 0; // Don't know
329 }

◆ jumpToImage()

bool QMngHandlerPrivate::jumpToImage ( int  imageNumber)

Definition at line 331 of file qmnghandler.cpp.

Referenced by jumpToNextImage().

332 {
333  if (imageNumber == nextIndex)
334  return true;
335 
336  if ((imageNumber == 0) && haveReadAll && (nextIndex == frameCount)) {
337  // Loop!
338  nextIndex = 0;
339  return true;
340  }
341  if (mng_display_freeze(hMNG) == MNG_NOERROR) {
342  if (mng_display_goframe(hMNG, imageNumber) == MNG_NOERROR) {
343  nextIndex = imageNumber;
344  return true;
345  }
346  }
347  return false;
348 }

◆ jumpToNextImage()

bool QMngHandlerPrivate::jumpToNextImage ( )

Definition at line 350 of file qmnghandler.cpp.

351 {
352  return jumpToImage((currentImageNumber()+1) % imageCount());
353 }
int imageCount() const
bool jumpToImage(int imageNumber)
int currentImageNumber() const

◆ nextImageDelay()

int QMngHandlerPrivate::nextImageDelay ( ) const

Definition at line 355 of file qmnghandler.cpp.

356 {
357  return nextDelay;
358 }

◆ processHeader()

mng_bool QMngHandlerPrivate::processHeader ( mng_uint32  iWidth,
mng_uint32  iHeight 
)

Definition at line 254 of file qmnghandler.cpp.

Referenced by myprocessheader().

255 {
256  if (mng_set_canvasstyle(hMNG, iStyle) != MNG_NOERROR)
257  return MNG_FALSE;
258  image = QImage(iWidth, iHeight, QImage::Format_ARGB32);
259  image.fill(0);
260  return MNG_TRUE;
261 }
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87

◆ readData()

mng_bool QMngHandlerPrivate::readData ( mng_ptr  pBuf,
mng_uint32  iSize,
mng_uint32p  pRead 
)

Definition at line 240 of file qmnghandler.cpp.

Referenced by myreaddata().

241 {
242  Q_Q(QMngHandler);
243  *pRead = q->device()->read((char *)pBuf, iSize);
244  return (*pRead > 0) ? MNG_TRUE : MNG_FALSE;
245 }
#define Q_Q(Class)
Definition: qglobal.h:2483

◆ setBackgroundColor()

bool QMngHandlerPrivate::setBackgroundColor ( const QColor color)

Definition at line 360 of file qmnghandler.cpp.

361 {
362  mng_uint16 iRed = (mng_uint16)(color.red() << 8);
363  mng_uint16 iBlue = (mng_uint16)(color.blue() << 8);
364  mng_uint16 iGreen = (mng_uint16)(color.green() << 8);
365  return (mng_set_bgcolor(hMNG, iRed, iBlue, iGreen) == MNG_NOERROR);
366 }
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244

◆ writeData()

mng_bool QMngHandlerPrivate::writeData ( mng_ptr  pBuf,
mng_uint32  iSize,
mng_uint32p  pWritten 
)

Definition at line 247 of file qmnghandler.cpp.

Referenced by mywritedata().

248 {
249  Q_Q(QMngHandler);
250  *pWritten = q->device()->write((char *)pBuf, iSize);
251  return MNG_TRUE;
252 }
#define Q_Q(Class)
Definition: qglobal.h:2483

◆ writeImage()

bool QMngHandlerPrivate::writeImage ( const QImage image)

Definition at line 290 of file qmnghandler.cpp.

291 {
292  mng_reset(hMNG);
293  if (mng_create(hMNG) != MNG_NOERROR)
294  return false;
295 
296  this->image = image.convertToFormat(QImage::Format_ARGB32);
297  int w = image.width();
298  int h = image.height();
299 
300  if (
301  // width, height, ticks, layercount, framecount, playtime, simplicity
302  (mng_putchunk_mhdr(hMNG, w, h, 1000, 0, 0, 0, 7) == MNG_NOERROR) &&
303  // termination_action, action_after_iterations, delay, iteration_max
304  (mng_putchunk_term(hMNG, 3, 0, 1, 0x7FFFFFFF) == MNG_NOERROR) &&
305  // width, height, bitdepth, colortype, compression, filter, interlace
306  (mng_putchunk_ihdr(hMNG, w, h, 8, 6, 0, 0, 0) == MNG_NOERROR) &&
307  // width, height, colortype, bitdepth, compression, filter, interlace, canvasstyle, getcanvasline
308  (mng_putimgdata_ihdr(hMNG, w, h, 6, 8, 0, 0, 0, iStyle, mygetcanvasline) == MNG_NOERROR) &&
309  (mng_putchunk_iend(hMNG) == MNG_NOERROR) &&
310  (mng_putchunk_mend(hMNG) == MNG_NOERROR) &&
311  (mng_write(hMNG) == MNG_NOERROR)
312  )
313  return true;
314  return false;
315 }
static mng_ptr mygetcanvasline(mng_handle hMNG, mng_uint32 iLinenr)
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

Properties

◆ elapsed

int QMngHandlerPrivate::elapsed

Definition at line 61 of file qmnghandler.cpp.

Referenced by mygettickcount(), and mysettimer().

◆ frameCount

int QMngHandlerPrivate::frameCount

Definition at line 66 of file qmnghandler.cpp.

Referenced by getNextImage(), imageCount(), and jumpToImage().

◆ frameIndex

int QMngHandlerPrivate::frameIndex

Definition at line 64 of file qmnghandler.cpp.

Referenced by currentImageNumber(), and getNextImage().

◆ haveReadAll

bool QMngHandlerPrivate::haveReadAll

Definition at line 58 of file qmnghandler.cpp.

Referenced by getNextImage(), imageCount(), jumpToImage(), and myclosestream().

◆ haveReadNone

bool QMngHandlerPrivate::haveReadNone

Definition at line 57 of file qmnghandler.cpp.

Referenced by getNextImage().

◆ hMNG

mng_handle QMngHandlerPrivate::hMNG

◆ image

QImage QMngHandlerPrivate::image

Definition at line 60 of file qmnghandler.cpp.

Referenced by getNextImage(), mygetcanvasline(), and processHeader().

◆ iStyle

mng_uint32 QMngHandlerPrivate::iStyle

Definition at line 67 of file qmnghandler.cpp.

Referenced by processHeader(), QMngHandlerPrivate(), and writeImage().

◆ iterCount

int QMngHandlerPrivate::iterCount

Definition at line 63 of file qmnghandler.cpp.

Referenced by myprocessterm().

◆ nextDelay

int QMngHandlerPrivate::nextDelay

Definition at line 62 of file qmnghandler.cpp.

Referenced by getNextImage(), mysettimer(), and nextImageDelay().

◆ nextIndex

int QMngHandlerPrivate::nextIndex

Definition at line 65 of file qmnghandler.cpp.

Referenced by getNextImage(), and jumpToImage().

◆ q_ptr

QMngHandler* QMngHandlerPrivate::q_ptr

Definition at line 82 of file qmnghandler.cpp.


The documentation for this class was generated from the following file: