LCOV - code coverage report
Current view: top level - frmts/kea - keamaskband.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 42 58 72.4 %
Date: 2024-04-27 17:22:41 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  keamaskband.cpp
       3             :  *
       4             :  *  Created by Pete Bunting on 01/08/2012.
       5             :  *  Copyright 2012 LibKEA. All rights reserved.
       6             :  *
       7             :  *  This file is part of LibKEA.
       8             :  *
       9             :  *  Permission is hereby granted, free of charge, to any person
      10             :  *  obtaining a copy of this software and associated documentation
      11             :  *  files (the "Software"), to deal in the Software without restriction,
      12             :  *  including without limitation the rights to use, copy, modify,
      13             :  *  merge, publish, distribute, sublicense, and/or sell copies of the
      14             :  *  Software, and to permit persons to whom the Software is furnished
      15             :  *  to do so, subject to the following conditions:
      16             :  *
      17             :  *  The above copyright notice and this permission notice shall be
      18             :  *  included in all copies or substantial portions of the Software.
      19             :  *
      20             :  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      21             :  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
      22             :  *  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      23             :  *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
      24             :  *  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
      25             :  *  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
      26             :  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      27             :  *
      28             :  */
      29             : 
      30             : #include "keamaskband.h"
      31             : 
      32             : // constructor
      33           3 : KEAMaskBand::KEAMaskBand(GDALRasterBand *pParent, kealib::KEAImageIO *pImageIO,
      34           3 :                          LockedRefCount *pRefCount)
      35             : {
      36           3 :     m_nSrcBand = pParent->GetBand();
      37           3 :     poDS = nullptr;
      38           3 :     nBand = 0;
      39             : 
      40           3 :     nRasterXSize = pParent->GetXSize();
      41           3 :     nRasterYSize = pParent->GetYSize();
      42             : 
      43           3 :     eDataType = GDT_Byte;
      44           3 :     pParent->GetBlockSize(&nBlockXSize, &nBlockYSize);
      45           3 :     eAccess = pParent->GetAccess();
      46             : 
      47             :     // grab the imageio class and its refcount
      48           3 :     this->m_pImageIO = pImageIO;
      49           3 :     this->m_pRefCount = pRefCount;
      50             :     // increment the refcount as we now have a reference to imageio
      51           3 :     this->m_pRefCount->IncRef();
      52           3 : }
      53             : 
      54           6 : KEAMaskBand::~KEAMaskBand()
      55             : {
      56             :     // according to the docs, this is required
      57           3 :     this->FlushCache(true);
      58             : 
      59             :     // decrement the recount and delete if needed
      60           3 :     if (m_pRefCount->DecRef())
      61             :     {
      62             :         try
      63             :         {
      64           0 :             m_pImageIO->close();
      65             :         }
      66           0 :         catch (const kealib::KEAIOException &)
      67             :         {
      68             :         }
      69           0 :         delete m_pImageIO;
      70           0 :         delete m_pRefCount;
      71             :     }
      72           6 : }
      73             : 
      74             : // overridden implementation - calls readImageBlock2BandMask instead
      75           2 : CPLErr KEAMaskBand::IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage)
      76             : {
      77             :     try
      78             :     {
      79             :         // GDAL deals in blocks - if we are at the end of a row
      80             :         // we need to adjust the amount read so we don't go over the edge
      81           2 :         int nxsize = this->nBlockXSize;
      82           2 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
      83           2 :         if (nxtotalsize > this->nRasterXSize)
      84             :         {
      85           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
      86             :         }
      87           2 :         int nysize = this->nBlockYSize;
      88           2 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
      89           2 :         if (nytotalsize > this->nRasterYSize)
      90             :         {
      91           0 :             nysize -= (nytotalsize - this->nRasterYSize);
      92             :         }
      93           2 :         this->m_pImageIO->readImageBlock2BandMask(
      94           2 :             this->m_nSrcBand, pImage, this->nBlockXSize * nBlockXOff,
      95           2 :             this->nBlockYSize * nBlockYOff, nxsize, nysize, this->nBlockXSize,
      96           2 :             this->nBlockYSize, kealib::kea_8uint);
      97             :     }
      98           0 :     catch (kealib::KEAIOException &e)
      99             :     {
     100           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to read file: %s",
     101           0 :                  e.what());
     102           0 :         return CE_Failure;
     103             :     }
     104           2 :     return CE_None;
     105             : }
     106             : 
     107             : // overridden implementation - calls writeImageBlock2BandMask instead
     108           2 : CPLErr KEAMaskBand::IWriteBlock(int nBlockXOff, int nBlockYOff, void *pImage)
     109             : {
     110             :     try
     111             :     {
     112             :         // GDAL deals in blocks - if we are at the end of a row
     113             :         // we need to adjust the amount written so we don't go over the edge
     114           2 :         int nxsize = this->nBlockXSize;
     115           2 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
     116           2 :         if (nxtotalsize > this->nRasterXSize)
     117             :         {
     118           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
     119             :         }
     120           2 :         int nysize = this->nBlockYSize;
     121           2 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
     122           2 :         if (nytotalsize > this->nRasterYSize)
     123             :         {
     124           0 :             nysize -= (nytotalsize - this->nRasterYSize);
     125             :         }
     126             : 
     127           2 :         this->m_pImageIO->writeImageBlock2BandMask(
     128           2 :             this->m_nSrcBand, pImage, this->nBlockXSize * nBlockXOff,
     129           2 :             this->nBlockYSize * nBlockYOff, nxsize, nysize, this->nBlockXSize,
     130           2 :             this->nBlockYSize, kealib::kea_8uint);
     131             :     }
     132           0 :     catch (kealib::KEAIOException &e)
     133             :     {
     134           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to write file: %s",
     135           0 :                  e.what());
     136           0 :         return CE_Failure;
     137             :     }
     138           2 :     return CE_None;
     139             : }

Generated by: LCOV version 1.14