31#include <jxl/decode.h>
54 .data_type = JXL_TYPE_UINT8,
55 .endianness = JXL_LITTLE_ENDIAN,
66 bool quirks,
struct content **c)
71 jpeg = calloc(1,
sizeof(
struct content));
95 JxlDecoderStatus decstatus;
97 const uint8_t *src_data;
112 jxldec = JxlDecoderCreate(NULL);
113 if (jxldec == NULL) {
114 NSLOG(netsurf, ERROR,
"Unable to allocate decoder");
118 decstatus = JxlDecoderSetUnpremultiplyAlpha(jxldec, !
bitmap_fmt.
pma);
119 if (decstatus != JXL_DEC_SUCCESS) {
120 NSLOG(netsurf, ERROR,
"unable to set premultiplied alpha status: %d",
122 JxlDecoderDestroy(jxldec);
126 decstatus= JxlDecoderSubscribeEvents(jxldec, JXL_DEC_FULL_IMAGE);
127 if (decstatus != JXL_DEC_SUCCESS) {
128 NSLOG(netsurf, ERROR,
"Unable to subscribe");
133 decstatus = JxlDecoderSetInput(jxldec, src_data, src_size);
134 if (decstatus != JXL_DEC_SUCCESS) {
135 NSLOG(netsurf, ERROR,
"unable to set input");
139 decstatus = JxlDecoderProcessInput(jxldec);
140 if (decstatus != JXL_DEC_NEED_IMAGE_OUT_BUFFER) {
141 NSLOG(netsurf, ERROR,
142 "expected status JXL_DEC_NEED_IMAGE_OUT_BUFFER(%d) got %d",
143 JXL_DEC_NEED_IMAGE_OUT_BUFFER,
145 JxlDecoderDestroy(jxldec);
149 decstatus = JxlDecoderGetBasicInfo(jxldec, &binfo);
150 if (decstatus != JXL_DEC_SUCCESS) {
151 NSLOG(netsurf, ERROR,
"unable to get basic info status:%d",decstatus);
152 JxlDecoderDestroy(jxldec);
157 if (binfo.alpha_bits > 0) {
164 JxlDecoderDestroy(jxldec);
170 if (output == NULL) {
173 JxlDecoderDestroy(jxldec);
177 if (decstatus != JXL_DEC_SUCCESS) {
178 NSLOG(netsurf, ERROR,
"unable to set output buffer callback status:%d",decstatus);
180 JxlDecoderDestroy(jxldec);
184 decstatus = JxlDecoderProcessInput(jxldec);
185 if (decstatus != JXL_DEC_FULL_IMAGE) {
186 NSLOG(netsurf, ERROR,
"did not get decode event");
188 JxlDecoderDestroy(jxldec);
192 JxlDecoderDestroy(jxldec);
206 NSLOG(netsurf, ERROR,
"%s decoder status:%d",
msg, decstatus);
220 JxlDecoderStatus decstatus = JXL_DEC_ERROR;
231 decsig = JxlSignatureCheck(data,size);
232 if ((decsig != JXL_SIG_CODESTREAM) && (decsig != JXL_SIG_CONTAINER)) {
233 NSLOG(netsurf, ERROR,
"signature failed");
240 jxldec = JxlDecoderCreate(NULL);
241 if (jxldec == NULL) {
244 decstatus= JxlDecoderSubscribeEvents(jxldec, JXL_DEC_BASIC_INFO);
245 if (decstatus != JXL_DEC_SUCCESS) {
248 decstatus = JxlDecoderSetInput(jxldec, data,size);
249 if (decstatus != JXL_DEC_SUCCESS) {
252 decstatus = JxlDecoderProcessInput(jxldec);
253 if (decstatus != JXL_DEC_BASIC_INFO) {
256 decstatus = JxlDecoderGetBasicInfo(jxldec, &binfo);
257 if (decstatus != JXL_DEC_SUCCESS) {
260 decstatus = JxlDecoderImageOutBufferSize(jxldec, &
jxl_output_format, &image_size);
261 if (decstatus != JXL_DEC_SUCCESS) {
265 JxlDecoderDestroy(jxldec);
267 NSLOG(netsurf, INFO,
"got basic info size:%ld x:%d y:%d", image_size, binfo.xsize, binfo.ysize);
269 c->
width = binfo.xsize;
271 c->
size = image_size;
300 jpegxl_c = calloc(1,
sizeof(
struct content));
301 if (jpegxl_c == NULL)
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.
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_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_R8G8B8A8
Bite-wise RGBA: Byte order: 0xRR, 0xGG, 0xBB, 0xAA.
static const JxlPixelFormat jxl_output_format
output image format
CONTENT_FACTORY_REGISTER_TYPES(nsjpegxl, nsjpegxl_types, nsjpegxl_content_handler)
static bool jxl_report_fail(struct content *c, JxlDecoderStatus decstatus, const char *msg)
report failiure
static bool nsjpegxl_convert(struct content *c)
Convert a CONTENT_JPEGXL for display.
static nserror nsjpegxl_clone(const struct content *old, struct content **newc)
Clone content.
static const char * nsjpegxl_types[]
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.
static struct bitmap * jpegxl_cache_convert(struct content *c)
create a bitmap from jpeg xl content.
static const content_handler nsjpegxl_content_handler
Content for image/jpegxl (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.
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.
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.
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 * msg
The message to log.
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.