MrSID Decode SDK for Raster Reference Manual  9.5.5.5244
DecodeMrSIDBandSelection.cpp
//
// This code is property of Celartem, Inc dba Extensis.
// Copyright (c) 1995-2023. All rights reserved.
// Use permitted only under license from Extensis.
//
/* PUBLIC */
// This demonstrates how to decode a sub-set of the bands in a MrSID file.
#include "main.h"
#include "support.h"
#include "lt_fileSpec.h"
#include "lti_scene.h"
#include "lti_pixel.h"
#include "lti_utils.h"
LT_USE_NAMESPACE(LizardTech);
LT_STATUS DecodeMrSIDBandSelection()
{
// make the image reader
TEST_BOOL(reader != nullptr);
TEST_SUCCESS(reader->initialize(LTFileSpec(INPUT_PATH("Tile7_rgbn_utm15.sid"))));
// decode the upper left corner
const LTIScene scene(0, 0, 256, 256, 1.0);
// construct a buffer that only has the near-infrared and alpha bands
lt_uint16 bandSelection[] = { 3, 4 };
LTIPixel pixelProps(reader->getPixelProps(), bandSelection, 2);
LTISceneBuffer sceneBuffer(pixelProps,
scene.getNumCols(),
scene.getNumRows(),
nullptr);
// perform the decode
TEST_SUCCESS(reader->read(scene, sceneBuffer));
// save the buffer as little endian BSQ
if(LTIUtils::needsSwapping(pixelProps.getDataType(), LTI_ENDIAN_LITTLE))
sceneBuffer.byteSwap();
FILE *file = fopen(OUTPUT_PATH("Tile7_rgbn_utm15-ia.bsq"), "wb");
lt_uint16 numBands = pixelProps.getNumBands();
for(lt_uint16 band = 0; band < numBands; band++)
{
lt_uint32 bytesPerSample = pixelProps.getSample(band).getNumBytes();
lt_uint32 numPixels = sceneBuffer.getNumCols() *
sceneBuffer.getNumRows();
void *bandBuffer = sceneBuffer.getBandData(band);
// make sure the "rowBytes" is the same width as the scene
if(sceneBuffer.getNumCols() != sceneBuffer.getTotalNumCols())
if(fwrite(bandBuffer, bytesPerSample, numPixels, file) != numPixels)
}
fclose(file);
// make sure got the right thing
TEST_BOOL(Compare(OUTPUT_PATH("Tile7_rgbn_utm15-ia.bsq"), INPUT_PATH("Tile7_rgbn_utm15-ia.bsq")));
Remove(OUTPUT_PATH("Tile7_rgbn_utm15-ia.bsq"));
}
lt_uint32 LT_STATUS
An integral status code.
Definition: lt_status.h:30
#define LT_STS_Uninit
status code indicating unintialized variable
Definition: lt_status.h:60
#define LT_STS_Failure
status code indicating failure
Definition: lt_status.h:51
#define LT_STS_Success
status code indicating success
Definition: lt_status.h:43
unsigned short lt_uint16
unsigned 16-bit integer
Definition: lt_types.h:40
unsigned int lt_uint32
unsigned 32-bit integer
Definition: lt_types.h:44
@ LTI_ENDIAN_LITTLE
Definition: lti_types.h:163
Represents a file or directory path.
Definition: lt_fileSpec.h:35
const LTIPixel & getPixelProps() const
get the pixel properties of the image
LT_STATUS read(const LTIScene &scene, LTISceneBuffer &buffer)
read (decode) a scene from the image
basic properties of a pixel
Definition: lti_pixel.h:32
representation of a scene
Definition: lti_scene.h:60
class to hold data passed between image stages
static bool needsSwapping(LTIDataType datatype, LTIEndian byteOrder)
reader for MrSID images (MG2, MG3 and MG4)
LT_STATUS initialize(const LTFileSpec &fileSpec, bool useWorldFile=false, MrSIDMemoryUsage memoryUsage=MRSID_MEMORY_USAGE_DEFAULT, MrSIDStreamUsage streamUsage=MRSID_STREAM_USAGE_DEFAULT)
initializer
static MrSIDImageReader * create(void)

Extensis