libwebsockets
Lightweight C library for HTML5 websockets
lws-upng.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum lws_upng_format_t lws_upng_format_t
 
typedef struct lws_upng_t lws_upng_t
 

Enumerations

enum  lws_upng_format_t {
  LWS_UPNG_BADFORMAT , LWS_UPNG_RGB8 , LWS_UPNG_RGB16 , LWS_UPNG_RGBA8 ,
  LWS_UPNG_RGBA16 , LWS_UPNG_LUMINANCE1 , LWS_UPNG_LUMINANCE2 , LWS_UPNG_LUMINANCE4 ,
  LWS_UPNG_LUMINANCE8 , LWS_UPNG_LUMINANCE_ALPHA1 , LWS_UPNG_LUMINANCE_ALPHA2 , LWS_UPNG_LUMINANCE_ALPHA4 ,
  LWS_UPNG_LUMINANCE_ALPHA8
}
 

Functions

LWS_VISIBLE LWS_EXTERN lws_upng_tlws_upng_new (void)
 
LWS_VISIBLE LWS_EXTERN void lws_upng_free (lws_upng_t **upng)
 
LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_upng_emit_next_line (lws_upng_t *upng, const uint8_t **ppix, const uint8_t **buf, size_t *size, char hold_at_metadata)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_width (const lws_upng_t *upng)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_height (const lws_upng_t *upng)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_bpp (const lws_upng_t *upng)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_bitdepth (const lws_upng_t *upng)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_components (const lws_upng_t *upng)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_pixelsize (const lws_upng_t *upng)
 
LWS_VISIBLE LWS_EXTERN lws_upng_format_t lws_upng_get_format (const lws_upng_t *upng)
 
LWS_VISIBLE LWS_EXTERN struct inflator_ctx * lws_upng_inflator_create (const uint8_t **outring, size_t *outringlen, size_t **opl, size_t **cl)
 
LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_upng_inflate_data (struct inflator_ctx *inf, const void *buf, size_t len)
 
LWS_VISIBLE LWS_EXTERN void lws_upng_inflator_destroy (struct inflator_ctx **inf)
 

Typedef Documentation

◆ lws_upng_format_t

◆ lws_upng_t

typedef struct lws_upng_t lws_upng_t

Definition at line 1 of file lws-upng.h.

Enumeration Type Documentation

◆ lws_upng_format_t

Enumerator
LWS_UPNG_BADFORMAT 
LWS_UPNG_RGB8 
LWS_UPNG_RGB16 
LWS_UPNG_RGBA8 
LWS_UPNG_RGBA16 
LWS_UPNG_LUMINANCE1 
LWS_UPNG_LUMINANCE2 
LWS_UPNG_LUMINANCE4 
LWS_UPNG_LUMINANCE8 
LWS_UPNG_LUMINANCE_ALPHA1 
LWS_UPNG_LUMINANCE_ALPHA2 
LWS_UPNG_LUMINANCE_ALPHA4 
LWS_UPNG_LUMINANCE_ALPHA8 

Definition at line 34 of file lws-upng.h.

34  {
lws_upng_format_t
Definition: lws-upng.h:34
@ LWS_UPNG_LUMINANCE8
Definition: lws-upng.h:43
@ LWS_UPNG_RGBA16
Definition: lws-upng.h:39
@ LWS_UPNG_RGBA8
Definition: lws-upng.h:38
@ LWS_UPNG_LUMINANCE2
Definition: lws-upng.h:41
@ LWS_UPNG_RGB16
Definition: lws-upng.h:37
@ LWS_UPNG_LUMINANCE4
Definition: lws-upng.h:42
@ LWS_UPNG_LUMINANCE_ALPHA8
Definition: lws-upng.h:47
@ LWS_UPNG_LUMINANCE_ALPHA4
Definition: lws-upng.h:46
@ LWS_UPNG_RGB8
Definition: lws-upng.h:36
@ LWS_UPNG_LUMINANCE1
Definition: lws-upng.h:40
@ LWS_UPNG_BADFORMAT
Definition: lws-upng.h:35
@ LWS_UPNG_LUMINANCE_ALPHA1
Definition: lws-upng.h:44
@ LWS_UPNG_LUMINANCE_ALPHA2
Definition: lws-upng.h:45

Function Documentation

◆ lws_upng_new()

LWS_VISIBLE LWS_EXTERN lws_upng_t* lws_upng_new ( void  )

lws_upng_new() - Create new UPNG decode object

Returns a new PNG decoding object, which should be destroyed with lws_upng_free() when done with, or NULL if OOM.

◆ lws_upng_free()

LWS_VISIBLE LWS_EXTERN void lws_upng_free ( lws_upng_t **  upng)

lws_upng_free() - Destroy a PNG decode object

Parameters
upngPointer to the decode object to destroy and set to NULL

This also frees any sub-allocations in the object.

◆ lws_upng_emit_next_line()

LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_upng_emit_next_line ( lws_upng_t upng,
const uint8_t **  ppix,
const uint8_t **  buf,
size_t *  size,
char  hold_at_metadata 
)

lws_upng_emit_next_line() - deocde the next line

Parameters
upngthe decode object
ppixpointer to a pointer set to the line's decoded pixel data
bufpointer to a const uint8_t array of PNG input
sizepointer to the count of bytes available at *buf
hold_at_metadatatrue if we should not advance to decode

Make PNG input available to the decoder so it can issue the next line's worth of pixels. If the call consumed any input, *buf and *size are adjusted accordingly.

The decoder is stateful so it is not sensitive to the chunk size for the input.

If hold_at_metadata is set, then the decoder will only go as far as picking out the metadata like image dimensions, but not start the decode, which requires the >30KB heap allocation. This lets you put off for as long as possible committing to the decode allocation... this only helps overall if you have flow controlled the incoming PNG data.

Return will be one of LWS_SRET_WANT_INPUT is the decoder is stalled waiting for more input to be provided, LWS_SRET_WANT_OUTPUT is the decoder stopped because it had produced a whole line of output pixels (which can be found starting at *ppix), LWS_SRET_OK is it completed and LWS_SRET_FATAL or larger if the decode failed.

◆ lws_upng_get_width()

LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_width ( const lws_upng_t upng)

◆ lws_upng_get_height()

LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_height ( const lws_upng_t upng)

◆ lws_upng_get_bpp()

LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_bpp ( const lws_upng_t upng)

◆ lws_upng_get_bitdepth()

LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_bitdepth ( const lws_upng_t upng)

◆ lws_upng_get_components()

LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_components ( const lws_upng_t upng)

◆ lws_upng_get_pixelsize()

LWS_VISIBLE LWS_EXTERN unsigned int lws_upng_get_pixelsize ( const lws_upng_t upng)

◆ lws_upng_get_format()

LWS_VISIBLE LWS_EXTERN lws_upng_format_t lws_upng_get_format ( const lws_upng_t upng)

◆ lws_upng_inflator_create()

LWS_VISIBLE LWS_EXTERN struct inflator_ctx* lws_upng_inflator_create ( const uint8_t **  outring,
size_t *  outringlen,
size_t **  opl,
size_t **  cl 
)

lws_upng_inflator_create() - create a gzip inflator context

Parameters
outringpointer set to the output ringbuffer on exit
outringlensize of the output ringbuffer set on exit
oplpointer to set to point to ctx outpos_linear
clpointer to set to point to ctx consumed_linear

Creates an opaque gzip inflator object.

◆ lws_upng_inflate_data()

LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_upng_inflate_data ( struct inflator_ctx *  inf,
const void *  buf,
size_t  len 
)

lws_upng_inflate_data() - inflate compressed data statefully

Parameters
infinflator context created with lws_upng_inflator_create()
bufNULL to continue consumption of existing input, or new input
lenignored if buf is NULL, else amount of new input at buf

Tries to progress the inflation. If output is available, *opl will be further along than before it was called. *cl should be set to opl to consume the available output data.

Output is into a ringfuffer, typically sized at 32KB. opl and cl are "linear", that is extend beyond the ringbuffer. They should be modulo outringlen (given when the inflator was created) when accessing outring.

◆ lws_upng_inflator_destroy()

LWS_VISIBLE LWS_EXTERN void lws_upng_inflator_destroy ( struct inflator_ctx **  inf)

lws_upng_inflator_destroy() - destroys the inflation context and ringbuffer

inf: pointer to pointer to inflation context

Frees the inflation context and its allocations, and sets *inf to NULL.