annotate src/jpeg.c @ 2104:3e7e5395f0bc

non-ASCII keybindings Alexander Voigt has kindly done some testing, and it seems that this makes bindings to most keys on a German keyboard possible -- except those that need AltGr don't work yet.
author corvid <corvid@lavabit.com>
date Thu, 23 Jun 2011 19:24:11 +0000
parents 7c7ff4d0202b
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: jpeg.c
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 0
diff changeset
4 * Copyright (C) 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 * The jpeg decoder for dillo. It is responsible for decoding JPEG data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 * and transferring it to the dicache. It uses libjpeg to do the actual
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 * decoding.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include <config.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 #ifdef ENABLE_JPEG
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include <stdio.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include <setjmp.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 /* avoid a redefinition of HAVE_STDLIB_H with old jpeglib.h */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #ifdef HAVE_STDLIB_H
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 # undef HAVE_STDLIB_H
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #endif
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #include <jpeglib.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 #ifdef HAVE_STDLIB_H
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 # undef HAVE_STDLIB_H
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 #endif
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 #include "image.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 #include "cache.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 #include "dicache.h"
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 152
diff changeset
36 #include "capi.h" /* get cache entry status */
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
37 #include "msg.h"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 typedef enum {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 DILLO_JPEG_INIT,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 DILLO_JPEG_STARTING,
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
42 DILLO_JPEG_READ_BEGIN_SCAN,
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
43 DILLO_JPEG_READ_IN_SCAN,
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
44 DILLO_JPEG_READ_END_SCAN,
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 DILLO_JPEG_DONE,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 DILLO_JPEG_ERROR
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 } DilloJpegState;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 /* An implementation of a suspending source manager */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 typedef struct {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 struct jpeg_source_mgr pub; /* public fields */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 struct DilloJpeg *jpeg; /* a pointer back to the jpeg object */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 } my_source_mgr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 struct my_error_mgr {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 struct jpeg_error_mgr pub; /* "public" fields */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 jmp_buf setjmp_buffer; /* for return to caller */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 typedef struct my_error_mgr * my_error_ptr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 typedef struct DilloJpeg {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 DilloImage *Image;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 int version;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 my_source_mgr Src;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 DilloJpegState state;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 size_t Start_Ofs, Skip, NewStart;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 char *Data;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 uint_t y;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 struct jpeg_decompress_struct cinfo;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 struct my_error_mgr jerr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 } DilloJpeg;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 * Forward declarations
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 static void Jpeg_write(DilloJpeg *jpeg, void *Buf, uint_t BufSize);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 METHODDEF(void) Jpeg_errorexit (j_common_ptr cinfo);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 /* this is the routine called by libjpeg when it detects an error. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 METHODDEF(void) Jpeg_errorexit (j_common_ptr cinfo)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 /* display message and return to setjmp buffer */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 my_error_ptr myerr = (my_error_ptr) cinfo->err;
1312
f5a186303478 only show JPEG errors if prefs.show_msg set
corvid <corvid@lavabit.com>
parents: 1310
diff changeset
91 if (prefs.show_msg) {
f5a186303478 only show JPEG errors if prefs.show_msg set
corvid <corvid@lavabit.com>
parents: 1310
diff changeset
92 DilloJpeg *jpeg =
f5a186303478 only show JPEG errors if prefs.show_msg set
corvid <corvid@lavabit.com>
parents: 1310
diff changeset
93 ((my_source_mgr *) ((j_decompress_ptr) cinfo)->src)->jpeg;
f5a186303478 only show JPEG errors if prefs.show_msg set
corvid <corvid@lavabit.com>
parents: 1310
diff changeset
94 MSG_WARN("\"%s\": ", URL_STR(jpeg->url));
f5a186303478 only show JPEG errors if prefs.show_msg set
corvid <corvid@lavabit.com>
parents: 1310
diff changeset
95 (*cinfo->err->output_message) (cinfo);
f5a186303478 only show JPEG errors if prefs.show_msg set
corvid <corvid@lavabit.com>
parents: 1310
diff changeset
96 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 longjmp(myerr->setjmp_buffer, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 /*
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
101 * Free the jpeg-decoding data structure.
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
102 */
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
103 static void Jpeg_free(DilloJpeg *jpeg)
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
104 {
1094
7401c51915da Silence the last image-debugging messages
Jorge Arellano Cid <jcid@dillo.org>
parents: 1092
diff changeset
105 _MSG("Jpeg_free: jpeg=%p\n", jpeg);
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
106 jpeg_destroy_decompress(&(jpeg->cinfo));
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
107 dFree(jpeg);
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
108 }
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
109
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
110 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 * Finish the decoding process
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 static void Jpeg_close(DilloJpeg *jpeg, CacheClient_t *Client)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 {
768
eeb44d8bf3a0 Make now-unused debug messages silent.
Jorge Arellano Cid <jcid@dillo.org>
parents: 741
diff changeset
115 _MSG("Jpeg_close\n");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 a_Dicache_close(jpeg->url, jpeg->version, Client);
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
117 Jpeg_free(jpeg);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119
879
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
120 /*
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
121 * The proper signature is:
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
122 * static void init_source(j_decompress_ptr cinfo)
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
123 * (declaring it with no parameter avoids a compiler warning)
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
124 */
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
125 static void init_source()
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 static boolean fill_input_buffer(j_decompress_ptr cinfo)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 DilloJpeg *jpeg = ((my_source_mgr *) cinfo->src)->jpeg;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
133 _MSG("fill_input_buffer\n");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 #if 0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 if (!cinfo->src->bytes_in_buffer) {
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
136 _MSG("fill_input_buffer: %ld bytes in buffer\n",
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
137 (long)cinfo->src->bytes_in_buffer);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139 jpeg->Start_Ofs = (ulong_t) jpeg->cinfo.src->next_input_byte -
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140 (ulong_t) jpeg->Data;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
141 #endif
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142 if (jpeg->Skip) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 jpeg->Start_Ofs = jpeg->NewStart + jpeg->Skip - 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 jpeg->Skip = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
146 jpeg->Start_Ofs = (ulong_t) jpeg->cinfo.src->next_input_byte -
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
147 (ulong_t) jpeg->Data;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 return FALSE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 #if 0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 return TRUE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 #endif
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158 DilloJpeg *jpeg;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
159
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 if (num_bytes < 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
162 jpeg = ((my_source_mgr *) cinfo->src)->jpeg;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
163
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
164 _MSG("skip_input_data: Start_Ofs = %lu, num_bytes = %ld,"
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
165 " %ld bytes in buffer\n",
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
166 (ulong_t)jpeg->Start_Ofs, num_bytes,(long)cinfo->src->bytes_in_buffer);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
168 cinfo->src->next_input_byte += num_bytes;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
169 if (num_bytes < (long)cinfo->src->bytes_in_buffer) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170 cinfo->src->bytes_in_buffer -= num_bytes;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
172 jpeg->Skip += num_bytes - cinfo->src->bytes_in_buffer + 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
173 cinfo->src->bytes_in_buffer = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
174 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
175 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
176
879
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
177 /*
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
178 * The proper signature is:
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
179 * static void term_source(j_decompress_ptr cinfo)
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
180 * (declaring it with no parameter avoids a compiler warning)
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
181 */
e546d78f9181 Avoid a couple of compiler warnings in jpeg.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
182 static void term_source()
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
185
874
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
186 void *a_Jpeg_new(DilloImage *Image, DilloUrl *url, int version)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
188 my_source_mgr *src;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
189 DilloJpeg *jpeg = dMalloc(sizeof(*jpeg));
1094
7401c51915da Silence the last image-debugging messages
Jorge Arellano Cid <jcid@dillo.org>
parents: 1092
diff changeset
190 _MSG("a_Jpeg_new: jpeg=%p\n", jpeg);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
191
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
192 jpeg->Image = Image;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
193 jpeg->url = url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
194 jpeg->version = version;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
195
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
196 jpeg->state = DILLO_JPEG_INIT;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
197 jpeg->Start_Ofs = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
198 jpeg->Skip = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
199
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
200 /* decompression step 1 (see libjpeg.doc) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
201 jpeg->cinfo.err = jpeg_std_error(&(jpeg->jerr.pub));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
202 jpeg->jerr.pub.error_exit = Jpeg_errorexit;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
203
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
204 jpeg_create_decompress(&(jpeg->cinfo));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
205
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
206 /* decompression step 2 (see libjpeg.doc) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
207 jpeg->cinfo.src = &jpeg->Src.pub;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
208 src = &jpeg->Src;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
209 src->pub.init_source = init_source;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 src->pub.fill_input_buffer = fill_input_buffer;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
211 src->pub.skip_input_data = skip_input_data;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212 src->pub.resync_to_restart = jpeg_resync_to_restart;/* use default method */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
213 src->pub.term_source = term_source;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214 src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
215 src->pub.next_input_byte = NULL;/* until buffer loaded */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
216
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
217 src->jpeg = jpeg;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
218
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
219 /* decompression steps continue in write method */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
220 return jpeg;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
221 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
222
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
223 void a_Jpeg_callback(int Op, void *data)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
224 {
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
225 if (Op == CA_Send) {
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
226 CacheClient_t *Client = data;
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
227 Jpeg_write(Client->CbData, Client->Buf, Client->BufSize);
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
228 } else if (Op == CA_Close) {
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
229 CacheClient_t *Client = data;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
230 Jpeg_close(Client->CbData, Client);
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
231 } else if (Op == CA_Abort) {
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
232 Jpeg_free(data);
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
233 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
234 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
235
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
236 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
237 * Receive and process new chunks of JPEG image data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
238 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
239 static void Jpeg_write(DilloJpeg *jpeg, void *Buf, uint_t BufSize)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
240 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
241 DilloImgType type;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
242 uchar_t *linebuf;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
243 JSAMPLE *array[1];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
244 int num_read;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
245
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
246 _MSG("Jpeg_write: (%p) Bytes in buff: %ld Ofs: %lu\n", jpeg,
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
247 (long) BufSize, (ulong_t)jpeg->Start_Ofs);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
248
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
249 /* See if we are supposed to skip ahead. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
250 if (BufSize <= jpeg->Start_Ofs)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
251 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
252
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
253 /* Concatenate with the partial input, if any. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
254 jpeg->cinfo.src->next_input_byte = (uchar_t *)Buf + jpeg->Start_Ofs;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
255 jpeg->cinfo.src->bytes_in_buffer = BufSize - jpeg->Start_Ofs;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
256 jpeg->NewStart = BufSize;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
257 jpeg->Data = Buf;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
258
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
259 if (setjmp(jpeg->jerr.setjmp_buffer)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
260 /* If we get here, the JPEG code has signaled an error. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261 jpeg->state = DILLO_JPEG_ERROR;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
262 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
263
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
264 /* Process the bytes in the input buffer. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
265 if (jpeg->state == DILLO_JPEG_INIT) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
267 /* decompression step 3 (see libjpeg.doc) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268 if (jpeg_read_header(&(jpeg->cinfo), TRUE) != JPEG_SUSPENDED) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
269 type = DILLO_IMG_TYPE_GRAY;
458
32363eb05dfc - Minor compiler warning fix.
Jorge Arellano Cid <jcid@dillo.org>
parents: 359
diff changeset
270 if (jpeg->cinfo.num_components == 1) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
271 type = DILLO_IMG_TYPE_GRAY;
458
32363eb05dfc - Minor compiler warning fix.
Jorge Arellano Cid <jcid@dillo.org>
parents: 359
diff changeset
272 } else if (jpeg->cinfo.num_components == 3) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273 type = DILLO_IMG_TYPE_RGB;
458
32363eb05dfc - Minor compiler warning fix.
Jorge Arellano Cid <jcid@dillo.org>
parents: 359
diff changeset
274 } else {
1408
e59742ef792a CMYK JPEGs, at least Adobe ones for now
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
275 MSG("4-component JPEG!\n");
e59742ef792a CMYK JPEGs, at least Adobe ones for now
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
276 if (jpeg->cinfo.jpeg_color_space == JCS_YCCK)
e59742ef792a CMYK JPEGs, at least Adobe ones for now
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
277 MSG("YCCK. Are the colors wrong?\n");
e59742ef792a CMYK JPEGs, at least Adobe ones for now
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
278 if (!jpeg->cinfo.saw_Adobe_marker)
e59742ef792a CMYK JPEGs, at least Adobe ones for now
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
279 MSG("No adobe marker! Is the image shown in reverse video?\n");
e59742ef792a CMYK JPEGs, at least Adobe ones for now
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
280 type = DILLO_IMG_TYPE_CMYK_INV;
458
32363eb05dfc - Minor compiler warning fix.
Jorge Arellano Cid <jcid@dillo.org>
parents: 359
diff changeset
281 }
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
282 /*
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 152
diff changeset
283 * If a multiple-scan image is not completely in cache,
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 152
diff changeset
284 * use progressive display, updating as it arrives.
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
285 */
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 152
diff changeset
286 if (jpeg_has_multiple_scans(&jpeg->cinfo) &&
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 152
diff changeset
287 !(a_Capi_get_flags(jpeg->url) & CAPI_Completed))
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
288 jpeg->cinfo.buffered_image = TRUE;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
289
1180
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
290 /* check max image size */
1199
81c2d1c2e0f0 Image size sanity checks (part 1)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1180
diff changeset
291 if (jpeg->cinfo.image_width <= 0 || jpeg->cinfo.image_height <= 0 ||
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1312
diff changeset
292 jpeg->cinfo.image_width >
1202
f77f7973534e use IMAGE_MAX_AREA instead of IMAGE_MAX_W and IMAGE_MAX_H
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1199
diff changeset
293 IMAGE_MAX_AREA / jpeg->cinfo.image_height) {
1964
7c7ff4d0202b clearer MSG for suspicious image size
corvid <corvid@lavabit.com>
parents: 1699
diff changeset
294 MSG("Jpeg_write: suspicious image size request %u x %u\n",
1180
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
295 (uint_t)jpeg->cinfo.image_width,
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
296 (uint_t)jpeg->cinfo.image_height);
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
297 jpeg->state = DILLO_JPEG_ERROR;
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
298 return;
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
299 }
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
300
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
301 a_Dicache_set_parms(jpeg->url, jpeg->version, jpeg->Image,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
302 (uint_t)jpeg->cinfo.image_width,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
303 (uint_t)jpeg->cinfo.image_height,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
304 type);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
305
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
306 /* decompression step 4 (see libjpeg.doc) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
307 jpeg->state = DILLO_JPEG_STARTING;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
308 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
309 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
310 if (jpeg->state == DILLO_JPEG_STARTING) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
311 /* decompression step 5 (see libjpeg.doc) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
312 if (jpeg_start_decompress(&(jpeg->cinfo))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
313 jpeg->y = 0;
152
3cea28afbca9 - Workaround to make _most_ cached jpeg images render in one pass.
jcid
parents: 104
diff changeset
314 jpeg->state = jpeg->cinfo.buffered_image ?
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
315 DILLO_JPEG_READ_BEGIN_SCAN : DILLO_JPEG_READ_IN_SCAN;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
316 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
317 }
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
318
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
319 /*
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
320 * A progressive jpeg contains multiple scans that can be used to display
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
321 * an increasingly sharp image as it is being received. The reading of each
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
322 * scan must be surrounded by jpeg_start_output()/jpeg_finish_output().
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
323 */
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
324
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
325 if (jpeg->state == DILLO_JPEG_READ_END_SCAN) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
326 if (jpeg_finish_output(&jpeg->cinfo)) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
327 if (jpeg_input_complete(&jpeg->cinfo)) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
328 jpeg->state = DILLO_JPEG_DONE;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
329 } else {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
330 jpeg->state = DILLO_JPEG_READ_BEGIN_SCAN;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
331 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
332 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
333 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
334
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
335 if (jpeg->state == DILLO_JPEG_READ_BEGIN_SCAN) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
336 if (jpeg_start_output(&jpeg->cinfo, jpeg->cinfo.input_scan_number)) {
703
e2b30a2f4654 [mq]: dicache-cleanup1
Jorge Arellano Cid <jcid@dillo.org>
parents: 458
diff changeset
337 a_Dicache_new_scan(jpeg->url, jpeg->version);
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
338 jpeg->state = DILLO_JPEG_READ_IN_SCAN;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
339 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
340 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
341
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
342 if (jpeg->state == DILLO_JPEG_READ_IN_SCAN) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
343 linebuf = dMalloc(jpeg->cinfo.image_width *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
344 jpeg->cinfo.num_components);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
345 array[0] = linebuf;
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
346
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
347 while (1) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
348 num_read = jpeg_read_scanlines(&(jpeg->cinfo), array, 1);
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
349 if (num_read == 0) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
350 /* out of input */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
351 break;
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
352 }
1050
6a270ab021ce Remove unused parameter in a_Dicache_write()
corvid <corvid@lavabit.com>
parents: 991
diff changeset
353 a_Dicache_write(jpeg->url, jpeg->version, linebuf, jpeg->y);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
354
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
355 jpeg->y++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
356
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
357 if (jpeg->y == jpeg->cinfo.image_height) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
358 /* end of scan */
152
3cea28afbca9 - Workaround to make _most_ cached jpeg images render in one pass.
jcid
parents: 104
diff changeset
359 if (!jpeg->cinfo.buffered_image) {
3cea28afbca9 - Workaround to make _most_ cached jpeg images render in one pass.
jcid
parents: 104
diff changeset
360 /* single scan */
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
361 jpeg->state = DILLO_JPEG_DONE;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
362 break;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
363 } else {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
364 jpeg->y = 0;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
365 if (jpeg_input_complete(&jpeg->cinfo)) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
366 if (jpeg->cinfo.input_scan_number ==
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
367 jpeg->cinfo.output_scan_number) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
368 jpeg->state = DILLO_JPEG_DONE;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
369 break;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
370 } else {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
371 /* one final loop through the scanlines */
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
372 jpeg_finish_output(&jpeg->cinfo);
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
373 jpeg_start_output(&jpeg->cinfo,
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
374 jpeg->cinfo.input_scan_number);
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
375 continue;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
376 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
377 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
378 jpeg->state = DILLO_JPEG_READ_END_SCAN;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
379 if (!jpeg_finish_output(&jpeg->cinfo)) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
380 /* out of input */
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
381 break;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
382 } else {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
383 if (jpeg_input_complete(&jpeg->cinfo)) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
384 jpeg->state = DILLO_JPEG_DONE;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
385 break;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
386 } else {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
387 jpeg->state = DILLO_JPEG_READ_BEGIN_SCAN;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
388 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
389 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
390 if (!jpeg_start_output(&jpeg->cinfo,
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
391 jpeg->cinfo.input_scan_number)) {
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
392 /* out of input */
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
393 break;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
394 }
703
e2b30a2f4654 [mq]: dicache-cleanup1
Jorge Arellano Cid <jcid@dillo.org>
parents: 458
diff changeset
395 a_Dicache_new_scan(jpeg->url, jpeg->version);
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
396 jpeg->state = DILLO_JPEG_READ_IN_SCAN;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
397 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 35
diff changeset
398 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
399 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
400 dFree(linebuf);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
401 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
402 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
403
874
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
404 #else /* ENABLE_JPEG */
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
405
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
406 void *a_Jpeg_new() { return 0; }
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
407 void a_Jpeg_callback() { return; }
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
408
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
409 #endif /* ENABLE_JPEG */