OpenJPH
Open-source implementation of JPEG2000 Part-15
|
mem_outfile stores encoded j2k codestreams in memory More...
#include <ojph_file.h>
Public Member Functions | |
mem_outfile () | |
~mem_outfile () override | |
void | open (size_t initial_size=65536, bool clear_mem=false) |
Call this function to open a memory file. | |
size_t | write (const void *ptr, size_t size) override |
Call this function to write data to the memory file. | |
si64 | tell () override |
Call this function to know the file size (i.e., number of bytes used to store the file). | |
int | seek (si64 offset, enum outfile_base::seek origin) override |
Call this function to change write pointer location; the function can expand file storage. | |
void | close () override |
const ui8 * | get_data () |
Call this function to access memory file data. | |
const ui8 * | get_data () const |
Call this function to access memory file data (for const objects) | |
void | write_to_file (const char *file_name) const |
Call this function to write the memory file data to a file. | |
![]() | |
virtual | ~outfile_base () |
virtual void | flush () |
Private Member Functions | |
void | expand_storage (size_t new_size, bool clear_all) |
This function expands storage by x1.5 needed space. | |
Private Attributes | |
bool | is_open |
bool | clear_mem |
size_t | buf_size |
size_t | used_size |
ui8 * | buf |
ui8 * | cur_ptr |
Additional Inherited Members | |
![]() | |
enum | seek : int { OJPH_SEEK_SET = SEEK_SET , OJPH_SEEK_CUR = SEEK_CUR , OJPH_SEEK_END = SEEK_END } |
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 126 of file ojph_file.h.
ojph::mem_outfile::mem_outfile | ( | ) |
|
override |
|
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 134 of file ojph_file.cpp.
References buf, cur_ptr, and is_open.
Referenced by ojph::stex::frames_handler::flush(), ojph::stex::frames_handler::init(), and ojph::stex::frames_handler::send_to_processing().
|
private |
This function expands storage by x1.5 needed space.
It sets cur_ptr correctly, and clears the extended area of the buffer. It optionally clear the whole buffer
new_size | New size of the buffer |
clear_all | Set to true to clear whole buffer, not just expansion |
Definition at line 199 of file ojph_file.cpp.
References buf, buf_size, clear_mem, cur_ptr, tell(), and used_size.
|
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.
Definition at line 187 of file ojph_file.h.
|
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.
Definition at line 198 of file ojph_file.h.
void ojph::mem_outfile::open | ( | size_t | initial_size = 65536 , |
bool | clear_mem = false |
||
) |
Call this function to open a memory file.
This function creates a memory buffer to be used for storing the generated j2k codestream.
initial_size | is the initial memory buffer size. The default value is 2^16. |
clear_mem | if set to true, all allocated memory is reset to 0 |
Definition at line 120 of file ojph_file.cpp.
References buf, clear_mem, cur_ptr, expand_storage(), is_open, and used_size.
Referenced by ojph::stex::frames_handler::init(), and ojph::stex::frames_handler::push().
|
overridevirtual |
Call this function to change write pointer location; the function can expand file storage.
The seek function expands the buffer whenever offset goes beyond the buffer end
Reimplemented from ojph::outfile_base.
Definition at line 142 of file ojph_file.cpp.
References buf, buf_size, cur_ptr, expand_storage(), ojph::outfile_base::OJPH_SEEK_CUR, ojph::outfile_base::OJPH_SEEK_END, ojph::outfile_base::OJPH_SEEK_SET, and tell().
|
inlineoverridevirtual |
Call this function to know the file size (i.e., number of bytes used to store the file).
Reimplemented from ojph::outfile_base.
Definition at line 163 of file ojph_file.h.
Referenced by expand_storage(), seek(), and write().
|
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.
ptr | is a pointer to new data. |
size | the number of bytes in the new data. |
Whenever the need arises, the buffer is expanded by a factor approx 1.5x
Implements ojph::outfile_base.
Definition at line 166 of file ojph_file.cpp.
References buf, buf_size, cur_ptr, expand_storage(), is_open, ojph_max, tell(), and used_size.
Referenced by ojph::stex::frames_handler::push().
void ojph::mem_outfile::write_to_file | ( | const char * | file_name | ) | const |
Call this function to write the memory file data to a file.
Definition at line 186 of file ojph_file.cpp.
References buf, is_open, OJPH_ERROR, and used_size.
Referenced by ojph::stex::j2k_frame_storer::execute().
|
private |
Definition at line 223 of file ojph_file.h.
Referenced by close(), expand_storage(), mem_outfile(), open(), seek(), write(), write_to_file(), and ~mem_outfile().
|
private |
Definition at line 221 of file ojph_file.h.
Referenced by expand_storage(), mem_outfile(), seek(), write(), and ~mem_outfile().
|
private |
Definition at line 220 of file ojph_file.h.
Referenced by expand_storage(), mem_outfile(), open(), and ~mem_outfile().
|
private |
Definition at line 224 of file ojph_file.h.
Referenced by close(), expand_storage(), mem_outfile(), open(), seek(), write(), and ~mem_outfile().
|
private |
Definition at line 219 of file ojph_file.h.
Referenced by close(), mem_outfile(), open(), write(), write_to_file(), and ~mem_outfile().
|
private |
Definition at line 222 of file ojph_file.h.
Referenced by expand_storage(), mem_outfile(), open(), write(), write_to_file(), and ~mem_outfile().