Debian Codegraph @

frmts/pcidsk/sdk/channel/cbandinterleavedchannel.cpp

raw symbols SCIP
1 /******************************************************************************
2 *
3 * Purpose: Implementation of the CBandInterleavedChannel class.
4 *
5 * This class is used to implement band interleaved channels within a
6 * PCIDSK file (which are always packed, and FILE interleaved data from
7 * external raw files which may not be packed.
8 *
9 ******************************************************************************
10 * Copyright (c) 2009
11 * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
12 *
13 * SPDX-License-Identifier: MIT
14 ****************************************************************************/
15
16 #include "pcidsk_config.h"cxx . . $ `<file>/frmts/pcidsk/sdk/pcidsk_config.h`/
17 #include "pcidsk_types.h"cxx . . $ `<file>/frmts/pcidsk/sdk/pcidsk_types.h`/
18 #include "pcidsk_channel.h"cxx . . $ `<file>/frmts/pcidsk/sdk/pcidsk_channel.h`/
19 #include "pcidsk_buffer.h"cxx . . $ `<file>/frmts/pcidsk/sdk/pcidsk_buffer.h`/
20 #include "pcidsk_exception.h"cxx . . $ `<file>/frmts/pcidsk/sdk/pcidsk_exception.h`/
21 #include "pcidsk_file.h"cxx . . $ `<file>/frmts/pcidsk/sdk/pcidsk_file.h`/
22 #include "core/pcidsk_utils.h"cxx . . $ `<file>/frmts/pcidsk/sdk/core/pcidsk_utils.h`/
23 #include "core/cpcidskfile.h"cxx . . $ `<file>/frmts/pcidsk/sdk/core/cpcidskfile.h`/
24 #include "core/clinksegment.h"cxx . . $ `<file>/frmts/pcidsk/sdk/core/clinksegment.h`/
25 #include "channel/cbandinterleavedchannel.h"cxx . . $ `<file>/frmts/pcidsk/sdk/channel/cbandinterleavedchannel.h`/
26 #include <cassert>
27 #include <cstring>
28 #include <cstdio>
29 #include <cstdlib>
30 #include <climits>
31 #include <limits>
32
33 using namespace PCIDSK;
34
35 /************************************************************************/
36 /* CBandInterleavedChannel() */
37 /************************************************************************/
38
39 CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#::CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#CBandInterleavedChannel(2bae6be8963ceac1).( PCIDSKBuffercxx . . $ PCIDSK/PCIDSKBuffer# &image_header,
40 uint64cxx . . $ PCIDSK/uint64# ih_offsetIn,
41 CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! PCIDSKBuffercxx . . $ PCIDSK/PCIDSKBuffer# &file_header,
42 int channelnum,
43 CPCIDSKFilecxx . . $ PCIDSK/CPCIDSKFile# *fileIn,
44 uint64cxx . . $ PCIDSK/uint64# image_offset,
45 eChanTypecxx . . $ PCIDSK/eChanType# pixel_typeIn )
46 : CPCIDSKChannelcxx . . $ PCIDSK/CPCIDSKChannel#( image_header, ih_offsetIn, fileIn, pixel_typeIn, channelnum)
47
48 {
49 io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. = nullptr;
50 io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p. = nullptr;
51
52 /* -------------------------------------------------------------------- */
53 /* Establish the data layout. */
54 /* -------------------------------------------------------------------- */
55 if( strcmp(filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetInterleavingcxx . . $ PCIDSK/CPCIDSKFile#GetInterleaving(219584694fe2b248).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(),"FILE") == 0 )
56 {
57 start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte. = atouint64cxx . . $ PCIDSK/atouint64(13e38edef8977abd).(image_header.Getcxx . . $ PCIDSK/PCIDSKBuffer#Get(30d1c21db0e2fae7).( 168, 16 ));
58 pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. = atouint64cxx . . $ PCIDSK/atouint64(13e38edef8977abd).(image_header.Getcxx . . $ PCIDSK/PCIDSKBuffer#Get(30d1c21db0e2fae7).( 184, 8 ));
59 line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. = atouint64cxx . . $ PCIDSK/atouint64(13e38edef8977abd).(image_header.Getcxx . . $ PCIDSK/PCIDSKBuffer#Get(30d1c21db0e2fae7).( 192, 8 ));
60 }
61 else
62 {
63 start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte. = image_offset;
64 pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. = DataTypeSizecxx . . $ PCIDSK/DataTypeSize(6442498fb7f5bc50).(pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type.);
65 line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. = pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. * widthcxx . . $ PCIDSK/CPCIDSKChannel#width.;
66 }
67
68 /* -------------------------------------------------------------------- */
69 /* Establish the file we will be accessing. */
70 /* -------------------------------------------------------------------- */
71 image_header.Getcxx . . $ PCIDSK/PCIDSKBuffer#Get(c044f1ffacd36540).(64,64,filenamecxx . . $ PCIDSK/CBandInterleavedChannel#filename.);
72
73 filenamecxx . . $ PCIDSK/CBandInterleavedChannel#filename. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). MassageLinkcxx . . $ PCIDSK/CBandInterleavedChannel#MassageLink(4fd28d93db21f07a).( filenamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5). );
74
75 if( filenamecxx . . $ PCIDSK/CBandInterleavedChannel#filename..lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() == 0 )
76 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetIODetailscxx . . $ PCIDSK/CPCIDSKFile#GetIODetails(6c2ede044444d67d).( &io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., &io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p. );
77
78 else
79 filenamecxx . . $ PCIDSK/CBandInterleavedChannel#filename. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetInterfacescxx . . $ PCIDSK/CPCIDSKFile#GetInterfaces(96fa11aafeb4f6da).()->MergeRelativePathcxx . . $ PCIDSK/PCIDSKInterfaces#MergeRelativePath.( filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetInterfacescxx . . $ PCIDSK/CPCIDSKFile#GetInterfaces(96fa11aafeb4f6da).()->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.,
80 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetFilenamecxx . . $ PCIDSK/CPCIDSKFile#GetFilename(219584694fe2b248).(),
81 filenamecxx . . $ PCIDSK/CBandInterleavedChannel#filename. );
82 }
83
84 /************************************************************************/
85 /* ~CBandInterleavedChannel() */
86 /************************************************************************/
87
88 CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#::~cxx . . $ PCIDSK/CBandInterleavedChannel#`~CBandInterleavedChannel`(ced63f7c635d850d).CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#()
89
90 {
91 }
92
93 /************************************************************************/
94 /* ReadBlock() */
95 /************************************************************************/
96
97 int CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#::ReadBlockcxx . . $ PCIDSK/CBandInterleavedChannel#ReadBlock(5de283763515624e).( int block_index, void *buffer,
98 int xoff, int yoff,
99 int xsize, int ysize )
100
101 {
102 PCIDSKInterfacescxx . . $ PCIDSK/PCIDSKInterfaces# *interfaces = filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetInterfacescxx . . $ PCIDSK/CPCIDSKFile#GetInterfaces(96fa11aafeb4f6da).();
103
104 /* -------------------------------------------------------------------- */
105 /* Check if we are reading from a valid channel. */
106 /* -------------------------------------------------------------------- */
107 if (line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. > std::numeric_limits<uint64>::max() / heightcxx . . $ PCIDSK/CPCIDSKChannel#height.)
108 {
109 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).(0, "Invalid line_offset: " PCIDSK_FRMT_UINT64cxx . . $ `frmts/pcidsk/sdk/pcidsk_config.h:126:11`!,
110 line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset.);
111 }
112
113 if (start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte. > std::numeric_limits<uint64>::max() - line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. * heightcxx . . $ PCIDSK/CPCIDSKChannel#height.)
114 {
115 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).(0, "Invalid start_byte: " PCIDSK_FRMT_UINT64cxx . . $ `frmts/pcidsk/sdk/pcidsk_config.h:126:11`!,
116 start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte.);
117 }
118
119 /* -------------------------------------------------------------------- */
120 /* Default window if needed. */
121 /* -------------------------------------------------------------------- */
122 if( xoff == -1 && yoff == -1 && xsize == -1 && ysize == -1 )
123 {
124 xoff = 0;
125 yoff = 0;
126 xsize = GetBlockWidthcxx . . $ PCIDSK/CPCIDSKChannel#GetBlockWidth(455f465bc33b4cdf).();
127 ysize = GetBlockHeightcxx . . $ PCIDSK/CPCIDSKChannel#GetBlockHeight(455f465bc33b4cdf).();
128 }
129
130 /* -------------------------------------------------------------------- */
131 /* Validate Window */
132 /* -------------------------------------------------------------------- */
133 if( xoff < 0 || xoff + xsize > GetBlockWidthcxx . . $ PCIDSK/CPCIDSKChannel#GetBlockWidth(455f465bc33b4cdf).()
134 || yoff < 0 || yoff + ysize > GetBlockHeightcxx . . $ PCIDSK/CPCIDSKChannel#GetBlockHeight(455f465bc33b4cdf).() )
135 {
136 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).( 0,
137 "Invalid window in ReadBlock(): xoff=%d,yoff=%d,xsize=%d,ysize=%d",
138 xoff, yoff, xsize, ysize );
139 }
140
141 /* -------------------------------------------------------------------- */
142 /* Establish region to read. */
143 /* -------------------------------------------------------------------- */
144 int pixel_size = DataTypeSizecxx . . $ PCIDSK/DataTypeSize(6442498fb7f5bc50).( pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type. );
145
146 if (pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. == 0 || pixel_size == 0)
147 {
148 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).( 0, "Invalid data type." );
149 }
150 if( xsize > 1 && pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. > static_cast<uint64cxx . . $ PCIDSK/uint64#>(INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`! / (xsize - 1)) )
151 {
152 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).( 0, "Int overflow in ReadBlock() ");
153 }
154 if( pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset.*(xsize-1) > static_cast<uint64cxx . . $ PCIDSK/uint64#>(INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`! - pixel_size) )
155 {
156 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).( 0, "Int overflow in ReadBlock() ");
157 }
158 int window_size = (int) (pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset.*(xsize-1) + pixel_size);
159
160 /* -------------------------------------------------------------------- */
161 /* Get file access handles if we don't already have them. */
162 /* -------------------------------------------------------------------- */
163 if( io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. == nullptr )
164 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetIODetailscxx . . $ PCIDSK/CPCIDSKFile#GetIODetails(6c2ede044444d67d).( &io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., &io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p., filenamecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(),
165 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetUpdatablecxx . . $ PCIDSK/CPCIDSKFile#GetUpdatable(50ce9a9e25b4a850).() );
166
167 /* -------------------------------------------------------------------- */
168 /* If the imagery is packed, we can read directly into the */
169 /* target buffer. */
170 /* -------------------------------------------------------------------- */
171 uint64cxx . . $ PCIDSK/uint64# offset = start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte. + line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. * block_index
172 + pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. * xoff;
173
174 if( pixel_size == (int) pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. )
175 {
176 MutexHoldercxx . . $ PCIDSK/MutexHolder# holdercxx . . $ PCIDSK/MutexHolder#MutexHolder(8d98a5c4ee0e4514).( *io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p. );
177
178 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Seekcxx . . $ PCIDSK/IOInterfaces#Seek(350c0c23da31eb7e).( *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., offset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`! );
179 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Readcxx . . $ PCIDSK/IOInterfaces#Read(80d12f920e9e9469).( buffer, 1, window_size, *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. );
180 }
181
182 /* -------------------------------------------------------------------- */
183 /* Otherwise we allocate a working buffer that holds the whole */
184 /* line, read into that, and pick out our data of interest. */
185 /* -------------------------------------------------------------------- */
186 else
187 {
188 int i;
189 PCIDSKBuffercxx . . $ PCIDSK/PCIDSKBuffer# line_from_diskcxx . . $ PCIDSK/PCIDSKBuffer#PCIDSKBuffer(d4f767463ce0a6b3).( window_size );
190 char *this_pixel;
191
192 MutexHoldercxx . . $ PCIDSK/MutexHolder# holdercxx . . $ PCIDSK/MutexHolder#MutexHolder(8d98a5c4ee0e4514).( *io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p. );
193
194 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Seekcxx . . $ PCIDSK/IOInterfaces#Seek(350c0c23da31eb7e).( *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., offset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`! );
195 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Readcxx . . $ PCIDSK/IOInterfaces#Read(80d12f920e9e9469).( line_from_disk.buffercxx . . $ PCIDSK/PCIDSKBuffer#buffer.,
196 1, line_from_disk.buffer_sizecxx . . $ PCIDSK/PCIDSKBuffer#buffer_size.,
197 *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. );
198
199 for( i = 0, this_pixel = line_from_disk.buffercxx . . $ PCIDSK/PCIDSKBuffer#buffer.; i < xsize; i++ )
200 {
201 memcpy( ((char *) buffer) + pixel_size * i,
202 this_pixel, pixel_size );
203 this_pixel += pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset.;
204 }
205 }
206
207 /* -------------------------------------------------------------------- */
208 /* Do byte swapping if needed. */
209 /* -------------------------------------------------------------------- */
210 if( needs_swapcxx . . $ PCIDSK/CPCIDSKChannel#needs_swap. )
211 SwapPixelscxx . . $ PCIDSK/SwapPixels(a8be7fa25538051a).( buffer, pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type., xsize );
212
213 return 1;
214 }
215
216 /************************************************************************/
217 /* WriteBlock() */
218 /************************************************************************/
219
220 int CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#::WriteBlockcxx . . $ PCIDSK/CBandInterleavedChannel#WriteBlock(74ddd077bf55c9c9).( int block_index, void *buffer )
221
222 {
223 PCIDSKInterfacescxx . . $ PCIDSK/PCIDSKInterfaces# *interfaces = filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetInterfacescxx . . $ PCIDSK/CPCIDSKFile#GetInterfaces(96fa11aafeb4f6da).();
224
225 /* -------------------------------------------------------------------- */
226 /* Check if we are writing to a valid channel. */
227 /* -------------------------------------------------------------------- */
228 if (line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. > std::numeric_limits<uint64>::max() / heightcxx . . $ PCIDSK/CPCIDSKChannel#height.)
229 {
230 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).(0, "Invalid line_offset: " PCIDSK_FRMT_UINT64cxx . . $ `frmts/pcidsk/sdk/pcidsk_config.h:126:11`!,
231 line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset.);
232 }
233
234 if (pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. > line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset.)
235 {
236 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).(0, "Invalid pixel_offset: " PCIDSK_FRMT_UINT64cxx . . $ `frmts/pcidsk/sdk/pcidsk_config.h:126:11`!,
237 pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset.);
238 }
239
240 if (start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte. > std::numeric_limits<uint64>::max() - line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. * heightcxx . . $ PCIDSK/CPCIDSKChannel#height.)
241 {
242 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).(0, "Invalid start_byte: " PCIDSK_FRMT_UINT64cxx . . $ `frmts/pcidsk/sdk/pcidsk_config.h:126:11`!,
243 start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte.);
244 }
245
246 if( !filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetUpdatablecxx . . $ PCIDSK/CPCIDSKFile#GetUpdatable(50ce9a9e25b4a850).() )
247 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).(0, "File not open for update in WriteBlock()" );
248
249 InvalidateOverviewscxx . . $ PCIDSK/CPCIDSKChannel#InvalidateOverviews(49f6e7a06ebc5aa8).();
250
251 /* -------------------------------------------------------------------- */
252 /* Establish region to read. */
253 /* -------------------------------------------------------------------- */
254 int pixel_size = DataTypeSizecxx . . $ PCIDSK/DataTypeSize(6442498fb7f5bc50).( pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type. );
255
256 if (pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. == 0 || pixel_size == 0)
257 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(811d273381043e7b).( 0, "Invalid data type." );
258
259 uint64cxx . . $ PCIDSK/uint64# offset = start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte. + line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. * block_index;
260 int window_size = (int) (pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset.*(widthcxx . . $ PCIDSK/CPCIDSKChannel#width.-1) + pixel_size);
261
262 /* -------------------------------------------------------------------- */
263 /* Get file access handles if we don't already have them. */
264 /* -------------------------------------------------------------------- */
265 if( io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. == nullptr )
266 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetIODetailscxx . . $ PCIDSK/CPCIDSKFile#GetIODetails(6c2ede044444d67d).( &io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., &io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p., filenamecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(),
267 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetUpdatablecxx . . $ PCIDSK/CPCIDSKFile#GetUpdatable(50ce9a9e25b4a850).() );
268
269 /* -------------------------------------------------------------------- */
270 /* If the imagery is packed, we can read directly into the */
271 /* target buffer. */
272 /* -------------------------------------------------------------------- */
273 if( pixel_size == (int) pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. )
274 {
275 MutexHoldercxx . . $ PCIDSK/MutexHolder# holdercxx . . $ PCIDSK/MutexHolder#MutexHolder(8d98a5c4ee0e4514).( *io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p. );
276
277 if( needs_swapcxx . . $ PCIDSK/CPCIDSKChannel#needs_swap. ) // swap before write.
278 SwapPixelscxx . . $ PCIDSK/SwapPixels(a8be7fa25538051a).( buffer, pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type., widthcxx . . $ PCIDSK/CPCIDSKChannel#width. );
279
280 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Seekcxx . . $ PCIDSK/IOInterfaces#Seek(350c0c23da31eb7e).( *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., offset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`! );
281 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Writecxx . . $ PCIDSK/IOInterfaces#Write(39a20432bc9d927d).( buffer, 1, window_size, *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. );
282
283 if( needs_swapcxx . . $ PCIDSK/CPCIDSKChannel#needs_swap. ) // restore to original order.
284 SwapPixelscxx . . $ PCIDSK/SwapPixels(a8be7fa25538051a).( buffer, pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type., widthcxx . . $ PCIDSK/CPCIDSKChannel#width. );
285 }
286
287 /* -------------------------------------------------------------------- */
288 /* Otherwise we allocate a working buffer that holds the whole */
289 /* line, read into that, and pick out our data of interest. */
290 /* -------------------------------------------------------------------- */
291 else
292 {
293 int i;
294 PCIDSKBuffercxx . . $ PCIDSK/PCIDSKBuffer# line_from_diskcxx . . $ PCIDSK/PCIDSKBuffer#PCIDSKBuffer(d4f767463ce0a6b3).( window_size );
295 char *this_pixel;
296
297 MutexHoldercxx . . $ PCIDSK/MutexHolder# holdercxx . . $ PCIDSK/MutexHolder#MutexHolder(8d98a5c4ee0e4514).( *io_mutex_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_mutex_p. );
298
299 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Seekcxx . . $ PCIDSK/IOInterfaces#Seek(350c0c23da31eb7e).( *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., offset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`! );
300 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Readcxx . . $ PCIDSK/IOInterfaces#Read(80d12f920e9e9469).( buffer, 1, line_from_disk.buffer_sizecxx . . $ PCIDSK/PCIDSKBuffer#buffer_size.,
301 *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. );
302
303 for( i = 0, this_pixel = line_from_disk.buffercxx . . $ PCIDSK/PCIDSKBuffer#buffer.; i < widthcxx . . $ PCIDSK/CPCIDSKChannel#width.; i++ )
304 {
305 memcpy( this_pixel, ((char *) buffer) + pixel_size * i,
306 pixel_size );
307
308 if( needs_swapcxx . . $ PCIDSK/CPCIDSKChannel#needs_swap. ) // swap before write.
309 SwapPixelscxx . . $ PCIDSK/SwapPixels(a8be7fa25538051a).( this_pixel, pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type., 1 );
310
311 this_pixel += pixel_size;
312 }
313
314 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Seekcxx . . $ PCIDSK/IOInterfaces#Seek(350c0c23da31eb7e).( *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p., offset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`! );
315 interfaces->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.->Writecxx . . $ PCIDSK/IOInterfaces#Write(39a20432bc9d927d).( buffer, 1, line_from_disk.buffer_sizecxx . . $ PCIDSK/PCIDSKBuffer#buffer_size.,
316 *io_handle_pcxx . . $ PCIDSK/CBandInterleavedChannel#io_handle_p. );
317 }
318
319 /* -------------------------------------------------------------------- */
320 /* Do byte swapping if needed. */
321 /* -------------------------------------------------------------------- */
322
323 return 1;
324 }
325
326 /************************************************************************/
327 /* GetChanInfo() */
328 /************************************************************************/
329 void CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#
330 ::GetChanInfocxx . . $ PCIDSK/CBandInterleavedChannel#GetChanInfo(4020778cc63624a2).( std::stringcxx . . $ std/string# &filename_ret, uint64cxx . . $ PCIDSK/uint64# &image_offset,
331 uint64cxx . . $ PCIDSK/uint64# &pixel_offsetOut, uint64cxx . . $ PCIDSK/uint64# &line_offsetOut,
332 bool &little_endian ) const
333
334 {
335 image_offset = start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte.;
336 pixel_offsetOut = this->pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset.;
337 line_offsetOut = this->line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset.;
338 little_endian = (byte_ordercxx . . $ PCIDSK/CPCIDSKChannel#byte_order. == 'S');
339
340 /* -------------------------------------------------------------------- */
341 /* We fetch the filename from the header since it will be the */
342 /* "clean" version without any paths. */
343 /* -------------------------------------------------------------------- */
344 PCIDSKBuffercxx . . $ PCIDSK/PCIDSKBuffer# ihcxx . . $ PCIDSK/PCIDSKBuffer#PCIDSKBuffer(d4f767463ce0a6b3).(64);
345 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->ReadFromFilecxx . . $ PCIDSK/CPCIDSKFile#ReadFromFile(5be386bfc4282a20).( ih.buffercxx . . $ PCIDSK/PCIDSKBuffer#buffer., ih_offsetcxx . . $ PCIDSK/CPCIDSKChannel#ih_offset.+64, 64 );
346
347 ih.Getcxx . . $ PCIDSK/PCIDSKBuffer#Get(c044f1ffacd36540).(0,64,filename_ret);
348 filename_ret =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). MassageLinkcxx . . $ PCIDSK/CBandInterleavedChannel#MassageLink(4fd28d93db21f07a).( filename_retcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5). );
349 }
350
351 /************************************************************************/
352 /* SetChanInfo() */
353 /************************************************************************/
354
355 void CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#
356 ::SetChanInfocxx . . $ PCIDSK/CBandInterleavedChannel#SetChanInfo(d33ccba62045a8e7).( std::stringcxx . . $ std/string# filenameIn, uint64cxx . . $ PCIDSK/uint64# image_offset,
357 uint64cxx . . $ PCIDSK/uint64# pixel_offsetIn, uint64cxx . . $ PCIDSK/uint64# line_offsetIn,
358 bool little_endian )
359
360 {
361 if( ih_offsetcxx . . $ PCIDSK/CPCIDSKChannel#ih_offset. == 0 )
362 return ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(326aeb464d16410c).( "No Image Header available for this channel." );
363
364 /* -------------------------------------------------------------------- */
365 /* Fetch the existing image header. */
366 /* -------------------------------------------------------------------- */
367 PCIDSKBuffercxx . . $ PCIDSK/PCIDSKBuffer# ihcxx . . $ PCIDSK/PCIDSKBuffer#PCIDSKBuffer(d4f767463ce0a6b3).(1024);
368
369 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->ReadFromFilecxx . . $ PCIDSK/CPCIDSKFile#ReadFromFile(5be386bfc4282a20).( ih.buffercxx . . $ PCIDSK/PCIDSKBuffer#buffer., ih_offsetcxx . . $ PCIDSK/CPCIDSKChannel#ih_offset., 1024 );
370
371 /* -------------------------------------------------------------------- */
372 /* If the linked filename is too long to fit in the 64 */
373 /* character IHi.2 field, then we need to use a link segment to */
374 /* store the filename. */
375 /* -------------------------------------------------------------------- */
376 std::stringcxx . . $ std/string# IHi2_filenamecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
377
378 if( filenameIn.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() > 64 )
379 {
380 int link_segment;
381
382 ih.Getcxx . . $ PCIDSK/PCIDSKBuffer#Get(c044f1ffacd36540).( 64, 64, IHi2_filename );
383
384 if( IHi2_filename.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0,3) ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "LNK" )
385 {
386 link_segment = std::atoi( IHi2_filename.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).() + 4 );
387 }
388 else
389 {
390 char link_filename[64];
391
392 link_segment =
393 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->CreateSegmentcxx . . $ PCIDSK/CPCIDSKFile#CreateSegment(7c4fd785b3bb3cbb).( "Link "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
394 "Long external channel filename link."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
395 SEG_SYScxx . . $ PCIDSK/SEG_SYS., 1 );
396
397 snprintf( link_filename, sizeof(link_filename), "LNK %4d", link_segment );
398 IHi2_filename =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). link_filename;
399 }
400
401 CLinkSegmentcxx . . $ PCIDSK/CLinkSegment# *link =
402 dynamic_cast<CLinkSegmentcxx . . $ PCIDSK/CLinkSegment#*>( filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetSegmentcxx . . $ PCIDSK/CPCIDSKFile#GetSegment(6d03ec1289e58bea).( link_segment ) );
403
404 if( link != nullptr )
405 {
406 link->SetPathcxx . . $ PCIDSK/CLinkSegment#SetPath(9c546c94e5fcce4e).( filenameIn );
407 link->Synchronizecxx . . $ PCIDSK/CLinkSegment#Synchronize(49f6e7a06ebc5aa8).();
408 }
409 }
410
411 /* -------------------------------------------------------------------- */
412 /* If we used to have a link segment but no longer need it, we */
413 /* need to delete the link segment. */
414 /* -------------------------------------------------------------------- */
415 else
416 {
417 ih.Getcxx . . $ PCIDSK/PCIDSKBuffer#Get(c044f1ffacd36540).( 64, 64, IHi2_filename );
418
419 if( IHi2_filename.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0,3) ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "LNK" )
420 {
421 int link_segment = std::atoi( IHi2_filename.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).() + 4 );
422
423 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->DeleteSegmentcxx . . $ PCIDSK/CPCIDSKFile#DeleteSegment(d4f767463ce0a6b3).( link_segment );
424 }
425
426 IHi2_filename =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). filenameIn;
427 }
428
429 /* -------------------------------------------------------------------- */
430 /* Update the image header. */
431 /* -------------------------------------------------------------------- */
432 // IHi.2
433 ih.Putcxx . . $ PCIDSK/PCIDSKBuffer#Put(dc7aba8d82da34e7).( IHi2_filename.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), 64, 64 );
434
435 // IHi.6.1
436 ih.Putcxx . . $ PCIDSK/PCIDSKBuffer#Put(56d9cb457f7bb6ee).( image_offset, 168, 16 );
437
438 // IHi.6.2
439 ih.Putcxx . . $ PCIDSK/PCIDSKBuffer#Put(56d9cb457f7bb6ee).( pixel_offsetIn, 184, 8 );
440
441 // IHi.6.3
442 ih.Putcxx . . $ PCIDSK/PCIDSKBuffer#Put(56d9cb457f7bb6ee).( line_offsetIn, 192, 8 );
443
444 // IHi.6.5
445 if( little_endian )
446 ih.Putcxx . . $ PCIDSK/PCIDSKBuffer#Put(dc7aba8d82da34e7).( "S", 201, 1 );
447 else
448 ih.Putcxx . . $ PCIDSK/PCIDSKBuffer#Put(dc7aba8d82da34e7).( "N", 201, 1 );
449
450 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->WriteToFilecxx . . $ PCIDSK/CPCIDSKFile#WriteToFile(a8dbaa77894e8038).( ih.buffercxx . . $ PCIDSK/PCIDSKBuffer#buffer., ih_offsetcxx . . $ PCIDSK/CPCIDSKChannel#ih_offset., 1024 );
451
452 /* -------------------------------------------------------------------- */
453 /* Update local configuration. */
454 /* -------------------------------------------------------------------- */
455 this->filenamecxx . . $ PCIDSK/CBandInterleavedChannel#filename. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetInterfacescxx . . $ PCIDSK/CPCIDSKFile#GetInterfaces(96fa11aafeb4f6da).()->MergeRelativePathcxx . . $ PCIDSK/PCIDSKInterfaces#MergeRelativePath.( filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetInterfacescxx . . $ PCIDSK/CPCIDSKFile#GetInterfaces(96fa11aafeb4f6da).()->iocxx . . $ PCIDSK/PCIDSKInterfaces#io.,
456 filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetFilenamecxx . . $ PCIDSK/CPCIDSKFile#GetFilename(219584694fe2b248).(),
457 filenameIn );
458
459 start_bytecxx . . $ PCIDSK/CBandInterleavedChannel#start_byte. = image_offset;
460 this->pixel_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#pixel_offset. = pixel_offsetIn;
461 this->line_offsetcxx . . $ PCIDSK/CBandInterleavedChannel#line_offset. = line_offsetIn;
462
463 if( little_endian )
464 byte_ordercxx . . $ PCIDSK/CPCIDSKChannel#byte_order. = 'S';
465 else
466 byte_ordercxx . . $ PCIDSK/CPCIDSKChannel#byte_order. = 'N';
467
468 /* -------------------------------------------------------------------- */
469 /* Determine if we need byte swapping. */
470 /* -------------------------------------------------------------------- */
471 unsigned short test_value = 1;
472
473 if( (reinterpret_cast<uint8cxx . . $ PCIDSK/uint8# *>(&test_value))[0] == 1 )
474 needs_swapcxx . . $ PCIDSK/CPCIDSKChannel#needs_swap. = (byte_ordercxx . . $ PCIDSK/CPCIDSKChannel#byte_order. != 'S');
475 else
476 needs_swapcxx . . $ PCIDSK/CPCIDSKChannel#needs_swap. = (byte_ordercxx . . $ PCIDSK/CPCIDSKChannel#byte_order. == 'S');
477
478 if( pixel_typecxx . . $ PCIDSK/CPCIDSKChannel#pixel_type. == CHN_8Ucxx . . $ PCIDSK/CHN_8U. )
479 needs_swapcxx . . $ PCIDSK/CPCIDSKChannel#needs_swap. = 0;
480 }
481
482 /************************************************************************/
483 /* MassageLink() */
484 /* */
485 /* Return the filename after applying translation of long */
486 /* linked filenames using a link segment. */
487 /************************************************************************/
488
489 std::stringcxx . . $ std/string# CBandInterleavedChannelcxx . . $ PCIDSK/CBandInterleavedChannel#::MassageLinkcxx . . $ PCIDSK/CBandInterleavedChannel#MassageLink(4fd28d93db21f07a).( std::stringcxx . . $ std/string# filename_in ) const
490
491 {
492 if (filename_in.findcxx . . $ std/__cxx11/basic_string#find(b733e800f6f8fb8b).("LNK") == 0)
493 {
494 std::stringcxx . . $ std/string# seg_strcxx . . $ std/__cxx11/basic_string#basic_string(9ac66ead75e9ceb1).(filename_in, 4, 4);
495 unsigned int seg_num = std::atoi(seg_str.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
496
497 if (seg_num == 0)
498 {
499 ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(326aeb464d16410c).("Unable to find link segment. Link name: %s",
500 filename_in.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
501 return ""cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
502 }
503
504 CLinkSegmentcxx . . $ PCIDSK/CLinkSegment#* link_seg =
505 dynamic_cast<CLinkSegmentcxx . . $ PCIDSK/CLinkSegment#*>(filecxx . . $ PCIDSK/CPCIDSKChannel#file.->GetSegmentcxx . . $ PCIDSK/CPCIDSKFile#GetSegment(6d03ec1289e58bea).(seg_num));
506 if (link_seg == nullptr)
507 {
508 ThrowPCIDSKExceptioncxx . . $ PCIDSK/ThrowPCIDSKException(326aeb464d16410c).("Failed to get Link Information Segment.");
509 return ""cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
510 }
511
512 filename_in =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). link_seg->GetPathcxx . . $ PCIDSK/CLinkSegment#GetPath(219584694fe2b248).();
513 }
514
515 return filename_incxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).;
516 }