From kde-commits Sat May 02 09:50:54 2015 From: Cyrille Berger Date: Sat, 02 May 2015 09:50:54 +0000 To: kde-commits Subject: [calligra] krita/plugins/formats/tiff: fix crash when opening grayscale floating point Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=143056026530089 Git commit d0f249c058b6b9f2accd9185cbbcefa1d81ab38d by Cyrille Berger. Committed on 02/05/2015 at 09:50. Pushed by berger into branch 'master'. fix crash when opening grayscale floating point CCBUG:344334 M +36 -13 krita/plugins/formats/tiff/kis_tiff_converter.cc M +8 -7 krita/plugins/formats/tiff/kis_tiff_reader.cc M +10 -4 krita/plugins/formats/tiff/kis_tiff_reader.h http://commits.kde.org/calligra/d0f249c058b6b9f2accd9185cbbcefa1d81ab38d diff --git a/krita/plugins/formats/tiff/kis_tiff_converter.cc b/krita/plugi= ns/formats/tiff/kis_tiff_converter.cc index dcf124f..583f878 100644 --- a/krita/plugins/formats/tiff/kis_tiff_converter.cc +++ b/krita/plugins/formats/tiff/kis_tiff_converter.cc @@ -55,7 +55,14 @@ QPair getColorSpaceForColorType(uint16= sampletype, uint16 colo if (nbchannels =3D=3D 0) nbchannels =3D 1; extrasamplescount =3D nbchannels - 1; // FIX the extrasamples coun= t in case of if (sampletype =3D=3D SAMPLEFORMAT_IEEEFP) { - return QPair(); + if (color_nb_bits =3D=3D 16) { + destDepth =3D 16; + return QPair(GrayAColorModelID.id(), Floa= t16BitsColorDepthID.id()); + } + else if (color_nb_bits =3D=3D 32) { + destDepth =3D 32; + return QPair(GrayAColorModelID.id(), Floa= t32BitsColorDepthID.id()); + } } if (color_nb_bits <=3D 8) { destDepth =3D 8; @@ -70,14 +77,14 @@ QPair getColorSpaceForColorType(uint1= 6 sampletype, uint16 colo if (nbchannels =3D=3D 0) nbchannels =3D 3; extrasamplescount =3D nbchannels - 3; // FIX the extrasamples coun= t in case of if (sampletype =3D=3D SAMPLEFORMAT_IEEEFP) { -// if (color_nb_bits =3D=3D 16) { -// destDepth =3D 16; -// return QPair(RGBAColorModelID.id(), Fl= oat16BitsColorDepthID.id()); -// } -// else if (color_nb_bits =3D=3D 32) { -// destDepth =3D 32; -// return QPair(RGBAColorModelID.id(), Fl= oat32BitsColorDepthID.id()); -// } + if (color_nb_bits =3D=3D 16) { + destDepth =3D 16; + return QPair(RGBAColorModelID.id(), Floa= t16BitsColorDepthID.id()); + } + else if (color_nb_bits =3D=3D 32) { + destDepth =3D 32; + return QPair(RGBAColorModelID.id(), Floa= t32BitsColorDepthID.id()); + } return QPair(); } else { @@ -447,10 +454,26 @@ KisImageBuilder_Result KisTIFFConverter::readTIFFDire= ctory(TIFF* image) tiffReader =3D new KisTIFFReaderTarget8bit(layer->paintDevice(), p= oses, alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, trans= form, postprocessor); } else if (dstDepth =3D=3D 16) { - tiffReader =3D new KisTIFFReaderTarget16bit(layer->paintDevice(), = poses, alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, tran= sform, postprocessor); + uint16 alphValue; + if(sampletype =3D=3D SAMPLEFORMAT_IEEEFP) + { + float alpha =3D 1.0f; + alphValue =3D *(uint16*)α + } else { + alphValue =3D quint16_MAX; + } + tiffReader =3D new KisTIFFReaderTarget16bit(layer->paintDevice(), = poses, alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, tran= sform, postprocessor, alphValue); } else if (dstDepth =3D=3D 32) { - tiffReader =3D new KisTIFFReaderTarget32bit(layer->paintDevice(), = poses, alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, tran= sform, postprocessor); + uint32 alphValue; + if(sampletype =3D=3D SAMPLEFORMAT_IEEEFP) + { + float alpha =3D 1.0; + alphValue =3D *(uint32*)α + } else { + alphValue =3D quint32_MAX; + } + tiffReader =3D new KisTIFFReaderTarget32bit(layer->paintDevice(), = poses, alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, tran= sform, postprocessor, alphValue); } = if (TIFFIsTiled(image)) { @@ -475,10 +498,10 @@ KisImageBuilder_Result KisTIFFConverter::readTIFFDire= ctory(TIFF* image) else { ps_buf =3D new tdata_t[nbchannels]; uint32 * lineSizes =3D new uint32[nbchannels]; - uint16 baseSize =3D TIFFTileSize(image) / nbchannels; + tmsize_t baseSize =3D TIFFTileSize(image) / nbchannels; for (uint i =3D 0; i < nbchannels; i++) { ps_buf[i] =3D _TIFFmalloc(baseSize); - lineSizes[i] =3D baseSize / lineSizeCoeffs[i]; + lineSizes[i] =3D tileWidth; // baseSize / lineSizeCoeffs[i= ]; } tiffstream =3D new KisBufferStreamSeperate((uint8**) ps_buf, n= bchannels, depth, lineSizes); delete [] lineSizes; diff --git a/krita/plugins/formats/tiff/kis_tiff_reader.cc b/krita/plugins/= formats/tiff/kis_tiff_reader.cc index a84a02d..7b6dc98 100644 --- a/krita/plugins/formats/tiff/kis_tiff_reader.cc +++ b/krita/plugins/formats/tiff/kis_tiff_reader.cc @@ -58,19 +58,20 @@ uint KisTIFFReaderTarget16bit::copyDataToChannels(quint= 32 x, quint32 y, quint32 { KisHLineIteratorSP it =3D paintDevice()->createHLineIteratorNG(x, y, d= ataWidth); double coeff =3D quint16_MAX / (double)(pow(2.0, sourceDepth()) - 1); + bool no_coeff =3D (sourceDepth() =3D=3D 16); // dbgFile <<" depth expension coefficient :" << coeff; do { quint16 *d =3D reinterpret_cast(it->rawData()); quint8 i; for (i =3D 0; i < nbColorsSamples(); i++) { - d[poses()[i]] =3D (quint16)(tiffstream->nextValue() * coeff); + d[poses()[i]] =3D no_coeff ? tiffstream->nextValue() : (quint1= 6)(tiffstream->nextValue() * coeff); } postProcessor()->postProcess16bit(d); if (transform()) transform()->transform((quint8*)d, (quint8*)d, 1); - d[poses()[i]] =3D quint16_MAX; + d[poses()[i]] =3D m_alphaValue; for (int k =3D 0; k < nbExtraSamples(); k++) { if (k =3D=3D alphaPos()) - d[poses()[i]] =3D (quint16)(tiffstream->nextValue() * coef= f); + d[poses()[i]] =3D no_coeff ? tiffstream->nextValue() : (qu= int16)(tiffstream->nextValue() * coeff); else tiffstream->nextValue(); } @@ -83,20 +84,20 @@ uint KisTIFFReaderTarget32bit::copyDataToChannels(quint= 32 x, quint32 y, quint32 { KisHLineIteratorSP it =3D paintDevice()->createHLineIteratorNG(x, y, d= ataWidth); double coeff =3D quint32_MAX / (double)(pow(2.0, sourceDepth()) - 1); + bool no_coeff =3D (sourceDepth() =3D=3D 32); // dbgFile <<" depth expension coefficient :" << coeff; do { quint32 *d =3D reinterpret_cast(it->rawData()); quint8 i; for (i =3D 0; i < nbColorsSamples(); i++) { - d[poses()[i]] =3D (quint32)(tiffstream->nextValue() * coeff); + d[poses()[i]] =3D no_coeff ? tiffstream->nextValue() : (quint3= 2)(tiffstream->nextValue() * coeff); } postProcessor()->postProcess32bit(d); if (transform()) transform()->transform((quint8*)d, (quint8*)d, 1); - d[poses()[i]] =3D quint32_MAX; - KoBgrF32Traits::setOpacity(it->rawData(), OPACITY_OPAQUE_F, 1); + d[poses()[i]] =3D m_alphaValue; for (int k =3D 0; k < nbExtraSamples(); k++) { if (k =3D=3D alphaPos()) - d[poses()[i]] =3D (quint32)(tiffstream->nextValue() * coef= f); + d[poses()[i]] =3D no_coeff ? tiffstream->nextValue() : (qu= int32)(tiffstream->nextValue() * coeff); else tiffstream->nextValue(); } diff --git a/krita/plugins/formats/tiff/kis_tiff_reader.h b/krita/plugins/f= ormats/tiff/kis_tiff_reader.h index 30a66cc..7a646e7 100644 --- a/krita/plugins/formats/tiff/kis_tiff_reader.h +++ b/krita/plugins/formats/tiff/kis_tiff_reader.h @@ -204,23 +204,29 @@ public: class KisTIFFReaderTarget16bit : public KisTIFFReaderBase { public: - KisTIFFReaderTarget16bit(KisPaintDeviceSP device, quint8* poses, int8 = alphapos, uint8 sourceDepth, uint16 sample_format, uint8 nbcolorssamples, u= int8 extrasamplescount, KoColorTransformation* transformProfile, KisTIFFPos= tProcessor* postprocessor) - : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, sample_f= ormat, nbcolorssamples, extrasamplescount, transformProfile, postprocessor) + KisTIFFReaderTarget16bit(KisPaintDeviceSP device, quint8* poses, int8 = alphapos, uint8 sourceDepth, uint16 sample_format, uint8 nbcolorssamples, u= int8 extrasamplescount, KoColorTransformation* transformProfile, KisTIFFPos= tProcessor* postprocessor, uint16 _alphaValue) + : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, sample_f= ormat, nbcolorssamples, extrasamplescount, transformProfile, postprocessor), + m_alphaValue(_alphaValue) { } public: virtual uint copyDataToChannels(quint32 x, quint32 y, quint32 dataWidt= h, KisBufferStreamBase* tiffstream) ; +private: + uint16 m_alphaValue; }; = class KisTIFFReaderTarget32bit : public KisTIFFReaderBase { public: - KisTIFFReaderTarget32bit(KisPaintDeviceSP device, quint8* poses, int8 = alphapos, uint8 sourceDepth, uint16 sample_format, uint8 nbcolorssamples, u= int8 extrasamplescount, KoColorTransformation* transformProfile, KisTIFFPos= tProcessor* postprocessor) - : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, sample_f= ormat, nbcolorssamples, extrasamplescount, transformProfile, postprocessor) + KisTIFFReaderTarget32bit(KisPaintDeviceSP device, quint8* poses, int8 = alphapos, uint8 sourceDepth, uint16 sample_format, uint8 nbcolorssamples, u= int8 extrasamplescount, KoColorTransformation* transformProfile, KisTIFFPos= tProcessor* postprocessor, uint32 _alphaValue) + : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, sample_f= ormat, nbcolorssamples, extrasamplescount, transformProfile, postprocessor), + m_alphaValue(_alphaValue) { } public: virtual uint copyDataToChannels(quint32 x, quint32 y, quint32 dataWidt= h, KisBufferStreamBase* tiffstream) ; +private: + uint32 m_alphaValue; }; = class KisTIFFReaderFromPalette : public KisTIFFReaderBase