Author: jghali
Date: Thu Sep 19 16:21:45 2019
New Revision: 23202

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23202
Log:
Refactor ScImgDataLoader_TIFF's getImageData_RGBA() 

Modified:
    trunk/Scribus/scribus/imagedataloaders/scimgdataloader_tiff.cpp

Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_tiff.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23202&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_tiff.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_tiff.cpp     
(original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_tiff.cpp     Thu Sep 
19 16:21:45 2019
@@ -118,7 +118,7 @@
 
        do
        {
-               char *layerName=nullptr;
+               char *layerName = nullptr;
                TIFFGetField(tif, TIFFTAG_PAGENAME, &layerName);
                QString name = QString(layerName);
                if (name.isEmpty())
@@ -353,42 +353,44 @@
 
 bool ScImgDataLoader_TIFF::getImageData_RGBA(TIFF* tif, RawImage *image, uint 
widtht, uint heightt, uint size, uint16 bitspersample, uint16 samplesperpixel)
 {
-       bool gotData = false;
        uint32* bits = (uint32 *) _TIFFmalloc(size * sizeof(uint32));
+       if (!bits)
+               return false;
+
        uint16  extrasamples(0), *extratypes(nullptr);
        if (!TIFFGetField (tif, TIFFTAG_EXTRASAMPLES, &extrasamples, 
&extratypes))
                extrasamples = 0;
-       if (bits)
-       {
-               if (TIFFReadRGBAImage(tif, widtht, heightt, bits, 0))
-               {
-                       for (unsigned int y = 0; y < heightt; y++)
-                       {
-                               memcpy(image->scanLine(heightt - 1 - y), bits + 
y * widtht, widtht * image->channels());
-                               if (QSysInfo::ByteOrder==QSysInfo::BigEndian)
-                               {
-                                       unsigned char *s = image->scanLine( 
heightt - 1 - y );
-                                       unsigned char r, g, b, a;
-                                       for (uint xi=0; xi < widtht; ++xi)
-                                       {
-                                               r = s[0];
-                                               g = s[1];
-                                               b = s[2];
-                                               a = s[3];
-                                               s[0] = a;
-                                               s[1] = b;
-                                               s[2] = g;
-                                               s[3] = r;
-                                               s += image->channels();
-                                       }
-                               }
-                       }
-                       if (extrasamples > 0 && extratypes[0] == 
EXTRASAMPLE_ASSOCALPHA)
-                               unmultiplyRGBA(image);
-                       gotData = true;
-               }
-               _TIFFfree(bits);
-       }
+       
+       bool gotData = false;
+       if (TIFFReadRGBAImage(tif, widtht, heightt, bits, 0))
+       {
+               for (unsigned int y = 0; y < heightt; y++)
+               {
+                       memcpy(image->scanLine(heightt - 1 - y), bits + y * 
widtht, widtht * image->channels());
+                       if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+                       {
+                               unsigned char *s = image->scanLine( heightt - 1 
- y );
+                               unsigned char r, g, b, a;
+                               for (uint xi=0; xi < widtht; ++xi)
+                               {
+                                       r = s[0];
+                                       g = s[1];
+                                       b = s[2];
+                                       a = s[3];
+                                       s[0] = a;
+                                       s[1] = b;
+                                       s[2] = g;
+                                       s[3] = r;
+                                       s += image->channels();
+                               }
+                       }
+               }
+               if (extrasamples > 0 && extratypes[0] == EXTRASAMPLE_ASSOCALPHA)
+                       unmultiplyRGBA(image);
+               gotData = true;
+       }
+       _TIFFfree(bits);
+
        return gotData;
 }
 


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to