120 unsigned int grid_width_log2;
121 unsigned int grid_height_log2;
122 unsigned int x_indent;
123 unsigned int y_indent;
124 unsigned int x_stride_log2;
125 unsigned int y_stride_log2;
126 unsigned int x_stride;
127 unsigned int y_stride;
135 interlace->
pass = pass;
138 grid_width_log2 = ( png->
passes / 2 );
139 grid_height_log2 = ( ( png->
passes - 1 ) / 2 );
144 ( 1 << ( grid_width_log2 - ( pass / 2 ) - 1 ) ) : 0 );
146 ( ( pass && ! ( pass & 1 ) ) ?
147 ( 1 << ( grid_height_log2 - ( ( pass - 1 ) / 2 ) - 1 ) ) : 0);
150 x_stride_log2 = ( grid_width_log2 - ( pass / 2 ) );
152 ( grid_height_log2 - ( pass ? ( ( pass - 1 ) / 2 ) : 0 ) );
153 interlace->
x_stride = x_stride = ( 1 << x_stride_log2 );
154 interlace->
y_stride = y_stride = ( 1 << y_stride_log2 );
160 ( ( width - x_indent + x_stride - 1 ) >> x_stride_log2 );
162 ( ( height - y_indent + y_stride - 1 ) >> y_stride_log2 );
205 if (
len !=
sizeof ( *ihdr ) ) {
206 DBGC (
image,
"PNG %s invalid IHDR length %zd\n",
217 DBGC (
image,
"PNG %s %dx%d depth %d type %d compression %d filter %d " 224 DBGC (
image,
"PNG %s unknown compression method %d\n",
229 DBGC (
image,
"PNG %s unknown filter method %d\n",
234 DBGC (
image,
"PNG %s unknown interlace method %d\n",
243 DBGC (
image,
"PNG %s could not allocate pixel buffer\n",
250 if ( ( png->
depth == 0 ) ||
251 ( ( png->
depth & ( png->
depth - 1 ) ) != 0 ) ) {
252 DBGC (
image,
"PNG %s invalid depth %d\n",
273 if ( interlace.
width == 0 )
282 DBGC (
image,
"PNG %s could not allocate data buffer\n",
305 for ( i = 0 ; i < (
sizeof ( png->
palette ) /
306 sizeof ( png->
palette[0] ) ) ; i++ ) {
309 if (
len <
sizeof ( *palette ) )
314 ( palette->
green << 8 ) |
315 ( palette->
blue << 0 ) );
316 DBGC2 (
image,
"PNG %s palette entry %d is %#06x\n",
321 len -=
sizeof ( *palette );
342 len, &png->
raw ) ) != 0 ) {
343 DBGC (
image,
"PNG %s could not decompress: %s\n",
363 unsigned int above_left
__unused ) {
380 unsigned int above_left
__unused ) {
382 return ( current + left );
397 unsigned int above_left
__unused ) {
399 return ( current + above );
414 unsigned int above_left
__unused ) {
416 return ( current + ( ( above + left ) >> 1 ) );
439 if ( ( pa <= pb ) && ( pa <= pc ) ) {
441 }
else if ( pb <= pc ) {
460 unsigned int above_left ) {
476 unsigned int ( *
unfilter ) (
unsigned int current,
479 unsigned int above_left );
508 unsigned int scanline;
510 unsigned int filter_type;
513 unsigned int above_left;
521 for ( scanline = 0 ; scanline < interlace->
height ; scanline++ ) {
524 filter_type = *(
data++);
527 DBGC (
image,
"PNG %s unknown filter type %d\n",
533 DBGC2 (
image,
"PNG %s pass %d scanline %d filter type %d\n",
543 for (
byte = 0 ;
byte < ( scanline_len - 1 ) ;
byte++ ) {
546 if (
byte >= pixel_len )
547 left = *(
data - pixel_len );
549 above = *(
data - scanline_len );
550 if ( ( scanline > 0 ) && (
byte >= pixel_len ) ) {
551 above_left = *(
data - scanline_len -
591 if ( interlace.
width == 0 )
596 &interlace ) ) != 0 )
612 static inline unsigned int png_pixel (
unsigned int raw,
unsigned int alpha,
621 return ( ( ( ( ( 0xff00 *
raw * alpha ) /
max ) /
max ) + 0x80 ) >> 8 );
644 unsigned int pixbuf_y_index;
645 unsigned int pixbuf_index;
646 unsigned int pixbuf_x_stride;
647 unsigned int pixbuf_y_stride;
664 data_stride = ( ( depth + 7 ) / 8 );
667 max = ( ( 1 << depth ) - 1 );
672 pixbuf_x_stride = interlace->
x_stride;
674 DBGC2 (
image,
"PNG %s pass %d %dx%d at (%d,%d) stride (%d,%d)\n",
680 for (
y = 0 ;
y < interlace->
height ;
y++ ) {
687 pixbuf_index = pixbuf_y_index;
688 for (
x = 0 ;
x < interlace->
width ;
x++ ) {
691 for ( c = 0 ; c < png->
channels ; c++ ) {
703 channel[c] = ( current >> ( 8 - depth ) );
715 alpha = ( has_alpha ?
720 for ( c = 0 ; c < 3 ; c++ ) {
724 pixel = ( ( pixel << 8 ) |
value );
730 pixbuf_index += pixbuf_x_stride;
734 pixbuf_y_index += pixbuf_y_stride;
763 if ( interlace.
width == 0 )
786 DBGC (
image,
"PNG %s invalid IEND length %zd\n",
791 DBGC (
image,
"PNG %s missing pixel buffer (no IHDR?)\n",
796 DBGC (
image,
"PNG %s decompression not complete\n",
801 DBGC (
image,
"PNG %s incorrect decompressed length (expected " 855 DBGC (
image,
"PNG %s chunk type %s offset %zd length %zd\n",
868 DBGC (
image,
"PNG %s unknown critical chunk type %s\n",
893 png =
zalloc (
sizeof ( *png ) );
906 if ( remaining < (
sizeof ( *
header ) +
sizeof ( *footer ) ) ){
907 DBGC (
image,
"PNG %s truncated chunk header/footer " 913 png->
offset +=
sizeof ( *header );
917 if ( chunk_len > ( remaining -
sizeof ( *
header ) -
918 sizeof ( *footer ) ) ) {
919 DBGC (
image,
"PNG %s truncated chunk data at offset " 931 png->
offset += ( chunk_len +
sizeof ( *footer ) );
937 DBGC (
image,
"PNG %s did not finish with IEND\n",
944 *pixbuf = pixbuf_get ( png->
pixbuf );
952 pixbuf_put ( png->
pixbuf );
static __always_inline void ufree(void *ptr)
Free external memory.
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
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.
struct pixel_buffer * alloc_pixbuf(unsigned int width, unsigned int height)
Allocate pixel buffer.
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.
Portable Network Graphics (PNG) format.
struct image_type png_image_type __image_type(PROBE_NORMAL)
PNG image type.
unsigned int x_indent
X starting indent.
static int png_palette(struct image *image, struct png_context *png, size_t len)
Handle PNG palette chunk.
UINT8_t filter
Receive packet filter.
const void * data
Read-only data.
unsigned int height
Height.
static void png_pixels(struct image *image, struct png_context *png)
Fill PNG pixels.
static int png_unfilter(struct image *image, struct png_context *png)
Unfilter PNG raw data.
#define ENOEXEC
Exec format error.
static const char * png_type_name(uint32_t type)
Transcribe PNG chunk type name (for debugging)
unsigned int y_stride
Y stride.
size_t offset
Offset within image.
uint32_t type
Operating system type.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static int png_image_data(struct image *image, struct png_context *png, size_t len)
Handle PNG image data chunk.
struct deflate_chunk raw
Decompression buffer for raw PNG data.
An executable image type.
#define PROBE_NORMAL
Normal image probe priority.
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.
int(* handle)(struct image *image, struct png_context *png, size_t len)
Handle chunk.
#define PNG_SIGNATURE
PNG file signature.
static unsigned int png_paeth_predictor(unsigned int a, unsigned int b, unsigned int c)
Paeth predictor function (defined in RFC 2083)
unsigned int pass
Pass number.
static struct png_chunk_handler png_chunk_handlers[]
PNG chunk handlers.
Above byte used as predictor.
char * name
Name of this image type.
#define ENOTSUP
Operation not supported.
unsigned int depth
Bit depth.
#define PNG_TYPE_IDAT
PNG image data chunk type.
First unknown filter method.
#define ENOMEM
Not enough space.
void deflate_init(struct deflate *deflate, enum deflate_format format)
Initialise decompressor.
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.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
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.
pseudo_bit_t value[0x00020]
static int deflate_finished(struct deflate *deflate)
Check if decompression has finished.
#define __unused
Declare a variable or data structure as unused.
#define PNG_TYPE_IEND
PNG image end chunk type.
Above and left bytes used as predictors.
uint32_t channel
RNDIS channel.
uint32_t * data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
char * strerror(int errno)
Retrieve string representation of error number.
static void(* free)(struct refcnt *refcnt))
#define PNG_PALETTE_COUNT
Maximum number of PNG palette entries.
void * zalloc(size_t size)
Allocate cleared memory.
size_t len
Length of raw file image.
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.
unsigned int x_stride
X stride.
int deflate_inflate(struct deflate *deflate, const void *data, size_t len, struct deflate_chunk *out)
Inflate compressed data.
size_t offset
Current offset.
static int png_pixbuf(struct image *image, struct pixel_buffer **pixbuf)
Convert PNG image to pixel buffer.
struct deflate deflate
Decompressor.
unsigned int colour_type
Colour type.
static int png_probe(struct image *image)
Probe PNG image.
Left byte used as predictor.
struct pixel_buffer * pixbuf
Pixel buffer.
static void png_pixels_pass(struct image *image, struct png_context *png, struct png_interlace *interlace)
Fill one interlace pass of PNG pixels.
#define PNG_TYPE_IHDR
PNG image header chunk type.
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 struct png_filter png_filters[]
PNG filter types.
static volatile void * bits
static uint8_t png_interlace_passes[]
Number of interlacing passes.
First unknown interlace method.
static __always_inline void * umalloc(size_t size)
Allocate external memory.
First unknown compression method.
static unsigned int unsigned int y
static int png_image_end(struct image *image, struct png_context *png, size_t len)
Handle PNG image end chunk.
struct ena_llq_option header
Header locations.
static int png_image_header(struct image *image, struct png_context *png, size_t len)
Handle PNG image header chunk.
static int png_unfilter_pass(struct image *image, struct png_context *png, struct png_interlace *interlace)
Unfilter one interlace pass of PNG raw data.
uint8_t data[48]
Additional event data.
unsigned int passes
Number of interlace passes.
DEFLATE decompression algorithm.
static unsigned int png_pixel_len(struct png_context *png)
Calculate PNG pixel length.
#define PNG_TYPE_PLTE
PNG palette chunk type.
static void png_interlace(struct png_context *png, unsigned int pass, struct png_interlace *interlace)
Calculate PNG interlace pass parameters.
u8 signature
CPU signature.
unsigned int channels
Number of channels.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
#define NULL
NULL pointer (VOID *)
size_t len
Length of data.
unsigned int height
Height.
unsigned int y_indent
Y starting indent.
static unsigned int png_pixel(unsigned int raw, unsigned int alpha, unsigned int max)
Calculate PNG pixel component value.