// The total number of frames for the image. Will scan the image data for the answer // (without necessarily decoding all of the individual frames). int GIFImageDecoder::frameCount() { // If the decoder had an earlier error, we will just return what we had decoded // so far. if (!m_frameCountValid) { // FIXME: Scanning all the data has O(n^2) behavior if the data were to come in really // slowly. Might be interesting to try to clone our existing read session to preserve // state, but for now we just crawl all the data. Note that this is no worse than what // ImageIO does on Mac right now (it also crawls all the data again). GIFImageDecoderPrivate reader; reader.decode(m_data, GIFFrameCountQuery); m_frameCountValid = true; m_frameBufferCache.resize(reader.frameCount()); } return m_frameBufferCache.size(); }
// The total number of frames for the image. Will scan the image data for the answer // (without necessarily decoding all of the individual frames). size_t GIFImageDecoder::frameCount() { // If the decoder had an earlier error, we will just return what we had decoded // so far. if (!m_frameCountValid) { // FIXME: Scanning all the data has O(n^2) behavior if the data were to come in really // slowly. Might be interesting to try to clone our existing read session to preserve // state, but for now we just crawl all the data. Note that this is no worse than what // ImageIO does on Mac right now (it also crawls all the data again). GIFImageDecoderPrivate reader; // This function may fail, but we want to keep any partial data it may // have decoded, so don't mark it is invalid. If there is an overflow // or some serious error, m_failed will have gotten set for us. reader.decode(m_data, GIFFrameCountQuery); m_frameCountValid = true; m_frameBufferCache.resize(reader.frameCount()); m_rects.resize(reader.frameCount()); } return m_frameBufferCache.size(); }