OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Private Attributes | List of all members
ossimKakaduCompressedTarget Class Reference

ossimKakaduCompressedTarget JPEG2000 (J2K) kdu_compressed_target that uses an ostream for writing to the file. More...

#include <ossimKakaduCompressedTarget.h>

Inheritance diagram for ossimKakaduCompressedTarget:

Public Member Functions

 ossimKakaduCompressedTarget ()
 default construtor More...
 
virtual ~ossimKakaduCompressedTarget ()
 virtural destructor More...
 
void setStream (std::ostream *stream)
 Sets the output stream. More...
 
virtual bool write (const kdu_core::kdu_byte *buf, int num_bytes)
 Write method. More...
 
virtual bool start_rewrite (kdu_core::kdu_long backtrack)
 
virtual bool end_rewrite ()
 

Private Attributes

std::ostream * m_stream
 
std::streamoff m_restorePosition
 

Detailed Description

ossimKakaduCompressedTarget JPEG2000 (J2K) kdu_compressed_target that uses an ostream for writing to the file.

Definition at line 27 of file ossimKakaduCompressedTarget.h.

Constructor & Destructor Documentation

◆ ossimKakaduCompressedTarget()

ossimKakaduCompressedTarget::ossimKakaduCompressedTarget ( )

default construtor

Definition at line 19 of file ossimKakaduCompressedTarget.cpp.

◆ ~ossimKakaduCompressedTarget()

ossimKakaduCompressedTarget::~ossimKakaduCompressedTarget ( )
virtual

virtural destructor

Definition at line 25 of file ossimKakaduCompressedTarget.cpp.

26 {
27 }

Member Function Documentation

◆ end_rewrite()

bool ossimKakaduCompressedTarget::end_rewrite ( )
virtual

Definition at line 89 of file ossimKakaduCompressedTarget.cpp.

References m_restorePosition, and m_stream.

90 {
91  bool result = false;
92  if (m_stream)
93  {
94  m_stream->seekp(m_restorePosition, std::ios_base::beg);
95  result = m_stream->good();
96  }
97  return result;
98 }

◆ setStream()

void ossimKakaduCompressedTarget::setStream ( std::ostream *  stream)

Sets the output stream.

Note the ossimKakaduCompressedTarget only uses the stream it does not take over(delete) memory on destruction.

Parameters
streamThe output stream.

Definition at line 29 of file ossimKakaduCompressedTarget.cpp.

References m_restorePosition, and m_stream.

30 {
31  if ( stream )
32  {
33  m_stream = stream;
34 
35  //---
36  // Keep track of the stream position for the start_rewrite call.
37  // ostream::tellp() on windows visual studio 10 x64 fails past
38  // 2^31-1(2GB) even though the std::streamoff held in the
39  // std::streampos is eight bytes.
40  // This call is safe as the stream is typically at 0.
41  //---
42  m_restorePosition = stream->tellp();
43  }
44 }

◆ start_rewrite()

bool ossimKakaduCompressedTarget::start_rewrite ( kdu_core::kdu_long  backtrack)
virtual

Definition at line 77 of file ossimKakaduCompressedTarget.cpp.

References m_restorePosition, and m_stream.

78 {
79  bool result = false;
80  if (m_stream)
81  {
82  std::streamoff off = m_restorePosition - static_cast<std::streamoff>(backtrack);
83  m_stream->seekp(off, std::ios_base::beg);
84  result = m_stream->good();
85  }
86  return result;
87 }

◆ write()

bool ossimKakaduCompressedTarget::write ( const kdu_core::kdu_byte *  buf,
int  num_bytes 
)
virtual

Write method.

Parameters
bufThe buffer to pull from.
num_bytesThe number of bytes to write.
Returns
true on success, false on error.

Definition at line 46 of file ossimKakaduCompressedTarget.cpp.

References m_restorePosition, and m_stream.

47 {
48  if ( m_restorePosition == 0 )
49  {
50  //---
51  // First write call. Do a tellp in case the stream was moved as in the case of
52  // nitf where the nitf header and nitf image header get written before we write
53  // pixel data.
54  //---
55  m_restorePosition = m_stream->tellp();
56  }
57 
58  bool result = false;
59  if (m_stream)
60  {
61  m_stream->write((const char*)buf,
62  static_cast<std::streamsize>(num_bytes));
63 
64  //---
65  // Keep track of the stream postition for the start_rewrite call. Do it
66  // manually as ostream::tellp() on windows visual studio 10 x64 fails
67  // past 2^31-1(2GB) even though the std::streamoff held in the
68  // std::streampos is eight bytes.
69  //---
70  m_restorePosition += static_cast<std::streamoff>(num_bytes);
71 
72  result = m_stream->good();
73  }
74  return result;
75 }

Member Data Documentation

◆ m_restorePosition

std::streamoff ossimKakaduCompressedTarget::m_restorePosition
private

Definition at line 63 of file ossimKakaduCompressedTarget.h.

Referenced by end_rewrite(), setStream(), start_rewrite(), and write().

◆ m_stream

std::ostream* ossimKakaduCompressedTarget::m_stream
private

Definition at line 62 of file ossimKakaduCompressedTarget.h.

Referenced by end_rewrite(), setStream(), start_rewrite(), and write().


The documentation for this class was generated from the following files: