LCOV - code coverage report
Current view: top level - frmts/kea - keaoverview.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 41 53 77.4 %
Date: 2024-04-27 17:22:41 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             :  *  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 "keaoverview.h"
      31             : 
      32             : // constructor
      33           3 : KEAOverview::KEAOverview(KEADataset *pDataset, int nSrcBand,
      34             :                          GDALAccess eAccessIn, kealib::KEAImageIO *pImageIO,
      35             :                          LockedRefCount *pRefCount, int nOverviewIndex,
      36           3 :                          uint64_t nXSize, uint64_t nYSize)
      37           3 :     : KEARasterBand(pDataset, nSrcBand, eAccessIn, pImageIO, pRefCount)
      38             : {
      39           3 :     this->m_nOverviewIndex = nOverviewIndex;
      40             :     // overridden from the band - not the same size as the band obviously
      41           3 :     this->nBlockXSize =
      42           3 :         pImageIO->getOverviewBlockSize(nSrcBand, nOverviewIndex);
      43           3 :     this->nBlockYSize =
      44           3 :         pImageIO->getOverviewBlockSize(nSrcBand, nOverviewIndex);
      45           3 :     this->nRasterXSize = static_cast<int>(nXSize);
      46           3 :     this->nRasterYSize = static_cast<int>(nYSize);
      47           3 : }
      48             : 
      49           6 : KEAOverview::~KEAOverview()
      50             : {
      51           6 : }
      52             : 
      53             : // overridden implementation - calls readFromOverview instead
      54           2 : CPLErr KEAOverview::IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage)
      55             : {
      56             :     try
      57             :     {
      58             :         // GDAL deals in blocks - if we are at the end of a row
      59             :         // we need to adjust the amount read so we don't go over the edge
      60           2 :         int nxsize = this->nBlockXSize;
      61           2 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
      62           2 :         if (nxtotalsize > this->nRasterXSize)
      63             :         {
      64           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
      65             :         }
      66           2 :         int nysize = this->nBlockYSize;
      67           2 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
      68           2 :         if (nytotalsize > this->nRasterYSize)
      69             :         {
      70           0 :             nysize -= (nytotalsize - this->nRasterYSize);
      71             :         }
      72           2 :         this->m_pImageIO->readFromOverview(
      73           2 :             this->nBand, this->m_nOverviewIndex, pImage,
      74           2 :             this->nBlockXSize * nBlockXOff, this->nBlockYSize * nBlockYOff,
      75           2 :             nxsize, nysize, this->nBlockXSize, this->nBlockYSize,
      76             :             this->m_eKEADataType);
      77           2 :         return CE_None;
      78             :     }
      79           0 :     catch (kealib::KEAIOException &e)
      80             :     {
      81           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to read file: %s",
      82           0 :                  e.what());
      83           0 :         return CE_Failure;
      84             :     }
      85             : }
      86             : 
      87             : // overridden implementation - calls writeToOverview instead
      88           1 : CPLErr KEAOverview::IWriteBlock(int nBlockXOff, int nBlockYOff, void *pImage)
      89             : {
      90             :     try
      91             :     {
      92             :         // GDAL deals in blocks - if we are at the end of a row
      93             :         // we need to adjust the amount written so we don't go over the edge
      94           1 :         int nxsize = this->nBlockXSize;
      95           1 :         int nxtotalsize = this->nBlockXSize * (nBlockXOff + 1);
      96           1 :         if (nxtotalsize > this->nRasterXSize)
      97             :         {
      98           0 :             nxsize -= (nxtotalsize - this->nRasterXSize);
      99             :         }
     100           1 :         int nysize = this->nBlockYSize;
     101           1 :         int nytotalsize = this->nBlockYSize * (nBlockYOff + 1);
     102           1 :         if (nytotalsize > this->nRasterYSize)
     103             :         {
     104           0 :             nysize -= (nytotalsize - this->nRasterYSize);
     105             :         }
     106             : 
     107           1 :         this->m_pImageIO->writeToOverview(
     108           1 :             this->nBand, this->m_nOverviewIndex, pImage,
     109           1 :             this->nBlockXSize * nBlockXOff, this->nBlockYSize * nBlockYOff,
     110           1 :             nxsize, nysize, this->nBlockXSize, this->nBlockYSize,
     111             :             this->m_eKEADataType);
     112           1 :         return CE_None;
     113             :     }
     114           0 :     catch (kealib::KEAIOException &e)
     115             :     {
     116           0 :         CPLError(CE_Failure, CPLE_AppDefined, "Failed to write file: %s",
     117           0 :                  e.what());
     118           0 :         return CE_Failure;
     119             :     }
     120             : }
     121             : 
     122           1 : GDALRasterAttributeTable *KEAOverview::GetDefaultRAT()
     123             : {
     124             :     // KEARasterBand implements this, but we don't want to
     125           1 :     return nullptr;
     126             : }
     127             : 
     128             : CPLErr
     129           1 : KEAOverview::SetDefaultRAT(CPL_UNUSED const GDALRasterAttributeTable *poRAT)
     130             : {
     131             :     // KEARasterBand implements this, but we don't want to
     132           1 :     return CE_Failure;
     133             : }

Generated by: LCOV version 1.14