NetSurf
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
png.c File Reference
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <png.h>
#include "netsurf/inttypes.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "netsurf/bitmap.h"
#include "content/llcache.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 dependency graph for png.c:

Go to the source code of this file.

Data Structures

struct  nspng_content
 
struct  png_cache_read_data_s
 

Macros

#define png_jmpbuf(png_ptr)   ((png_ptr)->jmpbuf)
 
#define png_set_expand_gray_1_2_4_to_8(png)   png_set_gray_1_2_4_to_8(png)
 

Typedefs

typedef struct nspng_content nspng_content
 

Enumerations

enum  nspng_cberr { CBERR_NONE = 0 , CBERR_LIBPNG , CBERR_NOPRE }
 Callbak error numbers. More...
 

Functions

static void nspng_warning (png_structp png_ptr, png_const_charp warning_message)
 nspng_warning – callback for libpng warnings More...
 
static void nspng_error (png_structp png_ptr, png_const_charp error_message)
 nspng_error – callback for libpng errors More...
 
static void nspng_setup_transforms (png_structp png_ptr, png_infop info_ptr)
 
static void info_callback (png_structp png_s, png_infop info)
 info_callback – PNG header has been completely received, prepare to process image data More...
 
static void row_callback (png_structp png_s, png_bytep new_row, png_uint_32 row_num, int pass)
 
static void end_callback (png_structp png_s, png_infop info)
 
static nserror nspng_create_png_data (nspng_content *png_c)
 
static nserror nspng_create (const 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)
 
static bool nspng_process_data (struct content *c, const char *data, unsigned int size)
 
static void png_cache_read_fn (png_structp png_ptr, png_bytep data, png_size_t length)
 PNG library read fucntion to read data from a memory array. More...
 
static png_bytep * calc_row_pointers (struct bitmap *bitmap)
 calculate an array of row pointers into a bitmap data area More...
 
static struct bitmappng_cache_convert (struct content *c)
 PNG content to bitmap conversion. More...
 
static bool nspng_convert (struct content *c)
 
static nserror nspng_clone (const struct content *old_c, struct content **new_c)
 
 CONTENT_FACTORY_REGISTER_TYPES (nspng, nspng_types, nspng_content_handler)
 

Variables

static unsigned int interlace_start [8] = {0, 16, 0, 8, 0, 4, 0}
 
static unsigned int interlace_step [8] = {28, 28, 12, 12, 4, 4, 0}
 
static unsigned int interlace_row_start [8] = {0, 0, 4, 0, 2, 0, 1}
 
static unsigned int interlace_row_step [8] = {8, 8, 8, 4, 4, 2, 2}
 
static const content_handler nspng_content_handler
 
static const char * nspng_types []
 

Macro Definition Documentation

◆ png_jmpbuf

#define png_jmpbuf (   png_ptr)    ((png_ptr)->jmpbuf)

Definition at line 44 of file png.c.

◆ png_set_expand_gray_1_2_4_to_8

#define png_set_expand_gray_1_2_4_to_8 (   png)    png_set_gray_1_2_4_to_8(png)

Definition at line 48 of file png.c.

Typedef Documentation

◆ nspng_content

typedef struct nspng_content nspng_content

Enumeration Type Documentation

◆ nspng_cberr

Callbak error numbers.

Enumerator
CBERR_NONE 
CBERR_LIBPNG 
CBERR_NOPRE 

Definition at line 69 of file png.c.

Function Documentation

◆ calc_row_pointers()

static png_bytep * calc_row_pointers ( struct bitmap bitmap)
static

calculate an array of row pointers into a bitmap data area

Definition at line 430 of file png.c.

References netsurf_table::bitmap, buffer, gui_bitmap_table::get_buffer, gui_bitmap_table::get_height, gui_bitmap_table::get_rowstride, guit, and height.

Referenced by png_cache_convert().

Here is the caller graph for this function:

◆ CONTENT_FACTORY_REGISTER_TYPES()

CONTENT_FACTORY_REGISTER_TYPES ( nspng  ,
nspng_types  ,
nspng_content_handler   
)

◆ end_callback()

static void end_callback ( png_structp  png_s,
png_infop  info 
)
static

Definition at line 267 of file png.c.

Referenced by nspng_create_png_data().

Here is the caller graph for this function:

◆ info_callback()

static void info_callback ( png_structp  png_s,
png_infop  info 
)
static

info_callback – PNG header has been completely received, prepare to process image data

Definition at line 176 of file png.c.

References nspng_content::base, nspng_content::bitmap, netsurf_table::bitmap, BITMAP_NONE, nspng_content::bpp, CBERR_NOPRE, gui_bitmap_table::create, gui_bitmap_table::get_rowstride, guit, content::height, height, image_cache_speculate(), nspng_content::interlace, NSLOG, nspng_setup_transforms(), png_jmpbuf, PRIsizet, nspng_content::rowbytes, nspng_content::rowstride, content::size, content::width, and width.

Referenced by nspng_create_png_data().

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

◆ nspng_clone()

static nserror nspng_clone ( const struct content old_c,
struct content **  new_c 
)
static

Definition at line 593 of file png.c.

References nspng_content::base, content__clone(), content__get_source_data(), content_destroy(), CONTENT_STATUS_DONE, CONTENT_STATUS_READY, png_cache_read_data_s::data, NSERROR_CLONE_FAILED, NSERROR_NOMEM, NSERROR_OK, nspng_convert(), nspng_create_png_data(), nspng_process_data(), png_cache_read_data_s::size, and content::status.

Here is the call graph for this function:

◆ nspng_convert()

static bool nspng_convert ( struct content c)
static

Definition at line 553 of file png.c.

References nspng_content::bitmap, netsurf_table::bitmap, bitmap_format_to_client(), bitmap_test_opaque(), content__set_title(), content_set_done(), content_set_ready(), content_set_status(), guit, content::height, image_cache_add(), nspng_content::info, content::llcache, llcache_handle_get_url(), messages_get_buff(), gui_bitmap_table::modified, nsurl_access_leaf(), nspng_content::png, png_cache_convert(), gui_bitmap_table::set_opaque, and content::width.

Referenced by nspng_clone().

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

◆ nspng_create()

static nserror nspng_create ( const 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 
)
static

Definition at line 308 of file png.c.

References nspng_content::base, content__init(), llcache, NSERROR_NOMEM, NSERROR_OK, and nspng_create_png_data().

Here is the call graph for this function:

◆ nspng_create_png_data()

static nserror nspng_create_png_data ( nspng_content png_c)
static

Definition at line 271 of file png.c.

References nspng_content::base, nspng_content::bitmap, content_broadcast_error(), end_callback(), nspng_content::info, info_callback(), NSERROR_NOMEM, NSERROR_OK, NSERROR_PNG_ERROR, NSLOG, nspng_error(), nspng_warning(), nspng_content::png, png_jmpbuf, and row_callback().

Referenced by nspng_clone(), and nspng_create().

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

◆ nspng_error()

static void nspng_error ( png_structp  png_ptr,
png_const_charp  error_message 
)
static

nspng_error – callback for libpng errors

Definition at line 86 of file png.c.

References CBERR_LIBPNG, NSLOG, and png_jmpbuf.

Referenced by nspng_create_png_data(), and png_cache_convert().

Here is the caller graph for this function:

◆ nspng_process_data()

static bool nspng_process_data ( struct content c,
const char *  data,
unsigned int  size 
)
static

Definition at line 347 of file png.c.

References nspng_content::bitmap, CBERR_NONE, CBERR_NOPRE, content_broadcast_error(), nspng_content::info, nspng_content::no_process_data, NSERROR_PNG_ERROR, NSLOG, nspng_content::png, png_jmpbuf, and content::size.

Referenced by nspng_clone().

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

◆ nspng_setup_transforms()

static void nspng_setup_transforms ( png_structp  png_ptr,
png_infop  info_ptr 
)
static

Definition at line 92 of file png.c.

References BITMAP_LAYOUT_A8B8G8R8, BITMAP_LAYOUT_A8R8G8B8, BITMAP_LAYOUT_B8G8R8A8, bitmap_fmt::layout, and png_set_expand_gray_1_2_4_to_8.

Referenced by info_callback(), and png_cache_convert().

Here is the caller graph for this function:

◆ nspng_warning()

static void nspng_warning ( png_structp  png_ptr,
png_const_charp  warning_message 
)
static

nspng_warning – callback for libpng warnings

Definition at line 78 of file png.c.

References NSLOG.

Referenced by nspng_create_png_data(), and png_cache_convert().

Here is the caller graph for this function:

◆ png_cache_convert()

static struct bitmap * png_cache_convert ( struct content c)
static

PNG content to bitmap conversion.

This routine generates a bitmap object from a PNG image content

Definition at line 461 of file png.c.

References netsurf_table::bitmap, bitmap(), bitmap_format_to_client(), BITMAP_NONE, bitmap_test_opaque(), calc_row_pointers(), content__get_source_data(), gui_bitmap_table::create, png_cache_read_data_s::data, gui_bitmap_table::destroy, guit, height, bitmap_fmt::layout, gui_bitmap_table::modified, nspng_error(), nspng_setup_transforms(), nspng_warning(), bitmap_fmt::pma, png_cache_read_fn(), png_jmpbuf, gui_bitmap_table::set_opaque, png_cache_read_data_s::size, and width.

Referenced by nspng_convert().

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

◆ png_cache_read_fn()

static void png_cache_read_fn ( png_structp  png_ptr,
png_bytep  data,
png_size_t  length 
)
static

PNG library read fucntion to read data from a memory array.

Definition at line 409 of file png.c.

References png_cache_read_data_s::data, and png_cache_read_data_s::size.

Referenced by png_cache_convert().

Here is the caller graph for this function:

◆ row_callback()

static void row_callback ( png_structp  png_s,
png_bytep  new_row,
png_uint_32  row_num,
int  pass 
)
static

Definition at line 214 of file png.c.

References nspng_content::bitmap, netsurf_table::bitmap, buffer, gui_bitmap_table::get_buffer, guit, nspng_content::interlace, interlace_row_start, interlace_row_step, interlace_start, interlace_step, png_jmpbuf, nspng_content::rowbytes, and nspng_content::rowstride.

Referenced by nspng_create_png_data().

Here is the caller graph for this function:

Variable Documentation

◆ interlace_row_start

unsigned int interlace_row_start[8] = {0, 0, 4, 0, 2, 0, 1}
static

Definition at line 65 of file png.c.

Referenced by row_callback().

◆ interlace_row_step

unsigned int interlace_row_step[8] = {8, 8, 8, 4, 4, 2, 2}
static

Definition at line 66 of file png.c.

Referenced by row_callback().

◆ interlace_start

unsigned int interlace_start[8] = {0, 16, 0, 8, 0, 4, 0}
static

Definition at line 63 of file png.c.

Referenced by row_callback().

◆ interlace_step

unsigned int interlace_step[8] = {28, 28, 12, 12, 4, 4, 0}
static

Definition at line 64 of file png.c.

Referenced by row_callback().

◆ nspng_content_handler

const content_handler nspng_content_handler
static
Initial value:
= {
.create = nspng_create,
.process_data = nspng_process_data,
.data_complete = nspng_convert,
.clone = nspng_clone,
.destroy = image_cache_destroy,
.redraw = image_cache_redraw,
.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 nspng_create(const 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)
Definition: png.c:308
static nserror nspng_clone(const struct content *old_c, struct content **new_c)
Definition: png.c:593
static bool nspng_convert(struct content *c)
Definition: png.c:553
static bool nspng_process_data(struct content *c, const char *data, unsigned int size)
Definition: png.c:347

Definition at line 638 of file png.c.

◆ nspng_types

const char* nspng_types[]
static
Initial value:
= {
"image/png",
"image/x-png"
}

Definition at line 651 of file png.c.