--- src/kernel/qasyncimageio.cpp +++ src/kernel/qasyncimageio.cpp 2004/08/12 09:16:19 @@ -992,6 +992,7 @@ accum = 0; bitcount = 0; sp = stack; + firstcode = oldcode = 0; needfirst = FALSE; out_of_bounds = FALSE; } --- src/kernel/qimage.cpp +++ src/kernel/qimage.cpp 2004/08/12 09:16:19 @@ -730,6 +730,15 @@ that->setAlphaBuffer( TRUE ); } image.setAlphaBuffer(hasAlphaBuffer()); + image.data->dpmx = dotsPerMeterX(); + image.data->dpmy = dotsPerMeterY(); + image.data->offset = offset(); +#ifndef QT_NO_IMAGE_TEXT + if ( data->misc ) { + image.data->misc = new QImageDataMisc; + *image.data->misc = misc(); + } +#endif return image; } @@ -4818,6 +4827,7 @@ if ( comp == BMP_RLE8 ) { // run length compression int x=0, y=0, b; register uchar *p = line[h-1]; + const uchar *endp = line[h-1]+w; while ( y < h ) { if ( (b=d->getch()) == EOF ) break; @@ -4835,9 +4845,20 @@ case 2: // delta (jump) x += d->getch(); y += d->getch(); + + // Protection + if ( (uint)x >= (uint)w ) + x = w-1; + if ( (uint)y >= (uint)h ) + y = h-1; + p = line[h-y-1] + x; break; default: // absolute mode + // Protection + if ( p + b > endp ) + b = endp-p; + if ( d->readBlock( (char *)p, b ) != b ) return FALSE; if ( (b & 1) == 1 ) @@ -4846,6 +4867,10 @@ p += b; } } else { // encoded mode + // Protection + if ( p + b > endp ) + b = endp-p; + memset( p, d->getch(), b ); // repeat pixel x += b; p += b; @@ -5639,6 +5664,21 @@ } + +static int nextColorSpec(const QCString & buf) +{ + int i = buf.find(" c "); + if (i < 0) + i = buf.find(" g "); + if (i < 0) + i = buf.find(" g4 "); + if (i < 0) + i = buf.find(" m "); + if (i < 0) + i = buf.find(" s "); + return i; +} + // // INTERNAL // @@ -5695,23 +5735,17 @@ index = buf.left( cpp ); buf = buf.mid( cpp ).simplifyWhiteSpace().lower(); buf.prepend( " " ); - i = buf.find( " c " ); - if ( i < 0 ) - i = buf.find( " g " ); - if ( i < 0 ) - i = buf.find( " g4 " ); - if ( i < 0 ) - i = buf.find( " m " ); + i = nextColorSpec(buf); if ( i < 0 ) { #if defined(QT_CHECK_RANGE) qWarning( "QImage: XPM color specification is missing: %s", buf.data()); #endif - return; // no c/g/g4/m specification at all + return; // no c/g/g4/m/s specification at all } buf = buf.mid( i+3 ); // Strip any other colorspec - int end = buf.find(' ', 4); - if ( end >= 0 ) + int end = nextColorSpec(buf); + if (end != -1) buf.truncate(end); buf = buf.stripWhiteSpace(); if ( buf == "none" ) { --- src/kernel/qjpegio.cpp +++ src/kernel/qjpegio.cpp 2004/08/12 09:16:19 @@ -254,15 +254,18 @@ scaleSize( sWidth, sHeight, cinfo.output_width, cinfo.output_height, sMode ); // qDebug( "Scaling the jpeg to %i x %i", sWidth, sHeight, sModeStr ); + bool created = FALSE; if ( cinfo.output_components == 3 || cinfo.output_components == 4) { - image.create( sWidth, sHeight, 32 ); + created = image.create( sWidth, sHeight, 32 ); } else if ( cinfo.output_components == 1 ) { - image.create( sWidth, sHeight, 8, 256 ); + created = image.create( sWidth, sHeight, 8, 256 ); for (int i=0; i<256; i++) image.setColor(i, qRgb(i,i,i)); } else { // Unsupported format } + if (!created) + image = QImage(); if (!image.isNull()) { QImage tmpImage( cinfo.output_width, 1, 32 ); @@ -296,53 +299,58 @@ } } (void) jpeg_finish_decompress(&cinfo); - } + } } else { + bool created = false; if ( cinfo.output_components == 3 || cinfo.output_components == 4) { - image.create( cinfo.output_width, cinfo.output_height, 32 ); + created = image.create( cinfo.output_width, cinfo.output_height, 32 ); } else if ( cinfo.output_components == 1 ) { - image.create( cinfo.output_width, cinfo.output_height, 8, 256 ); + created = image.create( cinfo.output_width, cinfo.output_height, 8, 256 ); for (int i=0; i<256; i++) image.setColor(i, qRgb(i,i,i)); } else { // Unsupported format } + if (!created) + image = QImage(); if (!image.isNull()) { uchar** lines = image.jumpTable(); while (cinfo.output_scanline < cinfo.output_height) (void) jpeg_read_scanlines(&cinfo, - lines + cinfo.output_scanline, - cinfo.output_height); + lines + cinfo.output_scanline, + cinfo.output_height); (void) jpeg_finish_decompress(&cinfo); - } - if ( cinfo.output_components == 3 ) { - // Expand 24->32 bpp. - for (uint j=0; j32 bpp. + for (uint j=0; jsetImage(image); - iio->setStatus(0); + iio->setStatus(image.isNull()); } jpeg_destroy_decompress(&cinfo); @@ -476,6 +484,21 @@ } jpeg_set_defaults(&cinfo); + + float diffInch = QABS(image.dotsPerMeterX()*2.54/100. - qRound(image.dotsPerMeterX()*2.54/100.)) + + QABS(image.dotsPerMeterY()*2.54/100. - qRound(image.dotsPerMeterY()*2.54/100.)); + float diffCm = (QABS(image.dotsPerMeterX()/100. - qRound(image.dotsPerMeterX()/100.)) + + QABS(image.dotsPerMeterY()/100. - qRound(image.dotsPerMeterY()/100.)))*2.54; + if (diffInch < diffCm) { + cinfo.density_unit = 1; // dots/inch + cinfo.X_density = qRound(image.dotsPerMeterX()*2.54/100.); + cinfo.Y_density = qRound(image.dotsPerMeterY()*2.54/100.); + } else { + cinfo.density_unit = 2; // dots/cm + cinfo.X_density = (image.dotsPerMeterX()+50) / 100; + cinfo.Y_density = (image.dotsPerMeterY()+50) / 100; + } + int quality = iio->quality() >= 0 ? QMIN(iio->quality(),100) : 75; #if defined(Q_OS_UNIXWARE) jpeg_set_quality(&cinfo, quality, B_TRUE /* limit to baseline-JPEG values */); --- src/kernel/qasyncimageio.cpp +++ src/kernel/qasyncimageio.cpp 2004/08/12 16:21:41 @@ -1107,7 +1107,7 @@ oldcode=incode; while (sp>stack) { --sp; - if (!out_of_bounds && *sp!=trans_index) + if (!out_of_bounds && line && *sp!=trans_index) line[y][x] = color(*sp); x++; if (x>=swidth) out_of_bounds = TRUE; --- src/kernel/qimage.cpp +++ src/kernel/qimage.cpp 2004/08/12 09:18:29 @@ -5681,6 +5681,9 @@ image.create( w, h, 8, ncols ); } + if (image.isNull()) + return; + QMap colorMap; int currentColor;