MrSID Decode SDK for Raster Reference Manual 9.5.5.5244
DerivedImageWriter.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 derive your own image writer. This example
// class just writes raw (BIP) files.
#include "main.h"
#include "support.h"
#include "lt_fileSpec.h"
#include "lt_ioStreamInf.h"
#include "lti_pixel.h"
#include "lti_utils.h"
LT_USE_NAMESPACE(LizardTech);
//---------------------------------------------------------------------------
// simple BIP (raw) writer take always write little endian data
//---------------------------------------------------------------------------
class MyWriter : public LTIGeoFileImageWriter
{
public:
MyWriter(void) :
m_rowBytes(0),
m_rowBuffer(nullptr)
{
}
~MyWriter()
{
}
LT_STATUS initialize(LTIImageStage* image)
{
}
{
const lt_uint32 numCols = scene.getNumCols();
const lt_uint32 bytesPerPixel = m_image->getPixelProps().getNumBytes();
m_rowBytes = numCols * bytesPerPixel;
m_rowBuffer = new lt_uint8[m_rowBytes];
}
const LTIScene& stripScene)
{
// swab data if not in little endian
stripBuffer.byteSwap();
const lt_uint32 numCols = stripScene.getNumCols();
const lt_uint32 numRows = stripScene.getNumRows();
const lt_uint32 totalNumCols = stripBuffer.getTotalNumCols();
const LTIPixel &pixel = stripBuffer.getPixelProps();
const lt_uint32 bytesPerPixel = pixel.getNumBytes();
const lt_uint32 bytesPerSample = pixel.getSample(0).getNumBytes();
const lt_uint16 numBands = stripBuffer.getNumBands();
LTIOStreamInf &stream = *getStream();
for (lt_uint32 row = 0; row < numRows; row++)
{
// export the BSQ SceneBuffer to BIP (one row at a time)
for(lt_uint16 band = 0; band < numBands; band++)
{
lt_uint8 *dst = m_rowBuffer + band * bytesPerSample;
const lt_uint8 *src = static_cast<lt_uint8 *>(stripBuffer.getBandData(band));
// skip down to the row of interest
src += row * totalNumCols * bytesPerSample;
for(lt_uint32 col = 0; col < numCols; col++, src += bytesPerSample, dst += bytesPerPixel)
memcpy(dst, src, bytesPerSample);
}
// write the BIP row to disk
if(stream.write(m_rowBuffer, m_rowBytes) != m_rowBytes)
return stream.getLastError();
}
}
{
delete [] m_rowBuffer;
m_rowBuffer = nullptr;
}
private:
lt_uint32 m_rowBytes;
lt_uint8 *m_rowBuffer;
};
//---------------------------------------------------------------------------
LT_STATUS DerivedImageWriter()
{
// read in a raw rgb image, and write it out as grayscale
// make the reader
const LTFileSpec fileSpec(INPUT_PATH("meg.bip"));
TEST_BOOL(reader != nullptr);
TEST_SUCCESS(reader->initialize(fileSpec));
// make the raw writer
MyWriter writer;
TEST_SUCCESS(writer.initialize(reader));
// set up the output file
TEST_SUCCESS(writer.setOutputFileSpec(OUTPUT_PATH("meg.bip")));
const LTIScene scene(0, 0, 640, 480, 1.0);
// write the scene to the file
TEST_SUCCESS(writer.write(scene));
// verify we got the right output
TEST_BOOL(Compare(OUTPUT_PATH("meg.bip"), INPUT_PATH("meg.bip")));
Remove(OUTPUT_PATH("meg.bip"));
reader->release();
reader = nullptr;
}
@ LTI_ENDIAN_LITTLE
Definition: lti_types.h:163
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
Represents a file or directory path.
Definition: lt_fileSpec.h:35
Abstract definition of a stream.
virtual LT_STATUS getLastError() const =0
Get status code of last error event.
virtual lt_uint32 write(const lt_uint8 *pSrc, lt_uint32 numBytes)=0
Store the specified number of bytes in the data source.
read an image from a BBB file
static LTIBBBImageReader * create(void)
LT_STATUS initialize(const LTFileSpec &fileSpec, bool useWorldFile=true)
intializer
class for writing geographic images to files or streams
LTIOStreamInf * getStream() const
get underlying stream
virtual LT_STATUS writeBegin(const LTIScene &scene)
begin an encode (write) operation
virtual LT_STATUS writeStrip(LTISceneBuffer &stripBuffer, const LTIScene &stripScene)=0
encode one strip of the scene
virtual LT_STATUS writeEnd(void)
complete an encode (write) operation
abstract class for decoding from an image
LT_STATUS init(LTIImageStage *imageStage)
initialization function
basic properties of a pixel
Definition: lti_pixel.h:32
LTIDataType getDataType() const
get the sample datatype
LTISample & getSample(lt_uint16) const
lt_uint32 getNumBytes() const
get the size of a pixel
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
lt_int32 getNumRows() const
returns the height of the scene
lt_int32 getNumCols() const
returns the width of the scene
class to hold data passed between image stages
lt_int32 getTotalNumCols() const
get width of (entire) buffer
void * getBandData(lt_uint16 band) const
get pointer to data (for 1 band)
lt_uint16 getNumBands() const
get number of bands
const LTIPixel & getPixelProps() const
get pixel type of buffer
void byteSwap()
export to memory (BSQ)
static bool needsSwapping(LTIDataType datatype, LTIEndian byteOrder)

Extensis