MrSID Decode SDK for Raster Reference Manual 9.5.5.5244
InterruptDelegate.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 interrupt delegate and use it
// inside of a decode request.
#include "main.h"
#include "support.h"
#include "lt_fileSpec.h"
#include "lti_delegates.h"
#include "lti_scene.h"
LT_USE_NAMESPACE(LizardTech);
// This class will simulate an interrupt event after N calls by the decoder
// to query the interrupt status. In a real system, the if-test would really
// be checking some external event, e.g. a ^C or button-press.
class MyInterrupt : public LTIInterruptDelegate
{
public:
MyInterrupt(int n) :
m_cnt(0),
m_max(n)
{
return;
}
{
printf("interrupt called %d times\n", m_cnt);
if (m_cnt == 10) return 999;
++m_cnt;
}
public:
int m_cnt; // public so we can query from the test routine
private:
const int m_max;
};
LT_STATUS InterruptDelegate()
{
// stop after 10 calls
MyInterrupt interrupt(10);
// make the image reader
const LTFileSpec fileSpec(INPUT_PATH("meg_cr20.sid"));
TEST_BOOL(reader != nullptr);
TEST_SUCCESS(reader->initialize(fileSpec));
reader->setInterruptDelegate(&interrupt);
const LTIScene scene(0, 0, 640, 480, 1.0);
LTISceneBuffer bufData(reader->getPixelProps(),
scene.getNumCols(), scene.getNumRows(),
nullptr);
// the decode will fail, return 999 from within the delegate
sts = reader->read(scene, bufData);
TEST_BOOL(sts == 999);
// verify the interrupt handler was called several times
TEST_BOOL(interrupt.m_cnt == 10);
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_Success
status code indicating success
Definition: lt_status.h:43
Represents a file or directory path.
Definition: lt_fileSpec.h:35
interrupt delegate (callback) base class
Definition: lti_delegates.h:35
virtual LT_STATUS getInterruptStatus(void)=0
check for interrupt
void setInterruptDelegate(LTIInterruptDelegate *delegate)
set interrupt delegate
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
virtual void release(void) const
decrement the reference counter and delete the object when the counter is zero
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)
static MrSIDImageReader * create(void)
LT_STATUS initialize(const LTFileSpec &fileSpec, bool useWorldFile=false, MrSIDMemoryUsage memoryUsage=MRSID_MEMORY_USAGE_DEFAULT, MrSIDStreamUsage streamUsage=MRSID_STREAM_USAGE_DEFAULT)
initializer

Extensis