55 #define Q_TRANSPARENT 0x00ffffff 58 #define FAST_SCAN_LINE(bits, bpl, y) (bits + (y) * bpl) 74 int *nextFrameDelay,
int *loopCount);
143 void nextY(
unsigned char *bits,
int bpl);
205 }
else if (
bgcol>=0) {
211 fillRect(image, l, t, r-l+1, b-t+1, bits[0]);
217 for (
int ln=t; ln<=b; ln++) {
220 (r-l+1)*
sizeof(
QRgb));
237 int *nextFrameDelay,
int *loopCount)
252 unsigned char *bits = image->
bits();
254 #define LM(l, m) (((m)<<8)|l) 256 const int initial = length;
259 unsigned char ch=*buffer++;
350 swidth = newleft + newwidth;
358 bits = image->
bits();
392 }
else if (
bgcol>=0) {
417 for (
int ln=0; ln<h; ln++) {
513 if (code==
table[0][code]) {
542 const int h = image->
height();
580 state=CommentExtension;
627 *nextFrameDelay = (delay < 2 ? 10 : delay) * 10;
629 bool havetrans=
hold[1]&0x1;
657 return initial-length;
670 if (!device->
seek(0))
674 int localColorCount = 0;
675 int globalColorCount = 0;
676 int colorReadCount = 0;
677 bool localColormap =
false;
678 bool globalColormap =
false;
687 const int readBufferSize = 40960;
690 if (readBuffer.isEmpty()) {
691 device->
seek(oldPos);
700 while (!readBuffer.isEmpty()) {
701 int length = readBuffer.size();
702 const uchar *buffer = (
const uchar *) readBuffer.constData();
703 while (!done && length) {
705 uchar ch = *buffer++;
717 imageWidth =
LM(hold[0], hold[1]);
718 imageHeight =
LM(hold[2], hold[3]);
719 globalColormap = !!(hold[4] & 0x80);
720 globalColorCount = 2 << (hold[4] & 0x7);
722 colorCount = globalColorCount;
723 if (globalColormap) {
724 int colorTableSize = 3 * globalColorCount;
725 if (length >= colorTableSize) {
727 length -= colorTableSize;
728 buffer += colorTableSize;
743 if (++colorReadCount >= colorCount) {
772 int newLeft =
LM(hold[1], hold[2]);
773 int newTop =
LM(hold[3], hold[4]);
774 int newWidth =
LM(hold[5], hold[6]);
775 int newHeight =
LM(hold[7], hold[8]);
777 if (imageWidth/10 >
qMax(newWidth,200))
779 if (imageHeight/10 >
qMax(newHeight,200))
783 imageWidth = newLeft + newWidth;
784 if (imageHeight <= 0)
785 imageHeight = newTop + newHeight;
787 *imageSizes <<
QSize(imageWidth, imageHeight);
789 localColormap = !!(hold[9] & 0x80);
790 localColorCount = localColormap ? (2 << (hold[9] & 0x7)) : 0;
792 colorCount = localColorCount;
794 colorCount = globalColorCount;
798 int colorTableSize = 3 * localColorCount;
799 if (length >= colorTableSize) {
801 length -= colorTableSize;
802 buffer += colorTableSize;
823 if (length >= blockSize) {
837 if (count == blockSize) {
859 if (count == hold[0] + 1) {
860 if (
qstrncmp((
char*)(hold+1),
"NETSCAPE", 8) == 0)
871 if (count == hold[0] + 1) {
888 if (count == blockSize) {
889 *loopCount =
LM(hold[1], hold[2]);
897 if (length >= blockSize) {
910 if (count == blockSize)
917 device->
seek(oldPos);
921 readBuffer = device->
read(readBufferSize);
923 device->
seek(oldPos);
930 for (
int j=0; j<h; j++) {
932 for (
int i=0; i<w; i++)
933 *(line+col+i) =
color;
953 for (i=1; i<=my; i++) {
982 for (i=1; i<=my; i++) {
1006 for (i=1; i<=my; i++) {
1048 scanIsCached =
false;
1060 const int GifChunkSize = 4096;
1062 while (!gifFormat->partialNewFrame) {
1063 if (buffer.isEmpty()) {
1064 buffer += device()->read(GifChunkSize);
1065 if (buffer.isEmpty())
1069 int decoded = gifFormat->decode(&lastImage, (
const uchar *)buffer.constData(), buffer.size(),
1070 &nextDelay, &loopCnt);
1073 buffer.remove(0, decoded);
1075 return gifFormat->partialNewFrame;
1080 if (canRead(device()) || imageIsComing()) {
1091 qWarning(
"QGifHandler::canRead() called with no device");
1096 if (device->
peek(head,
sizeof(head)) ==
sizeof(head))
1097 return qstrncmp(head,
"GIF87a", 6) == 0
1098 ||
qstrncmp(head,
"GIF89a", 6) == 0;
1104 const int GifChunkSize = 4096;
1106 while (!gifFormat->newFrame) {
1107 if (buffer.isEmpty()) {
1108 buffer += device()->read(GifChunkSize);
1109 if (buffer.isEmpty())
1113 int decoded = gifFormat->decode(&lastImage, (
const uchar *)buffer.constData(), buffer.size(),
1114 &nextDelay, &loopCnt);
1117 buffer.remove(0, decoded);
1119 if (gifFormat->newFrame || (gifFormat->partialNewFrame && device()->atEnd())) {
1122 gifFormat->newFrame =
false;
1123 gifFormat->partialNewFrame =
false;
1138 if (!device() || device()->isSequential())
1141 return option == Size
1147 if (option == Size) {
1148 if (!scanIsCached) {
1150 scanIsCached =
true;
1153 if (frameNumber == -1)
1156 if (frameNumber >= imageSizes.count() - 1)
1159 return imageSizes.at(frameNumber + 1);
1179 if (!scanIsCached) {
1181 scanIsCached =
true;
1183 return imageSizes.count();
1188 if (!scanIsCached) {
1190 scanIsCached =
true;
1195 else if (loopCnt == -1)
The QVariant class acts like a union for the most common Qt data types.
bool canRead() const
Returns true if an image can be read from the device (i.
Format
The following image formats are available in Qt.
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
int currentImageNumber() const
For image formats that support animation, this function returns the sequence number of the current im...
void setOption(ImageOption option, const QVariant &value)
Sets the option option with the value value.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
bool read(QImage *image)
Read an image from the device, and stores it in image.
The QByteArray class provides an array of bytes.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
int byteCount() const
Returns the number of bytes occupied by the image data.
int bytesPerLine() const
Returns the number of bytes per image scanline.
int imageCount() const
For image formats that support animation, this function returns the number of images in the animation...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
bool write(const QImage &image)
Writes the image image to the assigned device.
#define QT_BEGIN_NAMESPACE
This macro expands to.
ImageOption
This enum describes the different options supported by QImageIOHandler.
bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false...
qint64 peek(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, without side effects (i.
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
The State element defines configurations of objects and properties.
QByteArray name() const
Use format() instead.
uchar * bits()
Returns a pointer to the first pixel data.
int width() const
Returns the width of the image.
int loopCount() const
For image formats that support animation, this function returns the number of times the animation sho...
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
int qstrncmp(const char *str1, const char *str2, uint len)
int height() const
Returns the height of the image.
The Animation element is the base of all QML animations.
int nextImageDelay() const
For image formats that support animation, this function returns the number of milliseconds to wait un...
#define FAST_SCAN_LINE(bits, bpl, y)
The QSize class defines the size of a two-dimensional object using integer point precision.
bool imageIsComing() const
The QIODevice class is the base interface class of all I/O devices in Qt.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.