|
| | FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) |
| |
| 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 118 of file png.c.
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 );
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 198 of file png.c.
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 )
275 png->
raw.
len += ( interlace.height *
282 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 502 of file png.c.
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 -
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 578 of file png.c.
591 if ( interlace.width == 0 )
596 &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 635 of file png.c.
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;
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 751 of file png.c.
763 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 884 of file png.c.
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
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().