|
| 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 " 219 ntohl ( ihdr.height ), ihdr.depth, ihdr.colour_type,
220 ihdr.compression, ihdr.filter, ihdr.interlace );
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",
241 ntohl ( ihdr.height ) );
243 DBGC (
image,
"PNG %s could not allocate pixel buffer\n",
249 png->
depth = ihdr.depth;
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.
userptr_t data
Raw file image.
static size_t png_scanline_len(struct png_context *png, struct png_interlace *interlace)
Calculate PNG scanline length.
size_t offset
Offset within image.
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
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 __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.
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, copy_from_user(), 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_image_header::width, and png_interlace::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 505 of file png.c.
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 ) );
static size_t png_scanline_len(struct png_context *png, struct png_interlace *interlace)
Calculate PNG scanline length.
UINT8_t filter
Receive packet filter.
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
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)
static userptr_t size_t offset
Offset of the first segment within the content.
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.
size_t offset
Current offset.
static struct png_filter png_filters[]
PNG filter types.
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(), copy_from_user(), copy_to_user(), deflate_chunk::data, DBGC, DBGC2, ENOTSUP, filter, png_interlace::height, image::name, NULL, deflate_chunk::offset, 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 594 of file png.c.
607 if ( interlace.width == 0 )
612 &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 651 of file png.c.
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;
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.
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
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)
uint32_t channel
RNDIS channel.
pseudo_bit_t value[0x00020]
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.
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
userptr_t data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
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, c, channel, png_context::channels, png_context::colour_type, copy_from_user(), copy_to_user(), 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, png_interlace::x_indent, png_interlace::x_stride, 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 772 of file png.c.
784 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 905 of file png.c.
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 );
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
userptr_t data
Raw file image.
static int png_chunk(struct image *image, struct png_context *png, uint32_t type, size_t len)
Handle PNG chunk.
size_t offset
Offset within image.
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
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.
static __always_inline void ufree(userptr_t userptr)
Free external memory.
struct ena_aq_header header
Header.
References copy_from_user(), 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().