286
/************************************************************************/
288
/************************************************************************/
289
void CBandInterleavedChannel
290
::GetChanInfo( std::string &filename_ret, uint64 &image_offset,
291
uint64 &pixel_offset, uint64 &line_offset,
292
bool &little_endian ) const
295
image_offset = start_byte;
296
pixel_offset = this->pixel_offset;
297
line_offset = this->line_offset;
298
little_endian = (byte_order == 'S');
300
/* -------------------------------------------------------------------- */
301
/* We fetch the filename from the header since it will be the */
302
/* "clean" version without any paths. */
303
/* -------------------------------------------------------------------- */
305
file->ReadFromFile( ih.buffer, ih_offset+64, 64 );
307
ih.Get(0,64,filename_ret);
308
filename_ret = MassageLink( filename_ret );
311
/************************************************************************/
313
/************************************************************************/
315
void CBandInterleavedChannel
316
::SetChanInfo( std::string filename, uint64 image_offset,
317
uint64 pixel_offset, uint64 line_offset,
322
ThrowPCIDSKException( "No Image Header available for this channel." );
324
/* -------------------------------------------------------------------- */
325
/* Fetch the existing image header. */
326
/* -------------------------------------------------------------------- */
327
PCIDSKBuffer ih(1024);
329
file->ReadFromFile( ih.buffer, ih_offset, 1024 );
331
/* -------------------------------------------------------------------- */
332
/* If the linked filename is too long to fit in the 64 */
333
/* character IHi.2 field, then we need to use a link segment to */
334
/* store the filename. */
335
/* -------------------------------------------------------------------- */
336
std::string IHi2_filename;
338
if( filename.size() > 64 )
342
ih.Get( 64, 64, IHi2_filename );
344
if( IHi2_filename.substr(0,3) == "LNK" )
346
link_segment = std::atoi( IHi2_filename.c_str() + 4 );
350
char link_filename[64];
353
file->CreateSegment( "Link ",
354
"Long external channel filename link.",
357
sprintf( link_filename, "LNK %4d", link_segment );
358
IHi2_filename = link_filename;
362
dynamic_cast<CLinkSegment*>( file->GetSegment( link_segment ) );
366
link->SetPath( filename );
371
/* -------------------------------------------------------------------- */
372
/* If we used to have a link segment but no longer need it, we */
373
/* need to delete the link segment. */
374
/* -------------------------------------------------------------------- */
377
ih.Get( 64, 64, IHi2_filename );
379
if( IHi2_filename.substr(0,3) == "LNK" )
381
int link_segment = std::atoi( IHi2_filename.c_str() + 4 );
383
file->DeleteSegment( link_segment );
386
IHi2_filename = filename;
389
/* -------------------------------------------------------------------- */
390
/* Update the image header. */
391
/* -------------------------------------------------------------------- */
393
ih.Put( IHi2_filename.c_str(), 64, 64 );
396
ih.Put( image_offset, 168, 16 );
399
ih.Put( pixel_offset, 184, 8 );
402
ih.Put( line_offset, 192, 8 );
406
ih.Put( "S", 201, 1 );
408
ih.Put( "N", 201, 1 );
410
file->WriteToFile( ih.buffer, ih_offset, 1024 );
412
/* -------------------------------------------------------------------- */
413
/* Update local configuration. */
414
/* -------------------------------------------------------------------- */
415
this->filename = MergeRelativePath( file->GetInterfaces()->io,
419
start_byte = image_offset;
420
this->pixel_offset = pixel_offset;
421
this->line_offset = line_offset;
428
/* -------------------------------------------------------------------- */
429
/* Determine if we need byte swapping. */
430
/* -------------------------------------------------------------------- */
431
unsigned short test_value = 1;
433
if( ((uint8 *) &test_value)[0] == 1 )
434
needs_swap = (byte_order != 'S');
436
needs_swap = (byte_order == 'S');
438
if( pixel_type == CHN_8U )
442
/************************************************************************/
445
/* Return the filename after applying translation of long */
446
/* linked filenames using a link segment. */
447
/************************************************************************/
449
std::string CBandInterleavedChannel::MassageLink( std::string filename_in ) const
452
if (filename_in.find("LNK") == 0)
454
std::string seg_str(filename_in, 4, 4);
455
unsigned int seg_num = std::atoi(seg_str.c_str());
459
throw PCIDSKException("Unable to find link segment. Link name: %s",
460
filename_in.c_str());
463
CLinkSegment* link_seg =
464
dynamic_cast<CLinkSegment*>(file->GetSegment(seg_num));
465
if (link_seg == NULL)
467
throw PCIDSKException("Failed to get Link Information Segment.");
470
filename_in = link_seg->GetPath();