42 #include "private/qbmphandler_p.h" 44 #ifndef QT_NO_IMAGEFORMAT_BMP 58 for (i=0; i<nbytes/4; i++) {
63 for (i=0; i<(nbytes&3); i++) {
149 while (mask && !(mask & 1)) {
164 if (
qstrncmp(bf.bfType,
"BM",2) != 0)
177 int comp = bi.biCompression;
178 if (!(nbits == 1 || nbits == 4 || nbits == 8 || nbits == 16 || nbits == 24 || nbits == 32) ||
194 qDebug(
"offset...........%d", offset);
195 qDebug(
"startpos.........%d", startpos);
244 image =
QImage(w, h, format);
263 if (d->
read((
char *)&red_mask,
sizeof(red_mask)) !=
sizeof(red_mask))
265 if (d->
read((
char *)&green_mask,
sizeof(green_mask)) !=
sizeof(green_mask))
267 if (d->
read((
char *)&blue_mask,
sizeof(blue_mask)) !=
sizeof(blue_mask))
279 if (d->
read((
char *)&alpha_mask,
sizeof(alpha_mask)) !=
sizeof(alpha_mask))
281 if (d->
read((
char *)&CSType,
sizeof(CSType)) !=
sizeof(CSType))
283 if (d->
read((
char *)&endpoints,
sizeof(endpoints)) !=
sizeof(endpoints))
285 if (d->
read((
char *)&gamma_red,
sizeof(gamma_red)) !=
sizeof(gamma_red))
287 if (d->
read((
char *)&gamma_green,
sizeof(gamma_green)) !=
sizeof(gamma_green))
289 if (d->
read((
char *)&gamma_blue,
sizeof(gamma_blue)) !=
sizeof(gamma_blue))
298 if (d->
read((
char *)&intent,
sizeof(intent)) !=
sizeof(intent))
300 if (d->
read((
char *)&profileData,
sizeof(profileData)) !=
sizeof(profileData))
302 if (d->
read((
char *)&profileSize,
sizeof(profileSize)) !=
sizeof(profileSize))
304 if (d->
read((
char *)&reserved,
sizeof(reserved)) !=
sizeof(reserved) || reserved != 0)
312 int rgb_len = t ==
BMP_OLD ? 3 : 4;
313 for (
int i=0; i<ncols; i++) {
314 if (d->
read((
char *)rgb, rgb_len) != rgb_len)
320 }
else if (comp ==
BMP_BITFIELDS && (nbits == 16 || nbits == 32)) {
322 red_scale = 256 / ((red_mask >> red_shift) + 1);
324 green_scale = 256 / ((green_mask >> green_shift) + 1);
326 blue_scale = 256 / ((blue_mask >> blue_shift) + 1);
327 }
else if (comp ==
BMP_RGB && (nbits == 24 || nbits == 32)) {
328 blue_mask = 0x000000ff;
329 green_mask = 0x0000ff00;
330 red_mask = 0x00ff0000;
334 blue_scale = green_scale = red_scale = 1;
335 }
else if (comp ==
BMP_RGB && nbits == 16) {
348 if (offset>=0 && startpos + offset > d->
pos()) {
350 d->
seek(startpos + offset);
358 if (d->
read((
char*)(data + h*bpl), bpl) != bpl)
365 else if (nbits == 4) {
366 int buflen = ((w+7)/8)*4;
371 register uchar *p = data + (h-1)*bpl;
372 const uchar *endp = p + w;
377 if (!d->
getChar((
char *)&b) || b == 1) {
383 p = data + (h-y-1)*bpl;
400 p = data + (h-y-1)*bpl + x;
418 if ((((
c & 3) + 1) & 2) == 2)
439 memset(data, 0, h*bpl);
441 if (d->
read((
char*)buf,buflen) != buflen)
443 register uchar *p = data + h*bpl;
445 for (
int i=0; i<w/2; i++) {
456 else if (nbits == 8) {
460 register uchar *p = data + (h-1)*bpl;
461 const uchar *endp = p + w;
466 if (!d->
getChar((
char *)&b) || b == 1) {
472 p = data + (h-y-1)*bpl;
488 p = data + (h-y-1)*bpl + x;
495 if (d->
read((
char *)p, b) != b)
516 if (d->
read((
char *)data + h*bpl, bpl) != bpl)
522 else if (nbits == 16 || nbits == 24 || nbits == 32) {
526 int bpl24 = ((w*nbits+31)/32)*4;
531 p = (
QRgb *)(data + h*bpl);
533 if (d->
read((
char *)buf24,bpl24) != bpl24)
539 c |= *(
uchar*)(b+2)<<16;
540 *p++ =
qRgb(((c & red_mask) >> red_shift) * red_scale,
541 ((c & green_mask) >> green_shift) * green_scale,
542 ((c & blue_mask) >> blue_shift) * blue_scale);
553 for (
int y = 0; y < h/2; ++y) {
554 memcpy(buf, data + y*bpl, bpl);
555 memcpy(data + y*bpl, data + (h-y-1)*bpl, bpl);
556 memcpy(data + (h-y-1)*bpl, buf, bpl);
576 bpl_bmp = (((bpl+1)/2+3)/4)*4;
578 }
else if (image.
depth() == 32) {
579 bpl_bmp = ((image.
width()*24+31)/32)*4;
582 }
else if (image.
depth() == 1 || image.
depth() == 8) {
584 bpl_bmp = ((image.
width()*image.
depth()+31)/32)*4;
585 nbits = image.
depth();
589 nbits = image.
depth();
609 if (image.
depth() != 32) {
614 *rgb++ =
qBlue (c[i]);
616 *rgb++ =
qRed (c[i]);
620 delete [] color_table;
623 delete [] color_table;
631 if (nbits == 1 || nbits == 8) {
634 int pad = bpl_bmp - bpl;
637 for (y=image.
height()-1; y>=0; y--) {
641 if (d->
write(padding, pad) == -1)
652 memset(buf, 0, bpl_bmp);
653 for (y=image.
height()-1; y>=0; y--) {
657 end = b + image.
width()/2;
659 *b++ = (*p << 4) | (*(p+1) & 0x0f);
662 if (image.
width() & 1)
675 if (bpl_bmp != d->
write((
char*)buf, bpl_bmp)) {
737 qWarning(
"QBmpHandler::canRead() called with 0 pointer");
742 if (device->
peek(head,
sizeof(head)) !=
sizeof(head))
745 return (
qstrncmp(head,
"BM", 2) == 0);
754 qWarning(
"QBmpHandler::read: cannot read into null pointer");
806 bpl_bmp = (((bpl+1)/2+3)/4)*4;
807 }
else if (image.
depth() == 32) {
808 bpl_bmp = ((image.
width()*24+31)/32)*4;
817 memcpy(bf.
bfType,
"BM", 2);
832 return option ==
Size 838 if (option ==
Size) {
881 #endif // QT_NO_IMAGEFORMAT_BMP The QVariant class acts like a union for the most common Qt data types.
Status status() const
Returns the status of the data stream.
void setOption(ImageOption option, const QVariant &value)
Sets the option option with the value value.
static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, int offset, int startpos, QImage &image)
Format
The following image formats are available in Qt.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
int qstrncmp(const char *str1, const char *str2, uint len)
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
#define QT_END_NAMESPACE
This macro expands to.
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
bool qt_write_dib(QDataStream &s, QImage image)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
static void swapPixel01(QImage *image)
The QByteArray class provides an array of bytes.
bool qt_read_dib(QDataStream &s, QImage &image)
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
bool getChar(char *c)
Reads one character from the device and stores it in c.
int byteCount() const
Returns the number of bytes occupied by the image data.
int bytesPerLine() const
Returns the number of bytes per image scanline.
int dotsPerMeterY() const
Returns the number of pixels that fit vertically in a physical meter.
static int calc_shift(uint mask)
QByteArray name() const
Use format() instead.
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Format format() const
Returns the format of the image.
QByteArray format() const
Returns the format that is currently assigned to QImageIOHandler.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Q_CORE_EXPORT void qDebug(const char *,...)
void setColorCount(int)
Resizes the color table to contain colorCount entries.
#define QT_BEGIN_NAMESPACE
This macro expands to.
int readRawData(char *, int len)
Reads at most len bytes from the stream into s and returns the number of bytes read.
bool canRead() const
Returns true if an image can be read from the device (i.
ImageOption
This enum describes the different options supported by QImageIOHandler.
qint64 peek(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, without side effects (i.
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
static const char * data(const QByteArray &arr)
int qGray(int r, int g, int b)
void setByteOrder(ByteOrder)
Sets the serialization byte order to bo.
void setDotsPerMeterY(int)
Sets the number of pixels that fit vertically in a physical meter, to y.
int depth() const
Returns the depth of the image.
const int BMP_FILEHDR_SIZE
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
QSize size() const
Returns the size of the image, i.
static bool read_dib_fileheader(QDataStream &s, BMP_FILEHDR &bf)
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false...
uchar * bits()
Returns a pointer to the first pixel data.
int width() const
Returns the width of the image.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
QIODevice * device() const
Returns the I/O device currently set, or 0 if no device is currently set.
void setDotsPerMeterX(int)
Sets the number of pixels that fit horizontally in a physical meter, to x.
int colorCount() const
Returns the size of the color table for the image.
static bool read_dib_infoheader(QDataStream &s, BMP_INFOHDR &bi)
int qstrncmp(const char *str1, const char *str2, uint len)
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
int height() const
Returns the height of the image.
The QSize class defines the size of a two-dimensional object using integer point precision.
The QDataStream class provides serialization of binary data to a QIODevice.
bool read(QImage *image)
Read an image from the device, and stores it in image.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
static const KeyPair *const end
The QIODevice class is the base interface class of all I/O devices in Qt.
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
int dotsPerMeterX() const
Returns the number of pixels that fit horizontally in a physical meter.
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image's color table, or an empty list if the image does...
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.
QRgb color(int i) const
Returns the color in the color table at index i.
bool write(const QImage &image)
Writes the image image to the assigned device.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.