Blender V5.0
format_jp2.cc File Reference
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "IMB_colormanagement.hh"
#include "IMB_filetype.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "CLG_log.h"
#include "openjpeg.h"
#include <algorithm>
#include <cstring>

Go to the source code of this file.

Classes

struct  img_fol_t
struct  BufInfo

Macros

#define JP2_FILEHEADER_SIZE   12
#define PIXEL_LOOPER_BEGIN(_rect)
#define PIXEL_LOOPER_BEGIN_CHANNELS(_rect, _channels)
#define PIXEL_LOOPER_END
#define CINEMA_24_CS   1302083 /* Code-stream length for 24fps. */
#define CINEMA_48_CS   651041 /* Code-stream length for 48fps. */
#define COMP_24_CS   1041666 /* Maximum size per color component for 2K & 4K @ 24fps. */
#define COMP_48_CS   520833 /* Maximum size per color component for 2K @ 48fps. */

Functions

static bool check_jp2 (const uchar *mem, const size_t size)
static bool check_j2k (const uchar *mem, const size_t size)
static OPJ_CODEC_FORMAT format_from_header (const uchar mem[JP2_FILEHEADER_SIZE], const size_t size)
bool imb_is_a_jp2 (const uchar *buf, size_t size)
static void error_callback (const char *msg, void *)
static void warning_callback (const char *msg, void *)
static void info_callback (const char *msg, void *)
static ImBufimb_load_jp2_stream (opj_stream_t *stream, OPJ_CODEC_FORMAT p_format, int flags, ImFileColorSpace &r_colorspace)
ImBufimb_load_jp2 (const uchar *mem, size_t size, int flags, ImFileColorSpace &r_colorspace)
ImBufimb_load_jp2_filepath (const char *filepath, int flags, ImFileColorSpace &r_colorspace)
BLI_INLINE int UPSAMPLE_8_TO_12 (const uchar _val)
BLI_INLINE int UPSAMPLE_8_TO_16 (const uchar _val)
BLI_INLINE int DOWNSAMPLE_FLOAT_TO_8BIT (const float _val)
BLI_INLINE int DOWNSAMPLE_FLOAT_TO_12BIT (const float _val)
BLI_INLINE int DOWNSAMPLE_FLOAT_TO_16BIT (const float _val)
static int init_4K_poc (opj_poc_t *POC, int numres)
static void cinema_parameters (opj_cparameters_t *parameters)
static void cinema_setup_encoder (opj_cparameters_t *parameters, opj_image_t *image, img_fol_t *img_fol)
static float channel_colormanage_noop (float value)
static opj_image_t * ibuftoimage (ImBuf *ibuf, opj_cparameters_t *parameters)
bool imb_save_jp2_stream (ImBuf *ibuf, opj_stream_t *stream, int flags)
bool imb_save_jp2 (ImBuf *ibuf, const char *filepath, int flags)
Buffer Stream
static void opj_read_from_buffer_free (void *)
static OPJ_SIZE_T opj_read_from_buffer (void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
static OPJ_OFF_T opj_skip_from_buffer (OPJ_OFF_T p_nb_bytes, void *p_user_data)
static OPJ_BOOL opj_seek_from_buffer (OPJ_OFF_T p_nb_bytes, void *p_user_data)
static opj_stream_t * opj_stream_create_from_buffer (BufInfo *p_file, OPJ_UINT32 p_size, OPJ_BOOL p_is_read_stream)
File Stream
static void opj_free_from_file (void *p_user_data)
static OPJ_UINT64 opj_get_data_length_from_file (void *p_user_data)
static OPJ_SIZE_T opj_read_from_file (void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
static OPJ_SIZE_T opj_write_from_file (void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
static OPJ_OFF_T opj_skip_from_file (OPJ_OFF_T p_nb_bytes, void *p_user_data)
static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, void *p_user_data)
static opj_stream_t * opj_stream_create_from_file (const char *filepath, OPJ_UINT32 p_size, OPJ_BOOL p_is_read_stream, FILE **r_file)

Variables

static CLG_LogRef LOG = {"image.openjpeg"}
static const char JP2_HEAD []
static const char J2K_HEAD [] = {0xFF, 0x4F, 0xFF, 0x51, 0x00}

Macro Definition Documentation

◆ CINEMA_24_CS

#define CINEMA_24_CS   1302083 /* Code-stream length for 24fps. */

Definition at line 626 of file format_jp2.cc.

Referenced by cinema_setup_encoder().

◆ CINEMA_48_CS

#define CINEMA_48_CS   651041 /* Code-stream length for 48fps. */

Definition at line 627 of file format_jp2.cc.

Referenced by cinema_setup_encoder().

◆ COMP_24_CS

#define COMP_24_CS   1041666 /* Maximum size per color component for 2K & 4K @ 24fps. */

Definition at line 628 of file format_jp2.cc.

Referenced by cinema_setup_encoder().

◆ COMP_48_CS

#define COMP_48_CS   520833 /* Maximum size per color component for 2K @ 48fps. */

Definition at line 629 of file format_jp2.cc.

Referenced by cinema_setup_encoder().

◆ JP2_FILEHEADER_SIZE

#define JP2_FILEHEADER_SIZE   12

Definition at line 27 of file format_jp2.cc.

Referenced by format_from_header(), imb_load_jp2(), and imb_load_jp2_filepath().

◆ PIXEL_LOOPER_BEGIN

#define PIXEL_LOOPER_BEGIN ( _rect)
Value:
for (y = h - 1; y != uint(-1); y--) { \
for (i = y * w, i_next = (y + 1) * w; i < i_next; i++, _rect += 4) {
unsigned int uint
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
i
Definition text_draw.cc:230

Definition at line 106 of file format_jp2.cc.

Referenced by ibuftoimage(), and imb_load_jp2_stream().

◆ PIXEL_LOOPER_BEGIN_CHANNELS

#define PIXEL_LOOPER_BEGIN_CHANNELS ( _rect,
_channels )
Value:
for (y = h - 1; y != uint(-1); y--) { \
for (i = y * w, i_next = (y + 1) * w; i < i_next; i++, _rect += _channels) {

Definition at line 110 of file format_jp2.cc.

Referenced by ibuftoimage().

◆ PIXEL_LOOPER_END

#define PIXEL_LOOPER_END
Value:
} \
} \
(void)0

Definition at line 114 of file format_jp2.cc.

Referenced by ibuftoimage(), and imb_load_jp2_stream().

Function Documentation

◆ channel_colormanage_noop()

float channel_colormanage_noop ( float value)
static

Definition at line 795 of file format_jp2.cc.

Referenced by ibuftoimage().

◆ check_j2k()

bool check_j2k ( const uchar * mem,
const size_t size )
static

Definition at line 56 of file format_jp2.cc.

References false, J2K_HEAD, and size().

Referenced by format_from_header(), and imb_is_a_jp2().

◆ check_jp2()

bool check_jp2 ( const uchar * mem,
const size_t size )
static

Definition at line 48 of file format_jp2.cc.

References false, JP2_HEAD, and size().

Referenced by format_from_header(), and imb_is_a_jp2().

◆ cinema_parameters()

void cinema_parameters ( opj_cparameters_t * parameters)
static

Definition at line 650 of file format_jp2.cc.

Referenced by ibuftoimage().

◆ cinema_setup_encoder()

void cinema_setup_encoder ( opj_cparameters_t * parameters,
opj_image_t * image,
img_fol_t * img_fol )
static

Definition at line 684 of file format_jp2.cc.

References CINEMA_24_CS, CINEMA_48_CS, CLOG_WARN, COMP_24_CS, COMP_48_CS, float, i, init_4K_poc(), LOG, and img_fol_t::rates.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_12BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_12BIT ( const float _val)

Definition at line 605 of file format_jp2.cc.

References BLI_INLINE.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_16BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_16BIT ( const float _val)

Definition at line 609 of file format_jp2.cc.

References BLI_INLINE.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_8BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_8BIT ( const float _val)

Definition at line 601 of file format_jp2.cc.

References BLI_INLINE.

Referenced by ibuftoimage().

◆ error_callback()

void error_callback ( const char * msg,
void *  )
static

sample error callback expecting a FILE* client object

Definition at line 84 of file format_jp2.cc.

References CLOG_STR_ERROR, and LOG.

◆ format_from_header()

OPJ_CODEC_FORMAT format_from_header ( const uchar mem[JP2_FILEHEADER_SIZE],
const size_t size )
static

Definition at line 64 of file format_jp2.cc.

References check_j2k(), check_jp2(), JP2_FILEHEADER_SIZE, and size().

Referenced by imb_load_jp2(), and imb_load_jp2_filepath().

◆ ibuftoimage()

◆ imb_is_a_jp2()

bool imb_is_a_jp2 ( const uchar * buf,
size_t size )

Definition at line 76 of file format_jp2.cc.

References check_j2k(), check_jp2(), and size().

◆ imb_load_jp2()

ImBuf * imb_load_jp2 ( const uchar * mem,
size_t size,
int flags,
ImFileColorSpace & r_colorspace )

◆ imb_load_jp2_filepath()

ImBuf * imb_load_jp2_filepath ( const char * filepath,
int flags,
ImFileColorSpace & r_colorspace )

◆ imb_load_jp2_stream()

◆ imb_save_jp2()

bool imb_save_jp2 ( ImBuf * ibuf,
const char * filepath,
int flags )

Definition at line 1178 of file format_jp2.cc.

References imb_save_jp2_stream(), and opj_stream_create_from_file().

◆ imb_save_jp2_stream()

bool imb_save_jp2_stream ( ImBuf * ibuf,
opj_stream_t * stream,
int flags )

◆ info_callback()

void info_callback ( const char * msg,
void *  )
static

sample debug callback expecting no client object

Definition at line 100 of file format_jp2.cc.

References CLOG_STR_INFO, and LOG.

Referenced by imb_load_jp2_stream(), and imb_save_jp2_stream().

◆ init_4K_poc()

int init_4K_poc ( opj_poc_t * POC,
int numres )
static

Definition at line 631 of file format_jp2.cc.

Referenced by cinema_setup_encoder().

◆ opj_free_from_file()

void opj_free_from_file ( void * p_user_data)
static

Definition at line 214 of file format_jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_get_data_length_from_file()

OPJ_UINT64 opj_get_data_length_from_file ( void * p_user_data)
static

Definition at line 220 of file format_jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_read_from_buffer()

OPJ_SIZE_T opj_read_from_buffer ( void * p_buffer,
OPJ_SIZE_T p_nb_bytes,
void * p_user_data )
static

Definition at line 134 of file format_jp2.cc.

References BufInfo::buf, BufInfo::cur, and BufInfo::len.

Referenced by opj_stream_create_from_buffer().

◆ opj_read_from_buffer_free()

void opj_read_from_buffer_free ( void * )
static

Definition at line 129 of file format_jp2.cc.

Referenced by opj_stream_create_from_buffer().

◆ opj_read_from_file()

OPJ_SIZE_T opj_read_from_file ( void * p_buffer,
OPJ_SIZE_T p_nb_bytes,
void * p_user_data )
static

Definition at line 232 of file format_jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_seek_from_buffer()

OPJ_BOOL opj_seek_from_buffer ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 173 of file format_jp2.cc.

References BufInfo::buf, BufInfo::cur, BufInfo::len, and len.

Referenced by opj_stream_create_from_buffer().

◆ opj_seek_from_file()

OPJ_BOOL opj_seek_from_file ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 254 of file format_jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_skip_from_buffer()

OPJ_OFF_T opj_skip_from_buffer ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 162 of file format_jp2.cc.

References BufInfo::buf, BufInfo::cur, and BufInfo::len.

Referenced by opj_stream_create_from_buffer().

◆ opj_skip_from_file()

OPJ_OFF_T opj_skip_from_file ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 245 of file format_jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_stream_create_from_buffer()

opj_stream_t * opj_stream_create_from_buffer ( BufInfo * p_file,
OPJ_UINT32 p_size,
OPJ_BOOL p_is_read_stream )
static

Stream wrapper for memory buffer (would be nice if this was supported by the API).

Definition at line 188 of file format_jp2.cc.

References BufInfo::len, opj_read_from_buffer(), opj_read_from_buffer_free(), opj_seek_from_buffer(), and opj_skip_from_buffer().

Referenced by imb_load_jp2().

◆ opj_stream_create_from_file()

opj_stream_t * opj_stream_create_from_file ( const char * filepath,
OPJ_UINT32 p_size,
OPJ_BOOL p_is_read_stream,
FILE ** r_file )
static

Stream wrapper for memory file (would be nice if this was supported by the API).

Definition at line 268 of file format_jp2.cc.

References BLI_fopen(), opj_free_from_file(), opj_get_data_length_from_file(), opj_read_from_file(), opj_seek_from_file(), opj_skip_from_file(), and opj_write_from_file().

Referenced by imb_load_jp2_filepath(), and imb_save_jp2().

◆ opj_write_from_file()

OPJ_SIZE_T opj_write_from_file ( void * p_buffer,
OPJ_SIZE_T p_nb_bytes,
void * p_user_data )
static

Definition at line 239 of file format_jp2.cc.

Referenced by opj_stream_create_from_file().

◆ UPSAMPLE_8_TO_12()

BLI_INLINE int UPSAMPLE_8_TO_12 ( const uchar _val)

Definition at line 592 of file format_jp2.cc.

References BLI_INLINE.

Referenced by ibuftoimage().

◆ UPSAMPLE_8_TO_16()

BLI_INLINE int UPSAMPLE_8_TO_16 ( const uchar _val)

Definition at line 596 of file format_jp2.cc.

References BLI_INLINE.

Referenced by ibuftoimage().

◆ warning_callback()

void warning_callback ( const char * msg,
void *  )
static

sample warning callback expecting a FILE* client object

Definition at line 91 of file format_jp2.cc.

References CLOG_STR_WARN, and LOG.

Referenced by imb_load_jp2_stream(), and imb_save_jp2_stream().

Variable Documentation

◆ J2K_HEAD

const char J2K_HEAD[] = {0xFF, 0x4F, 0xFF, 0x51, 0x00}
static

Definition at line 31 of file format_jp2.cc.

Referenced by check_j2k().

◆ JP2_HEAD

const char JP2_HEAD[]
static
Initial value:
= {
0x0, 0x0, 0x0, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A}

Definition at line 29 of file format_jp2.cc.

Referenced by check_jp2().

◆ LOG

CLG_LogRef LOG = {"image.openjpeg"}
static

Definition at line 25 of file format_jp2.cc.