53 const char magic[2] = {0xFF, 0xD8};
65 struct jpeg_error_mgr
pub;
77 (*cinfo->err->output_message)(cinfo);
83 longjmp(
err->setjmp_buffer, 1);
98 struct jpeg_source_mgr pub;
120 src->pub.next_input_byte =
src->terminal;
121 src->pub.bytes_in_buffer = 2;
122 src->terminal[0] = (JOCTET)0xFF;
123 src->terminal[1] = (JOCTET)JPEG_EOI;
134 size_t skip_size = (size_t)num_bytes <= src->pub.bytes_in_buffer ? num_bytes :
135 src->pub.bytes_in_buffer;
137 src->pub.next_input_byte =
src->pub.next_input_byte + skip_size;
138 src->pub.bytes_in_buffer =
src->pub.bytes_in_buffer - skip_size;
151 if (cinfo->src ==
NULL) {
152 cinfo->src = (
struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)(
153 (j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(
my_source_mgr));
160 src->pub.resync_to_restart = jpeg_resync_to_restart;
163 src->pub.bytes_in_buffer =
size;
170 #define MAKESTMT(stuff) \
175 #define INPUT_VARS(cinfo) \
176 struct jpeg_source_mgr *datasrc = (cinfo)->src; \
177 const JOCTET *next_input_byte = datasrc->next_input_byte; \
178 size_t bytes_in_buffer = datasrc->bytes_in_buffer
181 #define INPUT_SYNC(cinfo) \
182 (datasrc->next_input_byte = next_input_byte, datasrc->bytes_in_buffer = bytes_in_buffer)
185 #define INPUT_RELOAD(cinfo) \
186 (next_input_byte = datasrc->next_input_byte, bytes_in_buffer = datasrc->bytes_in_buffer)
192 #define MAKE_BYTE_AVAIL(cinfo, action) \
193 if (bytes_in_buffer == 0) { \
194 if (!(*datasrc->fill_input_buffer)(cinfo)) { \
197 INPUT_RELOAD(cinfo); \
204 #define INPUT_BYTE(cinfo, V, action) \
205 MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; V = GETJOCTET(*next_input_byte++);)
210 #define INPUT_2BYTES(cinfo, V, action) \
211 MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; \
212 V = ((unsigned int)GETJOCTET(*next_input_byte++)) << 8; \
213 MAKE_BYTE_AVAIL(cinfo, action); \
215 V += GETJOCTET(*next_input_byte++);)
237 for (i = 0; i <
length; i++) {
248 (*cinfo->src->skip_input_data)(cinfo,
length);
259 JSAMPARRAY row_pointer;
262 int x,
y, depth,
r,
g,
b, k;
265 jpeg_saved_marker_ptr marker;
266 char *
str, *key, *value;
270 jpeg_set_marker_processor(cinfo, 0xe1,
handle_app1);
271 cinfo->dct_method = JDCT_FLOAT;
272 jpeg_save_markers(cinfo, JPEG_COM, 0xffff);
274 if (jpeg_read_header(cinfo,
false) == JPEG_HEADER_OK) {
275 depth = cinfo->num_components;
277 if (cinfo->jpeg_color_space == JCS_YCCK) {
278 cinfo->out_color_space = JCS_CMYK;
282 *r_width = cinfo->image_width;
285 *r_height = cinfo->image_height;
291 float scale = (
float)max_size /
MAX2(cinfo->image_width, cinfo->image_height);
292 cinfo->scale_denom = 8;
293 cinfo->scale_num =
max_uu(1,
min_uu(8, ceill(scale * (
float)cinfo->scale_denom)));
294 cinfo->dct_method = JDCT_FASTEST;
295 cinfo->dither_mode = JDITHER_ORDERED;
298 jpeg_start_decompress(cinfo);
300 x = cinfo->output_width;
301 y = cinfo->output_height;
304 jpeg_abort_decompress(cinfo);
308 jpeg_abort_decompress(cinfo);
311 row_stride = cinfo->output_width * depth;
313 row_pointer = (*cinfo->mem->alloc_sarray)((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
315 for (
y = ibuf->
y - 1;
y >= 0;
y--) {
316 jpeg_read_scanlines(cinfo, row_pointer, 1);
322 for (
x = ibuf->
x;
x > 0;
x--) {
329 for (
x = ibuf->
x;
x > 0;
x--) {
338 for (
x = ibuf->
x;
x > 0;
x--) {
358 marker = cinfo->marker_list;
360 if (marker->marker != JPEG_COM) {
361 goto next_stamp_marker;
393 goto next_stamp_marker;
396 key = strchr(
str,
':');
404 goto next_stamp_marker;
408 value = strchr(key,
':');
411 goto next_stamp_marker;
421 marker = marker->next;
424 jpeg_finish_decompress(cinfo);
429 if (cinfo->density_unit == 1) {
431 ibuf->
ppm[0] = cinfo->X_density / 0.0254f;
432 ibuf->
ppm[1] = cinfo->Y_density / 0.0254f;
434 else if (cinfo->density_unit == 2) {
435 ibuf->
ppm[0] = cinfo->X_density * 100.0f;
436 ibuf->
ppm[1] = cinfo->Y_density * 100.0f;
442 jpeg_destroy((j_common_ptr)cinfo);
453 struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
463 cinfo->err = jpeg_std_error(&jerr.
pub);
471 jpeg_destroy_decompress(cinfo);
475 jpeg_create_decompress(cinfo);
484 #define JPEG_MARKER_MSB (0xFF)
485 #define JPEG_MARKER_SOI (0xD8)
486 #define JPEG_MARKER_APP1 (0xE1)
487 #define JPEG_APP1_MAX (1 << 16)
491 const size_t max_thumb_size,
496 struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
502 cinfo->err = jpeg_std_error(&jerr.
pub);
510 jpeg_destroy_decompress(cinfo);
515 fprintf(stderr,
"can't open %s\n", filepath);
527 !feof(infile) && i--) {
529 if (i > 0 && !feof(infile)) {
549 fseek(infile, 0, SEEK_SET);
550 jpeg_create_decompress(cinfo);
552 jpeg_stdio_src(cinfo, infile);
559 #undef JPEG_MARKER_MSB
560 #undef JPEG_MARKER_SOI
561 #undef JPEG_MARKER_APP1
567 JSAMPROW row_pointer[1];
573 jpeg_start_compress(cinfo,
true);
575 strcpy(neogeo,
"NeoGeo");
577 memset(neogeo_word, 0,
sizeof(*neogeo_word));
579 jpeg_write_marker(cinfo, 0xe1, (JOCTET *)neogeo, 10);
583 char static_text[1024];
584 const int static_text_size =
ARRAY_SIZE(static_text);
589 jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)
IDP_String(prop), prop->
len + 1);
592 char *text = static_text;
593 int text_size = static_text_size;
596 const int text_length_required = 7 + 2 + strlen(prop->
name) + strlen(
IDP_String(prop)) + 1;
597 if (text_length_required <= static_text_size) {
598 text =
MEM_mallocN(text_length_required,
"jpeg metadata field");
599 text_size = text_length_required;
613 jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)text, text_len + 1);
618 if (text != static_text) {
625 row_pointer[0] =
MEM_mallocN(
sizeof(JSAMPLE) * cinfo->input_components * cinfo->image_width,
628 for (
y = ibuf->
y - 1;
y >= 0;
y--) {
632 switch (cinfo->in_color_space) {
634 for (
x = 0;
x < ibuf->
x;
x++) {
642 for (
x = 0;
x < ibuf->
x;
x++) {
648 memcpy(
buffer, rect, 4 * ibuf->
x);
656 jpeg_write_scanlines(cinfo, row_pointer, 1);
659 jpeg_finish_compress(cinfo);
663 static int init_jpeg(FILE *outfile,
struct jpeg_compress_struct *cinfo,
struct ImBuf *ibuf)
675 jpeg_create_compress(cinfo);
676 jpeg_stdio_dest(cinfo, outfile);
678 cinfo->image_width = ibuf->
x;
679 cinfo->image_height = ibuf->
y;
681 cinfo->in_color_space = JCS_RGB;
683 cinfo->in_color_space = JCS_GRAYSCALE;
690 cinfo->in_color_space = JCS_UNKNOWN;
693 switch (cinfo->in_color_space) {
695 cinfo->input_components = 3;
698 cinfo->input_components = 1;
701 cinfo->input_components = 4;
708 jpeg_set_defaults(cinfo);
712 cinfo->dct_method = JDCT_FLOAT;
713 jpeg_set_quality(cinfo,
quality,
true);
721 struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
728 cinfo->err = jpeg_std_error(&jerr.
pub);
736 jpeg_destroy_compress(cinfo);
747 jpeg_destroy_compress(cinfo);
typedef float(TangentPoint)[2]
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE uint min_uu(uint a, uint b)
MINLINE uint max_uu(uint a, uint b)
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ID and Library types, which are fundamental for sdna.
_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 GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_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
@ COLOR_ROLE_DEFAULT_BYTE
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void colorspace_set_default_role(char *colorspace, int size, int role)
SyclQueue void void * src
SyclQueue void void size_t num_bytes void
#define INPUT_BYTE(cinfo, V, action)
static const uchar jpeg_default_quality
static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int flags, int max_size, size_t *r_width, size_t *r_height)
static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags)
static bool save_stdjpeg(const char *name, struct ImBuf *ibuf)
my_source_mgr * my_src_ptr
#define INPUT_2BYTES(cinfo, V, action)
#define INPUT_VARS(cinfo)
struct my_error_mgr my_error_mgr
my_error_mgr * my_error_ptr
static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
BLI_STATIC_ASSERT(sizeof(struct NeoGeo_Word)==4, "Must be 4 bytes")
static void term_source(j_decompress_ptr cinfo)
static uchar ibuf_quality
static boolean handle_app1(j_decompress_ptr cinfo)
#define INPUT_SYNC(cinfo)
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
static void init_source(j_decompress_ptr cinfo)
static void jpeg_error(j_common_ptr cinfo) ATTR_NORETURN
static boolean fill_input_buffer(j_decompress_ptr cinfo)
struct 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)
bool imb_is_a_jpeg(const unsigned char *mem, const size_t size)
static void memory_source(j_decompress_ptr cinfo, const unsigned char *buffer, size_t size)
ImBuf * imb_load_jpeg(const unsigned char *buffer, size_t size, int flags, char colorspace[IM_MAX_SPACE])
ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
bool remove(void *owner, const AttributeIDRef &attribute_id)
T length(const vec_base< T, Size > &a)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
struct IDProperty * metadata
ImbFormatOptions foptions
struct jpeg_error_mgr pub
const unsigned char * buffer
static int magic(const Tex *tex, const float texvec[3], TexResult *texres)