Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qimagereader.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4848
    4949    \reentrant
    50     \ingroup multimedia
     50    \ingroup painting
    5151    \ingroup io
    5252
     
    196196
    197197static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
    198                                                 const QByteArray &format, bool autoDetectImageFormat)
     198                                                const QByteArray &format,
     199                                                bool autoDetectImageFormat,
     200                                                bool ignoresFormatAndExtension)
    199201{
    200202    if (!autoDetectImageFormat && format.isEmpty())
     
    218220#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    219221    int suffixPluginIndex = -1;
    220     if (device && format.isEmpty() && autoDetectImageFormat) {
     222    if (device && format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
    221223        // if there's no format, see if \a device is a file, and if so, find
    222224        // the file suffix and find support for that format among our plugins.
     
    241243
    242244    QByteArray testFormat = !form.isEmpty() ? form : suffix;
     245
     246    if (ignoresFormatAndExtension)
     247        testFormat = QByteArray();
    243248
    244249#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     
    259264    }
    260265
    261     if (!handler && !testFormat.isEmpty() && autoDetectImageFormat) {
     266    if (!handler && !testFormat.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
    262267        // check if any plugin supports the format (they are not allowed to
    263268        // read from the device yet).
     
    316321
    317322#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    318     if (!handler && autoDetectImageFormat) {
     323    if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
    319324        // check if any of our plugins recognize the file from its contents.
    320325        const qint64 pos = device ? device->pos() : 0;
     
    336341#endif
    337342
    338     if (!handler && autoDetectImageFormat) {
     343    if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
    339344        // check if any of our built-in handlers recognize the file from its
    340345        // contents.
     
    435440    QByteArray format;
    436441    bool autoDetectImageFormat;
     442    bool ignoresFormatAndExtension;
    437443    QIODevice *device;
    438444    bool deleteDevice;
     
    459465*/
    460466QImageReaderPrivate::QImageReaderPrivate(QImageReader *qq)
    461     : autoDetectImageFormat(true)
     467    : autoDetectImageFormat(true), ignoresFormatAndExtension(false)
    462468{
    463469    device = 0;
     
    466472    quality = -1;
    467473    imageReaderError = QImageReader::UnknownError;
    468     errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error"));
    469474
    470475    q = qq;
     
    523528
    524529    // assign a handler
    525     if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat)) == 0) {
     530    if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
    526531        imageReaderError = QImageReader::UnsupportedFormatError;
    527532        errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
     
    665670    when trying to read the image.
    666671
    667     \endlist   
     672    \endlist
    668673
    669674    By disabling image format autodetection, QImageReader will only query the
     
    682687    reader; otherwise returns false. By default, autodetection is enabled.
    683688
    684     \sa setAutoDetectImageFormat()   
     689    \sa setAutoDetectImageFormat()
    685690*/
    686691bool QImageReader::autoDetectImageFormat() const
     
    688693    return d->autoDetectImageFormat;
    689694}
     695
     696
     697/*!
     698    If \a ignored is set to true, then the image reader will ignore
     699    specified formats or file extensions and decide which plugin to
     700    use only based on the contents in the datastream.
     701
     702    Setting this flag means that all image plugins gets loaded. Each
     703    plugin will read the first bytes in the image data and decide if
     704    the plugin is compatible or not.
     705
     706    This also disables auto detecting the image format.
     707
     708    \sa decideFormatFromContent()
     709*/
     710
     711void QImageReader::setDecideFormatFromContent(bool ignored)
     712{
     713    d->ignoresFormatAndExtension = ignored;
     714}
     715
     716
     717/*!
     718    Returns whether the image reader should decide which plugin to use
     719    only based on the contents of the datastream rather than on the file
     720    extension.
     721
     722    \sa setDecideFormatFromContent()
     723*/
     724
     725bool QImageReader::decideFormatFromContent() const
     726{
     727    return d->ignoresFormatAndExtension;
     728}
     729
    690730
    691731/*!
     
    11741214
    11751215/*!
    1176     For image formats that support animation, this function returns
    1177     the number of times the animation should loop. Otherwise, it
    1178     returns -1.
    1179 
    1180     \sa supportsAnimation(), QImageIOHandler::loopCount()
     1216    For image formats that support animation, this function returns the number
     1217    of times the animation should loop. If this function returns -1, it can
     1218    either mean the animation should loop forever, or that an error occurred.
     1219    If an error occurred, canRead() will return false.
     1220
     1221    \sa supportsAnimation(), QImageIOHandler::loopCount(), canRead()
    11811222*/
    11821223int QImageReader::loopCount() const
     
    11881229
    11891230/*!
    1190     For image formats that support animation, this function returns
    1191     the total number of images in the animation.
    1192 
    1193     Certain animation formats do not support this feature, in which
    1194     case 0 is returned.
    1195 
    1196     \sa supportsAnimation(), QImageIOHandler::imageCount()
     1231    For image formats that support animation, this function returns the total
     1232    number of images in the animation. If the format does not support
     1233    animation, 0 is returned.
     1234
     1235    This function returns -1 if an error occurred.
     1236
     1237    \sa supportsAnimation(), QImageIOHandler::imageCount(), canRead()
    11971238*/
    11981239int QImageReader::imageCount() const
     
    12041245
    12051246/*!
    1206     For image formats that support animation, this function returns
    1207     the number of milliseconds to wait until displaying the next frame
    1208     in the animation. Otherwise, 0 is returned.
    1209 
    1210     \sa supportsAnimation(), QImageIOHandler::nextImageDelay()
     1247    For image formats that support animation, this function returns the number
     1248    of milliseconds to wait until displaying the next frame in the animation.
     1249    If the image format doesn't support animation, 0 is returned.
     1250
     1251    This function returns -1 if an error occurred.
     1252
     1253    \sa supportsAnimation(), QImageIOHandler::nextImageDelay(), canRead()
    12111254*/
    12121255int QImageReader::nextImageDelay() const
     
    12181261
    12191262/*!
    1220     For image formats that support animation, this function returns
    1221     the sequence number of the current frame. Otherwise, -1 is
    1222     returned.
    1223 
    1224     \sa supportsAnimation(), QImageIOHandler::currentImageNumber()
     1263    For image formats that support animation, this function returns the
     1264    sequence number of the current frame. If the image format doesn't support
     1265    animation, 0 is returned.
     1266
     1267    This function returns -1 if an error occurred.
     1268
     1269    \sa supportsAnimation(), QImageIOHandler::currentImageNumber(), canRead()
    12251270*/
    12261271int QImageReader::currentImageNumber() const
     
    12621307QString QImageReader::errorString() const
    12631308{
     1309    if (d->errorString.isEmpty())
     1310        return QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error"));
    12641311    return d->errorString;
    12651312}
     
    13101357{
    13111358    QByteArray format;
    1312     QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true);
     1359    QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true, false);
    13131360    if (handler) {
    13141361        if (handler->canRead())
     
    13381385    \row    \o XBM    \o X11 Bitmap
    13391386    \row    \o XPM    \o X11 Pixmap
     1387    \row    \o SVG    \o Scalable Vector Graphics
    13401388    \endtable
    13411389
Note: See TracChangeset for help on using the changeset viewer.