[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] krita/plugins/formats/tiff: fix crash when opening grayscale floating point
From:       Cyrille Berger <cberger () cberger ! net>
Date:       2015-05-02 9:50:54
Message-ID: E1YoU4U-0001HL-4U () scm ! kde ! org
[Download RAW message or body]

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/plugins/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<QString, QString> getColorSpaceForColorType(uint16 \
sampletype, uint16 colo  if (nbchannels == 0) nbchannels = 1;
         extrasamplescount = nbchannels - 1; // FIX the extrasamples count in case of
         if (sampletype == SAMPLEFORMAT_IEEEFP) {
-          return QPair<QString, QString>();
+           if (color_nb_bits == 16) {
+               destDepth = 16;
+               return QPair<QString, QString>(GrayAColorModelID.id(), \
Float16BitsColorDepthID.id()); +           }
+           else if (color_nb_bits == 32) {
+               destDepth = 32;
+               return QPair<QString, QString>(GrayAColorModelID.id(), \
Float32BitsColorDepthID.id()); +           }
         }
         if (color_nb_bits <= 8) {
             destDepth = 8;
@@ -70,14 +77,14 @@ QPair<QString, QString> getColorSpaceForColorType(uint16 \
sampletype, uint16 colo  if (nbchannels == 0) nbchannels = 3;
         extrasamplescount = nbchannels - 3; // FIX the extrasamples count in case of
         if (sampletype == SAMPLEFORMAT_IEEEFP) {
-//            if (color_nb_bits == 16) {
-//                destDepth = 16;
-//                return QPair<QString, QString>(RGBAColorModelID.id(), \
                Float16BitsColorDepthID.id());
-//            }
-//            else if (color_nb_bits == 32) {
-//                destDepth = 32;
-//                return QPair<QString, QString>(RGBAColorModelID.id(), \
                Float32BitsColorDepthID.id());
-//            }
+            if (color_nb_bits == 16) {
+                destDepth = 16;
+                return QPair<QString, QString>(RGBAColorModelID.id(), \
Float16BitsColorDepthID.id()); +            }
+            else if (color_nb_bits == 32) {
+                destDepth = 32;
+                return QPair<QString, QString>(RGBAColorModelID.id(), \
Float32BitsColorDepthID.id()); +            }
             return QPair<QString, QString>();
         }
         else {
@@ -447,10 +454,26 @@ KisImageBuilder_Result \
KisTIFFConverter::readTIFFDirectory(TIFF* image)  tiffReader = new \
KisTIFFReaderTarget8bit(layer->paintDevice(), poses, alphapos, depth, sampletype, \
nbcolorsamples, extrasamplescount, transform, postprocessor);  }
     else if (dstDepth == 16) {
-        tiffReader = new KisTIFFReaderTarget16bit(layer->paintDevice(), poses, \
alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, transform, \
postprocessor); +        uint16 alphValue;
+        if(sampletype == SAMPLEFORMAT_IEEEFP)
+        {
+          float alpha = 1.0f;
+          alphValue = *(uint16*)&alpha;
+        } else {
+          alphValue = quint16_MAX;
+        }
+        tiffReader = new KisTIFFReaderTarget16bit(layer->paintDevice(), poses, \
alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, transform, \
postprocessor, alphValue);  }
     else if (dstDepth == 32) {
-        tiffReader = new KisTIFFReaderTarget32bit(layer->paintDevice(), poses, \
alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, transform, \
postprocessor); +        uint32 alphValue;
+        if(sampletype == SAMPLEFORMAT_IEEEFP)
+        {
+          float alpha = 1.0;
+          alphValue = *(uint32*)&alpha;
+        } else {
+          alphValue = quint32_MAX;
+        }
+        tiffReader = new KisTIFFReaderTarget32bit(layer->paintDevice(), poses, \
alphapos, depth, sampletype, nbcolorsamples, extrasamplescount, transform, \
postprocessor, alphValue);  }
 
     if (TIFFIsTiled(image)) {
@@ -475,10 +498,10 @@ KisImageBuilder_Result \
KisTIFFConverter::readTIFFDirectory(TIFF* image)  else {
             ps_buf = new tdata_t[nbchannels];
             uint32 * lineSizes = new uint32[nbchannels];
-            uint16 baseSize = TIFFTileSize(image) / nbchannels;
+            tmsize_t baseSize = TIFFTileSize(image) / nbchannels;
             for (uint i = 0; i < nbchannels; i++) {
                 ps_buf[i] = _TIFFmalloc(baseSize);
-                lineSizes[i] = baseSize / lineSizeCoeffs[i];
+                lineSizes[i] = tileWidth; // baseSize / lineSizeCoeffs[i];
             }
             tiffstream = new KisBufferStreamSeperate((uint8**) ps_buf, nbchannels, \
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(quint32 x, \
quint32 y, quint32  {
     KisHLineIteratorSP it = paintDevice()->createHLineIteratorNG(x, y, dataWidth);
     double coeff = quint16_MAX / (double)(pow(2.0, sourceDepth()) - 1);
+    bool no_coeff = (sourceDepth() == 16);
 //         dbgFile <<" depth expension coefficient :" << coeff;
     do {
         quint16 *d = reinterpret_cast<quint16 *>(it->rawData());
         quint8 i;
         for (i = 0; i < nbColorsSamples(); i++) {
-            d[poses()[i]] = (quint16)(tiffstream->nextValue() * coeff);
+            d[poses()[i]] = no_coeff ? tiffstream->nextValue() : \
(quint16)(tiffstream->nextValue() * coeff);  }
         postProcessor()->postProcess16bit(d);
         if (transform()) transform()->transform((quint8*)d, (quint8*)d, 1);
-        d[poses()[i]] = quint16_MAX;
+        d[poses()[i]] = m_alphaValue;
         for (int k = 0; k < nbExtraSamples(); k++) {
             if (k == alphaPos())
-                d[poses()[i]] = (quint16)(tiffstream->nextValue() * coeff);
+                d[poses()[i]] = no_coeff ? tiffstream->nextValue() : \
(quint16)(tiffstream->nextValue() * coeff);  else
                 tiffstream->nextValue();
         }
@@ -83,20 +84,20 @@ uint KisTIFFReaderTarget32bit::copyDataToChannels(quint32 x, \
quint32 y, quint32  {
     KisHLineIteratorSP it = paintDevice()->createHLineIteratorNG(x, y, dataWidth);
     double coeff = quint32_MAX / (double)(pow(2.0, sourceDepth()) - 1);
+    bool no_coeff = (sourceDepth() == 32);
 //    dbgFile <<" depth expension coefficient :" << coeff;
     do {
         quint32 *d = reinterpret_cast<quint32 *>(it->rawData());
         quint8 i;
         for (i = 0; i < nbColorsSamples(); i++) {
-            d[poses()[i]] = (quint32)(tiffstream->nextValue() * coeff);
+            d[poses()[i]] = no_coeff ? tiffstream->nextValue() : \
(quint32)(tiffstream->nextValue() * coeff);  }
         postProcessor()->postProcess32bit(d);
         if (transform()) transform()->transform((quint8*)d, (quint8*)d, 1);
-        d[poses()[i]] = quint32_MAX;
-        KoBgrF32Traits::setOpacity(it->rawData(), OPACITY_OPAQUE_F, 1);
+        d[poses()[i]] = m_alphaValue;
         for (int k = 0; k < nbExtraSamples(); k++) {
             if (k == alphaPos())
-                d[poses()[i]] = (quint32)(tiffstream->nextValue() * coeff);
+                d[poses()[i]] = no_coeff ? tiffstream->nextValue() : \
(quint32)(tiffstream->nextValue() * coeff);  else
                 tiffstream->nextValue();
         }
diff --git a/krita/plugins/formats/tiff/kis_tiff_reader.h \
b/krita/plugins/formats/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, uint8 \
extrasamplescount, KoColorTransformation* transformProfile, KisTIFFPostProcessor* \
                postprocessor)
-        : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, sample_format, \
nbcolorssamples, extrasamplescount, transformProfile, postprocessor) +    \
KisTIFFReaderTarget16bit(KisPaintDeviceSP device, quint8* poses, int8 alphapos, uint8 \
sourceDepth, uint16 sample_format, uint8 nbcolorssamples, uint8 extrasamplescount, \
KoColorTransformation* transformProfile, KisTIFFPostProcessor* postprocessor, uint16 \
_alphaValue) +        : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, \
sample_format, nbcolorssamples, extrasamplescount, transformProfile, postprocessor), \
+          m_alphaValue(_alphaValue)  {
     }
 public:
     virtual uint copyDataToChannels(quint32 x, quint32 y, quint32 dataWidth, \
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, uint8 \
extrasamplescount, KoColorTransformation* transformProfile, KisTIFFPostProcessor* \
                postprocessor)
-        : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, sample_format, \
nbcolorssamples, extrasamplescount, transformProfile, postprocessor) +    \
KisTIFFReaderTarget32bit(KisPaintDeviceSP device, quint8* poses, int8 alphapos, uint8 \
sourceDepth, uint16 sample_format, uint8 nbcolorssamples, uint8 extrasamplescount, \
KoColorTransformation* transformProfile, KisTIFFPostProcessor* postprocessor, uint32 \
_alphaValue) +        : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, \
sample_format, nbcolorssamples, extrasamplescount, transformProfile, postprocessor), \
+          m_alphaValue(_alphaValue)  {
     }
 public:
     virtual uint copyDataToChannels(quint32 x, quint32 y, quint32 dataWidth, \
KisBufferStreamBase* tiffstream) ; +private:
+    uint32 m_alphaValue;
 };
 
 class KisTIFFReaderFromPalette : public  KisTIFFReaderBase


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic