44#define JPEG_INTERNAL_OPTIONS
51#define MIN_JPEG_SIZE 20
53#ifndef LIBJPEG_TURBO_VERSION
54#warning Using libjpeg (libjpeg-turbo is recommended)
67 bool quirks,
struct content **c)
72 jpeg = calloc(1,
sizeof(
struct content));
105 cinfo->src->bytes_in_buffer = 2;
116 if ((
long) cinfo->src->bytes_in_buffer < num_bytes) {
117 cinfo->src->next_input_byte = 0;
118 cinfo->src->bytes_in_buffer = 0;
120 cinfo->src->next_input_byte += num_bytes;
121 cinfo->src->bytes_in_buffer -= num_bytes;
155 jmp_buf *setjmp_buffer = (jmp_buf *) cinfo->client_data;
160 longjmp(*setjmp_buffer, 1);
167 struct jpeg_decompress_struct *cinfo,
168 uint8_t *
volatile pixels,
171 int width = cinfo->output_width * 4;
174 JSAMPROW scanlines[1] = {
176 (pixels + rowstride * cinfo->output_scanline),
178 jpeg_read_scanlines(cinfo, scanlines, 1);
180 for (
int i =
width - 4; 0 <= i; i -= 4) {
182 const int c = scanlines[0][i + 0];
183 const int m = scanlines[0][i + 1];
184 const int y = scanlines[0][i + 2];
185 const int k = scanlines[0][i + 3];
187 const int ck = c * k;
188 const int mk = m * k;
189 const int yk = y * k;
191#define DIV255(x) ((x) + 1 + ((x) >> 8)) >> 8
198 }
while (cinfo->output_scanline != cinfo->output_height);
205 struct jpeg_decompress_struct *cinfo,
206 uint8_t *
volatile pixels,
209#if RGB_RED != 0 || RGB_GREEN != 1 || RGB_BLUE != 2 || RGB_PIXELSIZE != 4
210 int width = cinfo->output_width;
214 JSAMPROW scanlines[1] = {
216 (pixels + rowstride * cinfo->output_scanline),
218 jpeg_read_scanlines(cinfo, scanlines, 1);
220#if RGB_RED != 0 || RGB_GREEN != 1 || RGB_BLUE != 2 || RGB_PIXELSIZE != 4
223 for (
int i =
width - 1; 0 <= i; i--) {
224 int r = scanlines[0][i * RGB_PIXELSIZE + RGB_RED];
225 int g = scanlines[0][i * RGB_PIXELSIZE + RGB_GREEN];
226 int b = scanlines[0][i * RGB_PIXELSIZE + RGB_BLUE];
233 }
while (cinfo->output_scanline != cinfo->output_height);
240 struct jpeg_decompress_struct *cinfo,
241 uint8_t *
volatile pixels,
245 JSAMPROW scanlines[1] = {
247 (pixels + rowstride * cinfo->output_scanline),
249 jpeg_read_scanlines(cinfo, scanlines, 1);
250 }
while (cinfo->output_scanline != cinfo->output_height);
259 const uint8_t *source_data;
261 struct jpeg_decompress_struct cinfo;
262 struct jpeg_error_mgr jerr;
263 jmp_buf setjmp_buffer;
265 uint8_t *
volatile pixels = NULL;
267 struct jpeg_source_mgr source_mgr = {
273 jpeg_resync_to_restart,
279 if ((source_data == NULL) ||
285 cinfo.err = jpeg_std_error(&jerr);
290 if (setjmp(setjmp_buffer)) {
291 jpeg_destroy_decompress(&cinfo);
295 cinfo.client_data = &setjmp_buffer;
296 jpeg_create_decompress(&cinfo);
299 source_mgr.next_input_byte = source_data;
300 source_mgr.bytes_in_buffer = source_size;
301 cinfo.src = &source_mgr;
304 jpeg_read_header(&cinfo, TRUE);
307 if (cinfo.jpeg_color_space == JCS_CMYK ||
308 cinfo.jpeg_color_space == JCS_YCCK) {
309 cinfo.out_color_space = JCS_CMYK;
311#ifdef JCS_ALPHA_EXTENSIONS
314 cinfo.out_color_space = JCS_EXT_RGBA;
317 cinfo.out_color_space = JCS_EXT_BGRA;
320 cinfo.out_color_space = JCS_EXT_ARGB;
323 cinfo.out_color_space = JCS_EXT_ABGR;
326 NSLOG(netsurf, ERROR,
"Unexpected bitmap format: %u",
328 jpeg_destroy_decompress(&cinfo);
332 cinfo.out_color_space = JCS_RGB;
335 cinfo.dct_method = JDCT_ISLOW;
338 jpeg_start_decompress(&cinfo);
346 jpeg_destroy_decompress(&cinfo);
351 if (pixels == NULL) {
354 jpeg_destroy_decompress(&cinfo);
361 switch (cinfo.out_color_space) {
377 jpeg_finish_decompress(&cinfo);
378 jpeg_destroy_decompress(&cinfo);
388 struct jpeg_decompress_struct cinfo;
389 struct jpeg_error_mgr jerr;
390 jmp_buf setjmp_buffer;
391 struct jpeg_source_mgr source_mgr = { 0, 0,
403 cinfo.err = jpeg_std_error(&jerr);
407 if (setjmp(setjmp_buffer)) {
408 jpeg_destroy_decompress(&cinfo);
416 cinfo.client_data = &setjmp_buffer;
417 jpeg_create_decompress(&cinfo);
418 source_mgr.next_input_byte = (
unsigned char *) data;
419 source_mgr.bytes_in_buffer = size;
420 cinfo.src = &source_mgr;
421 jpeg_read_header(&cinfo, TRUE);
422 cinfo.out_color_space = JCS_RGB;
423 cinfo.dct_method = JDCT_ISLOW;
425 jpeg_calc_output_dimensions(&cinfo);
427 c->
width = cinfo.output_width;
428 c->
height = cinfo.output_height;
431 jpeg_destroy_decompress(&cinfo);
461 jpeg_c = calloc(1,
sizeof(
struct content));
Content handling interface.
void content_destroy(struct content *c)
Destroy and free a content.
void content_broadcast(struct content *c, content_msg msg, const union content_msg_data *data)
Send a message to all users.
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
bool content__set_title(struct content *c, const char *title)
Set title associated with content.
nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks)
const uint8_t * content__get_source_data(struct content *c, size_t *size)
Retrieve source of content.
nserror content__clone(const struct content *c, struct content *nc)
Clone a content's data members.
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
void content_set_status(struct content *c, const char *status_message)
Updates content with new status.
Protected interface to Content handling.
@ CONTENT_STATUS_READY
Some parts of content still being loaded, but can be displayed.
@ CONTENT_STATUS_DONE
Content has completed all processing.
@ CONTENT_MSG_ERROR
error occurred
Internal core bitmap interface.
nserror
Enumeration of error codes.
@ NSERROR_UNKNOWN
Unknown error - DO NOT USE.
@ NSERROR_NOMEM
Memory exhaustion.
@ NSERROR_CLONE_FAILED
Failed to clone handle.
struct netsurf_table * guit
The global interface table.
Interface to core interface table.
content_type image_cache_content_type(void)
void * image_cache_get_internal(const struct content *c, void *context)
bool image_cache_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Generic content redraw callback.
void image_cache_destroy(struct content *content)
nserror image_cache_add(struct content *content, struct bitmap *bitmap, image_cache_convert_fn *convert)
adds an image content to be cached.
bool image_cache_is_opaque(struct content *c)
The image content handler intermediate image cache.
Generic bitmap handling interface.
@ BITMAP_OPAQUE
image is opaque
bitmap_layout
NetSurf bitmap pixel layout.
@ BITMAP_LAYOUT_B8G8R8A8
Bite-wise BGRA: Byte order: 0xBB, 0xGG, 0xRR, 0xAA.
@ BITMAP_LAYOUT_R8G8B8A8
Bite-wise RGBA: Byte order: 0xRR, 0xGG, 0xBB, 0xAA.
@ BITMAP_LAYOUT_A8B8G8R8
Bite-wise ABGR: Byte order: 0xAA, 0xBB, 0xGG, 0xRR.
@ BITMAP_LAYOUT_A8R8G8B8
Bite-wise ARGB: Byte order: 0xAA, 0xRR, 0xGG, 0xBB.
CONTENT_FACTORY_REGISTER_TYPES(nsjpeg, nsjpeg_types, nsjpeg_content_handler)
static nserror nsjpeg_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Content create entry point.
static void nsjpeg_term_source(j_decompress_ptr cinfo)
JPEG data source manager: terminate source.
static struct bitmap * jpeg_cache_convert(struct content *c)
create a bitmap from jpeg content.
static nserror nsjpeg_clone(const struct content *old, struct content **newc)
Clone content.
static const content_handler nsjpeg_content_handler
static void nsjpeg__decode_client_fmt(struct jpeg_decompress_struct *cinfo, uint8_t *volatile pixels, size_t rowstride)
Convert scan lines from CMYK to core client bitmap layout.
static void nsjpeg__decode_rgb(struct jpeg_decompress_struct *cinfo, uint8_t *volatile pixels, size_t rowstride)
Convert scan lines from CMYK to core client bitmap layout.
static bool nsjpeg_convert(struct content *c)
Convert a CONTENT_JPEG for display.
static void nsjpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
JPEG data source manager: skip num_bytes worth of data.
static void nsjpeg_init_source(j_decompress_ptr cinfo)
JPEG data source manager: initialize source.
static void nsjpeg_error_exit(j_common_ptr cinfo)
Fatal error handler for JPEG library.
static char nsjpeg_error_buffer[JMSG_LENGTH_MAX]
static const char * nsjpeg_types[]
static void nsjpeg_error_log(j_common_ptr cinfo)
Error output handler for JPEG library.
static unsigned char nsjpeg_eoi[]
#define MIN_JPEG_SIZE
absolute minimum size of a jpeg below which it is not even worth trying to read header data
static boolean nsjpeg_fill_input_buffer(j_decompress_ptr cinfo)
JPEG data source manager: fill the input buffer.
static void nsjpeg__decode_cmyk(struct jpeg_decompress_struct *cinfo, uint8_t *volatile pixels, size_t rowstride)
Convert scan lines from CMYK to core client bitmap layout.
Content for image/jpeg (interface).
static struct llcache_s * llcache
low level cache state
nsurl * llcache_handle_get_url(const llcache_handle *handle)
Retrieve the post-redirect URL of a low-level cache object.
Low-level resource cache (interface)
#define NSLOG(catname, level, logmsg, args...)
char * messages_get_buff(const char *key,...)
Formatted message from a key in the global message hash.
Localised message support (interface).
const char * nsurl_access_leaf(const nsurl *url)
Access a URL's path leaf as a string.
enum bitmap_layout layout
Colour component layout.
RISC OS wimp toolkit bitmap.
Content operation function table.
nserror(* create)(const struct content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, struct llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Content which corresponds to a single URL.
bool quirks
Content is in quirks mode.
int height
Height dimension, if applicable.
char * fallback_charset
Fallback charset, or NULL.
int width
Width dimension, if applicable.
const struct content_handler * handler
Handler for content.
struct llcache_handle * llcache
Low-level cache object.
content_status status
Current status.
unsigned int size
Estimated size of all data associated with this content.
void(* destroy)(void *bitmap)
Destroy a bitmap.
void *(* create)(int width, int height, enum gui_bitmap_flags flags)
Create a new bitmap.
size_t(* get_rowstride)(void *bitmap)
Get the number of bytes per row of the image.
void(* modified)(void *bitmap)
Marks a bitmap as modified.
unsigned char *(* get_buffer)(void *bitmap)
Get the image buffer from a bitmap.
Representation of an HTTP parameter.
Handle to low-level cache object.
struct gui_bitmap_table * bitmap
Bitmap table.
Extra data for some content_msg messages.
struct content_msg_data::@99 errordata
CONTENT_MSG_ERROR - Error from content or underlying fetch.
nserror errorcode
The error code to convey meaning.
const char * errormsg
The message.
Interface to a number of general purpose functionality.
static nserror bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Plot a bitmap.