LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk/core - pcidsk_pubutils.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 72 140 51.4 %
Date: 2024-05-03 15:49:35 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Purpose:  Various public (documented) utility functions.
       4             :  *
       5             :  ******************************************************************************
       6             :  * Copyright (c) 2009
       7             :  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
       8             :  *
       9             :  * Permission is hereby granted, free of charge, to any person obtaining a
      10             :  * copy of this software and associated documentation files (the "Software"),
      11             :  * to deal in the Software without restriction, including without limitation
      12             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      13             :  * and/or sell copies of the Software, and to permit persons to whom the
      14             :  * Software is furnished to do so, subject to the following conditions:
      15             :  *
      16             :  * The above copyright notice and this permission notice shall be included
      17             :  * in all copies or substantial portions of the Software.
      18             :  *
      19             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      20             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      22             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      24             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      25             :  * DEALINGS IN THE SOFTWARE.
      26             :  ****************************************************************************/
      27             : #include "pcidsk_config.h"
      28             : #include "pcidsk_types.h"
      29             : #include "pcidsk_exception.h"
      30             : #include "core/pcidsk_utils.h"
      31             : #include <cstdlib>
      32             : #include <cstring>
      33             : 
      34             : using namespace PCIDSK;
      35             : 
      36             : /************************************************************************/
      37             : /*                            DataTypeSize()                            */
      38             : /************************************************************************/
      39             : 
      40             : /**
      41             :  * Return size of data type.
      42             :  *
      43             :  * Note that type CHN_BIT exists to represent one bit backed data from
      44             :  * bitmap segments, but because the return of this functions is measured
      45             :  * in bytes, the size of a CHN_BIT pixel cannot be properly returned (one
      46             :  * eighth of a byte), so "1" is returned instead.
      47             :  *
      48             :  * @param chan_type the channel type enumeration value.
      49             :  *
      50             :  * @return the size of the passed data type in bytes, or zero for unknown
      51             :  * values.
      52             :  */
      53             : 
      54        3010 : int PCIDSK::DataTypeSize( eChanType chan_type )
      55             : 
      56             : {
      57        3010 :     switch( chan_type )
      58             :     {
      59        1106 :       case CHN_8U:
      60        1106 :         return 1;
      61         159 :       case CHN_16S:
      62         159 :         return 2;
      63         380 :       case CHN_16U:
      64         380 :         return 2;
      65         111 :       case CHN_32S:
      66         111 :         return 4;
      67         111 :       case CHN_32U:
      68         111 :         return 4;
      69         159 :       case CHN_32R:
      70         159 :         return 4;
      71         111 :       case CHN_64S:
      72         111 :         return 8;
      73         111 :       case CHN_64U:
      74         111 :         return 8;
      75         111 :       case CHN_64R:
      76         111 :         return 8;
      77         111 :       case CHN_C16U:
      78         111 :         return 4;
      79         159 :       case CHN_C16S:
      80         159 :         return 4;
      81         111 :       case CHN_C32U:
      82         111 :         return 8;
      83         111 :       case CHN_C32S:
      84         111 :         return 8;
      85         159 :       case CHN_C32R:
      86         159 :         return 8;
      87           0 :       case CHN_BIT:
      88           0 :         return 1; // not really accurate!
      89           0 :       default:
      90           0 :         return 0;
      91             :     }
      92             : }
      93             : 
      94             : /************************************************************************/
      95             : /*                            DataTypeName()                            */
      96             : /************************************************************************/
      97             : 
      98             : /**
      99             :  * Return name for the data type.
     100             :  *
     101             :  * The returned values are suitable for display to people, and matches
     102             :  * the portion of the name after the underscore (i.e. "8U" for CHN_8U.
     103             :  *
     104             :  * @param chan_type the channel type enumeration value to be translated.
     105             :  *
     106             :  * @return a string representing the data type.
     107             :  */
     108             : 
     109         131 : const char * PCIDSK::DataTypeName( eChanType chan_type )
     110             : 
     111             : {
     112         131 :     switch( chan_type )
     113             :     {
     114          92 :       case CHN_8U:
     115          92 :         return "8U";
     116           5 :       case CHN_16S:
     117           5 :         return "16S";
     118          19 :       case CHN_16U:
     119          19 :         return "16U";
     120           0 :       case CHN_32S:
     121           0 :         return "32S";
     122           0 :       case CHN_32U:
     123           0 :         return "32U";
     124           5 :       case CHN_32R:
     125           5 :         return "32R";
     126           0 :       case CHN_64S:
     127           0 :         return "64S";
     128           0 :       case CHN_64U:
     129           0 :         return "64U";
     130           0 :       case CHN_64R:
     131           0 :         return "64R";
     132           0 :       case CHN_C16U:
     133           0 :         return "C16U";
     134           5 :       case CHN_C16S:
     135           5 :         return "C16S";
     136           0 :       case CHN_C32U:
     137           0 :         return "C32U";
     138           0 :       case CHN_C32S:
     139           0 :         return "C32S";
     140           5 :       case CHN_C32R:
     141           5 :         return "C32R";
     142           0 :       case CHN_BIT:
     143           0 :         return "BIT";
     144           0 :       default:
     145           0 :         return "UNK";
     146             :     }
     147             : }
     148             : 
     149             : /************************************************************************/
     150             : /*                      GetDataTypeFromName()                           */
     151             : /************************************************************************/
     152             : 
     153             : /**
     154             :  * @brief Return the segment type code based on the contents of type_name
     155             :  *
     156             :  * @param pszDataType the type name, as a string
     157             :  *
     158             :  * @return the channel type code
     159             :  */
     160         388 : eChanType PCIDSK::GetDataTypeFromName(const char * pszDataType)
     161             : {
     162         388 :     if (strstr(pszDataType, "8U") != nullptr)
     163         265 :         return CHN_8U;
     164         123 :     if (strstr(pszDataType, "C16U") != nullptr)
     165           0 :         return CHN_C16U;
     166         123 :     if (strstr(pszDataType, "C16S") != nullptr)
     167           9 :         return CHN_C16S;
     168         114 :     if (strstr(pszDataType, "C32U") != nullptr)
     169           0 :         return CHN_C32U;
     170         114 :     if (strstr(pszDataType, "C32S") != nullptr)
     171           0 :         return CHN_C32S;
     172         114 :     if (strstr(pszDataType, "C32R") != nullptr)
     173           9 :         return CHN_C32R;
     174         105 :     if (strstr(pszDataType, "16U") != nullptr)
     175          87 :         return CHN_16U;
     176          18 :     if (strstr(pszDataType, "16S") != nullptr)
     177           9 :         return CHN_16S;
     178           9 :     if (strstr(pszDataType, "32U") != nullptr)
     179           0 :         return CHN_32U;
     180           9 :     if (strstr(pszDataType, "32S") != nullptr)
     181           0 :         return CHN_32S;
     182           9 :     if (strstr(pszDataType, "32R") != nullptr)
     183           9 :         return CHN_32R;
     184           0 :     if (strstr(pszDataType, "64U") != nullptr)
     185           0 :         return CHN_64U;
     186           0 :     if (strstr(pszDataType, "64S") != nullptr)
     187           0 :         return CHN_64S;
     188           0 :     if (strstr(pszDataType, "64R") != nullptr)
     189           0 :         return CHN_64R;
     190           0 :     if (strstr(pszDataType, "BIT") != nullptr)
     191           0 :         return CHN_BIT;
     192             : 
     193           0 :     return CHN_UNKNOWN;
     194             : }
     195             : 
     196             : /************************************************************************/
     197             : /*                       IsDataTypeComplex()                           */
     198             : /************************************************************************/
     199             : 
     200             : /**
     201             :  * @brief Return whether or not the data type is complex
     202             :  *
     203             :  * @param type the type
     204             :  *
     205             :  * @return true if the data type is complex, false otherwise
     206             :  */
     207           0 : bool PCIDSK::IsDataTypeComplex(eChanType type)
     208             : {
     209           0 :     switch(type)
     210             :     {
     211           0 :     case CHN_C32R:
     212             :     case CHN_C32U:
     213             :     case CHN_C32S:
     214             :     case CHN_C16U:
     215             :     case CHN_C16S:
     216           0 :         return true;
     217           0 :     default:
     218           0 :         return false;
     219             :     }
     220             : }
     221             : 
     222             : /************************************************************************/
     223             : /*                          SegmentTypeName()                           */
     224             : /************************************************************************/
     225             : 
     226             : /**
     227             :  * Return name for segment type.
     228             :  *
     229             :  * Returns a short name for the segment type code passed in.  This is normally
     230             :  * the portion of the enumeration name that comes after the underscore - i.e.
     231             :  * "BIT" for SEG_BIT.
     232             :  *
     233             :  * @param type the segment type code.
     234             :  *
     235             :  * @return the string for the segment type.
     236             :  */
     237             : 
     238        4111 : const char * PCIDSK::SegmentTypeName( int type )
     239             : {
     240        4111 :     switch( type )
     241             :     {
     242           0 :       case SEG_BIT:
     243           0 :         return "BIT";
     244        3547 :       case SEG_VEC:
     245        3547 :         return "VEC";
     246           0 :       case SEG_SIG:
     247           0 :         return "SIG";
     248           0 :       case SEG_TEX:
     249           0 :         return "TEX";
     250         238 :       case SEG_GEO:
     251         238 :         return "GEO";
     252           0 :       case SEG_ORB:
     253           0 :         return "ORB";
     254           0 :       case SEG_LUT:
     255           0 :         return "LUT";
     256           4 :       case SEG_PCT:
     257           4 :         return "PCT";
     258           0 :       case SEG_BLUT:
     259           0 :         return "BLUT";
     260           0 :       case SEG_BPCT:
     261           0 :         return "BPCT";
     262           0 :       case SEG_BIN:
     263           0 :         return "BIN";
     264           0 :       case SEG_ARR:
     265           0 :         return "ARR";
     266         322 :       case SEG_SYS:
     267         322 :         return "SYS";
     268           0 :       case SEG_GCPOLD:
     269           0 :         return "GCPOLD";
     270           0 :       case SEG_GCP2:
     271           0 :         return "GCP2";
     272           0 :       default:
     273           0 :         return "UNKNOWN";
     274             :     }
     275             : }

Generated by: LCOV version 1.14