src/gui/image/qbmphandler.cpp File Reference

#include "private/qbmphandler_p.h"
#include <qimage.h>
#include <qvariant.h>
#include <qvector.h>

Include dependency graph for qbmphandler.cpp:

Go to the source code of this file.

Functions

static void swapPixel01 (QImage *image)
QDataStreamoperator>> (QDataStream &s, BMP_FILEHDR &bf)
QDataStreamoperator<< (QDataStream &s, const BMP_FILEHDR &bf)
QDataStreamoperator>> (QDataStream &s, BMP_INFOHDR &bi)
QDataStreamoperator<< (QDataStream &s, const BMP_INFOHDR &bi)
static int calc_shift (int mask)
static bool read_dib_fileheader (QDataStream &s, BMP_FILEHDR &bf)
static bool read_dib_infoheader (QDataStream &s, BMP_INFOHDR &bi)
static bool read_dib_body (QDataStream &s, const BMP_INFOHDR &bi, int offset, int startpos, QImage &image)
bool qt_write_dib (QDataStream &s, QImage image)
bool qt_read_dib (QDataStream &s, QImage &image)

Variables

const int BMP_FILEHDR_SIZE = 14
const int BMP_OLD = 12
const int BMP_WIN = 40
const int BMP_OS2 = 64
const int BMP_RGB = 0
const int BMP_RLE8 = 1
const int BMP_RLE4 = 2
const int BMP_BITFIELDS = 3


Function Documentation

static int calc_shift ( int  mask  )  [static]

Definition at line 124 of file qbmphandler.cpp.

Referenced by read_dib_body().

00125 {
00126     int result = 0;
00127     while (!(mask & 1)) {
00128         result++;
00129         mask >>= 1;
00130     }
00131     return result;
00132 }

QDataStream& operator<< ( QDataStream s,
const BMP_INFOHDR bi 
)

Definition at line 111 of file qbmphandler.cpp.

References BMP_INFOHDR::biBitCount, BMP_INFOHDR::biClrImportant, BMP_INFOHDR::biClrUsed, BMP_INFOHDR::biCompression, BMP_INFOHDR::biHeight, BMP_INFOHDR::biPlanes, BMP_INFOHDR::biSize, BMP_INFOHDR::biSizeImage, BMP_INFOHDR::biWidth, BMP_INFOHDR::biXPelsPerMeter, BMP_INFOHDR::biYPelsPerMeter, and s.

00112 {
00113     s << bi.biSize;
00114     s << bi.biWidth << bi.biHeight;
00115     s << bi.biPlanes;
00116     s << bi.biBitCount;
00117     s << bi.biCompression;
00118     s << bi.biSizeImage;
00119     s << bi.biXPelsPerMeter << bi.biYPelsPerMeter;
00120     s << bi.biClrUsed << bi.biClrImportant;
00121     return s;
00122 }

QDataStream& operator<< ( QDataStream s,
const BMP_FILEHDR bf 
)

Definition at line 71 of file qbmphandler.cpp.

References BMP_FILEHDR::bfOffBits, BMP_FILEHDR::bfReserved1, BMP_FILEHDR::bfReserved2, BMP_FILEHDR::bfSize, BMP_FILEHDR::bfType, and s.

00072 {                                                // write file header
00073     s.writeRawData(bf.bfType, 2);
00074     s << bf.bfSize << bf.bfReserved1 << bf.bfReserved2 << bf.bfOffBits;
00075     return s;
00076 }

QDataStream& operator>> ( QDataStream s,
BMP_INFOHDR bi 
)

Definition at line 89 of file qbmphandler.cpp.

References BMP_INFOHDR::biBitCount, BMP_INFOHDR::biClrImportant, BMP_INFOHDR::biClrUsed, BMP_INFOHDR::biCompression, BMP_INFOHDR::biHeight, BMP_INFOHDR::biPlanes, BMP_INFOHDR::biSize, BMP_INFOHDR::biSizeImage, BMP_INFOHDR::biWidth, BMP_INFOHDR::biXPelsPerMeter, BMP_INFOHDR::biYPelsPerMeter, BMP_OS2, BMP_RGB, BMP_WIN, h, s, and w.

00090 {
00091     s >> bi.biSize;
00092     if (bi.biSize == BMP_WIN || bi.biSize == BMP_OS2) {
00093         s >> bi.biWidth >> bi.biHeight >> bi.biPlanes >> bi.biBitCount;
00094         s >> bi.biCompression >> bi.biSizeImage;
00095         s >> bi.biXPelsPerMeter >> bi.biYPelsPerMeter;
00096         s >> bi.biClrUsed >> bi.biClrImportant;
00097     }
00098     else {                                        // probably old Windows format
00099         qint16 w, h;
00100         s >> w >> h >> bi.biPlanes >> bi.biBitCount;
00101         bi.biWidth  = w;
00102         bi.biHeight = h;
00103         bi.biCompression = BMP_RGB;                // no compression
00104         bi.biSizeImage = 0;
00105         bi.biXPelsPerMeter = bi.biYPelsPerMeter = 0;
00106         bi.biClrUsed = bi.biClrImportant = 0;
00107     }
00108     return s;
00109 }

QDataStream& operator>> ( QDataStream s,
BMP_FILEHDR bf 
)

Definition at line 64 of file qbmphandler.cpp.

References BMP_FILEHDR::bfOffBits, BMP_FILEHDR::bfReserved1, BMP_FILEHDR::bfReserved2, BMP_FILEHDR::bfSize, BMP_FILEHDR::bfType, and s.

00065 {                                                // read file header
00066     s.readRawData(bf.bfType, 2);
00067     s >> bf.bfSize >> bf.bfReserved1 >> bf.bfReserved2 >> bf.bfOffBits;
00068     return s;
00069 }

bool qt_read_dib ( QDataStream s,
QImage image 
)

Definition at line 641 of file qbmphandler.cpp.

References BMP_FILEHDR_SIZE, image, read_dib_body(), read_dib_infoheader(), and s.

00642 {
00643     BMP_INFOHDR bi;
00644     if (!read_dib_infoheader(s, bi))
00645         return false;
00646     return read_dib_body(s, bi, -1, -BMP_FILEHDR_SIZE, image);
00647 }

Here is the call graph for this function:

bool qt_write_dib ( QDataStream s,
QImage  image 
)

Definition at line 521 of file qbmphandler.cpp.

References b, BMP_INFOHDR::biBitCount, BMP_INFOHDR::biClrImportant, BMP_INFOHDR::biClrUsed, BMP_INFOHDR::biCompression, BMP_INFOHDR::biHeight, BMP_INFOHDR::biPlanes, BMP_INFOHDR::biSize, BMP_INFOHDR::biSizeImage, BMP_INFOHDR::biWidth, BMP_INFOHDR::biXPelsPerMeter, BMP_INFOHDR::biYPelsPerMeter, BMP_RGB, BMP_WIN, buf, c, d, QImage::Format_Mono, QImage::Format_MonoLSB, i, image, nbits, QDataStream::Ok, p, QColor::qBlue(), QColor::qGreen(), QColor::qRed(), QColor::QRgb(), rgb, s, and y.

Referenced by QBmpHandler::write().

00522 {
00523     int        nbits;
00524     int        bpl_bmp;
00525     int        bpl = image.bytesPerLine();
00526 
00527     QIODevice* d = s.device();
00528     if (!d->isWritable())
00529         return false;
00530 
00531     if (image.depth() == 8 && image.numColors() <= 16) {
00532         bpl_bmp = (((bpl+1)/2+3)/4)*4;
00533         nbits = 4;
00534     } else if (image.depth() == 32) {
00535         bpl_bmp = ((image.width()*24+31)/32)*4;
00536         nbits = 24;
00537 #ifdef Q_WS_QWS
00538     } else if (image.depth() == 1 || image.depth() == 8) {
00539         // Qt/E doesn't word align.
00540         bpl_bmp = ((image.width()*image.depth()+31)/32)*4;
00541         nbits = image.depth();
00542 #endif
00543     } else {
00544         bpl_bmp = bpl;
00545         nbits = image.depth();
00546     }
00547 
00548     BMP_INFOHDR bi;
00549     bi.biSize               = BMP_WIN;                // build info header
00550     bi.biWidth               = image.width();
00551     bi.biHeight               = image.height();
00552     bi.biPlanes               = 1;
00553     bi.biBitCount      = nbits;
00554     bi.biCompression   = BMP_RGB;
00555     bi.biSizeImage     = bpl_bmp*image.height();
00556     bi.biXPelsPerMeter = image.dotsPerMeterX() ? image.dotsPerMeterX()
00557                                                 : 2834; // 72 dpi default
00558     bi.biYPelsPerMeter = image.dotsPerMeterY() ? image.dotsPerMeterY() : 2834;
00559     bi.biClrUsed       = image.numColors();
00560     bi.biClrImportant  = image.numColors();
00561     s << bi;                                        // write info header
00562     if (s.status() != QDataStream::Ok)
00563         return false;
00564 
00565     if (image.depth() != 32) {                // write color table
00566         uchar *color_table = new uchar[4*image.numColors()];
00567         uchar *rgb = color_table;
00568         QVector<QRgb> c = image.colorTable();
00569         for (int i=0; i<image.numColors(); i++) {
00570             *rgb++ = qBlue (c[i]);
00571             *rgb++ = qGreen(c[i]);
00572             *rgb++ = qRed  (c[i]);
00573             *rgb++ = 0;
00574         }
00575         if (d->write((char *)color_table, 4*image.numColors()) == -1) {
00576             delete [] color_table;
00577             return false;
00578         }
00579         delete [] color_table;
00580     }
00581 
00582     if (image.format() == QImage::Format_MonoLSB)
00583         image = image.convertToFormat(QImage::Format_Mono);
00584 
00585     int y;
00586 
00587     if (nbits == 1 || nbits == 8) {                // direct output
00588 #ifdef Q_WS_QWS
00589         // Qt/E doesn't word align.
00590         int pad = bpl_bmp - bpl;
00591         char padding[4];
00592 #endif
00593         for (y=image.height()-1; y>=0; y--) {
00594             if (d->write((char*)image.scanLine(y), bpl) == -1)
00595                 return false;
00596 #ifdef Q_WS_QWS
00597             if (d->write(padding, pad) == -1)
00598                 return false;
00599 #endif
00600         }
00601         return true;
00602     }
00603 
00604     uchar *buf        = new uchar[bpl_bmp];
00605     uchar *b, *end;
00606     register uchar *p;
00607 
00608     memset(buf, 0, bpl_bmp);
00609     for (y=image.height()-1; y>=0; y--) {        // write the image bits
00610         if (nbits == 4) {                        // convert 8 -> 4 bits
00611             p = image.scanLine(y);
00612             b = buf;
00613             end = b + image.width()/2;
00614             while (b < end) {
00615                 *b++ = (*p << 4) | (*(p+1) & 0x0f);
00616                 p += 2;
00617             }
00618             if (image.width() & 1)
00619                 *b = *p << 4;
00620         } else {                                // 32 bits
00621             QRgb *p   = (QRgb *)image.scanLine(y);
00622             QRgb *end = p + image.width();
00623             b = buf;
00624             while (p < end) {
00625                 *b++ = qBlue(*p);
00626                 *b++ = qGreen(*p);
00627                 *b++ = qRed(*p);
00628                 p++;
00629             }
00630         }
00631         if (bpl_bmp != d->write((char*)buf, bpl_bmp)) {
00632             delete[] buf;
00633             return false;
00634         }
00635     }
00636     delete[] buf;
00637     return true;
00638 }

Here is the call graph for this function:

static bool read_dib_body ( QDataStream s,
const BMP_INFOHDR bi,
int  offset,
int  startpos,
QImage image 
) [static]

Definition at line 166 of file qbmphandler.cpp.

References b, BMP_INFOHDR::biBitCount, BMP_INFOHDR::biClrImportant, BMP_INFOHDR::biClrUsed, BMP_INFOHDR::biCompression, BMP_INFOHDR::biHeight, BMP_INFOHDR::biPlanes, BMP_INFOHDR::biSize, BMP_INFOHDR::biSizeImage, BMP_INFOHDR::biWidth, BMP_INFOHDR::biXPelsPerMeter, BMP_INFOHDR::biYPelsPerMeter, BMP_BITFIELDS, BMP_FILEHDR_SIZE, BMP_OLD, BMP_RGB, BMP_RLE4, BMP_RLE8, buf, c, calc_shift(), d, data, QImage::Format_Indexed8, QImage::Format_Mono, QImage::Format_RGB32, h, i, image, nbits, p, qDebug(), QColor::qGray(), QColor::QRgb(), QColor::qRgb(), rgb, s, swapPixel01(), t, w, x, and y.

Referenced by qt_read_dib(), and QBmpHandler::read().

00167 {
00168     QIODevice* d = s.device();
00169     if (d->atEnd())                                // end of stream/file
00170         return false;
00171 #if 0
00172     qDebug("offset...........%d", offset);
00173     qDebug("startpos.........%d", startpos);
00174     qDebug("biSize...........%d", bi.biSize);
00175     qDebug("biWidth..........%d", bi.biWidth);
00176     qDebug("biHeight.........%d", bi.biHeight);
00177     qDebug("biPlanes.........%d", bi.biPlanes);
00178     qDebug("biBitCount.......%d", bi.biBitCount);
00179     qDebug("biCompression....%d", bi.biCompression);
00180     qDebug("biSizeImage......%d", bi.biSizeImage);
00181     qDebug("biXPelsPerMeter..%d", bi.biXPelsPerMeter);
00182     qDebug("biYPelsPerMeter..%d", bi.biYPelsPerMeter);
00183     qDebug("biClrUsed........%d", bi.biClrUsed);
00184     qDebug("biClrImportant...%d", bi.biClrImportant);
00185 #endif
00186     int w = bi.biWidth,         h = bi.biHeight,  nbits = bi.biBitCount;
00187     int t = bi.biSize,         comp = bi.biCompression;
00188     int red_mask = 0;
00189     int green_mask = 0;
00190     int blue_mask = 0;
00191     int red_shift = 0;
00192     int green_shift = 0;
00193     int blue_shift = 0;
00194     int red_scale = 0;
00195     int green_scale = 0;
00196     int blue_scale = 0;
00197 
00198     int ncols = 0;
00199     int depth = 0;
00200     QImage::Format format;
00201     switch (nbits) {
00202         case 32:
00203         case 24:
00204         case 16:
00205             depth = 32;
00206             format = QImage::Format_RGB32;
00207             break;
00208         case 8:
00209         case 4:
00210             depth = 8;
00211             format = QImage::Format_Indexed8;
00212             break;
00213         default:
00214             depth = 1;
00215             format = QImage::Format_Mono;
00216     }
00217 
00218     if (bi.biHeight < 0)
00219         h = -h;                  // support images with negative height
00220 
00221     if (image.size() != QSize(w, h) || image.format() != format) {
00222         image = QImage(w, h, format);
00223         if (image.isNull())                        // could not create image
00224             return false;
00225     }
00226 
00227     if (depth != 32) {
00228         ncols = bi.biClrUsed ? bi.biClrUsed : 1 << nbits;
00229         image.setNumColors(ncols);
00230     }
00231 
00232     image.setDotsPerMeterX(bi.biXPelsPerMeter);
00233     image.setDotsPerMeterY(bi.biYPelsPerMeter);
00234 
00235     if (!d->isSequential())
00236         d->seek(startpos + BMP_FILEHDR_SIZE + bi.biSize); // goto start of colormap
00237 
00238     if (ncols > 0) {                                // read color table
00239         uchar rgb[4];
00240         int   rgb_len = t == BMP_OLD ? 3 : 4;
00241         for (int i=0; i<ncols; i++) {
00242             if (d->read((char *)rgb, rgb_len) != rgb_len)
00243                 return false;
00244             image.setColor(i, qRgb(rgb[2],rgb[1],rgb[0]));
00245             if (d->atEnd())                        // truncated file
00246                 return false;
00247         }
00248     } else if (comp == BMP_BITFIELDS && (nbits == 16 || nbits == 32)) {
00249         if (d->read((char *)&red_mask, sizeof(red_mask)) != sizeof(red_mask))
00250             return false;
00251         if (d->read((char *)&green_mask, sizeof(green_mask)) != sizeof(green_mask))
00252             return false;
00253         if (d->read((char *)&blue_mask, sizeof(blue_mask)) != sizeof(blue_mask))
00254             return false;
00255         red_shift = calc_shift(red_mask);
00256         red_scale = 256 / ((red_mask >> red_shift) + 1);
00257         green_shift = calc_shift(green_mask);
00258         green_scale = 256 / ((green_mask >> green_shift) + 1);
00259         blue_shift = calc_shift(blue_mask);
00260         blue_scale = 256 / ((blue_mask >> blue_shift) + 1);
00261     } else if (comp == BMP_RGB && (nbits == 24 || nbits == 32)) {
00262         blue_mask = 0x000000ff;
00263         green_mask = 0x0000ff00;
00264         red_mask = 0x00ff0000;
00265         blue_shift = 0;
00266         green_shift = 8;
00267         red_shift = 16;
00268         blue_scale = green_scale = red_scale = 1;
00269     } else if (comp == BMP_RGB && nbits == 16) {
00270         blue_mask = 0x001f;
00271         green_mask = 0x03e0;
00272         red_mask = 0x7c00;
00273         blue_shift = 0;
00274         green_shift = 2;
00275         red_shift = 7;
00276         red_scale = 1;
00277         green_scale = 1;
00278         blue_scale = 8;
00279     }
00280 
00281     // offset can be bogus, be careful
00282     if (offset>=0 && startpos + offset > d->pos()) {
00283         if (!d->isSequential())
00284             d->seek(startpos + offset);                // start of image data
00285     }
00286 
00287     int             bpl = image.bytesPerLine();
00288 #ifdef Q_WS_QWS
00289     //
00290     // Guess the number of bytes-per-line if we don't know how much
00291     // image data is in the file (bogus image ?).
00292     //
00293     int bmpbpl = (bi.biHeight > 0 ? (bi.biSizeImage > 0 ?
00294                                      bi.biSizeImage / bi.biHeight :
00295                                      (d->size() - offset) / bi.biHeight)
00296                                   : 0);
00297     int pad = bmpbpl-bpl;
00298 #endif
00299     uchar *data = image.bits();
00300 
00301     if (nbits == 1) {                                // 1 bit BMP image
00302         while (--h >= 0) {
00303             if (d->read((char*)(data + h*bpl), bpl) != bpl)
00304                 break;
00305 #ifdef Q_WS_QWS
00306             if (pad > 0) {
00307                 if (!d->isSequential())
00308                     d->seek(d->pos()+pad);
00309             }
00310 #endif
00311         }
00312         if (ncols == 2 && qGray(image.color(0)) < qGray(image.color(1)))
00313             swapPixel01(&image);                // pixel 0 is white!
00314     }
00315 
00316     else if (nbits == 4) {                        // 4 bit BMP image
00317         int    buflen = ((w+7)/8)*4;
00318         uchar *buf    = new uchar[buflen];
00319         if (comp == BMP_RLE4) {                // run length compression
00320             int x=0, y=0, c, i;
00321             quint8 b;
00322             register uchar *p = data + (h-1)*bpl;
00323             const uchar *endp = p + w;
00324             while (y < h) {
00325                 if (!d->getChar((char *)&b))
00326                     break;
00327                 if (b == 0) {                        // escape code
00328                     if (!d->getChar((char *)&b) || b == 1) {
00329                         y = h;                // exit loop
00330                     } else switch (b) {
00331                         case 0:                        // end of line
00332                             x = 0;
00333                             y++;
00334                             p = data + (h-y-1)*bpl;
00335                             break;
00336                         case 2:                        // delta (jump)
00337                         {
00338                             quint8 tmp;
00339                             d->getChar((char *)&tmp);
00340                             x += tmp;
00341                             d->getChar((char *)&tmp);
00342                             y += tmp;
00343                         }
00344 
00345                             // Protection
00346                             if ((uint)x >= (uint)w)
00347                                 x = w-1;
00348                             if ((uint)y >= (uint)h)
00349                                 y = h-1;
00350 
00351                             p = data + (h-y-1)*bpl + x;
00352                             break;
00353                         default:                // absolute mode
00354                             // Protection
00355                             if (p + b > endp)
00356                                 b = endp-p;
00357 
00358                             i = (c = b)/2;
00359                             while (i--) {
00360                                 d->getChar((char *)&b);
00361                                 *p++ = b >> 4;
00362                                 *p++ = b & 0x0f;
00363                             }
00364                             if (c & 1) {
00365                                 unsigned char tmp;
00366                                 d->getChar((char *)&tmp);
00367                                 *p++ = tmp >> 4;
00368                             }
00369                             if ((((c & 3) + 1) & 2) == 2)
00370                                 d->getChar(0);        // align on word boundary
00371                             x += c;
00372                     }
00373                 } else {                        // encoded mode
00374                     // Protection
00375                     if (p + b > endp)
00376                         b = endp-p;
00377 
00378                     i = (c = b)/2;
00379                     d->getChar((char *)&b);                // 2 pixels to be repeated
00380                     while (i--) {
00381                         *p++ = b >> 4;
00382                         *p++ = b & 0x0f;
00383                     }
00384                     if (c & 1)
00385                         *p++ = b >> 4;
00386                     x += c;
00387                 }
00388             }
00389         } else if (comp == BMP_RGB) {                // no compression
00390             while (--h >= 0) {
00391                 if (d->read((char*)buf,buflen) != buflen)
00392                     break;
00393                 register uchar *p = data + h*bpl;
00394                 uchar *b = buf;
00395                 for (int i=0; i<w/2; i++) {        // convert nibbles to bytes
00396                     *p++ = *b >> 4;
00397                     *p++ = *b++ & 0x0f;
00398                 }
00399                 if (w & 1)                        // the last nibble
00400                     *p = *b >> 4;
00401             }
00402         }
00403         delete [] buf;
00404     }
00405 
00406     else if (nbits == 8) {                        // 8 bit BMP image
00407         if (comp == BMP_RLE8) {                // run length compression
00408             int x=0, y=0;
00409             quint8 b;
00410             register uchar *p = data + (h-1)*bpl;
00411             const uchar *endp = p + w;
00412             while (y < h) {
00413                 if (!d->getChar((char *)&b))
00414                     break;
00415                 if (b == 0) {                        // escape code
00416                     if (!d->getChar((char *)&b) || b == 1) {
00417                             y = h;                // exit loop
00418                     } else switch (b) {
00419                         case 0:                        // end of line
00420                             x = 0;
00421                             y++;
00422                             p = data + (h-y-1)*bpl;
00423                             break;
00424                         case 2:                        // delta (jump)
00425                             // Protection
00426                             if ((uint)x >= (uint)w)
00427                                 x = w-1;
00428                             if ((uint)y >= (uint)h)
00429                                 y = h-1;
00430 
00431                             {
00432                                 quint8 tmp;
00433                                 d->getChar((char *)&tmp);
00434                                 x += tmp;
00435                                 d->getChar((char *)&tmp);
00436                                 y += tmp;
00437                             }
00438                             p = data + (h-y-1)*bpl + x;
00439                             break;
00440                         default:                // absolute mode
00441                             // Protection
00442                             if (p + b > endp)
00443                                 b = endp-p;
00444 
00445                             if (d->read((char *)p, b) != b)
00446                                 return false;
00447                             if ((b & 1) == 1)
00448                                 d->getChar(0);        // align on word boundary
00449                             x += b;
00450                             p += b;
00451                     }
00452                 } else {                        // encoded mode
00453                     // Protection
00454                     if (p + b > endp)
00455                         b = endp-p;
00456 
00457                     char tmp;
00458                     d->getChar(&tmp);
00459                     memset(p, tmp, b); // repeat pixel
00460                     x += b;
00461                     p += b;
00462                 }
00463             }
00464         } else if (comp == BMP_RGB) {                // uncompressed
00465             while (--h >= 0) {
00466                 if (d->read((char *)data + h*bpl, bpl) != bpl)
00467                     break;
00468 #ifdef Q_WS_QWS
00469                 if (pad > 0) {
00470                     if (!d->isSequential())
00471                         d->seek(d->pos()+pad);
00472                 }
00473 #endif
00474             }
00475         }
00476     }
00477 
00478     else if (nbits == 16 || nbits == 24 || nbits == 32) { // 16,24,32 bit BMP image
00479         register QRgb *p;
00480         QRgb  *end;
00481         uchar *buf24 = new uchar[bpl];
00482         int    bpl24 = ((w*nbits+31)/32)*4;
00483         uchar *b;
00484         int c;
00485 
00486         while (--h >= 0) {
00487             p = (QRgb *)(data + h*bpl);
00488             end = p + w;
00489             if (d->read((char *)buf24,bpl24) != bpl24)
00490                 break;
00491             b = buf24;
00492             while (p < end) {
00493                 c = *(uchar*)b | (*(uchar*)(b+1)<<8);
00494                 if (nbits != 16)
00495                     c |= *(uchar*)(b+2)<<16;
00496                 *p++ = qRgb(((c & red_mask) >> red_shift) * red_scale,
00497                                         ((c & green_mask) >> green_shift) * green_scale,
00498                                         ((c & blue_mask) >> blue_shift) * blue_scale);
00499                 b += nbits/8;
00500             }
00501         }
00502         delete[] buf24;
00503     }
00504 
00505     if (bi.biHeight < 0) {
00506         // Flip the image
00507         uchar *buf = new uchar[bpl];
00508         h = -bi.biHeight;
00509         for (int y = 0; y < h/2; ++y) {
00510             memcpy(buf, data + y*bpl, bpl);
00511             memcpy(data + y*bpl, data + (h-y-1)*bpl, bpl);
00512             memcpy(data + (h-y-1)*bpl, buf, bpl);
00513         }
00514         delete [] buf;
00515     }
00516 
00517     return true;
00518 }

Here is the call graph for this function:

static bool read_dib_fileheader ( QDataStream s,
BMP_FILEHDR bf 
) [static]

Definition at line 134 of file qbmphandler.cpp.

References QDataStream::Ok, QByteArray::qstrncmp(), and s.

Referenced by QBmpHandler::readHeader().

00135 {
00136     // read BMP file header
00137     s >> bf;
00138     if (s.status() != QDataStream::Ok)
00139         return false;
00140 
00141     // check header
00142     if (qstrncmp(bf.bfType,"BM",2) != 0)
00143         return false;
00144 
00145     return true;
00146 }

Here is the call graph for this function:

static bool read_dib_infoheader ( QDataStream s,
BMP_INFOHDR bi 
) [static]

Definition at line 148 of file qbmphandler.cpp.

References BMP_BITFIELDS, BMP_RGB, BMP_RLE4, BMP_RLE8, nbits, QDataStream::Ok, and s.

Referenced by qt_read_dib(), and QBmpHandler::readHeader().

00149 {
00150     s >> bi;                                        // read BMP info header
00151     if (s.status() != QDataStream::Ok)
00152         return false;
00153 
00154     int nbits = bi.biBitCount;
00155     int comp = bi.biCompression;
00156     if (!(nbits == 1 || nbits == 4 || nbits == 8 || nbits == 16 || nbits == 24 || nbits == 32) ||
00157         bi.biPlanes != 1 || comp > BMP_BITFIELDS)
00158         return false;                                        // weird BMP image
00159     if (!(comp == BMP_RGB || (nbits == 4 && comp == BMP_RLE4) ||
00160         (nbits == 8 && comp == BMP_RLE8) || ((nbits == 16 || nbits == 32) && comp == BMP_BITFIELDS)))
00161          return false;                                // weird compression type
00162 
00163     return true;
00164 }

static void swapPixel01 ( QImage image  )  [static]

Definition at line 32 of file qbmphandler.cpp.

References i, image, p, QColor::QRgb(), and t.

Referenced by read_dib_body().

00032                                                       : swap 0 and 1 pixels
00033 {
00034     int i;
00035     if (image->depth() == 1 && image->numColors() == 2) {
00036         register uint *p = (uint *)image->bits();
00037         int nbytes = image->numBytes();
00038         for (i=0; i<nbytes/4; i++) {
00039             *p = ~*p;
00040             p++;
00041         }
00042         uchar *p2 = (uchar *)p;
00043         for (i=0; i<(nbytes&3); i++) {
00044             *p2 = ~*p2;
00045             p2++;
00046         }
00047         QRgb t = image->color(0);                // swap color 0 and 1
00048         image->setColor(0, image->color(1));
00049         image->setColor(1, t);
00050     }
00051 }

Here is the call graph for this function:


Variable Documentation

const int BMP_BITFIELDS = 3

Definition at line 86 of file qbmphandler.cpp.

Referenced by read_dib_body(), and read_dib_infoheader().

const int BMP_FILEHDR_SIZE = 14

Definition at line 62 of file qbmphandler.cpp.

Referenced by qt_read_dib(), read_dib_body(), and QBmpHandler::write().

const int BMP_OLD = 12

Definition at line 79 of file qbmphandler.cpp.

Referenced by read_dib_body().

const int BMP_OS2 = 64

Definition at line 81 of file qbmphandler.cpp.

Referenced by operator>>().

const int BMP_RGB = 0

Definition at line 83 of file qbmphandler.cpp.

Referenced by operator>>(), qt_write_dib(), read_dib_body(), and read_dib_infoheader().

const int BMP_RLE4 = 2

Definition at line 85 of file qbmphandler.cpp.

Referenced by read_dib_body(), and read_dib_infoheader().

const int BMP_RLE8 = 1

Definition at line 84 of file qbmphandler.cpp.

Referenced by read_dib_body(), and read_dib_infoheader().

const int BMP_WIN = 40

Definition at line 80 of file qbmphandler.cpp.

Referenced by operator>>(), qt_write_dib(), and QBmpHandler::write().


Generated on Thu Mar 15 13:18:23 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1