MrSID Decode SDK for Raster Reference Manual  9.5.5.5244
DecodeMrSIDToMemory.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 scene from a MrSID file into a
// byte array in memory, by directly performing a decode() operation
// on a MrSIDImageReader object.
#include "main.h"
#include "support.h"
#include "lt_fileSpec.h"
#include "lti_scene.h"
#include "lti_utils.h"
LT_USE_NAMESPACE(LizardTech);
LT_STATUS DecodeMrSIDToMemory()
{
// make the image reader
const LTFileSpec fileSpec(INPUT_PATH("meg_cr20.sid"));
TEST_BOOL(reader != nullptr);
TEST_SUCCESS(reader->initialize(fileSpec));
// decode the whole image at full resolution
const LTIScene scene(0, 0, 640, 480, 1.0);
// construct the buffer we're decoding into
// note we choose to allocate our own buffer, rather than let
// LTISceneBuffer implicitly allocate one for us
lt_uint16 numBands = reader->getNumBands();
LTIDataType datatype = reader->getDataType();
const lt_uint32 bytesPerSample = LTIUtils::getNumBytes(datatype);
const lt_uint32 numPixels = scene.getNumCols() * scene.getNumRows();
const lt_uint32 bytesPerBands = numPixels * bytesPerSample;
lt_uint8 **bsqData = new lt_uint8 *[numBands];
for(lt_uint16 i = 0; i < numBands; i++)
bsqData[i] = new lt_uint8[bytesPerBands];
LTISceneBuffer sceneBuffer(reader->getPixelProps(),
scene.getNumCols(),
scene.getNumRows(),
reinterpret_cast<void **>(bsqData));
// only let the decoder use the calling thread
// otherwise it will try to uses all the cores
reader->setMaxWorkerThreads(1);
// perform the decode
TEST_SUCCESS(reader->read(scene, sceneBuffer));
// store the BSQ data as BIP
FILE* fp = fopen(OUTPUT_PATH("meg_cr20.raw"), "wb");
TEST_BOOL(fp != nullptr);
for(lt_uint32 offset = 0; offset < bytesPerBands; offset += bytesPerSample)
{
for(lt_uint16 i = 0; i < numBands; i++)
TEST_BOOL(fwrite(bsqData[i] + offset, bytesPerSample, 1, fp) == 1);
}
fclose(fp);
// clean up
for(lt_uint16 i = 0; i < numBands; i++)
delete [] bsqData[i];
delete [] bsqData;
// make sure got the right thing
TEST_BOOL(Compare(OUTPUT_PATH("meg_cr20.raw"), INPUT_PATH("meg_cr20.raw")));
Remove(OUTPUT_PATH("meg_cr20.raw"));
}
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_Success
status code indicating success
Definition: lt_status.h:43
unsigned short lt_uint16
unsigned 16-bit integer
Definition: lt_types.h:40
unsigned char lt_uint8
unsigned 8-bit integer
Definition: lt_types.h:36
unsigned int lt_uint32
unsigned 32-bit integer
Definition: lt_types.h:44
LTIDataType
datatypes
Definition: lti_types.h:101
Represents a file or directory path.
Definition: lt_fileSpec.h:35
LTIDataType getDataType() const
get data type
lt_uint16 getNumBands() const
get number of bands
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
representation of a scene
Definition: lti_scene.h:60
class to hold data passed between image stages
static lt_uint8 getNumBytes(LTIDataType datatype)
returns number of bytes for a given a datatype
reader for MrSID images (MG2, MG3 and MG4)
void setMaxWorkerThreads(int numThreads)
set the maximum number of worker threads
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