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-04-27 17:22:41 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             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include <limits.h>
      30             : #include "fit.h"
      31             : 
      32          35 : GDALDataType fitDataType(int dtype)
      33             : {
      34          35 :     switch (dtype)
      35             :     {
      36           0 :         case 1:  // iflBit   /* single-bit */
      37           0 :             CPLError(CE_Failure, CPLE_NotSupported,
      38             :                      "GDAL unsupported data type (single-bit) in fitDataType");
      39           0 :             return GDT_Unknown;
      40          17 :         case 2:  // iflUChar    /* unsigned character (byte) */
      41          17 :             return GDT_Byte;
      42           0 :         case 4:  // iflChar     /* signed character (byte) */
      43           0 :             CPLError(CE_Failure, CPLE_NotSupported,
      44             :                      "GDAL unsupported data type (signed char) in fitDataType");
      45           0 :             return GDT_Unknown;
      46             :             //         return Byte;
      47           3 :         case 8:  // iflUShort   /* unsigned short integer (nominally 16 bits) */
      48           3 :             return GDT_UInt16;
      49           3 :         case 16:  // iflShort   /* signed short integer */
      50           3 :             return GDT_Int16;
      51           3 :         case 32:  // iflUInt    /* unsigned integer (nominally 32 bits) */
      52             :             //     case 32: // iflULong   /* deprecated, same as iflUInt */
      53           3 :             return GDT_UInt32;
      54             :             break;
      55           3 :         case 64:  // iflInt     /* integer */
      56             :             //     case 64: // iflLong    /* deprecated, same as iflULong */
      57           3 :             return GDT_Int32;
      58           3 :         case 128:  // iflFloat  /* floating point */
      59           3 :             return GDT_Float32;
      60           3 :         case 256:  // iflDouble /* double precision floating point */
      61           3 :             return GDT_Float64;
      62           0 :         default:
      63           0 :             CPLError(CE_Failure, CPLE_NotSupported,
      64             :                      "FIT - unknown data type %i in fitDataType", dtype);
      65           0 :             return GDT_Unknown;
      66             :     }  // switch
      67             : }
      68             : 
      69          32 : int fitGetDataType(GDALDataType eDataType)
      70             : {
      71          32 :     switch (eDataType)
      72             :     {
      73          16 :         case GDT_Byte:
      74          16 :             return 2;  // iflUChar - unsigned character (byte)
      75           2 :         case GDT_UInt16:
      76           2 :             return 8;  // iflUShort - unsigned short integer (nominally 16 bits)
      77           2 :         case GDT_Int16:
      78           2 :             return 16;  // iflShort - signed short integer
      79           2 :         case GDT_UInt32:
      80           2 :             return 32;  // iflUInt - unsigned integer (nominally 32 bits)
      81           2 :         case GDT_Int32:
      82           2 :             return 64;  // iflInt - integer
      83           2 :         case GDT_Float32:
      84           2 :             return 128;  // iflFloat - floating point
      85           2 :         case GDT_Float64:
      86           2 :             return 256;  // iflDouble - double precision floating point
      87           4 :         default:
      88           4 :             CPLError(CE_Failure, CPLE_NotSupported,
      89             :                      "FIT - unsupported GDALDataType %i in fitGetDataType",
      90             :                      eDataType);
      91           4 :             return 0;
      92             :     }  // switch
      93             : }
      94             : 
      95             : #define UNSUPPORTED_COMBO()                                                    \
      96             :     CPLError(CE_Failure, CPLE_NotSupported,                                    \
      97             :              "FIT write - unsupported combination (band 1 = %s "               \
      98             :              "and %i bands) - ignoring color model",                           \
      99             :              GDALGetColorInterpretationName(colorInterp), nBands);             \
     100             :     return 0
     101             : 
     102          28 : int fitGetColorModel(GDALColorInterp colorInterp, int nBands)
     103             : {
     104             :     // XXX - Should check colorInterp for all bands, not just first one.
     105             : 
     106          28 :     switch (colorInterp)
     107             :     {
     108           7 :         case GCI_GrayIndex:
     109           7 :             switch (nBands)
     110             :             {
     111           7 :                 case 1:
     112           7 :                     return 2;  // iflLuminance - luminance
     113           0 :                 case 2:
     114           0 :                     return 13;  // iflLuminanceAlpha - Luminance plus alpha
     115           0 :                 default:
     116           0 :                     UNSUPPORTED_COMBO();
     117             :             }  // switch
     118             : 
     119           0 :         case GCI_PaletteIndex:
     120           0 :             CPLError(CE_Failure, CPLE_NotSupported,
     121             :                      "FIT write - unsupported ColorInterp PaletteIndex\n");
     122           0 :             return 0;
     123             : 
     124           0 :         case GCI_RedBand:
     125           0 :             switch (nBands)
     126             :             {
     127           0 :                 case 3:
     128           0 :                     return 3;  // iflRGB - full color (Red, Green, Blue
     129             :                                // triplets)
     130           0 :                 case 4:
     131           0 :                     return 5;  // iflRGBA - full color with transparency (alpha
     132             :                                // channel)
     133           0 :                 default:
     134           0 :                     UNSUPPORTED_COMBO();
     135             :             }  // switch
     136             : 
     137           0 :         case GCI_BlueBand:
     138           0 :             switch (nBands)
     139             :             {
     140           0 :                 case 3:
     141           0 :                     return 9;  // iflBGR - full color (ordered Blue, Green, Red)
     142           0 :                 default:
     143           0 :                     UNSUPPORTED_COMBO();
     144             :             }  // switch
     145             : 
     146           0 :         case GCI_AlphaBand:
     147           0 :             switch (nBands)
     148             :             {
     149           0 :                 case 4:
     150           0 :                     return 10;  // iflABGR - Alpha, Blue, Green, Red (SGI frame
     151             :                                 // buffers)
     152           0 :                 default:
     153           0 :                     UNSUPPORTED_COMBO();
     154             :             }  // switch
     155             : 
     156           0 :         case GCI_HueBand:
     157           0 :             switch (nBands)
     158             :             {
     159           0 :                 case 3:
     160           0 :                     return 6;  // iflHSV - Hue, Saturation, Value
     161           0 :                 default:
     162           0 :                     UNSUPPORTED_COMBO();
     163             :             }  // switch
     164             : 
     165           0 :         case GCI_CyanBand:
     166           0 :             switch (nBands)
     167             :             {
     168           0 :                 case 3:
     169           0 :                     return 7;  // iflCMY - Cyan, Magenta, Yellow
     170           0 :                 case 4:
     171           0 :                     return 8;  // iflCMYK - Cyan, Magenta, Yellow, Black
     172           0 :                 default:
     173           0 :                     UNSUPPORTED_COMBO();
     174             :             }  // switch
     175             : 
     176           0 :         case GCI_GreenBand:
     177             :         case GCI_SaturationBand:
     178             :         case GCI_LightnessBand:
     179             :         case GCI_MagentaBand:
     180             :         case GCI_YellowBand:
     181             :         case GCI_BlackBand:
     182           0 :             CPLError(CE_Failure, CPLE_NotSupported,
     183             :                      "FIT write - unsupported combination (band 1 = %s) "
     184             :                      "- ignoring color model",
     185             :                      GDALGetColorInterpretationName(colorInterp));
     186           0 :             return 0;
     187             : 
     188          21 :         default:
     189          21 :             CPLDebug("FIT write",
     190             :                      "unrecognized colorInterp %i - deriving from "
     191             :                      "number of bands (%i)",
     192             :                      colorInterp, nBands);
     193             :             switch (nBands)
     194             :             {
     195          17 :                 case 1:
     196          17 :                     return 2;  // iflLuminance - luminance
     197           1 :                 case 2:
     198           1 :                     return 13;  // iflLuminanceAlpha - Luminance plus alpha
     199           1 :                 case 3:
     200           1 :                     return 3;  // iflRGB - full color (Red, Green, Blue
     201             :                                // triplets)
     202           1 :                 case 4:
     203           1 :                     return 5;  // iflRGBA - full color with transparency (alpha
     204             :                                // channel)
     205             :             }                  // switch
     206             : 
     207           1 :             CPLError(CE_Failure, CPLE_NotSupported,
     208             :                      "FIT write - unrecognized colorInterp %i and "
     209             :                      "unrecognized number of bands (%i)",
     210             :                      colorInterp, nBands);
     211             : 
     212           1 :             return 0;
     213             :     }  // switch
     214             : }

Generated by: LCOV version 1.14