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-11-21 22:18:42 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             :  * SPDX-License-Identifier: MIT
      10             :  *
      11             :  */
      12             : 
      13             : #include "keamaskband.h"
      14             : 
      15             : // constructor
      16           3 : KEAMaskBand::KEAMaskBand(GDALRasterBand *pParent, kealib::KEAImageIO *pImageIO,
      17           3 :                          LockedRefCount *pRefCount)
      18             : {
      19           3 :     m_nSrcBand = pParent->GetBand();
      20           3 :     poDS = nullptr;
      21           3 :     nBand = 0;
      22             : 
      23           3 :     nRasterXSize = pParent->GetXSize();
      24           3 :     nRasterYSize = pParent->GetYSize();
      25             : 
      26           3 :     eDataType = GDT_Byte;
      27           3 :     pParent->GetBlockSize(&nBlockXSize, &nBlockYSize);
      28           3 :     eAccess = pParent->GetAccess();
      29             : 
      30             :     // grab the imageio class and its refcount
      31           3 :     this->m_pImageIO = pImageIO;
      32           3 :     this->m_pRefCount = pRefCount;
      33             :     // increment the refcount as we now have a reference to imageio
      34           3 :     this->m_pRefCount->IncRef();
      35           3 : }
      36             : 
      37           6 : KEAMaskBand::~KEAMaskBand()
      38             : {
      39             :     // according to the docs, this is required
      40           3 :     this->FlushCache(true);
      41             : 
      42             :     // decrement the recount and delete if needed
      43           3 :     if (m_pRefCount->DecRef())
      44             :     {
      45             :         try
      46             :         {
      47           0 :             m_pImageIO->close();
      48             :         }
      49           0 :         catch (const kealib::KEAIOException &)
      50             :         {
      51             :         }
      52           0 :         delete m_pImageIO;
      53           0 :         delete m_pRefCount;
      54             :     }
      55           6 : }
      56             : 
      57             : // overridden implementation - calls readImageBlock2BandMask instead
      58           2 : CPLErr KEAMaskBand::IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage)
      59             : {
      60             :     try
      61             :     {
      62             :         // GDAL deals in blocks - if we are at the end of a row
      63             :         // we need to adjust the amount read so we don't go over the edge
      64           2 :         int nxsize = this->nBlockXSize;
      65           2 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
      66           2 :         if (nxtotalsize > this->nRasterXSize)
      67             :         {
      68           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
      69             :         }
      70           2 :         int nysize = this->nBlockYSize;
      71           2 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
      72           2 :         if (nytotalsize > this->nRasterYSize)
      73             :         {
      74           0 :             nysize -= (nytotalsize - this->nRasterYSize);
      75             :         }
      76           2 :         this->m_pImageIO->readImageBlock2BandMask(
      77           2 :             this->m_nSrcBand, pImage, this->nBlockXSize * nBlockXOff,
      78           2 :             this->nBlockYSize * nBlockYOff, nxsize, nysize, this->nBlockXSize,
      79           2 :             this->nBlockYSize, kealib::kea_8uint);
      80             :     }
      81           0 :     catch (kealib::KEAIOException &e)
      82             :     {
      83           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to read file: %s",
      84           0 :                  e.what());
      85           0 :         return CE_Failure;
      86             :     }
      87           2 :     return CE_None;
      88             : }
      89             : 
      90             : // overridden implementation - calls writeImageBlock2BandMask instead
      91           2 : CPLErr KEAMaskBand::IWriteBlock(int nBlockXOff, int nBlockYOff, void *pImage)
      92             : {
      93             :     try
      94             :     {
      95             :         // GDAL deals in blocks - if we are at the end of a row
      96             :         // we need to adjust the amount written so we don't go over the edge
      97           2 :         int nxsize = this->nBlockXSize;
      98           2 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
      99           2 :         if (nxtotalsize > this->nRasterXSize)
     100             :         {
     101           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
     102             :         }
     103           2 :         int nysize = this->nBlockYSize;
     104           2 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
     105           2 :         if (nytotalsize > this->nRasterYSize)
     106             :         {
     107           0 :             nysize -= (nytotalsize - this->nRasterYSize);
     108             :         }
     109             : 
     110           2 :         this->m_pImageIO->writeImageBlock2BandMask(
     111           2 :             this->m_nSrcBand, pImage, this->nBlockXSize * nBlockXOff,
     112           2 :             this->nBlockYSize * nBlockYOff, nxsize, nysize, this->nBlockXSize,
     113           2 :             this->nBlockYSize, kealib::kea_8uint);
     114             :     }
     115           0 :     catch (kealib::KEAIOException &e)
     116             :     {
     117           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to write file: %s",
     118           0 :                  e.what());
     119           0 :         return CE_Failure;
     120             :     }
     121           2 :     return CE_None;
     122             : }

Generated by: LCOV version 1.14