OpenJPH
Open-source implementation of JPEG2000 Part-15
ojph::mem_outfile Class Reference

mem_outfile stores encoded j2k codestreams in memory More...

#include <ojph_file.h>

Inheritance diagram for ojph::mem_outfile:
ojph::outfile_base

Public Member Functions

 mem_outfile ()
 
 ~mem_outfile () override
 
void open (size_t initial_size=65536)
 
size_t write (const void *ptr, size_t size) override
 
si64 tell () override
 
void close () override
 
const ui8get_data ()
 
const ui8get_data () const
 
- Public Member Functions inherited from ojph::outfile_base
virtual ~outfile_base ()
 
virtual size_t write (const void *ptr, size_t size)=0
 
virtual si64 tell ()
 
virtual void flush ()
 
virtual void close ()
 

Private Attributes

bool is_open
 
size_t buf_size
 
ui8buf
 
ui8cur_ptr
 

Detailed Description

mem_outfile stores encoded j2k codestreams in memory

This code was first developed by Chris Hafey https://github.com/chafey I took the code and integrated with OpenJPH, with some modifications.

This class serves as a memory-based file storage. For example, generated j2k codestream is stored in memory instead of a conventional file. The memory buffer associated with this class grows with the addition of new data.

memory data can be accessed using get_data()

Definition at line 116 of file ojph_file.h.

Constructor & Destructor Documentation

◆ mem_outfile()

ojph::mem_outfile::mem_outfile ( )

A constructor

Definition at line 102 of file ojph_file.cpp.

References buf, buf_size, cur_ptr, and is_open.

◆ ~mem_outfile()

ojph::mem_outfile::~mem_outfile ( )
override

A destructor

Definition at line 110 of file ojph_file.cpp.

References close().

Member Function Documentation

◆ close()

void ojph::mem_outfile::close ( )
overridevirtual

Call this function to close the file and deallocate memory

The object can be used again after calling close

Reimplemented from ojph::outfile_base.

Definition at line 132 of file ojph_file.cpp.

References buf, buf_size, cur_ptr, and is_open.

Referenced by ~mem_outfile().

◆ get_data() [1/2]

const ui8 * ojph::mem_outfile::get_data ( )
inline

Call this function to access memory file data.

It is not recommended to store the returned value because buffer storage address can change between write calls.

Returns
a constant pointer to the data.

Definition at line 164 of file ojph_file.h.

◆ get_data() [2/2]

const ui8 * ojph::mem_outfile::get_data ( ) const
inline

Call this function to access memory file data (for const objects)

This is similar to the above function, except that it can be used with constant objects.

Returns
a constant pointer to the data.

Definition at line 173 of file ojph_file.h.

◆ open()

void ojph::mem_outfile::open ( size_t  initial_size = 65536)

Call this function to open a memory file.

This function creates a memory buffer to be used for storing the generated j2k codestream.

Parameters
initial_sizeis the initial memory buffer size. The default value is 2^16.

Definition at line 116 of file ojph_file.cpp.

References buf, buf_size, cur_ptr, and is_open.

◆ tell()

si64 ojph::mem_outfile::tell ( )
inlineoverridevirtual

Call this function to know the file size (i.e., number of bytes used to store the file).

Returns
the file size.

Reimplemented from ojph::outfile_base.

Definition at line 149 of file ojph_file.h.

Referenced by write().

◆ write()

size_t ojph::mem_outfile::write ( const void *  ptr,
size_t  size 
)
overridevirtual

Call this function to write data to the memory file.

This function adds new data to the memory file. The memory buffer of the file grows as needed.

Parameters
ptris the address of the new data.
sizethe number of bytes in the new data.

The function starts with a buffer size of 65536. Then, whenever the need arises, this buffer is expanded by a factor approx 1.5x

Implements ojph::outfile_base.

Definition at line 143 of file ojph_file.cpp.

References buf, buf_size, cur_ptr, is_open, and tell().

Member Data Documentation

◆ buf

ui8* ojph::mem_outfile::buf
private

Definition at line 178 of file ojph_file.h.

Referenced by close(), mem_outfile(), open(), and write().

◆ buf_size

size_t ojph::mem_outfile::buf_size
private

Definition at line 177 of file ojph_file.h.

Referenced by close(), mem_outfile(), open(), and write().

◆ cur_ptr

ui8* ojph::mem_outfile::cur_ptr
private

Definition at line 179 of file ojph_file.h.

Referenced by close(), mem_outfile(), open(), and write().

◆ is_open

bool ojph::mem_outfile::is_open
private

Definition at line 176 of file ojph_file.h.

Referenced by close(), mem_outfile(), open(), and write().


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