|
| | FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) |
| |
| | FILE_SECBOOT (PERMITTED) |
| |
| static const char * | png_type_name (uint32_t type) |
| | Transcribe PNG chunk type name (for debugging) More...
|
| |
| static void | png_interlace (struct png_context *png, unsigned int pass, struct png_interlace *interlace) |
| | Calculate PNG interlace pass parameters. More...
|
| |
| static unsigned int | png_pixel_len (struct png_context *png) |
| | Calculate PNG pixel length. More...
|
| |
| static size_t | png_scanline_len (struct png_context *png, struct png_interlace *interlace) |
| | Calculate PNG scanline length. More...
|
| |
| static int | png_image_header (struct image *image, struct png_context *png, size_t len) |
| | Handle PNG image header chunk. More...
|
| |
| static int | png_palette (struct image *image, struct png_context *png, size_t len) |
| | Handle PNG palette chunk. More...
|
| |
| static int | png_image_data (struct image *image, struct png_context *png, size_t len) |
| | Handle PNG image data chunk. More...
|
| |
| 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. More...
|
| |
| 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. More...
|
| |
| 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. More...
|
| |
| 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. More...
|
| |
| static unsigned int | png_paeth_predictor (unsigned int a, unsigned int b, unsigned int c) |
| | Paeth predictor function (defined in RFC 2083) More...
|
| |
| 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. More...
|
| |
| static int | png_unfilter_pass (struct image *image, struct png_context *png, struct png_interlace *interlace) |
| | Unfilter one interlace pass of PNG raw data. More...
|
| |
| static int | png_unfilter (struct image *image, struct png_context *png) |
| | Unfilter PNG raw data. More...
|
| |
| static unsigned int | png_pixel (unsigned int raw, unsigned int alpha, unsigned int max) |
| | Calculate PNG pixel component value. More...
|
| |
| static void | png_pixels_pass (struct image *image, struct png_context *png, struct png_interlace *interlace) |
| | Fill one interlace pass of PNG pixels. More...
|
| |
| static void | png_pixels (struct image *image, struct png_context *png) |
| | Fill PNG pixels. More...
|
| |
| static int | png_image_end (struct image *image, struct png_context *png, size_t len) |
| | Handle PNG image end chunk. More...
|
| |
| static int | png_chunk (struct image *image, struct png_context *png, uint32_t type, size_t len) |
| | Handle PNG chunk. More...
|
| |
| static int | png_pixbuf (struct image *image, struct pixel_buffer **pixbuf) |
| | Convert PNG image to pixel buffer. More...
|
| |
| static int | png_probe (struct image *image) |
| | Probe PNG image. More...
|
| |
| struct image_type png_image_type | __image_type (PROBE_NORMAL) |
| | PNG image type. More...
|
| |
Portable Network Graphics (PNG) format.
The PNG format is defined in RFC 2083.
Definition in file png.c.
Calculate PNG interlace pass parameters.
- Parameters
-
| png | PNG context |
| pass | Pass number (0=first pass) |
| interlace | Interlace pass to fill in |
Definition at line 119 of file png.c.
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 );
unsigned int x_indent
X starting indent.
unsigned int height
Height.
unsigned int y_stride
Y stride.
unsigned int pass
Pass number.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int x_stride
X stride.
struct pixel_buffer * pixbuf
Pixel buffer.
unsigned int passes
Number of interlace passes.
unsigned int height
Height.
unsigned int y_indent
Y starting indent.
References assert(), pixel_buffer::height, png_interlace::height, png_interlace::pass, png_context::passes, png_context::pixbuf, pixel_buffer::width, png_interlace::width, png_interlace::x_indent, png_interlace::x_stride, png_interlace::y_indent, and png_interlace::y_stride.
Referenced by png_image_header(), png_pixels(), and png_unfilter().
Handle PNG image header chunk.
- Parameters
-
| image | PNG image |
| png | PNG context |
| len | Chunk length |
- Return values
-
Definition at line 199 of file png.c.
206 if (
len !=
sizeof ( *ihdr ) ) {
207 DBGC (
image,
"PNG %s invalid IHDR length %zd\n",
218 DBGC (
image,
"PNG %s %dx%d depth %d type %d compression %d filter %d " 225 DBGC (
image,
"PNG %s unknown compression method %d\n",
230 DBGC (
image,
"PNG %s unknown filter method %d\n",
235 DBGC (
image,
"PNG %s unknown interlace method %d\n",
244 DBGC (
image,
"PNG %s could not allocate pixel buffer\n",
251 if ( ( png->
depth == 0 ) ||
252 ( ( png->
depth & ( png->
depth - 1 ) ) != 0 ) ) {
253 DBGC (
image,
"PNG %s invalid depth %d\n",
274 if ( interlace.width == 0 )
276 png->
raw.
len += ( interlace.height *
283 DBGC (
image,
"PNG %s could not allocate data buffer\n",
#define EINVAL
Invalid argument.
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.
const void * data
Read-only data.
size_t offset
Offset within image.
struct deflate_chunk raw
Decompression buffer for raw PNG data.
unsigned int pass
Pass number.
#define ENOTSUP
Operation not supported.
unsigned int depth
Bit depth.
First unknown filter method.
#define ENOMEM
Not enough space.
unsigned int colour_type
Colour type.
struct pixel_buffer * pixbuf
Pixel buffer.
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.
unsigned int passes
Number of interlace passes.
static void png_interlace(struct png_context *png, unsigned int pass, struct png_interlace *interlace)
Calculate PNG interlace pass parameters.
unsigned int channels
Number of channels.
size_t len
Length of data.
References alloc_pixbuf(), png_context::channels, png_context::colour_type, png_image_header::colour_type, png_image_header::compression, image::data, deflate_chunk::data, DBGC, png_context::depth, png_image_header::depth, EINVAL, ENOMEM, ENOTSUP, png_image_header::filter, png_interlace::height, png_image_header::height, png_image_header::interlace, len, deflate_chunk::len, image::name, ntohl, png_context::offset, png_interlace::pass, png_context::passes, png_context::pixbuf, PNG_COLOUR_TYPE_ALPHA, PNG_COLOUR_TYPE_PALETTE, PNG_COLOUR_TYPE_RGB, PNG_COMPRESSION_UNKNOWN, PNG_FILTER_UNKNOWN, png_interlace(), png_interlace_passes, PNG_INTERLACE_UNKNOWN, png_scanline_len(), png_context::raw, umalloc(), png_interlace::width, and png_image_header::width.
Unfilter one interlace pass of PNG raw data.
- Parameters
-
| image | PNG image |
| png | PNG context |
| interlace | Interlace pass |
- Return values
-
This routine may assume that it is impossible to overrun the raw data buffer, since the size is determined by the image dimensions.
Definition at line 503 of file png.c.
509 unsigned int scanline;
511 unsigned int filter_type;
514 unsigned int above_left;
522 for ( scanline = 0 ; scanline < interlace->
height ; scanline++ ) {
525 filter_type = *(
data++);
528 DBGC (
image,
"PNG %s unknown filter type %d\n",
534 DBGC2 (
image,
"PNG %s pass %d scanline %d filter type %d\n",
544 for (
byte = 0 ;
byte < ( scanline_len - 1 ) ;
byte++ ) {
547 if (
byte >= pixel_len )
548 left = *(
data - pixel_len );
550 above = *(
data - scanline_len );
551 if ( ( scanline > 0 ) && (
byte >= pixel_len ) ) {
552 above_left = *(
data - scanline_len -
static size_t png_scanline_len(struct png_context *png, struct png_interlace *interlace)
Calculate PNG scanline length.
UINT8_t filter
Receive packet filter.
struct deflate_chunk raw
Decompression buffer for raw PNG data.
unsigned int pass
Pass number.
#define ENOTSUP
Operation not supported.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t offset
Current offset.
static struct png_filter png_filters[]
PNG filter types.
uint8_t data[48]
Additional event data.
static unsigned int png_pixel_len(struct png_context *png)
Calculate PNG pixel length.
#define NULL
NULL pointer (VOID *)
unsigned int height
Height.
References assert(), data, deflate_chunk::data, DBGC, DBGC2, ENOTSUP, filter, png_interlace::height, image::name, NULL, deflate_chunk::offset, png_interlace::pass, png_filters, png_pixel_len(), png_scanline_len(), and png_context::raw.
Referenced by png_unfilter().
Unfilter PNG raw data.
- Parameters
-
| image | PNG image |
| png | PNG context |
- Return values
-
This routine may assume that it is impossible to overrun the raw data buffer, since the size is determined by the image dimensions.
Definition at line 579 of file png.c.
592 if ( interlace.width == 0 )
597 &interlace ) ) != 0 )
struct arbelprm_rc_send_wqe rc
struct deflate_chunk raw
Decompression buffer for raw PNG data.
unsigned int pass
Pass number.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t offset
Current offset.
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.
static void png_interlace(struct png_context *png, unsigned int pass, struct png_interlace *interlace)
Calculate PNG interlace pass parameters.
size_t len
Length of data.
References assert(), deflate_chunk::len, deflate_chunk::offset, png_interlace::pass, png_context::passes, png_interlace(), png_unfilter_pass(), png_context::raw, rc, and png_interlace::width.
Referenced by png_image_end().
Fill one interlace pass of PNG pixels.
- Parameters
-
| image | PNG image |
| png | PNG context |
| interlace | Interlace pass |
This routine may assume that it is impossible to overrun either the raw data buffer or the pixel buffer, since the sizes of both are determined by the image dimensions.
Definition at line 636 of file png.c.
645 unsigned int pixbuf_y_index;
646 unsigned int pixbuf_index;
647 unsigned int pixbuf_x_stride;
648 unsigned int pixbuf_y_stride;
665 data_stride = ( ( depth + 7 ) / 8 );
668 max = ( ( 1 << depth ) - 1 );
673 pixbuf_x_stride = interlace->
x_stride;
675 DBGC2 (
image,
"PNG %s pass %d %dx%d at (%d,%d) stride (%d,%d)\n",
681 for (
y = 0 ;
y < interlace->
height ;
y++ ) {
688 pixbuf_index = pixbuf_y_index;
689 for (
x = 0 ;
x < interlace->
width ;
x++ ) {
692 for ( c = 0 ; c < png->
channels ; c++ ) {
704 channel[c] = ( current >> ( 8 - depth ) );
716 alpha = ( has_alpha ?
721 for ( c = 0 ; c < 3 ; c++ ) {
725 pixel = ( ( pixel << 8 ) |
value );
731 pixbuf_index += pixbuf_x_stride;
735 pixbuf_y_index += pixbuf_y_stride;
uint32_t palette[PNG_PALETTE_COUNT]
Palette, in iPXE's pixel buffer format.
unsigned int x_indent
X starting indent.
unsigned int y_stride
Y stride.
struct deflate_chunk raw
Decompression buffer for raw PNG data.
unsigned int pass
Pass number.
unsigned int depth
Bit depth.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
uint32_t channel
RNDIS channel.
uint32_t * data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
unsigned int x_stride
X stride.
size_t offset
Current offset.
unsigned int colour_type
Colour type.
struct pixel_buffer * pixbuf
Pixel buffer.
static volatile void * bits
static unsigned int unsigned int y
uint8_t data[48]
Additional event data.
unsigned int channels
Number of channels.
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.
References assert(), bits, channel, png_context::channels, png_context::colour_type, data, pixel_buffer::data, deflate_chunk::data, DBGC2, png_context::depth, png_interlace::height, max, image::name, deflate_chunk::offset, png_context::palette, png_interlace::pass, png_context::pixbuf, PNG_COLOUR_TYPE_ALPHA, PNG_COLOUR_TYPE_PALETTE, PNG_COLOUR_TYPE_RGB, png_pixel(), raw, png_context::raw, value, pixel_buffer::width, png_interlace::width, x, png_interlace::x_indent, png_interlace::x_stride, y, png_interlace::y_indent, and png_interlace::y_stride.
Referenced by png_pixels().
Fill PNG pixels.
- Parameters
-
| image | PNG image |
| png | PNG context |
This routine may assume that it is impossible to overrun either the raw data buffer or the pixel buffer, since the sizes of both are determined by the image dimensions.
Definition at line 752 of file png.c.
764 if ( interlace.width == 0 )
struct deflate_chunk raw
Decompression buffer for raw PNG data.
unsigned int pass
Pass number.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t offset
Current offset.
static void png_pixels_pass(struct image *image, struct png_context *png, struct png_interlace *interlace)
Fill one interlace pass of PNG pixels.
unsigned int passes
Number of interlace passes.
static void png_interlace(struct png_context *png, unsigned int pass, struct png_interlace *interlace)
Calculate PNG interlace pass parameters.
size_t len
Length of data.
References assert(), deflate_chunk::len, deflate_chunk::offset, png_interlace::pass, png_context::passes, png_interlace(), png_pixels_pass(), png_context::raw, and png_interlace::width.
Referenced by png_image_end().
Convert PNG image to pixel buffer.
- Parameters
-
| image | PNG image |
| pixbuf | Pixel buffer to fill in |
- Return values
-
Definition at line 885 of file png.c.
894 png =
zalloc (
sizeof ( *png ) );
907 if ( remaining < (
sizeof ( *
header ) +
sizeof ( *footer ) ) ){
908 DBGC (
image,
"PNG %s truncated chunk header/footer " 914 png->
offset +=
sizeof ( *header );
918 if ( chunk_len > ( remaining -
sizeof ( *
header ) -
919 sizeof ( *footer ) ) ) {
920 DBGC (
image,
"PNG %s truncated chunk data at offset " 932 png->
offset += ( chunk_len +
sizeof ( *footer ) );
938 DBGC (
image,
"PNG %s did not finish with IEND\n",
945 *pixbuf = pixbuf_get ( png->
pixbuf );
953 pixbuf_put ( png->
pixbuf );
static __always_inline void ufree(void *ptr)
Free external memory.
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
static int png_chunk(struct image *image, struct png_context *png, uint32_t type, size_t len)
Handle PNG chunk.
const void * data
Read-only data.
size_t offset
Offset within image.
struct deflate_chunk raw
Decompression buffer for raw PNG data.
#define ENOMEM
Not enough space.
void deflate_init(struct deflate *deflate, enum deflate_format format)
Initialise decompressor.
#define PNG_TYPE_IEND
PNG image end chunk type.
static void(* free)(struct refcnt *refcnt))
void * zalloc(size_t size)
Allocate cleared memory.
size_t len
Length of raw file image.
struct deflate deflate
Decompressor.
struct pixel_buffer * pixbuf
Pixel buffer.
struct ena_llq_option header
Header locations.
References image::data, deflate_chunk::data, DBGC, png_context::deflate, deflate_init(), DEFLATE_ZLIB, EINVAL, ENOMEM, free, header, htonl, image::len, image::name, ntohl, png_context::offset, png_context::pixbuf, png_chunk(), PNG_TYPE_IEND, png_context::raw, rc, ufree(), and zalloc().