changeset 31128:524cb3106432

__tiff__.cc: handled compiler warnings for unused params and old-style casts.
author magedrifaat <magedrifaat@gmail.com>
date Sun, 24 Jul 2022 21:21:11 +0200
parents 0d9633ee715e
children dfab9c6982bf
files libinterp/dldfcn/__tiff__.cc
diffstat 1 files changed, 56 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc	Sat Jul 23 23:06:43 2022 +0200
+++ b/libinterp/dldfcn/__tiff__.cc	Sun Jul 24 21:21:11 2022 +0200
@@ -16,8 +16,6 @@
 #  include <tiffio.h>
 #endif
 
-// TODO(maged): Fix warnings
-
 namespace octve
 {
 #if defined (HAVE_TIFF)
@@ -148,8 +146,8 @@
               {
                 // TODO(maged): is it necessary to check FillOrder?
                 uint8_t bit_number = 7 - pixel % 8;
-                img_fvec[pixel]
-                  = (((uint8_t *)img_fvec)[pixel / 8] >> bit_number) & 0x01;
+                uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec);
+                img_fvec[pixel] = (img_u8[pixel / 8] >> bit_number) & 0x01;
               }
             break;
           }
@@ -171,8 +169,8 @@
             for (int64_t pixel = strip_size - 1; pixel >= 0; pixel--)
               {
                 uint8_t shift = pixel % 2 == 0? 4: 0;
-                img_fvec[pixel]
-                  = (((uint8_t *)img_fvec)[pixel / 2] >> shift) & 0x0F;
+                uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec);
+                img_fvec[pixel] = (img_u8[pixel / 2] >> shift) & 0x0F;
               }
             break;
           }
@@ -183,7 +181,9 @@
           error ("Unsupported bit depth");
 
         // Advance the pointer by the amount of bytes read
-        img_fvec = (P*)((uint8_t *)img_fvec + strip_size);
+        img_fvec 
+          = reinterpret_cast<P *> (reinterpret_cast <uint8_t *> (img_fvec)
+                                   + strip_size);
         written_size += strip_size;
       }
 
@@ -256,7 +256,7 @@
     // the number of bytes present in the file as opposed to the actual
     // number of bytes of uncompressed data that is needed here
     int64_t tile_size;    
-    uint32_t written_size = 0;
+    uint64_t written_size = 0;
     for (uint32_t tile = 0; tile < tile_count; tile++)
       {
         tile_size = TIFFReadEncodedTile(tif, tile, img_fvec, -1);
@@ -288,8 +288,8 @@
               {
                 // TODO(maged): is it necessary to check FillOrder?
                 uint8_t bit_number = 7 - pixel % 8;
-                img_fvec[pixel]
-                  = (((uint8_t *)img_fvec)[pixel / 8] >> bit_number) & 0x01;
+                uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec);
+                img_fvec[pixel]= (img_u8[pixel / 8] >> bit_number) & 0x01;
               }
             break;
           }
@@ -311,8 +311,8 @@
             for (int64_t pixel = tile_size - 1; pixel >= 0; pixel--)
               {
                 uint8_t shift = pixel % 2 == 0? 4: 0;
-                img_fvec[pixel]
-                  = (((uint8_t *)img_fvec)[pixel / 2] >> shift) & 0x0F;
+                uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec);
+                img_fvec[pixel] = (img_u8[pixel / 2] >> shift) & 0x0F;
               }
             break;
           }
@@ -322,7 +322,9 @@
                  image_data->bits_per_sample != 64)
           error ("Unsupported bit depth");
         
-        img_fvec = (P*)((uint8_t *)img_fvec + tile_size);
+        img_fvec
+          = reinterpret_cast<P *> (reinterpret_cast<uint8_t *> (img_fvec)
+                                   + tile_size);
         written_size += tile_size;
       }
     
@@ -406,22 +408,22 @@
       case TIFF_BYTE:
       case TIFF_UNDEFINED:
         {
-          retval = (double)(*((uint8_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<uint8_t *> (data)));
           break;
         }
       case TIFF_SHORT:
         {
-          retval = (double)(*((uint16_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<uint16_t *> (data)));
           break;
         }
       case TIFF_LONG:
         {
-          retval = (double)(*((uint32_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<uint32_t *> (data)));
           break;
         }
       case TIFF_LONG8:
         {
-          retval = (double)(*((uint64_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<uint64_t *> (data)));
           break;
         }
       case TIFF_RATIONAL:
@@ -431,32 +433,32 @@
         }
       case TIFF_SBYTE:
         {
-          retval = (double)(*((int8_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<int8_t *> (data)));
           break;
         }
       case TIFF_SSHORT:
         {
-          retval = (double)(*((int16_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<int16_t *> (data)));
           break;
         }
       case TIFF_SLONG:
         {
-          retval = (double)(*((int32_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<int32_t *> (data)));
           break;
         }
       case TIFF_SLONG8:
         {
-          retval = (double)(*((int64_t *)data));
+          retval = static_cast<double> (*(reinterpret_cast<int64_t *> (data)));
           break;
         }
       case TIFF_FLOAT:
         {
-          retval = *((float *)data);
+          retval = *(reinterpret_cast<float *> (data));
           break;
         }
       case TIFF_DOUBLE:
         {
-          retval = *((double *)data);
+          retval = *(reinterpret_cast<double *> (data));
           break;
         }
       case TIFF_SRATIONAL:
@@ -499,14 +501,14 @@
               uint8NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((uint8_t *)data)[i];
+                  arr(i) = (reinterpret_cast<uint8_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
             }
           case TIFF_ASCII:
             {
-              retval = octave_value (*(char **)data);
+              retval = octave_value (*(reinterpret_cast<char **> (data)));
               break;
             }
           case TIFF_SHORT:
@@ -514,7 +516,7 @@
               uint16NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((uint16_t *)data)[i];
+                  arr(i) = (reinterpret_cast<uint16_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -524,7 +526,7 @@
               uint32NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((uint32_t *)data)[i];
+                  arr(i) = (reinterpret_cast<uint32_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -534,7 +536,7 @@
               uint64NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((uint64_t *)data)[i];
+                  arr(i) = (reinterpret_cast<uint64_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -544,8 +546,8 @@
               NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i+=2)
                 {
-                  arr(i / 2) = (float)((uint32_t *)data)[i] 
-                                / (float)((uint32_t *)data)[i+1];
+                  arr(i / 2) = static_cast<float> ((reinterpret_cast<uint32_t *> (data))[i])
+                               / static_cast<float> ((reinterpret_cast<uint32_t *> (data))[i+1]);
                 }
               retval = octave_value (arr);
               break;
@@ -555,7 +557,7 @@
               int8NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((int8_t *)data)[i];
+                  arr(i) = (reinterpret_cast<int8_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -565,7 +567,7 @@
               int16NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((int16_t *)data)[i];
+                  arr(i) = (reinterpret_cast<int16_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -575,7 +577,7 @@
               int32NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((int32_t *)data)[i];
+                  arr(i) = (reinterpret_cast<int32_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -585,7 +587,7 @@
               int64NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((int64_t *)data)[i];
+                  arr(i) = (reinterpret_cast<int64_t *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -595,7 +597,7 @@
               NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
                 {
-                  arr(i) = ((float *)data)[i];
+                  arr(i) = (reinterpret_cast<float *> (data))[i];
                 }
               retval = octave_value (arr);
               break;
@@ -605,7 +607,7 @@
               NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i++)
               {
-                  arr(i) = ((double *)data)[i];
+                  arr(i) = (reinterpret_cast<double *> (data))[i];
               }
               retval = octave_value (arr);
               break;
@@ -615,8 +617,8 @@
               NDArray arr (arr_dims);
               for (uint32_t i = 0; i < count; i+=2)
                 {
-                  arr(i / 2) = (float)((int32_t *)data)[i] 
-                                / (float)((int32_t *)data)[i+1];
+                  arr(i / 2) = static_cast<float> ((reinterpret_cast<int32_t *> (data))[i])
+                               / static_cast<float> ((reinterpret_cast<int32_t *> (data))[i+1]);
                 }
               retval = octave_value (arr);
               break;
@@ -958,7 +960,7 @@
 
 #endif
 
-  DEFUN_DLD (__open_tiff__, args, nargout,
+  DEFUN_DLD (__open_tiff__, args, ,
              "Open a Tiff file and return its handle")
   {
 #if defined (HAVE_TIFF)
@@ -981,10 +983,12 @@
       
     if (std::find(supported_modes.begin(), supported_modes.end(), mode)
         == supported_modes.end())
-      if (mode == "r+")
-        error ("Openning files in r+ mode is not yet supported");
-      else
-        error ("Invalid mode for openning Tiff file: %s", mode.c_str ());
+      {
+        if (mode == "r+")
+          error ("Openning files in r+ mode is not yet supported");
+        else
+          error ("Invalid mode for openning Tiff file: %s", mode.c_str ());
+      }
     
     // TODO(maged): Look into unwind action
     TIFF *tif = TIFFOpen (filename.c_str (), mode.c_str ());
@@ -996,12 +1000,13 @@
     octave_value tiff_ov = octave_value ((uint64_t)tif);
     return octave_value_list (tiff_ov);
 #else
+    octave_unused_parameter (args);
     err_disabled_feature ("Tiff", "Tiff");
 #endif
   }
 
 
-  DEFUN_DLD (__close_tiff__, args, nargout,
+  DEFUN_DLD (__close_tiff__, args, ,
              "Close a tiff file")
   {
 #if defined (HAVE_TIFF)
@@ -1020,7 +1025,7 @@
   }
 
 
-  DEFUN_DLD (__tiff_get_tag__, args, nargout,
+  DEFUN_DLD (__tiff_get_tag__, args, ,
              "Get the value of a tag from a tiff image")
   {
 #if defined (HAVE_TIFF)
@@ -1036,6 +1041,7 @@
 
     uint32_t tag_id;
     const TIFFField *fip;
+    // TODO(maged): support sq_string as well
     if (args (1).type_name () == "string")
       {
         std::string tagName = args (1).string_value ();
@@ -1061,7 +1067,7 @@
   }
 
 
-  DEFUN_DLD (__tiff_set_tag__, args, nargout,
+  DEFUN_DLD (__tiff_set_tag__, args, ,
              "Set the value of a tag in a tiff image")
   {
 #if defined (HAVE_TIFF)
@@ -1079,6 +1085,7 @@
     else
       {
         const TIFFField *fip;
+        // TODO(maged): support sq_string as well
         if (args (1).type_name () == "string")
           {
             std::string tagName = args (1).string_value ();
@@ -1118,6 +1125,7 @@
     TIFF *tif = (TIFF *)(args (0).uint64_value ());
 
     // TODO(maged): nargout and ycbcr
+    octave_unused_parameter (nargout);
 
     // Obtain all necessary tags
     // The main purpose of this struct is to hold all the necessary tags that
@@ -1173,7 +1181,7 @@
 #endif
   }
 
-  DEFUN_DLD (__tiff_write_encoded_strip__, args, nargout,
+  DEFUN_DLD (__tiff_write_encoded_strip__, args, ,
              "Write an encoded strip to the image")
   {
 #if defined (HAVE_TIFF)
@@ -1190,7 +1198,7 @@
     if (image_data.is_tiled)
       error ("Can't rite strips to a tiled image");
 
-    uint32_t strip_no = args (1).uint_value ();
+    uint32_t strip_no = args (1).uint32_scalar_value ();
     if (strip_no < 1 || strip_no > TIFFNumberOfStrips (tif))
       error ("Strip number out of range");