44 DILLO_JPEG_READ_BEGIN_SCAN,
45 DILLO_JPEG_READ_IN_SCAN,
46 DILLO_JPEG_READ_END_SCAN,
51typedef struct DilloJpeg DilloJpeg;
56 struct jpeg_source_mgr pub;
61 struct jpeg_error_mgr pub;
62 jmp_buf setjmp_buffer;
64typedef struct my_error_mgr *my_error_ptr;
74 size_t Start_Ofs, Skip, NewStart;
79 struct jpeg_decompress_struct cinfo;
80 struct my_error_mgr jerr;
86static void Jpeg_write(DilloJpeg *jpeg,
void *Buf,
uint_t BufSize);
90METHODDEF(
void) Jpeg_errorexit (j_common_ptr cinfo)
93 my_error_ptr myerr = (my_error_ptr) cinfo->err;
96 ((my_source_mgr *) ((j_decompress_ptr) cinfo)->src)->jpeg;
98 (*cinfo->err->output_message) (cinfo);
100 longjmp(myerr->setjmp_buffer, 1);
106static void Jpeg_free(DilloJpeg *jpeg)
108 _MSG(
"Jpeg_free: jpeg=%p\n", jpeg);
109 jpeg_destroy_decompress(&(jpeg->cinfo));
116static void Jpeg_close(DilloJpeg *jpeg,
CacheClient_t *Client)
118 _MSG(
"Jpeg_close\n");
123static void init_source(
struct jpeg_decompress_struct *p)
128static boolean fill_input_buffer(j_decompress_ptr cinfo)
130 DilloJpeg *jpeg = ((my_source_mgr *) cinfo->src)->jpeg;
132 _MSG(
"fill_input_buffer\n");
134 if (!cinfo->src->bytes_in_buffer) {
135 _MSG(
"fill_input_buffer: %ld bytes in buffer\n",
136 (
long)cinfo->src->bytes_in_buffer);
138 jpeg->Start_Ofs = (
ulong_t) jpeg->cinfo.src->next_input_byte -
142 jpeg->Start_Ofs = jpeg->NewStart + jpeg->Skip - 1;
145 jpeg->Start_Ofs = (
ulong_t) jpeg->cinfo.src->next_input_byte -
155static void skip_input_data(j_decompress_ptr cinfo,
long num_bytes)
161 jpeg = ((my_source_mgr *) cinfo->src)->jpeg;
163 _MSG(
"skip_input_data: Start_Ofs = %lu, num_bytes = %ld,"
164 " %ld bytes in buffer\n",
165 (
ulong_t)jpeg->Start_Ofs, num_bytes,(
long)cinfo->src->bytes_in_buffer);
167 cinfo->src->next_input_byte += num_bytes;
168 if (num_bytes < (
long)cinfo->src->bytes_in_buffer) {
169 cinfo->src->bytes_in_buffer -= num_bytes;
171 jpeg->Skip += num_bytes - cinfo->src->bytes_in_buffer + 1;
172 cinfo->src->bytes_in_buffer = 0;
181static void term_source(
struct jpeg_decompress_struct *p)
189 DilloJpeg *jpeg =
dMalloc(
sizeof(*jpeg));
190 _MSG(
"a_Jpeg_new: jpeg=%p\n", jpeg);
194 jpeg->version = version;
196 jpeg->state = DILLO_JPEG_INIT;
201 jpeg->cinfo.err = jpeg_std_error(&(jpeg->jerr.pub));
202 jpeg->jerr.pub.error_exit = Jpeg_errorexit;
204 jpeg_create_decompress(&(jpeg->cinfo));
207 jpeg->cinfo.src = &jpeg->Src.pub;
209 src->pub.init_source = init_source;
210 src->pub.fill_input_buffer = fill_input_buffer;
211 src->pub.skip_input_data = skip_input_data;
212 src->pub.resync_to_restart = jpeg_resync_to_restart;
213 src->pub.term_source = term_source;
214 src->pub.bytes_in_buffer = 0;
215 src->pub.next_input_byte = NULL;
230 Jpeg_close(Client->
CbData, Client);
239#define STR(x) QUOTE(x)
241#if defined(LIBJPEG_TURBO_VERSION)
242 return STR(LIBJPEG_TURBO_VERSION);
244 return STR(JPEG_LIB_VERSION);
254static void Jpeg_write(DilloJpeg *jpeg,
void *Buf,
uint_t BufSize)
261 _MSG(
"Jpeg_write: (%p) Bytes in buff: %ld Ofs: %lu\n", jpeg,
262 (
long) BufSize, (
ulong_t)jpeg->Start_Ofs);
265 if (BufSize <= jpeg->Start_Ofs)
269 jpeg->cinfo.src->next_input_byte = (
uchar_t *)Buf + jpeg->Start_Ofs;
270 jpeg->cinfo.src->bytes_in_buffer = BufSize - jpeg->Start_Ofs;
271 jpeg->NewStart = BufSize;
274 if (setjmp(jpeg->jerr.setjmp_buffer)) {
276 jpeg->state = DILLO_JPEG_ERROR;
280 if (jpeg->state == DILLO_JPEG_INIT) {
283 if (jpeg_read_header(&(jpeg->cinfo),
TRUE) != JPEG_SUSPENDED) {
285 if (jpeg->cinfo.num_components == 1) {
287 }
else if (jpeg->cinfo.num_components == 3) {
290 if (jpeg->cinfo.jpeg_color_space == JCS_YCCK)
291 MSG(
"YCCK JPEG. Are the colors wrong?\n");
292 if (!jpeg->cinfo.saw_Adobe_marker)
293 MSG(
"No adobe marker! Is the image shown in reverse video?\n");
300 if (jpeg_has_multiple_scans(&jpeg->cinfo) &&
302 jpeg->cinfo.buffered_image =
TRUE;
305 if (jpeg->cinfo.image_width <= 0 || jpeg->cinfo.image_height <= 0 ||
306 jpeg->cinfo.image_width >
308 MSG(
"Jpeg_write: suspicious image size request %u x %u\n",
309 (
uint_t)jpeg->cinfo.image_width,
310 (
uint_t)jpeg->cinfo.image_height);
311 jpeg->state = DILLO_JPEG_ERROR;
317 (
uint_t)jpeg->cinfo.image_width,
318 (
uint_t)jpeg->cinfo.image_height,
323 jpeg->state = DILLO_JPEG_STARTING;
326 if (jpeg->state == DILLO_JPEG_STARTING) {
328 if (jpeg_start_decompress(&(jpeg->cinfo))) {
330 jpeg->state = jpeg->cinfo.buffered_image ?
331 DILLO_JPEG_READ_BEGIN_SCAN : DILLO_JPEG_READ_IN_SCAN;
341 if (jpeg->state == DILLO_JPEG_READ_END_SCAN) {
342 if (jpeg_finish_output(&jpeg->cinfo)) {
343 if (jpeg_input_complete(&jpeg->cinfo)) {
344 jpeg->state = DILLO_JPEG_DONE;
346 jpeg->state = DILLO_JPEG_READ_BEGIN_SCAN;
351 if (jpeg->state == DILLO_JPEG_READ_BEGIN_SCAN) {
352 if (jpeg_start_output(&jpeg->cinfo, jpeg->cinfo.input_scan_number)) {
354 jpeg->state = DILLO_JPEG_READ_IN_SCAN;
358 if (jpeg->state == DILLO_JPEG_READ_IN_SCAN) {
360 jpeg->cinfo.num_components);
364 num_read = jpeg_read_scanlines(&(jpeg->cinfo), array, 1);
373 if (jpeg->y == jpeg->cinfo.image_height) {
375 if (!jpeg->cinfo.buffered_image) {
377 jpeg->state = DILLO_JPEG_DONE;
381 if (jpeg_input_complete(&jpeg->cinfo)) {
382 if (jpeg->cinfo.input_scan_number ==
383 jpeg->cinfo.output_scan_number) {
384 jpeg->state = DILLO_JPEG_DONE;
388 jpeg_finish_output(&jpeg->cinfo);
389 jpeg_start_output(&jpeg->cinfo,
390 jpeg->cinfo.input_scan_number);
394 jpeg->state = DILLO_JPEG_READ_END_SCAN;
395 if (!jpeg_finish_output(&jpeg->cinfo)) {
399 if (jpeg_input_complete(&jpeg->cinfo)) {
400 jpeg->state = DILLO_JPEG_DONE;
403 jpeg->state = DILLO_JPEG_READ_BEGIN_SCAN;
406 if (!jpeg_start_output(&jpeg->cinfo,
407 jpeg->cinfo.input_scan_number)) {
412 jpeg->state = DILLO_JPEG_READ_IN_SCAN;
int a_Capi_get_flags(const DilloUrl *Url)
Return status information of an URL's content-transfer process.
void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image, uint_t width, uint_t height, DilloImgType type, double gamma)
Set image's width, height & type.
void a_Dicache_new_scan(const DilloUrl *url, int version)
Reset for a new scan from a multiple-scan image.
void a_Dicache_close(DilloUrl *url, int version, CacheClient_t *Client)
Implement the close method of the decoding process.
void a_Dicache_write(DilloUrl *url, int version, const uchar_t *buf, uint_t Y)
Implement the write method (Write a scan line into the Dicache entry) buf: row buffer Y : row number.
void * dMalloc(size_t size)
const char * a_Jpeg_version(void)
DilloPrefs prefs
Global Data.
@ DILLO_IMG_TYPE_CMYK_INV
Data structure for cache clients.
void * CbData
Client function data.
uint_t BufSize
Valid size of cache-data.
void * Buf
Pointer to cache-data.