Blender V4.3
jpeg.cc File Reference
#include <algorithm>
#include <csetjmp>
#include <cstdio>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_idprop.hh"
#include "DNA_ID.h"
#include "IMB_colormanagement.hh"
#include "IMB_filetype.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "IMB_metadata.hh"
#include <cstring>
#include <jerror.h>
#include <jpeglib.h>

Go to the source code of this file.

Classes

struct  my_error_mgr
 
struct  my_source_mgr
 
struct  NeoGeo_Word
 

Macros

#define MAKESTMT(stuff)
 
#define INPUT_VARS(cinfo)
 
#define INPUT_SYNC(cinfo)    (datasrc->next_input_byte = next_input_byte, datasrc->bytes_in_buffer = bytes_in_buffer)
 
#define INPUT_RELOAD(cinfo)    (next_input_byte = datasrc->next_input_byte, bytes_in_buffer = datasrc->bytes_in_buffer)
 
#define MAKE_BYTE_AVAIL(cinfo, action)
 
#define INPUT_BYTE(cinfo, V, action)    MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; V = GETJOCTET(*next_input_byte++);)
 
#define INPUT_2BYTES(cinfo, V, action)
 
#define JPEG_MARKER_MSB   (0xFF)
 
#define JPEG_MARKER_SOI   (0xD8)
 
#define JPEG_MARKER_APP1   (0xE1)
 
#define JPEG_APP1_MAX   (1 << 16)
 

Typedefs

using my_error_ptr = my_error_mgr *
 
using my_src_ptr = my_source_mgr *
 

Functions

static void jpeg_error (j_common_ptr cinfo) ATTR_NORETURN
 
static void init_source (j_decompress_ptr cinfo)
 
static boolean fill_input_buffer (j_decompress_ptr cinfo)
 
static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 
static void term_source (j_decompress_ptr cinfo)
 
static void memory_source (j_decompress_ptr cinfo, const uchar *buffer, size_t size)
 
static boolean handle_app1 (j_decompress_ptr cinfo)
 
static ImBufibJpegImageFromCinfo (jpeg_decompress_struct *cinfo, int flags, int max_size, size_t *r_width, size_t *r_height)
 
bool imb_is_a_jpeg (const uchar *mem, const size_t size)
 
 BLI_STATIC_ASSERT (sizeof(NeoGeo_Word)==4, "Must be 4 bytes")
 
ImBufimb_load_jpeg (const uchar *buffer, size_t size, int flags, char colorspace[IM_MAX_SPACE])
 
ImBufimb_thumbnail_jpeg (const char *filepath, const int flags, const size_t max_thumb_size, char colorspace[IM_MAX_SPACE], size_t *r_width, size_t *r_height)
 
static void write_jpeg (jpeg_compress_struct *cinfo, ImBuf *ibuf)
 
static int init_jpeg (FILE *outfile, jpeg_compress_struct *cinfo, ImBuf *ibuf)
 
static bool save_stdjpeg (const char *filepath, ImBuf *ibuf)
 
bool imb_savejpeg (ImBuf *ibuf, const char *filepath, int flags)
 

Variables

static const uchar jpeg_default_quality = 75
 
static uchar ibuf_quality
 

Macro Definition Documentation

◆ INPUT_2BYTES

#define INPUT_2BYTES ( cinfo,
V,
action )
Value:
MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; \
V = uint(GETJOCTET(*next_input_byte++)) << 8; \
MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \
V += GETJOCTET(*next_input_byte++);)
unsigned int uint
#define MAKESTMT(stuff)
Definition jpeg.cc:161
#define MAKE_BYTE_AVAIL(cinfo, action)
Definition jpeg.cc:183
CCL_NAMESPACE_BEGIN struct Window V

Definition at line 201 of file jpeg.cc.

Referenced by handle_app1().

◆ INPUT_BYTE

#define INPUT_BYTE ( cinfo,
V,
action )    MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; V = GETJOCTET(*next_input_byte++);)

Definition at line 195 of file jpeg.cc.

Referenced by handle_app1().

◆ INPUT_RELOAD

#define INPUT_RELOAD ( cinfo)     (next_input_byte = datasrc->next_input_byte, bytes_in_buffer = datasrc->bytes_in_buffer)

Definition at line 176 of file jpeg.cc.

◆ INPUT_SYNC

#define INPUT_SYNC ( cinfo)     (datasrc->next_input_byte = next_input_byte, datasrc->bytes_in_buffer = bytes_in_buffer)

Definition at line 172 of file jpeg.cc.

Referenced by handle_app1().

◆ INPUT_VARS

#define INPUT_VARS ( cinfo)
Value:
jpeg_source_mgr *datasrc = (cinfo)->src; \
const JOCTET *next_input_byte = datasrc->next_input_byte; \
size_t bytes_in_buffer = datasrc->bytes_in_buffer

Definition at line 166 of file jpeg.cc.

Referenced by handle_app1().

◆ JPEG_APP1_MAX

#define JPEG_APP1_MAX   (1 << 16)

Definition at line 477 of file jpeg.cc.

Referenced by imb_thumbnail_jpeg().

◆ JPEG_MARKER_APP1

#define JPEG_MARKER_APP1   (0xE1)

Definition at line 476 of file jpeg.cc.

Referenced by imb_thumbnail_jpeg().

◆ JPEG_MARKER_MSB

#define JPEG_MARKER_MSB   (0xFF)

Definition at line 474 of file jpeg.cc.

Referenced by imb_thumbnail_jpeg().

◆ JPEG_MARKER_SOI

#define JPEG_MARKER_SOI   (0xD8)

Definition at line 475 of file jpeg.cc.

Referenced by imb_thumbnail_jpeg().

◆ MAKE_BYTE_AVAIL

#define MAKE_BYTE_AVAIL ( cinfo,
action )
Value:
if (bytes_in_buffer == 0) { \
if (!(*datasrc->fill_input_buffer)(cinfo)) { \
action; \
} \
INPUT_RELOAD(cinfo); \
} \
(void)0

Definition at line 183 of file jpeg.cc.

◆ MAKESTMT

#define MAKESTMT ( stuff)
Value:
do { \
stuff \
} while (0)

Definition at line 161 of file jpeg.cc.

Typedef Documentation

◆ my_error_ptr

Definition at line 68 of file jpeg.cc.

◆ my_src_ptr

Definition at line 96 of file jpeg.cc.

Function Documentation

◆ BLI_STATIC_ASSERT()

BLI_STATIC_ASSERT ( sizeof(NeoGeo_Word) = =4,
"Must be 4 bytes"  )

◆ fill_input_buffer()

static boolean fill_input_buffer ( j_decompress_ptr cinfo)
static

Definition at line 103 of file jpeg.cc.

References my_source_mgr::pub, and my_source_mgr::terminal.

Referenced by memory_source().

◆ handle_app1()

static boolean handle_app1 ( j_decompress_ptr cinfo)
static

◆ ibJpegImageFromCinfo()

◆ imb_is_a_jpeg()

bool imb_is_a_jpeg ( const uchar * mem,
const size_t size )

Definition at line 49 of file jpeg.cc.

References magic().

Referenced by imb_load_jpeg().

◆ imb_load_jpeg()

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

◆ imb_savejpeg()

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

Definition at line 746 of file jpeg.cc.

References ImBuf::flags, and save_stdjpeg().

◆ imb_thumbnail_jpeg()

ImBuf * imb_thumbnail_jpeg ( const char * filepath,
const int flags,
const size_t max_thumb_size,
char colorspace[IM_MAX_SPACE],
size_t * r_width,
size_t * r_height )

◆ init_jpeg()

static int init_jpeg ( FILE * outfile,
jpeg_compress_struct * cinfo,
ImBuf * ibuf )
static

◆ init_source()

static void init_source ( j_decompress_ptr cinfo)
static

Definition at line 98 of file jpeg.cc.

Referenced by memory_source().

◆ jpeg_error()

static void jpeg_error ( j_common_ptr cinfo)
static

Definition at line 70 of file jpeg.cc.

References my_error_mgr::setjmp_buffer.

Referenced by imb_load_jpeg(), imb_thumbnail_jpeg(), and save_stdjpeg().

◆ memory_source()

static void memory_source ( j_decompress_ptr cinfo,
const uchar * buffer,
size_t size )
static

◆ save_stdjpeg()

static bool save_stdjpeg ( const char * filepath,
ImBuf * ibuf )
static

◆ skip_input_data()

static void skip_input_data ( j_decompress_ptr cinfo,
long num_bytes )
static

Definition at line 119 of file jpeg.cc.

References my_source_mgr::pub.

Referenced by memory_source().

◆ term_source()

static void term_source ( j_decompress_ptr cinfo)
static

Definition at line 133 of file jpeg.cc.

Referenced by memory_source().

◆ write_jpeg()

Variable Documentation

◆ ibuf_quality

uchar ibuf_quality
static

Definition at line 47 of file jpeg.cc.

Referenced by handle_app1(), and ibJpegImageFromCinfo().

◆ jpeg_default_quality

const uchar jpeg_default_quality = 75
static

Definition at line 46 of file jpeg.cc.

Referenced by ibJpegImageFromCinfo(), and init_jpeg().