LCOV - code coverage report
Current view: top level - frmts/kea - keaoverview.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 42 54 77.8 %
Date: 2024-11-21 22:18:42 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  keaoverview.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 "keaoverview.h"
      14             : 
      15             : // constructor
      16           3 : KEAOverview::KEAOverview(KEADataset *pDataset, int nSrcBand,
      17             :                          GDALAccess eAccessIn, kealib::KEAImageIO *pImageIO,
      18             :                          LockedRefCount *pRefCount, int nOverviewIndex,
      19           3 :                          uint64_t nXSize, uint64_t nYSize)
      20           3 :     : KEARasterBand(pDataset, nSrcBand, eAccessIn, pImageIO, pRefCount)
      21             : {
      22           3 :     this->m_nOverviewIndex = nOverviewIndex;
      23             :     // overridden from the band - not the same size as the band obviously
      24           3 :     this->nBlockXSize =
      25           3 :         pImageIO->getOverviewBlockSize(nSrcBand, nOverviewIndex);
      26           3 :     this->nBlockYSize =
      27           3 :         pImageIO->getOverviewBlockSize(nSrcBand, nOverviewIndex);
      28           3 :     this->nRasterXSize = static_cast<int>(nXSize);
      29           3 :     this->nRasterYSize = static_cast<int>(nYSize);
      30           3 : }
      31             : 
      32           6 : KEAOverview::~KEAOverview()
      33             : {
      34             :     // according to the docs, this is required
      35             :     // otherwise not all tiles will be written.
      36           3 :     this->FlushCache();
      37           6 : }
      38             : 
      39             : // overridden implementation - calls readFromOverview instead
      40           2 : CPLErr KEAOverview::IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage)
      41             : {
      42             :     try
      43             :     {
      44             :         // GDAL deals in blocks - if we are at the end of a row
      45             :         // we need to adjust the amount read so we don't go over the edge
      46           2 :         int nxsize = this->nBlockXSize;
      47           2 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
      48           2 :         if (nxtotalsize > this->nRasterXSize)
      49             :         {
      50           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
      51             :         }
      52           2 :         int nysize = this->nBlockYSize;
      53           2 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
      54           2 :         if (nytotalsize > this->nRasterYSize)
      55             :         {
      56           0 :             nysize -= (nytotalsize - this->nRasterYSize);
      57             :         }
      58           2 :         this->m_pImageIO->readFromOverview(
      59           2 :             this->nBand, this->m_nOverviewIndex, pImage,
      60           2 :             this->nBlockXSize * nBlockXOff, this->nBlockYSize * nBlockYOff,
      61           2 :             nxsize, nysize, this->nBlockXSize, this->nBlockYSize,
      62             :             this->m_eKEADataType);
      63           2 :         return CE_None;
      64             :     }
      65           0 :     catch (kealib::KEAIOException &e)
      66             :     {
      67           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to read file: %s",
      68           0 :                  e.what());
      69           0 :         return CE_Failure;
      70             :     }
      71             : }
      72             : 
      73             : // overridden implementation - calls writeToOverview instead
      74           1 : CPLErr KEAOverview::IWriteBlock(int nBlockXOff, int nBlockYOff, void *pImage)
      75             : {
      76             :     try
      77             :     {
      78             :         // GDAL deals in blocks - if we are at the end of a row
      79             :         // we need to adjust the amount written so we don't go over the edge
      80           1 :         int nxsize = this->nBlockXSize;
      81           1 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
      82           1 :         if (nxtotalsize > this->nRasterXSize)
      83             :         {
      84           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
      85             :         }
      86           1 :         int nysize = this->nBlockYSize;
      87           1 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
      88           1 :         if (nytotalsize > this->nRasterYSize)
      89             :         {
      90           0 :             nysize -= (nytotalsize - this->nRasterYSize);
      91             :         }
      92             : 
      93           1 :         this->m_pImageIO->writeToOverview(
      94           1 :             this->nBand, this->m_nOverviewIndex, pImage,
      95           1 :             this->nBlockXSize * nBlockXOff, this->nBlockYSize * nBlockYOff,
      96           1 :             nxsize, nysize, this->nBlockXSize, this->nBlockYSize,
      97             :             this->m_eKEADataType);
      98           1 :         return CE_None;
      99             :     }
     100           0 :     catch (kealib::KEAIOException &e)
     101             :     {
     102           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to write file: %s",
     103           0 :                  e.what());
     104           0 :         return CE_Failure;
     105             :     }
     106             : }
     107             : 
     108           1 : GDALRasterAttributeTable *KEAOverview::GetDefaultRAT()
     109             : {
     110             :     // KEARasterBand implements this, but we don't want to
     111           1 :     return nullptr;
     112             : }
     113             : 
     114             : CPLErr
     115           1 : KEAOverview::SetDefaultRAT(CPL_UNUSED const GDALRasterAttributeTable *poRAT)
     116             : {
     117             :     // KEARasterBand implements this, but we don't want to
     118           1 :     return CE_Failure;
     119             : }

Generated by: LCOV version 1.14