49 jpeg_decompress_struct *cinfo,
int flags,
int max_size,
size_t *r_width,
size_t *r_height);
56 const char magic[2] = {0xFF, 0xD8};
80 (*cinfo->err->output_message)(cinfo);
117 src->
pub.bytes_in_buffer = 2;
119 src->
terminal[1] = (JOCTET)JPEG_EOI;
130 size_t skip_size = size_t(num_bytes) <= src->
pub.bytes_in_buffer ? num_bytes :
131 src->
pub.bytes_in_buffer;
133 src->
pub.next_input_byte = src->
pub.next_input_byte + skip_size;
134 src->
pub.bytes_in_buffer = src->
pub.bytes_in_buffer - skip_size;
147 if (cinfo->src ==
nullptr) {
148 cinfo->src = (jpeg_source_mgr *)(*cinfo->mem->alloc_small)(
149 (j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(
my_source_mgr));
156 src->
pub.resync_to_restart = jpeg_resync_to_restart;
159 src->
pub.bytes_in_buffer =
size;
160 src->
pub.next_input_byte = buffer;
166#define MAKESTMT(stuff) \
171#define INPUT_VARS(cinfo) \
172 jpeg_source_mgr *datasrc = (cinfo)->src; \
173 const JOCTET *next_input_byte = datasrc->next_input_byte; \
174 size_t bytes_in_buffer = datasrc->bytes_in_buffer
177#define INPUT_SYNC(cinfo) \
178 (datasrc->next_input_byte = next_input_byte, datasrc->bytes_in_buffer = bytes_in_buffer)
181#define INPUT_RELOAD(cinfo) \
182 (next_input_byte = datasrc->next_input_byte, bytes_in_buffer = datasrc->bytes_in_buffer)
188#define MAKE_BYTE_AVAIL(cinfo, action) \
189 if (bytes_in_buffer == 0) { \
190 if (!(*datasrc->fill_input_buffer)(cinfo)) { \
193 INPUT_RELOAD(cinfo); \
200#define INPUT_BYTE(cinfo, V, action) \
201 MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; V = GETJOCTET(*next_input_byte++);)
206#define INPUT_2BYTES(cinfo, V, action) \
207 MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; \
208 V = uint(GETJOCTET(*next_input_byte++)) << 8; \
209 MAKE_BYTE_AVAIL(cinfo, action); \
211 V += GETJOCTET(*next_input_byte++);)
244 (*cinfo->src->skip_input_data)(cinfo,
length);
250 jpeg_decompress_struct *cinfo,
int flags,
int max_size,
size_t *r_width,
size_t *r_height)
252 JSAMPARRAY row_pointer;
253 JSAMPLE *buffer =
nullptr;
255 int x,
y, depth, r, g,
b, k;
256 ImBuf *ibuf =
nullptr;
258 jpeg_saved_marker_ptr marker;
259 char *
str, *key, *value;
263 jpeg_set_marker_processor(cinfo, 0xe1,
handle_app1);
264 cinfo->dct_method = JDCT_FLOAT;
265 jpeg_save_markers(cinfo, JPEG_COM, 0xffff);
267 if (jpeg_read_header(cinfo,
false) == JPEG_HEADER_OK) {
268 depth = cinfo->num_components;
270 if (cinfo->jpeg_color_space == JCS_YCCK) {
271 cinfo->out_color_space = JCS_CMYK;
275 *r_width = cinfo->image_width;
278 *r_height = cinfo->image_height;
284 float scale =
float(max_size) / std::max(cinfo->image_width, cinfo->image_height);
285 cinfo->scale_denom = 8;
286 cinfo->scale_num =
max_uu(1,
min_uu(8, ceill(scale *
float(cinfo->scale_denom))));
287 cinfo->dct_method = JDCT_FASTEST;
288 cinfo->dither_mode = JDITHER_ORDERED;
291 jpeg_start_decompress(cinfo);
293 x = cinfo->output_width;
294 y = cinfo->output_height;
297 jpeg_abort_decompress(cinfo);
303 jpeg_abort_decompress(cinfo);
306 row_stride = cinfo->output_width * depth;
308 row_pointer = (*cinfo->mem->alloc_sarray)((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
310 for (
y = ibuf->
y - 1;
y >= 0;
y--) {
311 jpeg_read_scanlines(cinfo, row_pointer, 1);
313 buffer = row_pointer[0];
317 for (
x = ibuf->
x;
x > 0;
x--) {
319 rect[0] = rect[1] = rect[2] = *buffer++;
324 for (
x = ibuf->
x;
x > 0;
x--) {
333 for (
x = ibuf->
x;
x > 0;
x--) {
353 marker = cinfo->marker_list;
355 if (marker->marker != JPEG_COM) {
356 goto next_stamp_marker;
366 BLI_strnlen((
const char *)marker->data, marker->data_length));
391 goto next_stamp_marker;
394 key = strchr(
str,
':');
402 goto next_stamp_marker;
406 value = strchr(key,
':');
409 goto next_stamp_marker;
419 marker = marker->next;
422 jpeg_finish_decompress(cinfo);
427 if (cinfo->density_unit == 1) {
429 ibuf->
ppm[0] = double(cinfo->X_density) / 0.0254;
430 ibuf->
ppm[1] = double(cinfo->Y_density) / 0.0254;
432 else if (cinfo->density_unit == 2) {
433 ibuf->
ppm[0] = double(cinfo->X_density) * 100.0;
434 ibuf->
ppm[1] = double(cinfo->Y_density) * 100.0;
440 jpeg_destroy((j_common_ptr)cinfo);
451 jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
459 cinfo->err = jpeg_std_error(&jerr.
pub);
467 jpeg_destroy_decompress(cinfo);
471 jpeg_create_decompress(cinfo);
480#define JPEG_MARKER_MSB (0xFF)
481#define JPEG_MARKER_SOI (0xD8)
482#define JPEG_MARKER_APP1 (0xE1)
483#define JPEG_APP1_MAX (1 << 16)
487 const size_t max_thumb_size,
492 jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
494 FILE *infile =
nullptr;
496 cinfo->err = jpeg_std_error(&jerr.
pub);
504 jpeg_destroy_decompress(cinfo);
508 if ((infile =
BLI_fopen(filepath,
"rb")) ==
nullptr) {
522 !feof(infile) &&
i--)
525 if (
i > 0 && !feof(infile)) {
527 ImBuf *ibuf =
nullptr;
545 fseek(infile, 0, SEEK_SET);
546 jpeg_create_decompress(cinfo);
548 jpeg_stdio_src(cinfo, infile);
555#undef JPEG_MARKER_MSB
556#undef JPEG_MARKER_SOI
557#undef JPEG_MARKER_APP1
562 JSAMPLE *buffer =
nullptr;
563 JSAMPROW row_pointer[1];
569 jpeg_start_compress(cinfo,
true);
573 memset(neogeo_word, 0,
sizeof(*neogeo_word));
575 jpeg_write_marker(cinfo, 0xe1, (JOCTET *)neogeo, 10);
579 char static_text[1024];
580 const size_t static_text_size =
ARRAY_SIZE(static_text);
584 if (
STREQ(prop->name,
"None")) {
585 jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)
IDP_string_get(prop), prop->len);
588 char *text = static_text;
589 size_t text_size = static_text_size;
593 const size_t text_length_required = 7 + 2 + strlen(prop->name) +
595 if (text_length_required > static_text_size) {
597 text_size = text_length_required;
610 text, text_size,
"Blender:%s:%s", prop->name,
IDP_string_get(prop));
612 jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)text,
uint(text_len));
617 if (text != static_text) {
629 icc_profile.
prepend({
'I',
'C',
'C',
'_',
'P',
'R',
'O',
'F',
'I',
'L',
'E', 0, 0, 1});
630 jpeg_write_marker(cinfo,
632 reinterpret_cast<const JOCTET *
>(icc_profile.
data()),
638 size_t(cinfo->input_components) * size_t(cinfo->image_width),
"jpeg row_pointer");
640 for (
y = ibuf->
y - 1;
y >= 0;
y--) {
642 buffer = row_pointer[0];
644 switch (cinfo->in_color_space) {
646 for (
x = 0;
x < ibuf->
x;
x++) {
654 for (
x = 0;
x < ibuf->
x;
x++) {
660 memcpy(buffer, rect, 4 * ibuf->
x);
668 jpeg_write_scanlines(cinfo, row_pointer, 1);
671 jpeg_finish_compress(cinfo);
683 quality = std::min(quality, 100);
685 jpeg_create_compress(cinfo);
686 jpeg_stdio_dest(cinfo, outfile);
688 cinfo->image_width = ibuf->
x;
689 cinfo->image_height = ibuf->
y;
691 cinfo->in_color_space = JCS_RGB;
693 cinfo->in_color_space = JCS_GRAYSCALE;
700 cinfo->in_color_space = JCS_UNKNOWN;
703 switch (cinfo->in_color_space) {
705 cinfo->input_components = 3;
708 cinfo->input_components = 1;
711 cinfo->input_components = 4;
718 jpeg_set_defaults(cinfo);
722 cinfo->dct_method = JDCT_FLOAT;
723 jpeg_set_quality(cinfo, quality,
true);
731 jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
734 if ((outfile =
BLI_fopen(filepath,
"wb")) ==
nullptr) {
738 cinfo->err = jpeg_std_error(&jerr.
pub);
746 jpeg_destroy_compress(cinfo);
757 jpeg_destroy_compress(cinfo);
#define IDP_string_get(prop)
blender::ocio::ColorSpace ColorSpace
#define BLI_STATIC_ASSERT(a, msg)
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define LISTBASE_FOREACH(type, var, list)
MINLINE uint min_uu(uint a, uint b)
MINLINE uint max_uu(uint a, uint b)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_snprintf_utf8_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define STRNCPY_UTF8(dst, src)
#define CLOG_ERROR(clg_ref,...)
ID and Library types, which are fundamental for SDNA.
blender::Vector< char > IMB_colormanagement_space_to_icc_profile(const ColorSpace *colorspace)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
@ IB_uninitialized_pixels
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void prepend(const T &value)
float length(VecOp< float, D >) RET
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
const ColorSpace * colorspace
ImbFormatOptions foptions
ImBufByteBuffer byte_buffer
static int magic(const Tex *tex, const float texvec[3], TexResult *texres)