/*! Call this function to decode some data into image changes. The data will be decoded, sending change information to the QImageConsumer of this QImageDecoder, until one of the change functions of the consumer returns FALSE. Returns the number of bytes consumed, 0 if consumption is complete, and -1 if decoding fails due to invalid data. */ int QImageDecoder::decode(const uchar* buffer, int length) { if (!actual_decoder) { int i=0; while (i < length && d->count < max_header) d->header[d->count++] = buffer[i++]; QImageDecoderPrivate::ensureFactories(); for (QImageFormatType* f = QImageDecoderPrivate::factories->first(); f && !actual_decoder; f = QImageDecoderPrivate::factories->next()) { actual_decoder = f->decoderFor(d->header, d->count); } if (!actual_decoder) { if ( d->count < max_header ) { // not enough info yet return i; } else { // failure - nothing matches max_header bytes return -1; } } } return actual_decoder->decode(img, consumer, buffer, length); }
/*! Returns a QImageFormatType by name. This might be used in cases where the user needs to force data to be interpreted as being in a certain format. \a name is one of the formats listed by QImageDecoder::inputFormats(). Note that you will still need to supply decodable data to result->decoderFor() before you can begin decoding the data. */ QImageFormatType* QImageDecoder::format( const char* name ) { for (QImageFormatType* f = QImageDecoderPrivate::factories->first(); f; f = QImageDecoderPrivate::factories->next()) { if ( qstricmp(name,f->formatName())==0 ) return f; } return 0; }
/*! Returns a QImageFormatType by name. This might be used when the user needs to force data to be interpreted as being in a certain format. \a name is one of the formats listed by QImageDecoder::inputFormats(). Note that you will still need to supply decodable data to result->decoderFor() before you can begin decoding the data. */ QImageFormatType* QImageDecoder::format( const char* name ) { QImageDecoderPrivate::ensureFactories(); qt_init_image_plugins(); for (QImageFormatType* f = QImageDecoderPrivate::factories->first(); f; f = QImageDecoderPrivate::factories->next()) { if ( qstricmp(name,f->formatName())==0 ) return f; } return 0; }
/*! Returns a sorted list of formats for which asynchronous loading is supported. */ QStrList QImageDecoder::inputFormats() { QImageDecoderPrivate::ensureFactories(); QStrList result; for (QImageFormatType* f = QImageDecoderPrivate::factories->first(); f; f = QImageDecoderPrivate::factories->next()) { if ( !result.contains( f->formatName() ) ) { result.inSort( f->formatName() ); } } return result; }
/*! Call this function to find the name of the format of the given header. The returned string is statically allocated. Returns 0 if the format is not recognized. */ const char* QImageDecoder::formatName(const uchar* buffer, int length) { QImageDecoderPrivate::ensureFactories(); const char* name = 0; for (QImageFormatType* f = QImageDecoderPrivate::factories->first(); f && !name; f = QImageDecoderPrivate::factories->next()) { QImageFormat *decoder = f->decoderFor(buffer, length); if (decoder) { name = f->formatName(); delete decoder; } } return name; }