NetSurf
Functions | Variables
jpegxl.c File Reference

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

#include <stdbool.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
#include <jxl/decode.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 "image/jpegxl.h"
Include dependency graph for jpegxl.c:

Go to the source code of this file.

Functions

static nserror nsjpegxl_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 struct bitmapjpegxl_cache_convert (struct content *c)
 create a bitmap from jpeg xl content. More...
 
static bool jxl_report_fail (struct content *c, JxlDecoderStatus decstatus, const char *msg)
 report failiure More...
 
static bool nsjpegxl_convert (struct content *c)
 Convert a CONTENT_JPEGXL for display. More...
 
static nserror nsjpegxl_clone (const struct content *old, struct content **newc)
 Clone content. More...
 
 CONTENT_FACTORY_REGISTER_TYPES (nsjpegxl, nsjpegxl_types, nsjpegxl_content_handler)
 

Variables

static const JxlPixelFormat jxl_output_format
 output image format More...
 
static const content_handler nsjpegxl_content_handler
 
static const char * nsjpegxl_types []
 

Detailed Description

implementation of content handling for image/jpegxl

This implementation uses the JXL library.

Definition in file jpegxl.c.

Function Documentation

◆ CONTENT_FACTORY_REGISTER_TYPES()

CONTENT_FACTORY_REGISTER_TYPES ( nsjpegxl  ,
nsjpegxl_types  ,
nsjpegxl_content_handler   
)

◆ jpegxl_cache_convert()

static struct bitmap * jpegxl_cache_convert ( struct content c)
static

create a bitmap from jpeg xl content.

TODO: At the moment we have to set the layout to the only pixel layout that libjxl supports. It looks like they plan to add support for decoding to other layouts in the future, as shown by the TODO in the docs:

https://libjxl.readthedocs.io/en/latest/api_common.html#_CPPv414JxlPixelFormat

Definition at line 91 of file jpegxl.c.

References netsurf_table::bitmap, bitmap(), bitmap_format_to_client(), BITMAP_LAYOUT_R8G8B8A8, BITMAP_NONE, BITMAP_OPAQUE, content__get_source_data(), gui_bitmap_table::create, gui_bitmap_table::destroy, gui_bitmap_table::get_buffer, guit, content::height, jxl_output_format, bitmap_fmt::layout, gui_bitmap_table::modified, NSLOG, bitmap_fmt::pma, content::size, and content::width.

Referenced by nsjpegxl_convert().

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

◆ jxl_report_fail()

static bool jxl_report_fail ( struct content c,
JxlDecoderStatus  decstatus,
const char *  msg 
)
static

report failiure

Definition at line 203 of file jpegxl.c.

References content_broadcast(), CONTENT_MSG_ERROR, content_msg_data::errorcode, content_msg_data::errordata, content_msg_data::errormsg, content_msg_data::msg, NSERROR_UNKNOWN, and NSLOG.

Referenced by nsjpegxl_convert().

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

◆ nsjpegxl_clone()

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

Clone content.

Definition at line 295 of file jpegxl.c.

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

Here is the call graph for this function:

◆ nsjpegxl_convert()

static bool nsjpegxl_convert ( struct content c)
static

Convert a CONTENT_JPEGXL for display.

Definition at line 216 of file jpegxl.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(), jpegxl_cache_convert(), jxl_output_format, jxl_report_fail(), content::llcache, llcache_handle_get_url(), messages_get_buff(), NSERROR_UNKNOWN, NSLOG, nsurl_access_leaf(), content::size, content_msg_data::title, and content::width.

Referenced by nsjpegxl_clone().

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

◆ nsjpegxl_create()

static nserror nsjpegxl_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 63 of file jpegxl.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:

Variable Documentation

◆ jxl_output_format

const JxlPixelFormat jxl_output_format
static
Initial value:
= {
.num_channels = 4,
.data_type = JXL_TYPE_UINT8,
.endianness = JXL_LITTLE_ENDIAN,
.align = 0,
}

output image format

Definition at line 52 of file jpegxl.c.

Referenced by jpegxl_cache_convert(), and nsjpegxl_convert().

◆ nsjpegxl_content_handler

const content_handler nsjpegxl_content_handler
static
Initial value:
= {
.create = nsjpegxl_create,
.data_complete = nsjpegxl_convert,
.destroy = image_cache_destroy,
.redraw = image_cache_redraw,
.clone = nsjpegxl_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 bool nsjpegxl_convert(struct content *c)
Convert a CONTENT_JPEGXL for display.
Definition: jpegxl.c:216
static nserror nsjpegxl_clone(const struct content *old, struct content **newc)
Clone content.
Definition: jpegxl.c:295
static nserror nsjpegxl_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: jpegxl.c:63

Definition at line 324 of file jpegxl.c.

◆ nsjpegxl_types

const char* nsjpegxl_types[]
static
Initial value:
= {
"image/jxl",
}

Definition at line 336 of file jpegxl.c.