43 DILLO_JPEG_READ_BEGIN_SCAN,
44 DILLO_JPEG_READ_IN_SCAN,
45 DILLO_JPEG_READ_END_SCAN,
50typedef struct DilloJpeg DilloJpeg;
55 struct jpeg_source_mgr pub;
60 struct jpeg_error_mgr pub;
61 jmp_buf setjmp_buffer;
63typedef struct my_error_mgr *my_error_ptr;
73 size_t Start_Ofs, Skip, NewStart;
78 struct jpeg_decompress_struct cinfo;
79 struct my_error_mgr jerr;
85static void Jpeg_write(DilloJpeg *jpeg,
void *Buf,
uint_t BufSize);
89METHODDEF(
void) Jpeg_errorexit (j_common_ptr cinfo)
92 my_error_ptr myerr = (my_error_ptr) cinfo->err;
95 ((my_source_mgr *) ((j_decompress_ptr) cinfo)->src)->jpeg;
97 (*cinfo->err->output_message) (cinfo);
99 longjmp(myerr->setjmp_buffer, 1);
105static void Jpeg_free(DilloJpeg *jpeg)
107 _MSG(
"Jpeg_free: jpeg=%p\n", jpeg);
108 jpeg_destroy_decompress(&(jpeg->cinfo));
115static void Jpeg_close(DilloJpeg *jpeg,
CacheClient_t *Client)
117 _MSG(
"Jpeg_close\n");
122static void init_source(
struct jpeg_decompress_struct *p)
127static boolean fill_input_buffer(j_decompress_ptr cinfo)
129 DilloJpeg *jpeg = ((my_source_mgr *) cinfo->src)->jpeg;
131 _MSG(
"fill_input_buffer\n");
133 if (!cinfo->src->bytes_in_buffer) {
134 _MSG(
"fill_input_buffer: %ld bytes in buffer\n",
135 (
long)cinfo->src->bytes_in_buffer);
137 jpeg->Start_Ofs = (
ulong_t) jpeg->cinfo.src->next_input_byte -
141 jpeg->Start_Ofs = jpeg->NewStart + jpeg->Skip - 1;
144 jpeg->Start_Ofs = (
ulong_t) jpeg->cinfo.src->next_input_byte -
154static void skip_input_data(j_decompress_ptr cinfo,
long num_bytes)
160 jpeg = ((my_source_mgr *) cinfo->src)->jpeg;
162 _MSG(
"skip_input_data: Start_Ofs = %lu, num_bytes = %ld,"
163 " %ld bytes in buffer\n",
164 (
ulong_t)jpeg->Start_Ofs, num_bytes,(
long)cinfo->src->bytes_in_buffer);
166 cinfo->src->next_input_byte += num_bytes;
167 if (num_bytes < (
long)cinfo->src->bytes_in_buffer) {
168 cinfo->src->bytes_in_buffer -= num_bytes;
170 jpeg->Skip += num_bytes - cinfo->src->bytes_in_buffer + 1;
171 cinfo->src->bytes_in_buffer = 0;
180static void term_source(
struct jpeg_decompress_struct *p)
188 DilloJpeg *jpeg =
dMalloc(
sizeof(*jpeg));
189 _MSG(
"a_Jpeg_new: jpeg=%p\n", jpeg);
193 jpeg->version = version;
195 jpeg->state = DILLO_JPEG_INIT;
200 jpeg->cinfo.err = jpeg_std_error(&(jpeg->jerr.pub));
201 jpeg->jerr.pub.error_exit = Jpeg_errorexit;
203 jpeg_create_decompress(&(jpeg->cinfo));
206 jpeg->cinfo.src = &jpeg->Src.pub;
208 src->pub.init_source = init_source;
209 src->pub.fill_input_buffer = fill_input_buffer;
210 src->pub.skip_input_data = skip_input_data;
211 src->pub.resync_to_restart = jpeg_resync_to_restart;
212 src->pub.term_source = term_source;
213 src->pub.bytes_in_buffer = 0;
214 src->pub.next_input_byte = NULL;
229 Jpeg_close(Client->
CbData, Client);
238static void Jpeg_write(DilloJpeg *jpeg,
void *Buf,
uint_t BufSize)
245 _MSG(
"Jpeg_write: (%p) Bytes in buff: %ld Ofs: %lu\n", jpeg,
246 (
long) BufSize, (
ulong_t)jpeg->Start_Ofs);
249 if (BufSize <= jpeg->Start_Ofs)
253 jpeg->cinfo.src->next_input_byte = (
uchar_t *)Buf + jpeg->Start_Ofs;
254 jpeg->cinfo.src->bytes_in_buffer = BufSize - jpeg->Start_Ofs;
255 jpeg->NewStart = BufSize;
258 if (setjmp(jpeg->jerr.setjmp_buffer)) {
260 jpeg->state = DILLO_JPEG_ERROR;
264 if (jpeg->state == DILLO_JPEG_INIT) {
267 if (jpeg_read_header(&(jpeg->cinfo),
TRUE) != JPEG_SUSPENDED) {
269 if (jpeg->cinfo.num_components == 1) {
271 }
else if (jpeg->cinfo.num_components == 3) {
274 if (jpeg->cinfo.jpeg_color_space == JCS_YCCK)
275 MSG(
"YCCK JPEG. Are the colors wrong?\n");
276 if (!jpeg->cinfo.saw_Adobe_marker)
277 MSG(
"No adobe marker! Is the image shown in reverse video?\n");
284 if (jpeg_has_multiple_scans(&jpeg->cinfo) &&
286 jpeg->cinfo.buffered_image =
TRUE;
289 if (jpeg->cinfo.image_width <= 0 || jpeg->cinfo.image_height <= 0 ||
290 jpeg->cinfo.image_width >
292 MSG(
"Jpeg_write: suspicious image size request %u x %u\n",
293 (
uint_t)jpeg->cinfo.image_width,
294 (
uint_t)jpeg->cinfo.image_height);
295 jpeg->state = DILLO_JPEG_ERROR;
301 (
uint_t)jpeg->cinfo.image_width,
302 (
uint_t)jpeg->cinfo.image_height,
307 jpeg->state = DILLO_JPEG_STARTING;
310 if (jpeg->state == DILLO_JPEG_STARTING) {
312 if (jpeg_start_decompress(&(jpeg->cinfo))) {
314 jpeg->state = jpeg->cinfo.buffered_image ?
315 DILLO_JPEG_READ_BEGIN_SCAN : DILLO_JPEG_READ_IN_SCAN;
325 if (jpeg->state == DILLO_JPEG_READ_END_SCAN) {
326 if (jpeg_finish_output(&jpeg->cinfo)) {
327 if (jpeg_input_complete(&jpeg->cinfo)) {
328 jpeg->state = DILLO_JPEG_DONE;
330 jpeg->state = DILLO_JPEG_READ_BEGIN_SCAN;
335 if (jpeg->state == DILLO_JPEG_READ_BEGIN_SCAN) {
336 if (jpeg_start_output(&jpeg->cinfo, jpeg->cinfo.input_scan_number)) {
338 jpeg->state = DILLO_JPEG_READ_IN_SCAN;
342 if (jpeg->state == DILLO_JPEG_READ_IN_SCAN) {
344 jpeg->cinfo.num_components);
348 num_read = jpeg_read_scanlines(&(jpeg->cinfo), array, 1);
357 if (jpeg->y == jpeg->cinfo.image_height) {
359 if (!jpeg->cinfo.buffered_image) {
361 jpeg->state = DILLO_JPEG_DONE;
365 if (jpeg_input_complete(&jpeg->cinfo)) {
366 if (jpeg->cinfo.input_scan_number ==
367 jpeg->cinfo.output_scan_number) {
368 jpeg->state = DILLO_JPEG_DONE;
372 jpeg_finish_output(&jpeg->cinfo);
373 jpeg_start_output(&jpeg->cinfo,
374 jpeg->cinfo.input_scan_number);
378 jpeg->state = DILLO_JPEG_READ_END_SCAN;
379 if (!jpeg_finish_output(&jpeg->cinfo)) {
383 if (jpeg_input_complete(&jpeg->cinfo)) {
384 jpeg->state = DILLO_JPEG_DONE;
387 jpeg->state = DILLO_JPEG_READ_BEGIN_SCAN;
390 if (!jpeg_start_output(&jpeg->cinfo,
391 jpeg->cinfo.input_scan_number)) {
396 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)
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.