43#warning you have an antique libpng
44#define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
47#if PNG_LIBPNG_VER < 10209
48#define png_set_expand_gray_1_2_4_to_8(png) png_set_gray_1_2_4_to_8(png)
78static void nspng_warning(png_structp png_ptr, png_const_charp warning_message)
80 NSLOG(netsurf, INFO,
"%s", warning_message);
86static void nspng_error(png_structp png_ptr, png_const_charp error_message)
88 NSLOG(netsurf, INFO,
"%s", error_message);
94 int bit_depth, color_type, intent;
97 bit_depth = png_get_bit_depth(png_ptr, info_ptr);
98 color_type = png_get_color_type(png_ptr, info_ptr);
101 if (color_type == PNG_COLOR_TYPE_PALETTE) {
102 png_set_palette_to_rgb(png_ptr);
105 if ((color_type == PNG_COLOR_TYPE_GRAY) && (bit_depth < 8)) {
109 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
110 png_set_tRNS_to_alpha(png_ptr);
113 if (bit_depth == 16) {
114 png_set_strip_16(png_ptr);
117 if (color_type == PNG_COLOR_TYPE_GRAY ||
118 color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
119 png_set_gray_to_rgb(png_ptr);
125 png_set_bgr(png_ptr);
132 if (!(color_type & PNG_COLOR_MASK_ALPHA)) {
136 png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
140 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
147 png_set_swap_alpha(png_ptr);
159 if (png_get_sRGB(png_ptr, info_ptr, &intent)) {
160 png_set_gamma(png_ptr, 2.2, 0.45455);
162 if (png_get_gAMA(png_ptr, info_ptr, &gamma)) {
163 png_set_gamma(png_ptr, 2.2, gamma);
165 png_set_gamma(png_ptr, 2.2, 0.45455);
169 png_read_update_info(png_ptr, info_ptr);
182 width = png_get_image_width(png_s, info);
183 height = png_get_image_height(png_s, info);
184 interlace = png_get_interlace_type(png_s, info);
197 if (png_c->
bitmap == NULL) {
203 png_c->
bpp =
sizeof(uint32_t);
207 png_c->
rowbytes = png_get_rowbytes(png_s, info);
208 png_c->
interlace = (interlace == PNG_INTERLACE_ADAM7);
215 png_uint_32 row_num,
int pass)
218 unsigned long rowbytes = png_c->
rowbytes;
219 unsigned char *
buffer, *row;
222 if (png_c->
bitmap == NULL)
241 unsigned long dst_off;
242 unsigned long src_off = 0;
243 unsigned int start, step;
254 for (dst_off = start; dst_off < rowbytes; dst_off += step) {
255 row[dst_off++] = new_row[src_off++];
256 row[dst_off++] = new_row[src_off++];
257 row[dst_off++] = new_row[src_off++];
258 row[dst_off++] = new_row[src_off++];
262 memcpy(row, new_row, rowbytes);
275 png_c->
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
276 if (png_c->
png == NULL) {
283 png_c->
info = png_create_info_struct(png_c->
png);
284 if (png_c->
info == NULL) {
285 png_destroy_read_struct(&png_c->
png, &png_c->
info, 0);
292 png_destroy_read_struct(&png_c->
png, &png_c->
info, 0);
293 NSLOG(netsurf, INFO,
"Failed to set callbacks");
301 png_set_progressive_read_fn(png_c->
png, png_c,
309 lwc_string *imime_type,
312 const char *fallback_charset,
351 volatile bool ret =
true;
359 png_process_data(png_c->
png, png_c->
info, (uint8_t *)data,
size);
367 if (png_c->
bitmap != NULL) {
384 "Fatal PNG error during header, error content");
386 png_destroy_read_struct(&png_c->
png, &png_c->
info, 0);
412 png_cache_read_data = png_get_io_ptr(png_ptr);
414 if (length > png_cache_read_data->
size) {
415 length = png_cache_read_data->
size;
419 png_error(png_ptr,
"Read Error");
422 memcpy(
data, png_cache_read_data->
data, length);
424 png_cache_read_data->
data += length;
425 png_cache_read_data->
size -= length;
445 row_ptrs = malloc(
sizeof(png_bytep) *
height);
447 if (row_ptrs != NULL) {
448 for (hloop = 0; hloop <
height; hloop++) {
449 row_ptrs[hloop] =
buffer + (rowstride * hloop);
465 png_infop end_info_ptr;
469 volatile png_bytep *
volatile row_pointers = NULL;
471 png_cache_read_data.
data =
474 if ((png_cache_read_data.
data == NULL) ||
475 (png_cache_read_data.
size <= 8)) {
479 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
481 if (png_ptr == NULL) {
485 info_ptr = png_create_info_struct(png_ptr);
486 if (info_ptr == NULL) {
487 png_destroy_read_struct(&png_ptr, NULL, NULL);
491 end_info_ptr = png_create_info_struct(png_ptr);
492 if (end_info_ptr == NULL) {
493 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
500 goto png_cache_convert_error;
507 png_read_info(png_ptr, info_ptr);
512 width = png_get_image_width(png_ptr, info_ptr);
513 height = png_get_image_height(png_ptr, info_ptr);
519 goto png_cache_convert_error;
524 if (row_pointers != NULL) {
525 png_read_image(png_ptr, (png_bytep *) row_pointers);
531png_cache_convert_error:
534 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info_ptr);
536 if (row_pointers != NULL) {
537 free((png_bytep *) row_pointers);
558 assert(png_c->
png != NULL);
559 assert(png_c->
info != NULL);
562 png_destroy_read_struct(&png_c->
png, &png_c->
info, 0);
573 if (png_c->
bitmap != NULL) {
577 .layout = bitmap_fmt.layout,
578 .pma = opaque ? bitmap_fmt.pma : false,
601 if (clone_png_c == NULL)
633 *new_c = (
struct content *)clone_png_c;
static osspriteop_area * buffer
The buffer characteristics.
void content_destroy(struct content *c)
Destroy and free a content.
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.
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
Send an error message to all users.
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.
Internal core bitmap interface.
static void bitmap_format_to_client(void *bitmap, const bitmap_fmt_t *current_fmt)
Convert a bitmap to the client bitmap format.
nserror
Enumeration of error codes.
@ NSERROR_PNG_ERROR
A PNG error occurred.
@ 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.
bool image_cache_speculate(struct content *c)
Decide if a content should be speculatively converted.
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.
bool bitmap_test_opaque(void *bitmap)
Test whether a bitmap is completely opaque (no transparency).
@ BITMAP_LAYOUT_B8G8R8A8
Bite-wise BGRA: Byte order: 0xBB, 0xGG, 0xRR, 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.
Netsurf additional integer type formatting macros.
#define PRIsizet
c99 standard printf formatting for size_t type
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.
static void nspng_error(png_structp png_ptr, png_const_charp error_message)
nspng_error – callback for libpng errors
static unsigned int interlace_row_start[8]
static void end_callback(png_structp png_s, png_infop info)
CONTENT_FACTORY_REGISTER_TYPES(nspng, nspng_types, nspng_content_handler)
struct nspng_content nspng_content
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.
static const content_handler nspng_content_handler
static nserror nspng_create_png_data(nspng_content *png_c)
static unsigned int interlace_start[8]
static const char * nspng_types[]
nspng_cberr
Callbak error numbers.
#define png_jmpbuf(png_ptr)
#define png_set_expand_gray_1_2_4_to_8(png)
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 void row_callback(png_structp png_s, png_bytep new_row, png_uint_32 row_num, int pass)
static void nspng_warning(png_structp png_ptr, png_const_charp warning_message)
nspng_warning – callback for libpng warnings
static png_bytep * calc_row_pointers(struct bitmap *bitmap)
calculate an array of row pointers into a bitmap data area
static void info_callback(png_structp png_s, png_infop info)
info_callback – PNG header has been completely received, prepare to process image data
static unsigned int interlace_step[8]
static struct bitmap * png_cache_convert(struct content *c)
PNG content to bitmap conversion.
static unsigned int interlace_row_step[8]
static void nspng_setup_transforms(png_structp png_ptr, png_infop info_ptr)
static nserror nspng_clone(const struct content *old_c, struct content **new_c)
static bool nspng_convert(struct content *c)
static bool nspng_process_data(struct content *c, const char *data, unsigned int size)
Interface to utility string handling.
bool pma
Premultiplied alpha.
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.
int height
Height dimension, if applicable.
int width
Width dimension, if applicable.
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(* set_opaque)(void *bitmap, bool opaque)
Set the opacity of a bitmap.
int(* get_height)(void *bitmap)
Get the bitmap height.
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.
size_t rowbytes
Number of bytes per row.
bool no_process_data
Do not continue to process data as it arrives.
struct bitmap * bitmap
Created NetSurf bitmap.
struct content base
base content type
size_t bpp
Bitmap rowstride and bpp.
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.