From cb6380beb81ab9571c547270c144988781fed465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 7 Sep 2010 12:07:34 +0200 Subject: fix tiff reader to handle TIFFTAG_SAMPLESPERPIXEL for grayscale images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes reading a .tiff file from ImageMagick which reports the following: TIFFTAG_BITSPERSAMPLE = 8 TIFFTAG_SAMPLESPERPIXEL = 2 TIFFTAG_PHOTOMETRIC = PHOTOMETRIC_MINISBLACK The reader uses QImage::Format_Indexed8, but since the samples per pixel value this should be (non-existent) QImage::Format_Indexed16, causing memory corruption. The fix falls back to the "normal" way of reading tiff images. Merge-request: 2467 Reviewed-by: Samuel Rødal --- src/gui/image/qtiffhandler.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/image/qtiffhandler.cpp b/src/gui/image/qtiffhandler.cpp index de4f680..2e8b998 100644 --- a/src/gui/image/qtiffhandler.cpp +++ b/src/gui/image/qtiffhandler.cpp @@ -196,9 +196,12 @@ bool QTiffHandler::read(QImage *image) uint16 bitPerSample; if (!TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bitPerSample)) bitPerSample = 1; + uint16 samplesPerPixel; // they may be e.g. grayscale with 2 samples per pixel + if (!TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel)) + samplesPerPixel = 1; bool grayscale = photometric == PHOTOMETRIC_MINISBLACK || photometric == PHOTOMETRIC_MINISWHITE; - if (grayscale && bitPerSample == 1) { + if (grayscale && bitPerSample == 1 && samplesPerPixel == 1) { if (image->size() != QSize(width, height) || image->format() != QImage::Format_Mono) *image = QImage(width, height, QImage::Format_Mono); QVector colortable(2); @@ -220,7 +223,7 @@ bool QTiffHandler::read(QImage *image) } } } else { - if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8) { + if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8 && samplesPerPixel == 1) { if (image->size() != QSize(width, height) || image->format() != QImage::Format_Indexed8) *image = QImage(width, height, QImage::Format_Indexed8); if (!image->isNull()) { -- cgit v0.12 From 0ac41424ef143d00461e55087ccceb4b9dc11745 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Tue, 14 Sep 2010 15:12:16 +0200 Subject: Fix crash in Mac font loading Commit f2f6330d915cbe3d0989ad280738ed0a6954cd35 introduced an extra CFRelease of QCFString, which will cause crash. Also, since we are not refering to ATS font in Cocoa code anymore, conversion of CTFontRef to CGFontRef should not rely on platform fonts, we use CTFontCopyGraphicsFont to get the corresponding CGFontRef directly. Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfontdatabase_mac.cpp | 4 +--- src/gui/text/qfontengine_mac.mm | 7 ++----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/gui/text/qfontdatabase_mac.cpp b/src/gui/text/qfontdatabase_mac.cpp index 5c41e0a..712bdb4 100644 --- a/src/gui/text/qfontdatabase_mac.cpp +++ b/src/gui/text/qfontdatabase_mac.cpp @@ -309,11 +309,10 @@ void QFontDatabase::load(const QFontPrivate *d, int script) if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) { QByteArray family_name = db->families[k]->name.toUtf8(); #if defined(QT_MAC_USE_COCOA) - CTFontRef ctFont = CTFontCreateWithName(QCFString(db->families[k]->name), 12, NULL); + QCFType ctFont = CTFontCreateWithName(QCFString(db->families[k]->name), 12, NULL); if (ctFont) { fontName = CTFontCopyFullName(ctFont); familyName = CTFontCopyFamilyName(ctFont); - CFRelease(ctFont); goto FamilyFound; } #else @@ -337,7 +336,6 @@ FamilyFound: #ifdef QT_MAC_USE_COCOA fontDef.family = familyName; QFontEngine *engine = new QCoreTextFontEngineMulti(fontName, fontDef, d->kerning); - CFRelease(fontName); #else QCFString actualName; if (ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr) diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm index 894de44..6e524f6 100644 --- a/src/gui/text/qfontengine_mac.mm +++ b/src/gui/text/qfontengine_mac.mm @@ -419,8 +419,7 @@ QCoreTextFontEngine::QCoreTextFontEngine(CTFontRef font, const QFontDef &def, synthesisFlags = 0; ctfont = font; CFRetain(ctfont); - ATSFontRef atsfont = CTFontGetPlatformFont(ctfont, 0); - cgFont = CGFontCreateWithPlatformFont(&atsfont); + cgFont = CTFontCopyGraphicsFont(ctfont, NULL); CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ctfont); if (fontDef.weight >= QFont::Bold && !(traits & kCTFontBoldTrait)) { synthesisFlags |= SynthesizedBold; @@ -440,8 +439,8 @@ QCoreTextFontEngine::QCoreTextFontEngine(CTFontRef font, const QFontDef &def, QCoreTextFontEngine::~QCoreTextFontEngine() { - CFRelease(ctfont); CFRelease(cgFont); + CFRelease(ctfont); } bool QCoreTextFontEngine::stringToCMap(const QChar *, int, QGlyphLayout *, int *, QTextEngine::ShaperFlags) const @@ -693,8 +692,6 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); CGContextSetTextDrawingMode(ctx, kCGTextFill); - ATSFontRef atsfont = CTFontGetPlatformFont(ctfont, 0); - QCFType cgFont = CGFontCreateWithPlatformFont(&atsfont); CGContextSetFont(ctx, cgFont); qreal pos_x = -br.x.toReal() + subPixelPosition.toReal(); -- cgit v0.12