bool GifDecoder::readBitmap(DataBlock* dataBlock) { uint8_t packed; if (!dataBlock->read(&ix) || !dataBlock->read(&iy) || // (sub)image position & size !dataBlock->read(&iw) || !dataBlock->read(&ih) || !dataBlock->read(&packed, 1)) { return false; } bool lctFlag = (packed & 0x80) != 0; // 1 - local color table flag interlace int32_t lctSize = 2 << (packed & 0x07); // 3 - sort flag // 4-5 - reserved lctSize = 2 << (packed & 7); // 6-8 - local color // table size interlace = (packed & 0x40) != 0; uint32_t lct[256]; uint32_t* act; if (lctFlag) { if (!readColorTable(dataBlock, lct, lctSize)) { // read table return false; } act = lct; // make local table active } else { act = gct; // make global table active if (bgIndex == transIndex) { bgColor = 0; } } uint32_t save; if (transparency) { save = act[transIndex]; act[transIndex] = 0; // set transparent color if specified } if (!decodeBitmapData(dataBlock) || !skip(dataBlock)) { // decode pixel data return false; } frameCount++; // create new image to receive frame data setPixels(act); // transfer pixel data to image if (transparency) { act[transIndex] = save; } resetFrame(); return true; }
bool GifDecoder::readHeader(DataBlock* dataBlock) { uint8_t buffer[6]; if (!dataBlock->read(buffer, 6)) { return false; } if (0 != memcmp("GIF", buffer, 3)) { return false; } if (!readLSD(dataBlock)) { return false; } if (gctFlag) { if (!readColorTable(dataBlock, gct, gctSize)) { return false; } bgColor = gct[bgIndex]; } return true; }
Sequence* ReaderWriterILDA::readFile(const QString& fileName) { QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { bool eof = false; QDataStream stream(&file); stream.setByteOrder(QDataStream::BigEndian); _sequence = new Sequence(); while (!stream.atEnd() && !eof) { char signature[4]; stream.readRawData(signature, 4); if (memcmp(signature, "ILDA", 4)) { file.close(); return 0L; } quint32 formatType; stream >> formatType; if (!_ildaVersion.contains(formatType)) _ildaVersion.append(formatType); switch (formatType) { case 0: // 3D Frame eof = readFrameSection(stream, true); break; case 1: // 2D Frame eof = readFrameSection(stream, false); break; case 2: // Color Table eof = readColorTable(stream); break; case 3: // True Color eof = readTrueColorSection(stream); break; case 4: eof = readFormat5(stream, true); break; case 5: eof = readFormat5(stream, false); break; default: // Unknow section type { qint32 dataLength; qint32 numberOfPoints; stream >> dataLength >> numberOfPoints; stream.skipRawData(dataLength); } break; } } file.close(); }