⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpicture.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        return false;    }    int cs_start = sizeof(quint32);                // pos of checksum word    int data_start = cs_start + sizeof(quint16);    quint16 cs,ccs;    QByteArray buf = pictb.buffer();        // pointer to data    s >> cs;                                // read checksum    ccs = (quint16) qChecksum(buf.constData() + data_start, buf.size() - data_start);    if (ccs != cs) {        qWarning("QPicturePaintEngine::checkFormat: Invalid checksum %x, %x expected",                  ccs, cs);        pictb.close();        return false;    }    quint16 major, minor;    s >> major >> minor;                        // read version number    if (major > mfhdr_maj) {                // new, incompatible version        qWarning("QPicturePaintEngine::checkFormat: Incompatible version %d.%d",                  major, minor);        pictb.close();        return false;    }    s.setVersion(major != 4 ? major : 3);    quint8  c, clen;    s >> c >> clen;    if (c == QPicturePrivate::PdcBegin) {        if (!(major >= 1 && major <= 3)) {            qint32 l, t, w, h;            s >> l >> t >> w >> h;            brect = QRect(l, t, w, h);        }    } else {        qWarning("QPicturePaintEngine::checkFormat: Format error");        pictb.close();        return false;    }    pictb.close();    formatOk = true;                        // picture seems to be ok    formatMajor = major;    formatMinor = minor;    return true;}/*! \internal */QPaintEngine *QPicture::paintEngine() const{    if (!d_func()->paintEngine)        const_cast<QPicture*>(this)->d_func()->paintEngine = new QPicturePaintEngine;    return d_func()->paintEngine;}/*****************************************************************************  QPicture stream functions *****************************************************************************//*!    \relates QPicture    Writes picture \a r to the stream \a s and returns a reference to    the stream.*/QDataStream &operator<<(QDataStream &s, const QPicture &r){    quint32 size = r.d_func()->pictb.buffer().size();    s << size;    // null picture ?    if (size == 0)        return s;    // just write the whole buffer to the stream    s.writeRawData (r.d_func()->pictb.buffer(), r.d_func()->pictb.buffer().size());    return s;}/*!    \relates QPicture    Reads a picture from the stream \a s into picture \a r and returns    a reference to the stream.*/QDataStream &operator>>(QDataStream &s, QPicture &r){    QDataStream sr;    // "init"; this code is similar to the beginning of QPicture::cmd()    sr.setDevice(&r.d_func()->pictb);    sr.setVersion(r.d_func()->formatMajor);    quint32 len;    s >> len;    QByteArray data;    if (len > 0) {        data.resize(len);        s.readRawData(data.data(), len);    }    r.d_func()->pictb.setData(data);    r.d_func()->resetFormat();    return s;}#ifndef QT_NO_PICTUREIO#include "qregexp.h"#include "qapplication.h"#include "qpictureformatplugin.h"/*!    Returns a string that specifies the picture format of the file \a    fileName, or 0 if the file cannot be read or if the format is not    recognized.    The QPictureIO documentation lists the guaranteed supported picture    formats, or use QPicture::inputFormats() and QPicture::outputFormats()    to get lists that include the installed formats.    \sa load() save()*/const char* QPicture::pictureFormat(const QString &fileName){    return QPictureIO::pictureFormat(fileName);}/*!    Returns a list of picture formats that are supported for picture    input.    \sa outputFormats() inputFormatList() QPictureIO*/QList<QByteArray> QPicture::inputFormats(){    return QPictureIO::inputFormats();}static QStringList qToStringList(const QList<QByteArray> arr){    QStringList list;    for (int i = 0; i < arr.count(); ++i)        list.append(QString(arr.at(i)));    return list;}/*!    Returns a list of picture formats that are supported for picture    input.    Note that if you want to iterate over the list, you should iterate    over a copy, e.g.    \quotefromfile snippets/picture/picture.cpp    \skipto FORMATS    \skipto QStringList    \printuntil myProcessing    \sa outputFormatList() inputFormats() QPictureIO*/QStringList QPicture::inputFormatList(){    return qToStringList(QPictureIO::inputFormats());}/*!    Returns a list of picture formats that are supported for picture    output.    Note that if you want to iterate over the list, you should iterate    over a copy, e.g.    \quotefromfile snippets/picture/picture.cpp    \skipto OUTPUT    \skipto QStringList    \printuntil myProcessing    \sa inputFormatList() outputFormats() QPictureIO*/QStringList QPicture::outputFormatList(){    return qToStringList(QPictureIO::outputFormats());}/*!    Returns a list of picture formats that are supported for picture    output.    \sa inputFormats() outputFormatList() QPictureIO*/QList<QByteArray> QPicture::outputFormats(){    return QPictureIO::outputFormats();}/*****************************************************************************  QPictureIO member functions *****************************************************************************//*!    \class QPictureIO qpicture.h    \brief The QPictureIO class contains parameters for loading and    saving pictures.    \ingroup multimedia    \ingroup io    QPictureIO contains a QIODevice object that is used for picture data    I/O. The programmer can install new picture file formats in addition    to those that Qt provides.    You don't normally need to use this class; QPicture::load(),    QPicture::save().    \sa QPicture QPixmap QFile*/struct QPictureIOData{    QPicture        pi;                                // picture    int                iostat;                                // IO status    QByteArray        frmt;                                // picture format    QIODevice  *iodev;                                // IO device    QString        fname;                                // file name    QString     descr;                                // picture description    const char *parameters;    int quality;    float gamma;};/*!    Constructs a QPictureIO object with all parameters set to zero.*/QPictureIO::QPictureIO(){    init();}/*!    Constructs a QPictureIO object with the I/O device \a ioDevice and a    \a format tag.*/QPictureIO::QPictureIO(QIODevice *ioDevice, const char *format){    init();    d->iodev = ioDevice;    d->frmt = format;}/*!    Constructs a QPictureIO object with the file name \a fileName and a    \a format tag.*/QPictureIO::QPictureIO(const QString &fileName, const char* format){    init();    d->frmt = format;    d->fname = fileName;}/*!    Contains initialization common to all QPictureIO constructors.*/void QPictureIO::init(){    d = new QPictureIOData();    d->parameters = 0;    d->quality = -1; // default quality of the current format    d->gamma=0.0f;    d->iostat = 0;    d->iodev  = 0;}/*!    Destroys the object and all related data.*/QPictureIO::~QPictureIO(){    if (d->parameters)        delete [] (char*)d->parameters;    delete d;}/*****************************************************************************  QPictureIO picture handler functions *****************************************************************************/class QPictureHandler{public:    QPictureHandler(const char *f, const char *h, const QByteArray& fl,                     picture_io_handler r, picture_io_handler w);    QByteArray              format;                        // picture format    QRegExp              header;                        // picture header pattern    enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode;    picture_io_handler  read_picture;                // picture read function    picture_io_handler  write_picture;                // picture write function    bool              obsolete;                        // support not "published"};QPictureHandler::QPictureHandler(const char *f, const char *h, const QByteArray& fl,                              picture_io_handler r, picture_io_handler w)    : format(f), header(QString::fromLatin1(h)){    text_mode = Untranslated;    if (fl.contains('t'))        text_mode = TranslateIn;    else if (fl.contains('T'))        text_mode = TranslateInOut;    obsolete = fl.contains('O');    read_picture  = r;    write_picture = w;}typedef QList<QPictureHandler *> QPHList;static QPHList pictureHandlers;#ifndef QT_NO_LIBRARYQ_GLOBAL_STATIC(QMutex, mutex)Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,                          (QPictureFormatInterface_iid,                           QCoreApplication::libraryPaths(),                           "/pictureformats"))#endifvoid qt_init_picture_plugins(){#ifndef QT_NO_LIBRARY    QMutexLocker locker(mutex());    QFactoryLoader *loader = ::loader();    QStringList keys = loader->keys();    for (int i = 0; i < keys.count(); ++i)        if (QPictureFormatInterface *format = qobject_cast<QPictureFormatInterface*>(loader->instance(keys.at(i))))            format->installIOHandler(keys.at(i));#endif}static void cleanup(){    // make sure that picture handlers are delete before plugin manager    while (!pictureHandlers.isEmpty())        delete pictureHandlers.takeFirst();}void qt_init_picture_handlers()                // initialize picture handlers{    static bool done = false;    if (done) return;    done = true;    qAddPostRoutine(cleanup);}static QPictureHandler *get_picture_handler(const char *format){                                                // get pointer to handler    qt_init_picture_handlers();    qt_init_picture_plugins();    for (int i = 0; i < pictureHandlers.size(); ++i) {        if (pictureHandlers.at(i)->format == format)            return pictureHandlers.at(i);    }    return 0;                                        // no such handler}/*!    Defines a picture I/O handler for the picture format called \a    format, which is recognized using the regular    expression defined in \a header, read using \a readPicture and    written using \a writePicture.    \a flags is a string of single-character flags for this format.    The only flag defined currently is T (upper case), so the only    legal value for \a flags are "T" and the empty string. The "T"    flag means that the picture file is a text file, and Qt should treat    all newline conventions as equivalent. (XPM files and some PPM    files are text files for example.)    \a format is used to select a handler to write a QPicture; \a header    is used to select a handler to read an picture file.    If \a readPicture is a null pointer, the QPictureIO will not be able    to read pictures in \a format. If \a writePicture is a null pointer,    the QPictureIO will not be able to write pictures in \a format. If    both are null, the QPictureIO object is valid but useless.    Example:    \quotefromfile snippets/picture/picture.cpp    \skipto SVG READ    \skipto readSVG    \printuntil }    \skipto SVG WRITE    \skipto writeSVG    \printuntil }    \skipto USE SVG    \skipto add    \printuntil ...    Before the regulare expression test, all the 0 bytes in the file header are    converted to 1 bytes. This is done because when Qt was ASCII-based, QRegExp    could not handle 0 bytes in strings.    The regexp is only applied on the first 14 bytes of the file.    (Note that if one handlerIO supports writing a format and another    supports reading it, Qt supports both reading and writing. If two    handlers support the same operation, Qt chooses one arbitrarily.)*/void QPictureIO::defineIOHandler(const char *format,                                const char *header,                                const char *flags,                                picture_io_handler readPicture,                                picture_io_handler writePicture){    qt_init_picture_handlers();    QPictureHandler *p;    p = new QPictureHandler(format, header, QByteArray(flags), readPicture, writePicture);    pictureHandlers.prepend(p);}/*****************************************************************************  QPictureIO normal member functions *****************************************************************************//*!    Returns the picture currently set.    \sa setPicture()*/const QPicture &QPictureIO::picture() const { return d->pi; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -