Blender V4.3
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 "openjpeg.h"
#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 *client_data)
 
static void warning_callback (const char *msg, void *client_data)
 
static void info_callback (const char *msg, void *client_data)
 
static ImBufimb_load_jp2_stream (opj_stream_t *stream, OPJ_CODEC_FORMAT p_format, int flags, char colorspace[IM_MAX_SPACE])
 
ImBufimb_load_jp2 (const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
 
ImBufimb_load_jp2_filepath (const char *filepath, int flags, char colorspace[IM_MAX_SPACE])
 
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 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 629 of file jp2.cc.

Referenced by cinema_setup_encoder().

◆ CINEMA_48_CS

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

Definition at line 630 of file 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 631 of file 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 632 of file jp2.cc.

Referenced by cinema_setup_encoder().

◆ JP2_FILEHEADER_SIZE

#define JP2_FILEHEADER_SIZE   12

Definition at line 22 of file jp2.cc.

Referenced by 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

Definition at line 104 of file 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 108 of file jp2.cc.

Referenced by ibuftoimage().

◆ PIXEL_LOOPER_END

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

Definition at line 112 of file jp2.cc.

Referenced by ibuftoimage(), and imb_load_jp2_stream().

Function Documentation

◆ channel_colormanage_noop()

static float channel_colormanage_noop ( float value)
static

Definition at line 800 of file jp2.cc.

Referenced by ibuftoimage().

◆ check_j2k()

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

Definition at line 51 of file jp2.cc.

References false, and J2K_HEAD.

Referenced by format_from_header(), and imb_is_a_jp2().

◆ check_jp2()

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

Definition at line 43 of file jp2.cc.

References false, and JP2_HEAD.

Referenced by format_from_header(), and imb_is_a_jp2().

◆ cinema_parameters()

static void cinema_parameters ( opj_cparameters_t * parameters)
static

Definition at line 653 of file jp2.cc.

References parameters.

Referenced by ibuftoimage().

◆ cinema_setup_encoder()

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

Definition at line 687 of file jp2.cc.

References CINEMA_24_CS, CINEMA_48_CS, COMP_24_CS, COMP_48_CS, float, init_4K_poc(), parameters, 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 608 of file jp2.cc.

References int.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_16BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_16BIT ( const float _val)

Definition at line 612 of file jp2.cc.

References int.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_8BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_8BIT ( const float _val)

Definition at line 604 of file jp2.cc.

References int.

Referenced by ibuftoimage().

◆ error_callback()

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

sample error callback expecting a FILE* client object

Definition at line 79 of file jp2.cc.

◆ format_from_header()

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

Definition at line 59 of file jp2.cc.

References check_j2k(), and check_jp2().

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 71 of file jp2.cc.

References check_j2k(), and check_jp2().

◆ imb_load_jp2()

ImBuf * imb_load_jp2 ( const uchar * mem,
size_t size,
int flags,
char colorspace[IM_MAX_SPACE] )

◆ imb_load_jp2_filepath()

ImBuf * imb_load_jp2_filepath ( const char * filepath,
int flags,
char colorspace[IM_MAX_SPACE] )

◆ imb_load_jp2_stream()

◆ imb_save_jp2()

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

Definition at line 1183 of file 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()

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

sample debug callback expecting no client object

Definition at line 97 of file jp2.cc.

Referenced by imb_load_jp2_stream(), and imb_save_jp2_stream().

◆ init_4K_poc()

static int init_4K_poc ( opj_poc_t * POC,
int numres )
static

Definition at line 634 of file jp2.cc.

Referenced by cinema_setup_encoder().

◆ opj_free_from_file()

static void opj_free_from_file ( void * p_user_data)
static

Definition at line 212 of file jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_get_data_length_from_file()

static OPJ_UINT64 opj_get_data_length_from_file ( void * p_user_data)
static

Definition at line 218 of file jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_read_from_buffer()

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

Definition at line 132 of file jp2.cc.

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

Referenced by opj_stream_create_from_buffer().

◆ opj_read_from_buffer_free()

static void opj_read_from_buffer_free ( void * )
static

Definition at line 127 of file jp2.cc.

Referenced by opj_stream_create_from_buffer().

◆ opj_read_from_file()

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

Definition at line 230 of file jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_seek_from_buffer()

static OPJ_BOOL opj_seek_from_buffer ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 171 of file jp2.cc.

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

Referenced by opj_stream_create_from_buffer().

◆ opj_seek_from_file()

static OPJ_BOOL opj_seek_from_file ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 252 of file jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_skip_from_buffer()

static OPJ_OFF_T opj_skip_from_buffer ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 160 of file jp2.cc.

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

Referenced by opj_stream_create_from_buffer().

◆ opj_skip_from_file()

static OPJ_OFF_T opj_skip_from_file ( OPJ_OFF_T p_nb_bytes,
void * p_user_data )
static

Definition at line 243 of file jp2.cc.

Referenced by opj_stream_create_from_file().

◆ opj_stream_create_from_buffer()

static 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 186 of file 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()

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 )
static

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

Definition at line 266 of file 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()

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

Definition at line 237 of file 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 595 of file jp2.cc.

Referenced by ibuftoimage().

◆ UPSAMPLE_8_TO_16()

BLI_INLINE int UPSAMPLE_8_TO_16 ( const uchar _val)

Definition at line 599 of file jp2.cc.

Referenced by ibuftoimage().

◆ warning_callback()

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

sample warning callback expecting a FILE* client object

Definition at line 87 of file jp2.cc.

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 26 of file 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 24 of file jp2.cc.

Referenced by check_jp2().