OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimKakaduCompressedTarget.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Description:
8 //
9 // Class definition for JPEG2000 (J2K) kdu_compressed_target that uses an
10 // ostream for writing to the file.
11 //
12 //----------------------------------------------------------------------------
13 // $Id: ossimKakaduCompressedTarget.cpp 22884 2014-09-12 13:14:35Z dburken $
14 
16 #include <iostream>
17 #include <ostream>
18 
20  : m_stream(0),
21  m_restorePosition(0)
22 {
23 }
24 
26 {
27 }
28 
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 }
45 
46 bool ossimKakaduCompressedTarget::write(const kdu_core::kdu_byte *buf, int num_bytes)
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 }
76 
77 bool ossimKakaduCompressedTarget::start_rewrite(kdu_core::kdu_long backtrack)
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 }
88 
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 }
virtual ~ossimKakaduCompressedTarget()
virtural destructor
void setStream(std::ostream *stream)
Sets the output stream.
ossimKakaduCompressedTarget()
default construtor
virtual bool start_rewrite(kdu_core::kdu_long backtrack)
virtual bool write(const kdu_core::kdu_byte *buf, int num_bytes)
Write method.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23