LCOV - code coverage report
Current view: top level - frmts/fit - fit.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 53 106 50.0 %
Date: 2024-11-21 22:18:42 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  FIT Driver
       4             :  * Purpose:  Implement FIT Support - not using the SGI iflFIT library.
       5             :  * Author:   Philip Nemec, nemec@keyholecorp.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2001, Keyhole, Inc.
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include <limits.h>
      14             : #include "fit.h"
      15             : 
      16          35 : GDALDataType fitDataType(int dtype)
      17             : {
      18          35 :     switch (dtype)
      19             :     {
      20           0 :         case 1:  // iflBit   /* single-bit */
      21           0 :             CPLError(CE_Failure, CPLE_NotSupported,
      22             :                      "GDAL unsupported data type (single-bit) in fitDataType");
      23           0 :             return GDT_Unknown;
      24          17 :         case 2:  // iflUChar    /* unsigned character (byte) */
      25          17 :             return GDT_Byte;
      26           0 :         case 4:  // iflChar     /* signed character (byte) */
      27           0 :             CPLError(CE_Failure, CPLE_NotSupported,
      28             :                      "GDAL unsupported data type (signed char) in fitDataType");
      29           0 :             return GDT_Unknown;
      30             :             //         return Byte;
      31           3 :         case 8:  // iflUShort   /* unsigned short integer (nominally 16 bits) */
      32           3 :             return GDT_UInt16;
      33           3 :         case 16:  // iflShort   /* signed short integer */
      34           3 :             return GDT_Int16;
      35           3 :         case 32:  // iflUInt    /* unsigned integer (nominally 32 bits) */
      36             :             //     case 32: // iflULong   /* deprecated, same as iflUInt */
      37           3 :             return GDT_UInt32;
      38             :             break;
      39           3 :         case 64:  // iflInt     /* integer */
      40             :             //     case 64: // iflLong    /* deprecated, same as iflULong */
      41           3 :             return GDT_Int32;
      42           3 :         case 128:  // iflFloat  /* floating point */
      43           3 :             return GDT_Float32;
      44           3 :         case 256:  // iflDouble /* double precision floating point */
      45           3 :             return GDT_Float64;
      46           0 :         default:
      47           0 :             CPLError(CE_Failure, CPLE_NotSupported,
      48             :                      "FIT - unknown data type %i in fitDataType", dtype);
      49           0 :             return GDT_Unknown;
      50             :     }  // switch
      51             : }
      52             : 
      53          32 : int fitGetDataType(GDALDataType eDataType)
      54             : {
      55          32 :     switch (eDataType)
      56             :     {
      57          16 :         case GDT_Byte:
      58          16 :             return 2;  // iflUChar - unsigned character (byte)
      59           2 :         case GDT_UInt16:
      60           2 :             return 8;  // iflUShort - unsigned short integer (nominally 16 bits)
      61           2 :         case GDT_Int16:
      62           2 :             return 16;  // iflShort - signed short integer
      63           2 :         case GDT_UInt32:
      64           2 :             return 32;  // iflUInt - unsigned integer (nominally 32 bits)
      65           2 :         case GDT_Int32:
      66           2 :             return 64;  // iflInt - integer
      67           2 :         case GDT_Float32:
      68           2 :             return 128;  // iflFloat - floating point
      69           2 :         case GDT_Float64:
      70           2 :             return 256;  // iflDouble - double precision floating point
      71           4 :         default:
      72           4 :             CPLError(CE_Failure, CPLE_NotSupported,
      73             :                      "FIT - unsupported GDALDataType %i in fitGetDataType",
      74             :                      eDataType);
      75           4 :             return 0;
      76             :     }  // switch
      77             : }
      78             : 
      79             : #define UNSUPPORTED_COMBO()                                                    \
      80             :     CPLError(CE_Failure, CPLE_NotSupported,                                    \
      81             :              "FIT write - unsupported combination (band 1 = %s "               \
      82             :              "and %i bands) - ignoring color model",                           \
      83             :              GDALGetColorInterpretationName(colorInterp), nBands);             \
      84             :     return 0
      85             : 
      86          28 : int fitGetColorModel(GDALColorInterp colorInterp, int nBands)
      87             : {
      88             :     // XXX - Should check colorInterp for all bands, not just first one.
      89             : 
      90          28 :     switch (colorInterp)
      91             :     {
      92           7 :         case GCI_GrayIndex:
      93           7 :             switch (nBands)
      94             :             {
      95           7 :                 case 1:
      96           7 :                     return 2;  // iflLuminance - luminance
      97           0 :                 case 2:
      98           0 :                     return 13;  // iflLuminanceAlpha - Luminance plus alpha
      99           0 :                 default:
     100           0 :                     UNSUPPORTED_COMBO();
     101             :             }  // switch
     102             : 
     103           0 :         case GCI_PaletteIndex:
     104           0 :             CPLError(CE_Failure, CPLE_NotSupported,
     105             :                      "FIT write - unsupported ColorInterp PaletteIndex\n");
     106           0 :             return 0;
     107             : 
     108           0 :         case GCI_RedBand:
     109           0 :             switch (nBands)
     110             :             {
     111           0 :                 case 3:
     112           0 :                     return 3;  // iflRGB - full color (Red, Green, Blue
     113             :                                // triplets)
     114           0 :                 case 4:
     115           0 :                     return 5;  // iflRGBA - full color with transparency (alpha
     116             :                                // channel)
     117           0 :                 default:
     118           0 :                     UNSUPPORTED_COMBO();
     119             :             }  // switch
     120             : 
     121           0 :         case GCI_BlueBand:
     122           0 :             switch (nBands)
     123             :             {
     124           0 :                 case 3:
     125           0 :                     return 9;  // iflBGR - full color (ordered Blue, Green, Red)
     126           0 :                 default:
     127           0 :                     UNSUPPORTED_COMBO();
     128             :             }  // switch
     129             : 
     130           0 :         case GCI_AlphaBand:
     131           0 :             switch (nBands)
     132             :             {
     133           0 :                 case 4:
     134           0 :                     return 10;  // iflABGR - Alpha, Blue, Green, Red (SGI frame
     135             :                                 // buffers)
     136           0 :                 default:
     137           0 :                     UNSUPPORTED_COMBO();
     138             :             }  // switch
     139             : 
     140           0 :         case GCI_HueBand:
     141           0 :             switch (nBands)
     142             :             {
     143           0 :                 case 3:
     144           0 :                     return 6;  // iflHSV - Hue, Saturation, Value
     145           0 :                 default:
     146           0 :                     UNSUPPORTED_COMBO();
     147             :             }  // switch
     148             : 
     149           0 :         case GCI_CyanBand:
     150           0 :             switch (nBands)
     151             :             {
     152           0 :                 case 3:
     153           0 :                     return 7;  // iflCMY - Cyan, Magenta, Yellow
     154           0 :                 case 4:
     155           0 :                     return 8;  // iflCMYK - Cyan, Magenta, Yellow, Black
     156           0 :                 default:
     157           0 :                     UNSUPPORTED_COMBO();
     158             :             }  // switch
     159             : 
     160           0 :         case GCI_GreenBand:
     161             :         case GCI_SaturationBand:
     162             :         case GCI_LightnessBand:
     163             :         case GCI_MagentaBand:
     164             :         case GCI_YellowBand:
     165             :         case GCI_BlackBand:
     166           0 :             CPLError(CE_Failure, CPLE_NotSupported,
     167             :                      "FIT write - unsupported combination (band 1 = %s) "
     168             :                      "- ignoring color model",
     169             :                      GDALGetColorInterpretationName(colorInterp));
     170           0 :             return 0;
     171             : 
     172          21 :         default:
     173          21 :             CPLDebug("FIT write",
     174             :                      "unrecognized colorInterp %i - deriving from "
     175             :                      "number of bands (%i)",
     176             :                      colorInterp, nBands);
     177             :             switch (nBands)
     178             :             {
     179          17 :                 case 1:
     180          17 :                     return 2;  // iflLuminance - luminance
     181           1 :                 case 2:
     182           1 :                     return 13;  // iflLuminanceAlpha - Luminance plus alpha
     183           1 :                 case 3:
     184           1 :                     return 3;  // iflRGB - full color (Red, Green, Blue
     185             :                                // triplets)
     186           1 :                 case 4:
     187           1 :                     return 5;  // iflRGBA - full color with transparency (alpha
     188             :                                // channel)
     189             :             }                  // switch
     190             : 
     191           1 :             CPLError(CE_Failure, CPLE_NotSupported,
     192             :                      "FIT write - unrecognized colorInterp %i and "
     193             :                      "unrecognized number of bands (%i)",
     194             :                      colorInterp, nBands);
     195             : 
     196           1 :             return 0;
     197             :     }  // switch
     198             : }

Generated by: LCOV version 1.14