MrSID Decode SDK for Raster Reference Manual  9.5.5.5244
SceneBuffer.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 some of the features of the LTISceneBuffer class,
// by decoding an image into a larger "frame" colored grey.
#include "main.h"
#include "support.h"
#include "lt_fileSpec.h"
#include "lti_scene.h"
#include "lti_pixel.h"
LT_USE_NAMESPACE(LizardTech);
//
// For more examples on how to use the LTISceneBuffer class see the
// following:
//
// * Loading BIP data into a SceneBuffer
// DerivedImageReader.cpp: MyReader::decodeStrip()
//
// * Exporting a SceneBuffer to BIP
// DerivedImageWriter.cpp: MyWriter::writeStrip()
//
// * Accessing the BSQ bands of a SceneBuffer
// DerivedImageFilter.cpp: MyFilter::decodeStrip()
//
// * Allocating the BSQ band data that the SceneBuffer uses
// DecodeMrSIDToMemory.cpp and DecodeJP2ToMemory.cpp
//
LT_STATUS SceneBuffer()
{
// make the image reader
const LTFileSpec fileSpec(INPUT_PATH("meg_cr20.sid"));
TEST_BOOL(reader != nullptr);
TEST_SUCCESS(reader->initialize(fileSpec));
// Construct the buffer we're decoding into: we are going to
// use a buffer that is 150x150 and put the image into the
// middle of it. Note we let the buffer allocate its own
// storage.
const LTIPixel &pixelProps = reader->getPixelProps();
LTISceneBuffer sceneBuffer(pixelProps, 150, 150, nullptr);
// some sanity checks
TEST_BOOL(sceneBuffer.getNumCols() == 150);
TEST_BOOL(sceneBuffer.getNumRows() == 150);
TEST_BOOL(sceneBuffer.getTotalNumCols() == 150);
// fill the buffer with pink
LTIPixel pink(reader->getPixelProps());
pink.getSample(0).setValueUint8(255);
pink.getSample(1).setValueUint8(128);
pink.getSample(2).setValueUint8(128);
sceneBuffer.fill(pink);
// decode a 100x100 scene from the middle of the 640x480 image
const LTIScene scene(270, 190, 100, 100, 1.0);
// make a window into the larger buffer, at offset (25, 25)
LTISceneBuffer subSceneBuffer(sceneBuffer, 25, 25, 100, 100);
// some more sanity checks
TEST_BOOL(subSceneBuffer.getNumCols() == 100);
TEST_BOOL(subSceneBuffer.getNumRows() == 100);
TEST_BOOL(subSceneBuffer.getTotalNumCols() == 150);
// perform the decode
TEST_SUCCESS(reader->read(scene, subSceneBuffer));
// export the image in BSQ form to disk
{
FILE *file = fopen(OUTPUT_PATH("meg_framed_bsq.raw"), "wb");
for(lt_uint16 band = 0; band < reader->getNumBands(); band++)
{
lt_uint32 bytesPerSample = pixelProps.getSample(band).getNumBytes();
lt_uint32 numPixels = sceneBuffer.getNumCols() *
sceneBuffer.getNumRows();
void *bandBuffer = sceneBuffer.getBandData(band);
if(fwrite(bandBuffer, bytesPerSample, numPixels, file) != numPixels)
}
fclose(file);
}
TEST_BOOL( Compare(OUTPUT_PATH("meg_framed_bsq.raw"), INPUT_PATH("meg_framed_bsq.raw")) );
Remove(OUTPUT_PATH("meg_framed_bsq.raw"));
reader->release();
reader = nullptr;
}
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
Represents a file or directory path.
Definition: lt_fileSpec.h:35
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
basic properties of a pixel
Definition: lti_pixel.h:32
LTISample & getSample(lt_uint16) const
virtual void release(void) const
decrement the reference counter and delete the object when the counter is zero
lt_uint32 getNumBytes() const
get the size of a sample
representation of a scene
Definition: lti_scene.h:60
class to hold data passed between image stages
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