src/gui/image/qimagereader.cpp
changeset 18 2f34d5167611
parent 0 1918ee327afb
child 30 5dc02b23752f
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   261         }
   261         }
   262         if (device && !device->isSequential())
   262         if (device && !device->isSequential())
   263             device->seek(pos);
   263             device->seek(pos);
   264     }
   264     }
   265 
   265 
   266     if (!handler && !testFormat.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
   266     if (!handler && !testFormat.isEmpty() && !ignoresFormatAndExtension) {
   267         // check if any plugin supports the format (they are not allowed to
   267         // check if any plugin supports the format (they are not allowed to
   268         // read from the device yet).
   268         // read from the device yet).
   269         const qint64 pos = device ? device->pos() : 0;
   269         const qint64 pos = device ? device->pos() : 0;
   270         for (int i = 0; i < keys.size(); ++i) {
   270 
   271             if (i != suffixPluginIndex) {
   271         if (autoDetectImageFormat) {
   272                 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i)));
   272             for (int i = 0; i < keys.size(); ++i) {
   273                 if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
   273                 if (i != suffixPluginIndex) {
       
   274                     QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i)));
       
   275                     if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
   274 #ifdef QIMAGEREADER_DEBUG
   276 #ifdef QIMAGEREADER_DEBUG
   275                     qDebug() << "QImageReader::createReadHandler: the" << keys.at(i) << "plugin can read this format";
   277                         qDebug() << "QImageReader::createReadHandler: the" << keys.at(i) << "plugin can read this format";
   276 #endif
   278 #endif
   277                     handler = plugin->create(device, testFormat);
   279                         handler = plugin->create(device, testFormat);
   278                     break;
   280                         break;
       
   281                     }
   279                 }
   282                 }
       
   283             }
       
   284         } else {
       
   285             QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QLatin1String(testFormat)));
       
   286             if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
       
   287 #ifdef QIMAGEREADER_DEBUG
       
   288                 qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format";
       
   289 #endif
       
   290                 handler = plugin->create(device, testFormat);
   280             }
   291             }
   281         }
   292         }
   282         if (device && !device->isSequential())
   293         if (device && !device->isSequential())
   283             device->seek(pos);
   294             device->seek(pos);
   284     }
   295     }
       
   296 
   285 #endif // QT_NO_LIBRARY
   297 #endif // QT_NO_LIBRARY
   286 
   298 
   287     // if we don't have a handler yet, check if we have built-in support for
   299     // if we don't have a handler yet, check if we have built-in support for
   288     // the format
   300     // the format
   289     if (!handler && !testFormat.isEmpty()) {
   301     if (!handler && !testFormat.isEmpty()) {
   469     device = 0;
   481     device = 0;
   470     deleteDevice = false;
   482     deleteDevice = false;
   471     handler = 0;
   483     handler = 0;
   472     quality = -1;
   484     quality = -1;
   473     imageReaderError = QImageReader::UnknownError;
   485     imageReaderError = QImageReader::UnknownError;
   474     errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error"));
       
   475 
   486 
   476     q = qq;
   487     q = qq;
   477 }
   488 }
   478 
   489 
   479 /*!
   490 /*!
  1212         return false;
  1223         return false;
  1213     return d->handler->jumpToImage(imageNumber);
  1224     return d->handler->jumpToImage(imageNumber);
  1214 }
  1225 }
  1215 
  1226 
  1216 /*!
  1227 /*!
  1217     For image formats that support animation, this function returns
  1228     For image formats that support animation, this function returns the number
  1218     the number of times the animation should loop. Otherwise, it
  1229     of times the animation should loop. If this function returns -1, it can
  1219     returns -1.
  1230     either mean the animation should loop forever, or that an error occurred.
  1220 
  1231     If an error occurred, canRead() will return false.
  1221     \sa supportsAnimation(), QImageIOHandler::loopCount()
  1232 
       
  1233     \sa supportsAnimation(), QImageIOHandler::loopCount(), canRead()
  1222 */
  1234 */
  1223 int QImageReader::loopCount() const
  1235 int QImageReader::loopCount() const
  1224 {
  1236 {
  1225     if (!d->initHandler())
  1237     if (!d->initHandler())
  1226         return -1;
  1238         return -1;
  1227     return d->handler->loopCount();
  1239     return d->handler->loopCount();
  1228 }
  1240 }
  1229 
  1241 
  1230 /*!
  1242 /*!
  1231     For image formats that support animation, this function returns
  1243     For image formats that support animation, this function returns the total
  1232     the total number of images in the animation.
  1244     number of images in the animation. If the format does not support
  1233 
  1245     animation, 0 is returned.
  1234     Certain animation formats do not support this feature, in which
  1246 
  1235     case 0 is returned.
  1247     This function returns -1 if an error occurred.
  1236 
  1248 
  1237     \sa supportsAnimation(), QImageIOHandler::imageCount()
  1249     \sa supportsAnimation(), QImageIOHandler::imageCount(), canRead()
  1238 */
  1250 */
  1239 int QImageReader::imageCount() const
  1251 int QImageReader::imageCount() const
  1240 {
  1252 {
  1241     if (!d->initHandler())
  1253     if (!d->initHandler())
  1242         return -1;
  1254         return -1;
  1243     return d->handler->imageCount();
  1255     return d->handler->imageCount();
  1244 }
  1256 }
  1245 
  1257 
  1246 /*!
  1258 /*!
  1247     For image formats that support animation, this function returns
  1259     For image formats that support animation, this function returns the number
  1248     the number of milliseconds to wait until displaying the next frame
  1260     of milliseconds to wait until displaying the next frame in the animation.
  1249     in the animation. Otherwise, 0 is returned.
  1261     If the image format doesn't support animation, 0 is returned.
  1250 
  1262 
  1251     \sa supportsAnimation(), QImageIOHandler::nextImageDelay()
  1263     This function returns -1 if an error occurred.
       
  1264 
       
  1265     \sa supportsAnimation(), QImageIOHandler::nextImageDelay(), canRead()
  1252 */
  1266 */
  1253 int QImageReader::nextImageDelay() const
  1267 int QImageReader::nextImageDelay() const
  1254 {
  1268 {
  1255     if (!d->initHandler())
  1269     if (!d->initHandler())
  1256         return -1;
  1270         return -1;
  1257     return d->handler->nextImageDelay();
  1271     return d->handler->nextImageDelay();
  1258 }
  1272 }
  1259 
  1273 
  1260 /*!
  1274 /*!
  1261     For image formats that support animation, this function returns
  1275     For image formats that support animation, this function returns the
  1262     the sequence number of the current frame. Otherwise, -1 is
  1276     sequence number of the current frame. If the image format doesn't support
  1263     returned.
  1277     animation, 0 is returned.
  1264 
  1278 
  1265     \sa supportsAnimation(), QImageIOHandler::currentImageNumber()
  1279     This function returns -1 if an error occurred.
       
  1280 
       
  1281     \sa supportsAnimation(), QImageIOHandler::currentImageNumber(), canRead()
  1266 */
  1282 */
  1267 int QImageReader::currentImageNumber() const
  1283 int QImageReader::currentImageNumber() const
  1268 {
  1284 {
  1269     if (!d->initHandler())
  1285     if (!d->initHandler())
  1270         return -1;
  1286         return -1;
  1300 
  1316 
  1301     \sa error()
  1317     \sa error()
  1302 */
  1318 */
  1303 QString QImageReader::errorString() const
  1319 QString QImageReader::errorString() const
  1304 {
  1320 {
       
  1321     if (d->errorString.isEmpty())
       
  1322         return QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error"));
  1305     return d->errorString;
  1323     return d->errorString;
  1306 }
  1324 }
  1307 
  1325 
  1308 /*!
  1326 /*!
  1309     \since 4.2
  1327     \since 4.2