MrSID Decode SDK for Raster Reference Manual 9.5.5.5244
UsingStreams.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 example shows some of the basic operations supported by
// the LTIOStreamInf class.
#include "main.h"
#include "support.h"
#include "lt_ioSubStream.h"
LT_USE_NAMESPACE(LizardTech);
LT_STATUS UsingStreams()
{
// make and open a file-based stream
TEST_SUCCESS(stream.initialize(INPUT_PATH("meg.hdr"), "r"));
TEST_SUCCESS(stream.open());
// read the first five bytes
lt_uint8 buf[5];
TEST_BOOL(stream.read(buf, 5) == 5);
TEST_BOOL(memcmp(buf, "NROWS", 5)==0);
// seek ahead two bytes
TEST_SUCCESS(stream.seek(2, LTIO_SEEK_DIR_CUR));
TEST_BOOL(stream.tell() == 7);
// read two more bytes
TEST_BOOL(stream.read(buf, 2) == 2);
TEST_BOOL(memcmp(buf, "80", 2) == 0);
// all done
TEST_SUCCESS(stream.close());
//
// now test the substream class
//
TEST_SUCCESS(stream.open());
LTIOSubStream substream;
TEST_SUCCESS(substream.initialize(&stream, 7, 9, false));
TEST_SUCCESS(substream.open());
TEST_BOOL(substream.read(buf, 2) == 2);
TEST_BOOL(memcmp(buf, "80", 2)==0);
TEST_BOOL(stream.tell() == 9);
TEST_BOOL(substream.tell() == 2);
substream.close();
stream.close();
}
@ LTIO_SEEK_DIR_CUR
Offset from the current read/write position.
Definition: lt_lib_io.h:34
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 char lt_uint8
unsigned 8-bit integer
Definition: lt_types.h:36
File stream.
virtual lt_uint32 read(lt_uint8 *pDest, lt_uint32 numBytes)
Default Constructor.
virtual LT_STATUS seek(lt_int64 offset, LTIOSeekDir origin)
Default Constructor.
virtual lt_int64 tell()
Default Constructor.
virtual LT_STATUS close()
Default Constructor.
virtual LT_STATUS initialize(const LTFileSpec &fs, const char *mode)
Initializes the stream from a file spec.
virtual LT_STATUS open()
Default Constructor.
LTIOSubStream.
virtual LT_STATUS initialize(LTIOStreamInf *stream, lt_int64 start, lt_int64 end, bool takeOwnership=false)
Initializes the stream.
virtual lt_uint32 read(lt_uint8 *pDest, lt_uint32 numBytes)
Retrieve the specified number of bytes from the data source and place them in pDest.
virtual LT_STATUS close()
Closes the stream.
virtual lt_int64 tell()
Returns the current data access position as an offset from the start of the data.
virtual LT_STATUS open()
Opens the stream.

Extensis