121 unsigned int grid_width_log2;
122 unsigned int grid_height_log2;
123 unsigned int x_indent;
124 unsigned int y_indent;
125 unsigned int x_stride_log2;
126 unsigned int y_stride_log2;
127 unsigned int x_stride;
128 unsigned int y_stride;
136 interlace->
pass = pass;
139 grid_width_log2 = ( png->
passes / 2 );
140 grid_height_log2 = ( ( png->
passes - 1 ) / 2 );
145 ( 1 << ( grid_width_log2 - ( pass / 2 ) - 1 ) ) : 0 );
147 ( ( pass && ! ( pass & 1 ) ) ?
148 ( 1 << ( grid_height_log2 - ( ( pass - 1 ) / 2 ) - 1 ) ) : 0);
151 x_stride_log2 = ( grid_width_log2 - ( pass / 2 ) );
153 ( grid_height_log2 - ( pass ? ( ( pass - 1 ) / 2 ) : 0 ) );
154 interlace->
x_stride = x_stride = ( 1 << x_stride_log2 );
155 interlace->
y_stride = y_stride = ( 1 << y_stride_log2 );
161 ( ( width - x_indent + x_stride - 1 ) >> x_stride_log2 );
163 ( ( height - y_indent + y_stride - 1 ) >> y_stride_log2 );
196 return ( 1 + (
bits / 8 ) + ( !! (
bits & 7 ) ) );
216 if (
len !=
sizeof ( *ihdr ) ) {
217 DBGC (
image,
"PNG %s invalid IHDR length %zd\n",
228 DBGC (
image,
"PNG %s %dx%d depth %d type %d compression %d filter %d "
235 DBGC (
image,
"PNG %s unknown compression method %d\n",
240 DBGC (
image,
"PNG %s unknown filter method %d\n",
245 DBGC (
image,
"PNG %s unknown interlace method %d\n",
254 DBGC (
image,
"PNG %s could not allocate pixel buffer\n",
261 if ( ( png->
depth == 0 ) ||
262 ( ( png->
depth & ( png->
depth - 1 ) ) != 0 ) ) {
263 DBGC (
image,
"PNG %s invalid depth %d\n",
284 if ( interlace.
width == 0 )
287 if ( ! scanline_len )
289 pass_len = ( interlace.
height * scanline_len );
290 if ( ( pass_len / scanline_len ) != interlace.
height )
293 if ( png->
raw.
len < pass_len )
300 DBGC (
image,
"PNG %s could not allocate data buffer\n",
323 for ( i = 0 ; i < (
sizeof ( png->
palette ) /
324 sizeof ( png->
palette[0] ) ) ; i++ ) {
327 if (
len <
sizeof ( *palette ) )
332 ( palette->
green << 8 ) |
333 ( palette->
blue << 0 ) );
334 DBGC2 (
image,
"PNG %s palette entry %d is %#06x\n",
339 len -=
sizeof ( *palette );
360 len, &png->
raw ) ) != 0 ) {
361 DBGC (
image,
"PNG %s could not decompress: %s\n",
381 unsigned int above_left
__unused ) {
398 unsigned int above_left
__unused ) {
400 return ( current + left );
415 unsigned int above_left
__unused ) {
417 return ( current + above );
432 unsigned int above_left
__unused ) {
434 return ( current + ( ( above + left ) >> 1 ) );
457 if ( ( pa <= pb ) && ( pa <= pc ) ) {
459 }
else if ( pb <= pc ) {
478 unsigned int above_left ) {
494 unsigned int ( *
unfilter ) (
unsigned int current,
497 unsigned int above_left );
526 unsigned int scanline;
528 unsigned int filter_type;
531 unsigned int above_left;
539 for ( scanline = 0 ; scanline < interlace->
height ; scanline++ ) {
542 filter_type = *(
data++);
545 DBGC (
image,
"PNG %s unknown filter type %d\n",
551 DBGC2 (
image,
"PNG %s pass %d scanline %d filter type %d\n",
561 for (
byte = 0 ;
byte < ( scanline_len - 1 ) ;
byte++ ) {
564 if (
byte >= pixel_len )
565 left = *(
data - pixel_len );
567 above = *(
data - scanline_len );
568 if ( ( scanline > 0 ) && (
byte >= pixel_len ) ) {
569 above_left = *(
data - scanline_len -
609 if ( interlace.
width == 0 )
614 &interlace ) ) != 0 )
630static inline unsigned int png_pixel (
unsigned int raw,
unsigned int alpha,
639 return ( ( ( ( ( 0xff00 *
raw * alpha ) /
max ) /
max ) + 0x80 ) >> 8 );
662 unsigned int pixbuf_y_index;
663 unsigned int pixbuf_index;
664 unsigned int pixbuf_x_stride;
665 unsigned int pixbuf_y_stride;
682 data_stride = ( ( depth + 7 ) / 8 );
685 max = ( ( 1 << depth ) - 1 );
690 pixbuf_x_stride = interlace->
x_stride;
692 DBGC2 (
image,
"PNG %s pass %d %dx%d at (%d,%d) stride (%d,%d)\n",
698 for (
y = 0 ;
y < interlace->
height ;
y++ ) {
705 pixbuf_index = pixbuf_y_index;
706 for (
x = 0 ;
x < interlace->
width ;
x++ ) {
709 for ( c = 0 ; c < png->
channels ; c++ ) {
721 channel[c] = ( current >> ( 8 - depth ) );
733 alpha = ( has_alpha ?
738 for ( c = 0 ; c < 3 ; c++ ) {
742 pixel = ( ( pixel << 8 ) |
value );
748 pixbuf_index += pixbuf_x_stride;
752 pixbuf_y_index += pixbuf_y_stride;
781 if ( interlace.
width == 0 )
804 DBGC (
image,
"PNG %s invalid IEND length %zd\n",
809 DBGC (
image,
"PNG %s missing pixel buffer (no IHDR?)\n",
814 DBGC (
image,
"PNG %s decompression not complete\n",
819 DBGC (
image,
"PNG %s incorrect decompressed length (expected "
873 DBGC (
image,
"PNG %s chunk type %s offset %zd length %zd\n",
886 DBGC (
image,
"PNG %s unknown critical chunk type %s\n",
911 png =
zalloc (
sizeof ( *png ) );
924 if ( remaining < (
sizeof ( *
header ) +
sizeof ( *footer ) ) ){
925 DBGC (
image,
"PNG %s truncated chunk header/footer "
931 png->
offset +=
sizeof ( *header );
935 if ( chunk_len > ( remaining -
sizeof ( *
header ) -
936 sizeof ( *footer ) ) ) {
937 DBGC (
image,
"PNG %s truncated chunk data at offset "
949 png->
offset += ( chunk_len +
sizeof ( *footer ) );
955 DBGC (
image,
"PNG %s did not finish with IEND\n",
962 *pixbuf = pixbuf_get ( png->
pixbuf );
970 pixbuf_put ( png->
pixbuf );
#define NULL
NULL pointer (VOID *).
u8 signature
CPU signature.
struct arbelprm_rc_send_wqe rc
pseudo_bit_t value[0x00020]
static volatile void * bits
#define assert(condition)
Assert a condition at run-time.
void deflate_init(struct deflate *deflate, enum deflate_format format)
Initialise decompressor.
int deflate_inflate(struct deflate *deflate, const void *data, size_t len, struct deflate_chunk *out)
Inflate compressed data.
DEFLATE decompression algorithm.
static int deflate_finished(struct deflate *deflate)
Check if decompression has finished.
@ DEFLATE_ZLIB
ZLIB header and footer.
union @104331263140136355135267063077374276003064103115 u
uint32_t type
Operating system type.
uint8_t data[48]
Additional event data.
struct ena_llq_option header
Header locations.
#define __unused
Declare a variable or data structure as unused.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define EINVAL
Invalid argument.
#define ENOEXEC
Exec format error.
#define ENOMEM
Not enough space.
#define ENOTSUP
Operation not supported.
#define ERANGE
Result too large.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define PROBE_NORMAL
Normal image probe priority.
#define __image_type(probe_order)
An executable image type.
static __always_inline void * umalloc(size_t size)
Allocate external memory.
static __always_inline void ufree(void *ptr)
Free external memory.
void * zalloc(size_t size)
Allocate cleared memory.
uint32_t channel
RNDIS channel.
struct pixel_buffer * alloc_pixbuf(unsigned int width, unsigned int height)
Allocate pixel buffer.
static unsigned int unsigned int y
static int png_unfilter_pass(struct image *image, struct png_context *png, struct png_interlace *interlace)
Unfilter one interlace pass of PNG raw data.
static int png_pixbuf(struct image *image, struct pixel_buffer **pixbuf)
Convert PNG image to pixel buffer.
static unsigned int png_unfilter_average(unsigned int current, unsigned int left, unsigned int above, unsigned int above_left __unused)
Unfilter byte using the "Average" filter.
static unsigned int png_pixel(unsigned int raw, unsigned int alpha, unsigned int max)
Calculate PNG pixel component value.
static int png_unfilter(struct image *image, struct png_context *png)
Unfilter PNG raw data.
static void png_pixels_pass(struct image *image, struct png_context *png, struct png_interlace *interlace)
Fill one interlace pass of PNG pixels.
static int png_image_data(struct image *image, struct png_context *png, size_t len)
Handle PNG image data chunk.
static uint8_t png_interlace_passes[]
Number of interlacing passes.
static int png_palette(struct image *image, struct png_context *png, size_t len)
Handle PNG palette chunk.
static unsigned int png_pixel_len(struct png_context *png)
Calculate PNG pixel length.
static unsigned int png_unfilter_none(unsigned int current, unsigned int left __unused, unsigned int above __unused, unsigned int above_left __unused)
Unfilter byte using the "None" filter.
static int png_probe(struct image *image)
Probe PNG image.
static int png_image_header(struct image *image, struct png_context *png, size_t len)
Handle PNG image header chunk.
static struct png_chunk_handler png_chunk_handlers[]
PNG chunk handlers.
static unsigned int png_unfilter_sub(unsigned int current, unsigned int left, unsigned int above __unused, unsigned int above_left __unused)
Unfilter byte using the "Sub" filter.
static size_t png_scanline_len(struct png_context *png, struct png_interlace *interlace)
Calculate PNG scanline length.
static int png_chunk(struct image *image, struct png_context *png, uint32_t type, size_t len)
Handle PNG chunk.
static unsigned int png_paeth_predictor(unsigned int a, unsigned int b, unsigned int c)
Paeth predictor function (defined in RFC 2083).
static void png_pixels(struct image *image, struct png_context *png)
Fill PNG pixels.
static void png_interlace(struct png_context *png, unsigned int pass, struct png_interlace *interlace)
Calculate PNG interlace pass parameters.
static int png_image_end(struct image *image, struct png_context *png, size_t len)
Handle PNG image end chunk.
static unsigned int png_unfilter_up(unsigned int current, unsigned int left __unused, unsigned int above, unsigned int above_left __unused)
Unfilter byte using the "Up" filter.
static const char * png_type_name(uint32_t type)
Transcribe PNG chunk type name (for debugging).
static unsigned int png_unfilter_paeth(unsigned int current, unsigned int left, unsigned int above, unsigned int above_left)
Unfilter byte using the "Paeth" filter.
static struct png_filter png_filters[]
PNG filter types.
Portable Network Graphics (PNG) format.
#define PNG_TYPE_IDAT
PNG image data chunk type.
@ PNG_CHUNK_ANCILLARY
Chunk is ancillary.
#define PNG_SIGNATURE
PNG file signature.
@ PNG_FILTER_UNKNOWN
First unknown filter method.
@ PNG_INTERLACE_NONE
No interlacing.
@ PNG_INTERLACE_UNKNOWN
First unknown interlace method.
@ PNG_INTERLACE_ADAM7
Adam7 interlacing.
#define PNG_TYPE_IHDR
PNG image header chunk type.
#define PNG_TYPE_IEND
PNG image end chunk type.
@ PNG_FILTER_BASIC_SUB
Left byte used as predictor.
@ PNG_FILTER_BASIC_UP
Above byte used as predictor.
@ PNG_FILTER_BASIC_PAETH
Paeth filter.
@ PNG_FILTER_BASIC_AVERAGE
Above and left bytes used as predictors.
@ PNG_FILTER_BASIC_NONE
No filtering.
#define PNG_TYPE_PLTE
PNG palette chunk type.
#define PNG_PALETTE_COUNT
Maximum number of PNG palette entries.
@ PNG_COLOUR_TYPE_ALPHA
Alpha channel is used.
@ PNG_COLOUR_TYPE_PALETTE
Palette is used.
@ PNG_COLOUR_TYPE_RGB
RGB colour is used.
@ PNG_COMPRESSION_UNKNOWN
First unknown compression method.
UINT8_t filter
Receive packet filter.
static void(* free)(struct refcnt *refcnt))
char * strerror(int errno)
Retrieve string representation of error number.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
size_t offset
Current offset.
size_t len
Length of data.
An executable image type.
const void * data
Read-only data.
size_t len
Length of raw file image.
unsigned int height
Height.
uint32_t * data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
int(* handle)(struct image *image, struct png_context *png, size_t len)
Handle chunk.
size_t offset
Offset within image.
struct deflate_chunk raw
Decompression buffer for raw PNG data.
struct pixel_buffer * pixbuf
Pixel buffer.
struct deflate deflate
Decompressor.
unsigned int channels
Number of channels.
unsigned int colour_type
Colour type.
unsigned int passes
Number of interlace passes.
unsigned int depth
Bit depth.
uint32_t palette[PNG_PALETTE_COUNT]
Palette, in iPXE's pixel buffer format.
unsigned int(* unfilter)(unsigned int current, unsigned int left, unsigned int above, unsigned int above_left)
Unfilter byte.
unsigned int x_stride
X stride.
unsigned int height
Height.
unsigned int y_stride
Y stride.
unsigned int y_indent
Y starting indent.
unsigned int x_indent
X starting indent.
unsigned int pass
Pass number.