20 #define INT32 long // jpeg's definition
25 #pragma warning (push)
26 #pragma warning (disable : 4091)
47 struct jpeg_error_mgr pub;
64 auto* mybuffer = (JOCTET *) cinfo->client_data;
67 mybuffer[0] = (JOCTET) 0xFF;
68 mybuffer[1] = (JOCTET) JPEG_EOI;
69 cinfo->src->next_input_byte = mybuffer;
70 cinfo->src->bytes_in_buffer = 2;
76 (*cinfo->err->output_message) (cinfo);
77 longjmp(myerr->setjmp_buffer, 1);
85 while (num_bytes > (
long) src->bytes_in_buffer) {
86 num_bytes -= (long) src->bytes_in_buffer;
87 (
void) (*src->fill_input_buffer) (cinfo);
89 src->next_input_byte += (size_t) num_bytes;
90 src->bytes_in_buffer -= (size_t) num_bytes;
97 void jpeg_net_src (j_decompress_ptr cinfo,
char *buf,
int buflen) {
99 if (cinfo->src ==
nullptr) {
100 cinfo->src = (
struct jpeg_source_mgr *)
101 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
102 sizeof(jpeg_source_mgr));
109 src->resync_to_restart = jpeg_resync_to_restart;
111 src->bytes_in_buffer = buflen;
112 src->next_input_byte = (JOCTET *)buf;
119 struct jpeg_decompress_struct cinfo;
121 JOCTET error_buffer[4];
123 void* readEnvelopeCallbackData{
nullptr};
127 memset(&cinfo, 0,
sizeof(jpeg_decompress_struct));
134 readEnvelopeCallback = callback;
135 readEnvelopeCallbackData = data;
140 jpeg_create_decompress(&cinfo);
147 cinfo.client_data = &error_buffer;
148 cinfo.err = jpeg_std_error(&jerr.pub);
151 if (setjmp(jerr.setjmp_buffer)) {
152 jpeg_finish_decompress(&cinfo);
157 jpeg_save_markers(&cinfo, JPEG_COM, 0xFFFF);
158 jpeg_read_header(&cinfo, TRUE);
159 jpeg_calc_output_dimensions(&cinfo);
161 if(cinfo.jpeg_color_space == JCS_GRAYSCALE) {
170 img.
resize(cinfo.output_width,cinfo.output_height);
171 jpeg_start_decompress(&cinfo);
175 while (cinfo.output_scanline < cinfo.output_height) {
178 jpeg_read_scanlines(&cinfo, lines, 1);
181 if(readEnvelopeCallback && cinfo.marker_list && cinfo.marker_list->data_length > 0) {
182 Bytes envelope(
reinterpret_cast<char*
>(cinfo.marker_list->data), cinfo.marker_list->data_length);
183 readEnvelopeCallback(readEnvelopeCallbackData, envelope);
186 jpeg_finish_decompress(&cinfo);
191 jpeg_destroy_decompress(&cinfo);
202 #define HELPER(x) (*((MjpegDecompressionHelper*)(x)))
210 if (system_resource!=
nullptr) {
211 delete &
HELPER(system_resource);
212 system_resource =
nullptr;
232 #ifdef MJPEG_AUTOCOMPRESS