LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/pmtiles - gdalpmtilesrasterband.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 35 35 100.0 %
Date: 2026-05-29 23:25:07 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implementation of PMTiles
       5             :  * Author:   Even Rouault <even.rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2026, Even Rouault <even.rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogr_pmtiles.h"
      14             : 
      15             : /************************************************************************/
      16             : /*                       GDALPMTilesRasterBand()                        */
      17             : /************************************************************************/
      18             : 
      19         210 : GDALPMTilesRasterBand::GDALPMTilesRasterBand(OGRPMTilesDataset *poDSIn,
      20         210 :                                              int nBandIn, int nBlockSize)
      21             : {
      22         210 :     poDS = poDSIn;
      23         210 :     nBand = nBandIn;
      24         210 :     eDataType = GDT_Byte;
      25         210 :     nRasterXSize = poDS->GetRasterXSize();
      26         210 :     nRasterYSize = poDS->GetRasterYSize();
      27         210 :     nBlockXSize = nBlockSize;
      28         210 :     nBlockYSize = nBlockSize;
      29         210 : }
      30             : 
      31             : /************************************************************************/
      32             : /*                          GetOverviewCount()                          */
      33             : /************************************************************************/
      34             : 
      35          18 : int GDALPMTilesRasterBand::GetOverviewCount()
      36             : {
      37          18 :     auto poGDS = cpl::down_cast<OGRPMTilesDataset *>(poDS);
      38          18 :     return static_cast<int>(poGDS->m_apoOverviews.size());
      39             : }
      40             : 
      41             : /************************************************************************/
      42             : /*                            GetOverview()                             */
      43             : /************************************************************************/
      44             : 
      45           9 : GDALRasterBand *GDALPMTilesRasterBand::GetOverview(int idx)
      46             : {
      47           9 :     if (idx < 0 || idx >= GetOverviewCount())
      48           2 :         return nullptr;
      49           7 :     auto poGDS = cpl::down_cast<OGRPMTilesDataset *>(poDS);
      50           7 :     return poGDS->m_apoOverviews[idx]->GetRasterBand(nBand);
      51             : }
      52             : 
      53             : /************************************************************************/
      54             : /*                       GetColorInterpretation()                       */
      55             : /************************************************************************/
      56             : 
      57          21 : GDALColorInterp GDALPMTilesRasterBand::GetColorInterpretation()
      58             : {
      59          21 :     if (poDS->GetRasterCount() <= 2)
      60           2 :         return nBand == 1 ? GCI_GrayIndex : GCI_AlphaBand;
      61          19 :     return static_cast<GDALColorInterp>(GCI_RedBand + nBand - 1);
      62             : }
      63             : 
      64             : /************************************************************************/
      65             : /*                             IReadBlock()                             */
      66             : /************************************************************************/
      67             : 
      68           9 : CPLErr GDALPMTilesRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff,
      69             :                                          void *pData)
      70             : {
      71             :     int nXSize, nYSize;
      72           9 :     GetActualBlockSize(nBlockXOff, nBlockYOff, &nXSize, &nYSize);
      73           9 :     const GSpacing nDTSize = GDALGetDataTypeSizeBytes(eDataType);
      74             :     GDALRasterIOExtraArg sExtraArg;
      75           9 :     INIT_RASTERIO_EXTRA_ARG(sExtraArg);
      76          18 :     return IRasterIO(GF_Read, nBlockXOff * nBlockXSize,
      77           9 :                      nBlockYOff * nBlockYSize, nXSize, nYSize, pData, nXSize,
      78           9 :                      nYSize, eDataType, nDTSize, nDTSize * nBlockXSize,
      79          18 :                      &sExtraArg);
      80             : }
      81             : 
      82             : /************************************************************************/
      83             : /*                             IRasterIO()                              */
      84             : /************************************************************************/
      85             : 
      86          25 : CPLErr GDALPMTilesRasterBand::IRasterIO(
      87             :     GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
      88             :     void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
      89             :     GSpacing nPixelSpace, GSpacing nLineSpace, GDALRasterIOExtraArg *psExtraArg)
      90             : {
      91             :     // Re-route to dataset IRasterIO
      92          25 :     auto poGDS = cpl::down_cast<OGRPMTilesDataset *>(poDS);
      93          25 :     int anBand[] = {nBand};
      94          25 :     return poGDS->IRasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize, pData,
      95             :                             nBufXSize, nBufYSize, eBufType, 1, anBand,
      96          50 :                             nPixelSpace, nLineSpace, 0, psExtraArg);
      97             : }

Generated by: LCOV version 1.14