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