Blender  V3.3
Classes | Macros | Typedefs | Functions | Variables
jp2.c File Reference
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_math.h"
#include "IMB_filetype.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_colormanagement.h"
#include "IMB_colormanagement_intern.h"
#include "openjpeg.h"

Go to the source code of this file.

Classes

struct  img_folder
 
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. */
 

Typedefs

typedef struct img_folder img_fol_t
 

Functions

static bool check_jp2 (const unsigned char *mem, const size_t size)
 
static bool check_j2k (const unsigned char *mem, const size_t size)
 
static OPJ_CODEC_FORMAT format_from_header (const unsigned char mem[JP2_FILEHEADER_SIZE], const size_t size)
 
bool imb_is_a_jp2 (const unsigned char *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 ImBufimb_load_jp2_stream (opj_stream_t *stream, OPJ_CODEC_FORMAT p_format, int flags, char colorspace[IM_MAX_SPACE])
 
ImBufimb_load_jp2 (const unsigned char *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 unsigned char _val)
 
BLI_INLINE int UPSAMPLE_8_TO_16 (const unsigned char _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 (struct ImBuf *ibuf, opj_stream_t *stream, int flags)
 
bool imb_save_jp2 (struct ImBuf *ibuf, const char *filepath, int flags)
 
bool imb_save_jp2_stream (struct ImBuf *ibuf, opj_stream_t *stream, int UNUSED(flags))
 
Buffer Stream
static void opj_read_from_buffer_free (void *UNUSED(p_user_data))
 
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 (struct 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 636 of file jp2.c.

◆ CINEMA_48_CS

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

Definition at line 637 of file jp2.c.

◆ COMP_24_CS

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

Definition at line 638 of file jp2.c.

◆ COMP_48_CS

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

Definition at line 639 of file jp2.c.

◆ JP2_FILEHEADER_SIZE

#define JP2_FILEHEADER_SIZE   12

Definition at line 21 of file jp2.c.

◆ PIXEL_LOOPER_BEGIN

#define PIXEL_LOOPER_BEGIN (   _rect)
Value:
for (y = h - 1; y != (unsigned int)(-1); y--) { \
for (i = y * w, i_next = (y + 1) * w; i < i_next; i++, _rect += 4) {
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119

Definition at line 104 of file jp2.c.

◆ PIXEL_LOOPER_BEGIN_CHANNELS

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

Definition at line 108 of file jp2.c.

◆ PIXEL_LOOPER_END

#define PIXEL_LOOPER_END
Value:
} \
} \
(void)0
SyclQueue void void size_t num_bytes void

Definition at line 112 of file jp2.c.

Typedef Documentation

◆ img_fol_t

typedef struct img_folder img_fol_t

Function Documentation

◆ channel_colormanage_noop()

static float channel_colormanage_noop ( float  value)
static

Definition at line 807 of file jp2.c.

Referenced by ibuftoimage().

◆ check_j2k()

static bool check_j2k ( const unsigned char *  mem,
const size_t  size 
)
static

Definition at line 50 of file jp2.c.

References J2K_HEAD, and size().

Referenced by format_from_header(), and imb_is_a_jp2().

◆ check_jp2()

static bool check_jp2 ( const unsigned char *  mem,
const size_t  size 
)
static

Definition at line 42 of file jp2.c.

References JP2_HEAD, and size().

Referenced by format_from_header(), and imb_is_a_jp2().

◆ cinema_parameters()

static void cinema_parameters ( opj_cparameters_t *  parameters)
static

Definition at line 660 of file jp2.c.

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 694 of file jp2.c.

References CINEMA_24_CS, CINEMA_48_CS, COMP_24_CS, COMP_48_CS, float(), image(), init_4K_poc(), parameters, and img_folder::rates.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_12BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_12BIT ( const float  _val)

Definition at line 615 of file jp2.c.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_16BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_16BIT ( const float  _val)

Definition at line 619 of file jp2.c.

Referenced by ibuftoimage().

◆ DOWNSAMPLE_FLOAT_TO_8BIT()

BLI_INLINE int DOWNSAMPLE_FLOAT_TO_8BIT ( const float  _val)

Definition at line 611 of file jp2.c.

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.c.

Referenced by imb_load_jp2_stream(), and imb_save_jp2_stream().

◆ format_from_header()

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

Definition at line 58 of file jp2.c.

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

Referenced by imb_load_jp2(), and imb_load_jp2_filepath().

◆ ibuftoimage()

static opj_image_t* ibuftoimage ( ImBuf ibuf,
opj_cparameters_t *  parameters 
)
static

◆ imb_is_a_jp2()

bool imb_is_a_jp2 ( const unsigned char *  buf,
size_t  size 
)

Definition at line 71 of file jp2.c.

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

◆ imb_load_jp2()

ImBuf* imb_load_jp2 ( const unsigned char *  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()

static ImBuf * imb_load_jp2_stream ( opj_stream_t *  stream,
OPJ_CODEC_FORMAT  p_format,
int  flags,
char  colorspace[IM_MAX_SPACE] 
)
static

◆ imb_save_jp2()

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

Definition at line 1187 of file jp2.c.

References ImBuf::flags, imb_save_jp2_stream(), NULL, and opj_stream_create_from_file().

◆ imb_save_jp2_stream() [1/2]

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

Referenced by imb_save_jp2().

◆ imb_save_jp2_stream() [2/2]

bool imb_save_jp2_stream ( struct ImBuf ibuf,
opj_stream_t *  stream,
int   UNUSEDflags 
)

◆ init_4K_poc()

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

Definition at line 641 of file jp2.c.

Referenced by cinema_setup_encoder().

◆ opj_free_from_file()

static void opj_free_from_file ( void p_user_data)
static

Definition at line 213 of file jp2.c.

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 219 of file jp2.c.

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.c.

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

Definition at line 127 of file jp2.c.

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 231 of file jp2.c.

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.c.

References BufInfo::buf, BufInfo::cur, len, and BufInfo::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 253 of file jp2.c.

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.c.

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 244 of file jp2.c.

Referenced by opj_stream_create_from_file().

◆ opj_stream_create_from_buffer()

static opj_stream_t* opj_stream_create_from_buffer ( struct 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 187 of file jp2.c.

References BufInfo::len, NULL, 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 267 of file jp2.c.

References BLI_fopen(), NULL, 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 238 of file jp2.c.

Referenced by opj_stream_create_from_file().

◆ UPSAMPLE_8_TO_12()

BLI_INLINE int UPSAMPLE_8_TO_12 ( const unsigned char  _val)

Definition at line 602 of file jp2.c.

Referenced by ibuftoimage().

◆ UPSAMPLE_8_TO_16()

BLI_INLINE int UPSAMPLE_8_TO_16 ( const unsigned char  _val)

Definition at line 606 of file jp2.c.

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.c.

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 25 of file jp2.c.

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 23 of file jp2.c.

Referenced by check_jp2().