DecodeMrSIDBandSelection.cpp
#include "main.h"
#include "support.h"
#include "lt_fileSpec.h"
#include "lti_scene.h"
#include "lti_pixel.h"
#include "lti_sceneBuffer.h"
#include "lti_utils.h"
#include "MrSIDImageReader.h"
LT_USE_NAMESPACE(LizardTech);
LT_STATUS DecodeMrSIDBandSelection()
{
LT_STATUS sts = LT_STS_Uninit;
MrSIDImageReader *reader = MrSIDImageReader::create();
TEST_BOOL(reader != NULL);
TEST_SUCCESS(reader->initialize(LTFileSpec(INPUT_PATH("Tile7_rgbn_utm15.sid"))));
const LTIScene scene(0, 0, 256, 256, 1.0);
lt_uint16 bandSelection[] = { 3, 4 };
LTIPixel pixelProps(reader->getPixelProps(), bandSelection, 2);
LTISceneBuffer sceneBuffer(pixelProps,
scene.getNumCols(),
scene.getNumRows(),
NULL);
TEST_SUCCESS(reader->read(scene, sceneBuffer));
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);
if(sceneBuffer.getNumCols() != sceneBuffer.getTotalNumCols())
return LT_STS_Failure;
if(fwrite(bandBuffer, bytesPerSample, numPixels, file) != numPixels)
return LT_STS_Failure;
}
fclose(file);
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"));
return LT_STS_Success;
}