NetSurf
Macros | Functions | Variables
jpeg.c File Reference

implementation of content handling for image/jpeg More...

#include <stdbool.h>
#include <stdlib.h>
#include <setjmp.h>
#include "utils/utils.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "netsurf/bitmap.h"
#include "content/llcache.h"
#include "content/content.h"
#include "content/content_protected.h"
#include "content/content_factory.h"
#include "desktop/gui_internal.h"
#include "desktop/bitmap.h"
#include "image/image_cache.h"
#include "jpeglib.h"
#include "jpeg.h"
Include dependency graph for jpeg.c:

Go to the source code of this file.

Macros

#define JPEG_INTERNAL_OPTIONS
 
#define MIN_JPEG_SIZE   20
 absolute minimum size of a jpeg below which it is not even worth trying to read header data More...
 
#define DIV255(x)   ((x) + 1 + ((x) >> 8)) >> 8
 

Functions

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. More...
 
static void nsjpeg_init_source (j_decompress_ptr cinfo)
 JPEG data source manager: initialize source. More...
 
static boolean nsjpeg_fill_input_buffer (j_decompress_ptr cinfo)
 JPEG data source manager: fill the input buffer. More...
 
static void nsjpeg_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 JPEG data source manager: skip num_bytes worth of data. More...
 
static void nsjpeg_term_source (j_decompress_ptr cinfo)
 JPEG data source manager: terminate source. More...
 
static void nsjpeg_error_log (j_common_ptr cinfo)
 Error output handler for JPEG library. More...
 
static void nsjpeg_error_exit (j_common_ptr cinfo)
 Fatal error handler for JPEG library. More...
 
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. More...
 
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. More...
 
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. More...
 
static struct bitmapjpeg_cache_convert (struct content *c)
 create a bitmap from jpeg content. More...
 
static bool nsjpeg_convert (struct content *c)
 Convert a CONTENT_JPEG for display. More...
 
static nserror nsjpeg_clone (const struct content *old, struct content **newc)
 Clone content. More...
 
 CONTENT_FACTORY_REGISTER_TYPES (nsjpeg, nsjpeg_types, nsjpeg_content_handler)
 

Variables

static char nsjpeg_error_buffer [JMSG_LENGTH_MAX]
 
static unsigned char nsjpeg_eoi [] = { 0xff, JPEG_EOI }
 
static const content_handler nsjpeg_content_handler
 
static const char * nsjpeg_types []
 

Detailed Description

implementation of content handling for image/jpeg

This implementation uses the IJG JPEG library.

Definition in file jpeg.c.

Macro Definition Documentation

◆ DIV255

#define DIV255 (   x)    ((x) + 1 + ((x) >> 8)) >> 8

◆ JPEG_INTERNAL_OPTIONS

#define JPEG_INTERNAL_OPTIONS

Definition at line 44 of file jpeg.c.

◆ MIN_JPEG_SIZE

#define MIN_JPEG_SIZE   20

absolute minimum size of a jpeg below which it is not even worth trying to read header data

Definition at line 51 of file jpeg.c.

Function Documentation

◆ CONTENT_FACTORY_REGISTER_TYPES()

CONTENT_FACTORY_REGISTER_TYPES ( nsjpeg  ,
nsjpeg_types  ,
nsjpeg_content_handler   
)

◆ jpeg_cache_convert()

static struct bitmap * jpeg_cache_convert ( struct content c)
static

create a bitmap from jpeg content.

Definition at line 257 of file jpeg.c.

References netsurf_table::bitmap, bitmap(), BITMAP_LAYOUT_A8B8G8R8, BITMAP_LAYOUT_A8R8G8B8, BITMAP_LAYOUT_B8G8R8A8, BITMAP_LAYOUT_R8G8B8A8, BITMAP_OPAQUE, content__get_source_data(), gui_bitmap_table::create, gui_bitmap_table::destroy, gui_bitmap_table::get_buffer, gui_bitmap_table::get_rowstride, guit, bitmap_fmt::layout, MIN_JPEG_SIZE, gui_bitmap_table::modified, nsjpeg__decode_client_fmt(), nsjpeg__decode_cmyk(), nsjpeg__decode_rgb(), nsjpeg_error_exit(), nsjpeg_error_log(), nsjpeg_fill_input_buffer(), nsjpeg_init_source(), nsjpeg_skip_input_data(), nsjpeg_term_source(), NSLOG, and bitmap::rowstride.

Referenced by nsjpeg_convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsjpeg__decode_client_fmt()

static void nsjpeg__decode_client_fmt ( struct jpeg_decompress_struct *  cinfo,
uint8_t *volatile  pixels,
size_t  rowstride 
)
inlinestatic

Convert scan lines from CMYK to core client bitmap layout.

Definition at line 239 of file jpeg.c.

Referenced by jpeg_cache_convert().

Here is the caller graph for this function:

◆ nsjpeg__decode_cmyk()

static void nsjpeg__decode_cmyk ( struct jpeg_decompress_struct *  cinfo,
uint8_t *volatile  pixels,
size_t  rowstride 
)
inlinestatic

Convert scan lines from CMYK to core client bitmap layout.

Definition at line 166 of file jpeg.c.

References DIV255, and width.

Referenced by jpeg_cache_convert().

Here is the caller graph for this function:

◆ nsjpeg__decode_rgb()

static void nsjpeg__decode_rgb ( struct jpeg_decompress_struct *  cinfo,
uint8_t *volatile  pixels,
size_t  rowstride 
)
inlinestatic

Convert scan lines from CMYK to core client bitmap layout.

Definition at line 204 of file jpeg.c.

References width.

Referenced by jpeg_cache_convert().

Here is the caller graph for this function:

◆ nsjpeg_clone()

static nserror nsjpeg_clone ( const struct content old,
struct content **  newc 
)
static

Clone content.

Definition at line 456 of file jpeg.c.

References content__clone(), content_destroy(), CONTENT_STATUS_DONE, CONTENT_STATUS_READY, NSERROR_CLONE_FAILED, NSERROR_NOMEM, NSERROR_OK, nsjpeg_convert(), and content::status.

Here is the call graph for this function:

◆ nsjpeg_convert()

static bool nsjpeg_convert ( struct content c)
static

Convert a CONTENT_JPEG for display.

Definition at line 386 of file jpeg.c.

References content__get_source_data(), content__set_title(), content_broadcast(), CONTENT_MSG_ERROR, content_set_done(), content_set_ready(), content_set_status(), content_msg_data::errorcode, content_msg_data::errordata, content_msg_data::errormsg, content::height, image_cache_add(), jpeg_cache_convert(), content::llcache, llcache_handle_get_url(), messages_get_buff(), NSERROR_UNKNOWN, nsjpeg_error_buffer, nsjpeg_error_exit(), nsjpeg_error_log(), nsjpeg_fill_input_buffer(), nsjpeg_init_source(), nsjpeg_skip_input_data(), nsjpeg_term_source(), nsurl_access_leaf(), content::size, content_msg_data::title, and content::width.

Referenced by nsjpeg_clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsjpeg_create()

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 
)
static

Content create entry point.

Definition at line 64 of file jpeg.c.

References content__init(), content::fallback_charset, content::handler, llcache, NSERROR_NOMEM, NSERROR_OK, and content::quirks.

Here is the call graph for this function:

◆ nsjpeg_error_exit()

static void nsjpeg_error_exit ( j_common_ptr  cinfo)
static

Fatal error handler for JPEG library.

This prevents jpeglib calling exit() on a fatal error.

Definition at line 153 of file jpeg.c.

References nsjpeg_error_buffer, and NSLOG.

Referenced by jpeg_cache_convert(), and nsjpeg_convert().

Here is the caller graph for this function:

◆ nsjpeg_error_log()

static void nsjpeg_error_log ( j_common_ptr  cinfo)
static

Error output handler for JPEG library.

This logs to NetSurf log instead of stderr. Warnings only - fatal errors are trapped by nsjpeg_error_exit and do not call the output handler.

Definition at line 141 of file jpeg.c.

References nsjpeg_error_buffer, and NSLOG.

Referenced by jpeg_cache_convert(), and nsjpeg_convert().

Here is the caller graph for this function:

◆ nsjpeg_fill_input_buffer()

static boolean nsjpeg_fill_input_buffer ( j_decompress_ptr  cinfo)
static

JPEG data source manager: fill the input buffer.

This can only occur if the JPEG data was truncated or corrupted. Insert a fake EOI marker to allow the decompressor to output as much as possible.

Definition at line 102 of file jpeg.c.

References nsjpeg_eoi.

Referenced by jpeg_cache_convert(), and nsjpeg_convert().

Here is the caller graph for this function:

◆ nsjpeg_init_source()

static void nsjpeg_init_source ( j_decompress_ptr  cinfo)
static

JPEG data source manager: initialize source.

Definition at line 91 of file jpeg.c.

Referenced by jpeg_cache_convert(), and nsjpeg_convert().

Here is the caller graph for this function:

◆ nsjpeg_skip_input_data()

static void nsjpeg_skip_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)
static

JPEG data source manager: skip num_bytes worth of data.

Definition at line 114 of file jpeg.c.

Referenced by jpeg_cache_convert(), and nsjpeg_convert().

Here is the caller graph for this function:

◆ nsjpeg_term_source()

static void nsjpeg_term_source ( j_decompress_ptr  cinfo)
static

JPEG data source manager: terminate source.

Definition at line 129 of file jpeg.c.

Referenced by jpeg_cache_convert(), and nsjpeg_convert().

Here is the caller graph for this function:

Variable Documentation

◆ nsjpeg_content_handler

const content_handler nsjpeg_content_handler
static
Initial value:
= {
.create = nsjpeg_create,
.data_complete = nsjpeg_convert,
.destroy = image_cache_destroy,
.redraw = image_cache_redraw,
.clone = nsjpeg_clone,
.get_internal = image_cache_get_internal,
.is_opaque = image_cache_is_opaque,
.no_share = false,
}
content_type image_cache_content_type(void)
Definition: image_cache.c:873
void * image_cache_get_internal(const struct content *c, void *context)
Definition: image_cache.c:856
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.
Definition: image_cache.c:798
void image_cache_destroy(struct content *content)
Definition: image_cache.c:841
bool image_cache_is_opaque(struct content *c)
Definition: image_cache.c:862
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.
Definition: jpeg.c:64
static nserror nsjpeg_clone(const struct content *old, struct content **newc)
Clone content.
Definition: jpeg.c:456
static bool nsjpeg_convert(struct content *c)
Convert a CONTENT_JPEG for display.
Definition: jpeg.c:386

Definition at line 485 of file jpeg.c.

◆ nsjpeg_eoi

unsigned char nsjpeg_eoi[] = { 0xff, JPEG_EOI }
static

Definition at line 59 of file jpeg.c.

Referenced by nsjpeg_fill_input_buffer().

◆ nsjpeg_error_buffer

char nsjpeg_error_buffer[JMSG_LENGTH_MAX]
static

Definition at line 57 of file jpeg.c.

Referenced by nsjpeg_convert(), nsjpeg_error_exit(), and nsjpeg_error_log().

◆ nsjpeg_types

const char* nsjpeg_types[]
static
Initial value:
= {
"image/jpeg",
"image/jpg",
"image/pjpeg"
}

Definition at line 497 of file jpeg.c.