OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
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

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

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 123 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 ( )

A destructor

Definition at line 110 of file ojph_file.cpp.

References close().

Member Function Documentation

◆ close()

void ojph::mem_outfile::close ( )
virtual

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]

OJPH_EXPORT 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 178 of file ojph_file.h.

References buf.

◆ get_data() [2/2]

OJPH_EXPORT 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 188 of file ojph_file.h.

References buf.

◆ 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()

virtual OJPH_EXPORT si64 ojph::mem_outfile::tell ( )
inlinevirtual

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 161 of file ojph_file.h.

References buf, and cur_ptr.

Referenced by write().

◆ write()

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

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 193 of file ojph_file.h.

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

◆ buf_size

size_t ojph::mem_outfile::buf_size
private

Definition at line 192 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 194 of file ojph_file.h.

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

◆ is_open

bool ojph::mem_outfile::is_open
private

Definition at line 191 of file ojph_file.h.

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


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