LCOV - code coverage report
Current view: top level - frmts/ecw - jp2userbox.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 27 34 79.4 %
Date: 2024-05-04 12:52:34 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL ECW Driver
       4             :  * Purpose:  JP2UserBox implementation - arbitrary box read/write.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : // ncsjpcbuffer.h needs the min and max macros.
      30             : #undef NOMINMAX
      31             : 
      32             : #include "gdal_ecw.h"
      33             : 
      34             : #if defined(HAVE_COMPRESS)
      35             : 
      36             : /************************************************************************/
      37             : /*                             JP2UserBox()                             */
      38             : /************************************************************************/
      39             : 
      40          62 : JP2UserBox::JP2UserBox()
      41             : {
      42          62 :     pabyData = nullptr;
      43          62 :     nDataLength = 0;
      44             : 
      45          62 :     m_nTBox = 0;
      46          62 : }
      47             : 
      48             : /************************************************************************/
      49             : /*                            ~JP2UserBox()                             */
      50             : /************************************************************************/
      51             : 
      52         124 : JP2UserBox::~JP2UserBox()
      53             : 
      54             : {
      55          62 :     if (pabyData != nullptr)
      56             :     {
      57          62 :         CPLFree(pabyData);
      58          62 :         pabyData = nullptr;
      59             :     }
      60         124 : }
      61             : 
      62             : /************************************************************************/
      63             : /*                              SetData()                               */
      64             : /************************************************************************/
      65             : 
      66          62 : void JP2UserBox::SetData(int nLengthIn, const unsigned char *pabyDataIn)
      67             : 
      68             : {
      69          62 :     if (pabyData != nullptr)
      70           0 :         CPLFree(pabyData);
      71             : 
      72          62 :     nDataLength = nLengthIn;
      73          62 :     pabyData = static_cast<unsigned char *>(CPLMalloc(nDataLength));
      74          62 :     memcpy(pabyData, pabyDataIn, nDataLength);
      75             : 
      76          62 :     m_bValid = true;
      77          62 : }
      78             : 
      79             : /************************************************************************/
      80             : /*                            UpdateXLBox()                             */
      81             : /************************************************************************/
      82             : 
      83          48 : void JP2UserBox::UpdateXLBox()
      84             : 
      85             : {
      86          48 :     m_nXLBox = 8 + nDataLength;
      87          48 :     m_nLDBox = nDataLength;
      88          48 : }
      89             : 
      90             : /************************************************************************/
      91             : /*                               Parse()                                */
      92             : /*                                                                      */
      93             : /*      Parse box, and data contents from file into memory.             */
      94             : /************************************************************************/
      95             : #if ECWSDK_VERSION >= 55
      96             : CNCSError JP2UserBox::Parse(CPL_UNUSED NCS::SDK::CFileBase &JP2File,
      97             :                             CPL_UNUSED const NCS::CIOStreamPtr &Stream)
      98             : #elif ECWSDK_VERSION >= 40
      99             : CNCSError JP2UserBox::Parse(CPL_UNUSED NCS::SDK::CFileBase &JP2File,
     100             :                             CPL_UNUSED NCS::CIOStream &Stream)
     101             : #else
     102           0 : CNCSError JP2UserBox::Parse(CPL_UNUSED class CNCSJP2File &JP2File,
     103             :                             CPL_UNUSED CNCSJPCIOStream &Stream)
     104             : #endif
     105             : {
     106           0 :     CNCSError Error(GetCNCSError(NCS_SUCCESS));
     107             : 
     108           0 :     return Error;
     109             : }
     110             : 
     111             : /************************************************************************/
     112             : /*                              UnParse()                               */
     113             : /*                                                                      */
     114             : /*      Write box meta information, and data to file.                   */
     115             : /************************************************************************/
     116             : #if ECWSDK_VERSION >= 55
     117             : CNCSError JP2UserBox::UnParse(NCS::SDK::CFileBase &JP2File,
     118             :                               const NCS::CIOStreamPtr &Stream)
     119             : #elif ECWSDK_VERSION >= 40
     120             : CNCSError JP2UserBox::UnParse(NCS::SDK::CFileBase &JP2File,
     121             :                               NCS::CIOStream &Stream)
     122             : #else
     123          48 : CNCSError JP2UserBox::UnParse(class CNCSJP2File &JP2File,
     124             :                               CNCSJPCIOStream &Stream)
     125             : #endif
     126             : {
     127          48 :     CNCSError Error(GetCNCSError(NCS_SUCCESS));
     128             : 
     129          48 :     if (m_nTBox == 0)
     130             :     {
     131           0 :         Error = GetCNCSError(NCS_UNKNOWN_ERROR);
     132           0 :         CPLError(CE_Failure, CPLE_AppDefined,
     133             :                  "No box type set in JP2UserBox::UnParse()");
     134           0 :         return Error;
     135             :     }
     136             : #if ECWSDK_VERSION < 50
     137          48 :     Error = CNCSJP2Box::UnParse(JP2File, Stream);
     138             : #else
     139             :     Error = CNCSSDKBox::UnParse(JP2File, Stream);
     140             : #endif
     141             : 
     142             : #if ECWSDK_VERSION >= 55
     143             :     Stream->Write(pabyData, nDataLength);
     144             : #else
     145          48 :     Stream.Write(pabyData, nDataLength);
     146             : #endif
     147             : 
     148          48 :     return Error;
     149             : }
     150             : 
     151             : #endif /* defined(HAVE_COMPRESS) */

Generated by: LCOV version 1.14