1 : /******************************************************************************
2 : * $Id: jp2userbox.cpp 10645 2007-01-18 02:22:39Z 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 "jp2userbox.h"
31 :
32 : CPL_CVSID("$Id: jp2userbox.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
33 :
34 : /************************************************************************/
35 : /* JP2UserBox() */
36 : /************************************************************************/
37 :
38 32 : JP2UserBox::JP2UserBox()
39 : {
40 32 : pabyData = NULL;
41 32 : nDataLength = 0;
42 :
43 32 : m_nTBox = 0;
44 32 : }
45 :
46 : /************************************************************************/
47 : /* ~JP2UserBox() */
48 : /************************************************************************/
49 :
50 64 : JP2UserBox::~JP2UserBox()
51 :
52 : {
53 32 : if( pabyData != NULL )
54 : {
55 32 : CPLFree( pabyData );
56 32 : pabyData = NULL;
57 : }
58 64 : }
59 :
60 : /************************************************************************/
61 : /* SetData() */
62 : /************************************************************************/
63 :
64 32 : void JP2UserBox::SetData( int nLengthIn, const unsigned char *pabyDataIn )
65 :
66 : {
67 32 : if( pabyData != NULL )
68 0 : CPLFree( pabyData );
69 :
70 32 : nDataLength = nLengthIn;
71 32 : pabyData = (unsigned char *) CPLMalloc(nDataLength);
72 32 : memcpy( pabyData, pabyDataIn, nDataLength );
73 :
74 32 : m_bValid = true;
75 32 : }
76 :
77 : /************************************************************************/
78 : /* UpdateXLBox() */
79 : /************************************************************************/
80 :
81 26 : void JP2UserBox::UpdateXLBox()
82 :
83 : {
84 26 : m_nXLBox = 8 + nDataLength;
85 26 : m_nLDBox = nDataLength;
86 26 : }
87 :
88 : /************************************************************************/
89 : /* Parse() */
90 : /* */
91 : /* Parse box, and data contents from file into memory. */
92 : /************************************************************************/
93 :
94 0 : CNCSError JP2UserBox::Parse( class CNCSJP2File &JP2File,
95 : CNCSJPCIOStream &Stream )
96 :
97 : {
98 0 : CNCSError Error = NCS_SUCCESS;
99 :
100 : return Error;
101 : }
102 :
103 : /************************************************************************/
104 : /* UnParse() */
105 : /* */
106 : /* Write box meta information, and data to file. */
107 : /************************************************************************/
108 :
109 26 : CNCSError JP2UserBox::UnParse( class CNCSJP2File &JP2File,
110 : CNCSJPCIOStream &Stream )
111 :
112 : {
113 26 : CNCSError Error = NCS_SUCCESS;
114 :
115 26 : if( m_nTBox == 0 )
116 : {
117 0 : Error = NCS_UNKNOWN_ERROR;
118 : CPLError( CE_Failure, CPLE_AppDefined,
119 0 : "No box type set in JP2UserBox::UnParse()" );
120 0 : return Error;
121 : }
122 :
123 26 : Error = CNCSJP2Box::UnParse(JP2File, Stream);
124 :
125 : // NCSJP2_CHECKIO_BEGIN(Error, Stream);
126 26 : Stream.Write(pabyData, nDataLength);
127 : // NCSJP2_CHECKIO_END();
128 :
129 26 : return Error;
130 1140 : }
|