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 sizeof ( palette ) );
316 ( palette.
green << 8 ) |
317 ( palette.
blue << 0 ) );
318 DBGC2 (
image,
"PNG %s palette entry %d is %#06x\n",
322 offset +=
sizeof ( palette );
323 len -=
sizeof ( palette );
346 DBGC (
image,
"PNG %s could not decompress: %s\n",
366 unsigned int above_left
__unused ) {
383 unsigned int above_left
__unused ) {
385 return ( current + left );
400 unsigned int above_left
__unused ) {
402 return ( current + above );
417 unsigned int above_left
__unused ) {
419 return ( current + ( ( above + left ) >> 1 ) );
442 if ( ( pa <= pb ) && ( pa <= pc ) ) {
444 }
else if ( pb <= pc ) {
463 unsigned int above_left ) {
479 unsigned int ( *
unfilter ) (
unsigned int current,
482 unsigned int above_left );
511 unsigned int scanline;
525 for ( scanline = 0 ; scanline < interlace->
height ; scanline++ ) {
529 sizeof ( filter_type ) );
532 DBGC (
image,
"PNG %s unknown filter type %d\n",
538 DBGC2 (
image,
"PNG %s pass %d scanline %d filter type %d\n",
548 for (
byte = 0 ;
byte < ( scanline_len - 1 ) ;
byte++ ) {
551 if (
byte >= pixel_len ) {
556 if ( scanline > 0 ) {
558 (
offset - scanline_len ),
561 if ( ( scanline > 0 ) && (
byte >= pixel_len ) ) {
565 sizeof ( above_left ) );
570 offset, sizeof ( current ) );
571 current =
filter->unfilter ( current, left, above,
574 ¤t, sizeof ( current ) );
607 if ( interlace.
width == 0 )
612 &interlace ) ) != 0 )
628 static inline unsigned int png_pixel (
unsigned int raw,
unsigned int alpha,
637 return ( ( ( ( ( 0xff00 *
raw * alpha ) /
max ) /
max ) + 0x80 ) >> 8 );
659 size_t pixbuf_y_offset;
660 size_t pixbuf_offset;
661 size_t pixbuf_x_stride;
662 size_t pixbuf_y_stride;
680 raw_stride = ( ( depth + 7 ) / 8 );
683 max = ( ( 1 << depth ) - 1 );
687 interlace->
x_indent ) *
sizeof ( pixel ) );
688 pixbuf_x_stride = ( interlace->
x_stride *
sizeof ( pixel ) );
691 DBGC2 (
image,
"PNG %s pass %d %dx%d at (%d,%d) stride (%d,%d)\n",
697 for ( y = 0 ; y < interlace->
height ; y++ ) {
704 pixbuf_offset = pixbuf_y_offset;
705 for ( x = 0 ; x < interlace->
width ; x++ ) {
717 sizeof ( current ) );
718 raw_offset += raw_stride;
723 channel[
c] = ( current >> ( 8 - depth ) );
735 alpha = ( has_alpha ?
740 for (
c = 0 ;
c < 3 ;
c++ ) {
744 pixel = ( ( pixel << 8 ) |
value );
750 &pixel, sizeof ( pixel ) );
751 pixbuf_offset += pixbuf_x_stride;
755 pixbuf_y_offset += pixbuf_y_stride;
784 if ( interlace.
width == 0 )
807 DBGC (
image,
"PNG %s invalid IEND length %zd\n",
812 DBGC (
image,
"PNG %s missing pixel buffer (no IHDR?)\n",
817 DBGC (
image,
"PNG %s decompression not complete\n",
822 DBGC (
image,
"PNG %s incorrect decompressed length (expected " 876 DBGC (
image,
"PNG %s chunk type %s offset %zd length %zd\n",
889 DBGC (
image,
"PNG %s unknown critical chunk type %s\n",
914 png =
zalloc (
sizeof ( *png ) );
927 if ( remaining < (
sizeof (
header ) +
sizeof ( footer ) ) ) {
928 DBGC (
image,
"PNG %s truncated chunk header/footer " 939 if ( chunk_len > ( remaining -
sizeof (
header ) -
940 sizeof ( footer ) ) ) {
941 DBGC (
image,
"PNG %s truncated chunk data at offset " 953 png->
offset += ( chunk_len +
sizeof ( footer ) );
959 DBGC (
image,
"PNG %s did not finish with IEND\n",
966 *pixbuf = pixbuf_get ( png->
pixbuf );
974 pixbuf_put ( png->
pixbuf );
int deflate_inflate(struct deflate *deflate, struct deflate_chunk *in, struct deflate_chunk *out)
Inflate compressed data.
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
static __always_inline void off_t int c
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.
userptr_t data
Raw file image.
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.
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.
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
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.
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 __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
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.
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 __always_inline void ufree(userptr_t userptr)
Free external memory.
static __always_inline userptr_t umalloc(size_t size)
Allocate external memory.
static uint8_t png_interlace_passes[]
Number of interlacing passes.
First unknown interlace method.
First unknown compression method.
static int png_image_end(struct image *image, struct png_context *png, size_t len)
Handle PNG image end chunk.
struct ena_aq_header header
Header.
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.
unsigned int passes
Number of interlace passes.
uint16_t offset
Offset to command line.
userptr_t data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
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.