Commit 381f5ae82cccec3774b68674b4c0e782e9f49f6f

  • avatar
  • Trond Kjernåsen <trond @trol…ech.com>
  • Fri Feb 05 16:08:53 CET 2010
Fixed QGifHandler::loopCount().

Task-number: QTBUG-7037
Reviewed-by: Kim
  
7272
7373 int decode(QImage *image, const uchar* buffer, int length,
7474 int *nextFrameDelay, int *loopCount);
75 static void scan(QIODevice *device, QVector<QSize> *imageSizes);
75 static void scan(QIODevice *device, QVector<QSize> *imageSizes, int *loopCount);
7676
7777 bool newFrame;
7878 bool partialNewFrame;
646646 Scans through the data stream defined by \a device and returns the image
647647 sizes found in the stream in the \a imageSizes vector.
648648*/
649void QGIFFormat::scan(QIODevice *device, QVector<QSize> *imageSizes)
649void QGIFFormat::scan(QIODevice *device, QVector<QSize> *imageSizes, int *loopCount)
650650{
651651 if (!device)
652652 return;
842842 hold[count] = ch;
843843 ++count;
844844 if (count == hold[0] + 1) {
845 state = SkipBlockSize;
845 if (qstrncmp((char*)(hold+1), "NETSCAPE", 8) == 0)
846 state=NetscapeExtensionBlockSize;
847 else
848 state=SkipBlockSize;
846849 count = 0;
847850 }
848851 break;
858858 state = SkipBlockSize;
859859 }
860860 break;
861 case NetscapeExtensionBlockSize: // fallthrough
861 case NetscapeExtensionBlockSize:
862 blockSize = ch;
863 count = 0;
864 if (blockSize)
865 state = NetscapeExtensionBlock;
866 else
867 state = Introducer;
868 break;
869 case NetscapeExtensionBlock:
870 if (count < 3)
871 hold[count] = ch;
872 count++;
873 if (count == blockSize) {
874 *loopCount = LM(hold[1], hold[2]);
875 state = SkipBlockSize;
876 }
877 break;
862878 case SkipBlockSize:
863879 blockSize = ch;
864880 count = 0;
890890 state = Introducer;
891891 }
892892 break;
893 case NetscapeExtensionBlock: // fallthrough
894893 case SkipBlock:
895894 ++count;
896895 if (count == blockSize)
10271027{
10281028 gifFormat = new QGIFFormat;
10291029 nextDelay = 0;
1030 loopCnt = 0;
1030 loopCnt = 1;
10311031 frameNumber = -1;
10321032 scanIsCached = false;
10331033}
11271127{
11281128 if (option == Size) {
11291129 if (!scanIsCached) {
1130 QGIFFormat::scan(device(), &imageSizes);
1130 QGIFFormat::scan(device(), &imageSizes, &loopCnt);
11311131 scanIsCached = true;
11321132 }
11331133 // before the first frame is read, or we have an empty data stream
11581158int QGifHandler::imageCount() const
11591159{
11601160 if (!scanIsCached) {
1161 QGIFFormat::scan(device(), &imageSizes);
1161 QGIFFormat::scan(device(), &imageSizes, &loopCnt);
11621162 scanIsCached = true;
11631163 }
11641164 return imageSizes.count();
11661166
11671167int QGifHandler::loopCount() const
11681168{
1169 if (!scanIsCached) {
1170 QGIFFormat::scan(device(), &imageSizes, &loopCnt);
1171 scanIsCached = true;
1172 }
11691173 return loopCnt-1; // In GIF, loop count is iteration count, so subtract one
11701174}
11711175
  
11<RCC>
2 <qresource prefix="/" >
2 <qresource prefix="/">
33 <file>images/16bpp.bmp</file>
44 <file>images/4bpp-rle.bmp</file>
55 <file>images/YCbCr_cmyk.jpg</file>
5959 <file>images/qt8.gif</file>
6060 <file>images/endless-anim.gif</file>
6161 <file>images/four-frames.gif</file>
62 <file>images/qt-gif-anim.gif</file>
63 <file>images/qt-gif-noanim.gif</file>
6264 </qresource>
6365</RCC>
  
142142 void gifHandlerBugs();
143143 void animatedGif();
144144 void gifImageCount();
145 void gifLoopCount();
145146#endif
146147
147148 void readCorruptImage_data();
885885 QVERIFY(io.size() == QSize(128,64));
886886 }
887887}
888
889void tst_QImageReader::gifLoopCount()
890{
891 {
892 QImageReader io(":images/qt-gif-anim.gif");
893 QCOMPARE(io.loopCount(), -1); // infinite loop
894 }
895 {
896 QImageReader io(":images/qt-gif-noanim.gif");
897 QCOMPARE(io.loopCount(), 0); // no loop
898 }
899}
900
888901#endif
889902
890903class Server : public QObject