iPXE
|
Portable Network Graphics (PNG) format. More...
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/umalloc.h>
#include <ipxe/pixbuf.h>
#include <ipxe/deflate.h>
#include <ipxe/png.h>
Go to the source code of this file.
Data Structures | |
struct | png_context |
PNG context. More... | |
struct | png_interlace |
A PNG interlace pass. More... | |
struct | png_filter |
A PNG filter. More... | |
struct | png_chunk_handler |
A PNG chunk handler. More... | |
Functions | |
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... | |
Variables | |
static struct png_signature | png_signature = PNG_SIGNATURE |
PNG file signature. More... | |
static uint8_t | png_interlace_passes [] |
Number of interlacing passes. More... | |
static struct png_filter | png_filters [] |
PNG filter types. More... | |
static struct png_chunk_handler | png_chunk_handlers [] |
PNG chunk handlers. More... | |
Portable Network Graphics (PNG) format.
The PNG format is defined in RFC 2083.
Definition in file png.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Transcribe PNG chunk type name (for debugging)
type | Chunk type |
name | Chunk type name |
Definition at line 101 of file png.c.
Referenced by png_chunk().
|
static |
Calculate PNG interlace pass parameters.
png | PNG context |
pass | Pass number (0=first pass) |
interlace | Interlace pass to fill in |
Definition at line 118 of file png.c.
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().
|
static |
Calculate PNG pixel length.
png | PNG context |
pixel_len | Pixel length |
Definition at line 171 of file png.c.
References png_context::channels, and png_context::depth.
Referenced by png_unfilter_pass().
|
static |
Calculate PNG scanline length.
png | PNG context |
interlace | Interlace pass |
scanline_len | Scanline length (including filter byte) |
Definition at line 183 of file png.c.
References png_context::channels, png_context::depth, and png_interlace::width.
Referenced by png_image_header(), and png_unfilter_pass().
|
static |
Handle PNG image header chunk.
image | PNG image |
png | PNG context |
len | Chunk length |
rc | Return status code |
Definition at line 198 of file png.c.
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.
|
static |
Handle PNG palette chunk.
image | PNG image |
png | PNG context |
len | Chunk length |
rc | Return status code |
Definition at line 298 of file png.c.
References png_palette_entry::blue, copy_from_user(), image::data, DBGC2, png_palette_entry::green, len, image::name, offset, png_context::offset, png_context::palette, and png_palette_entry::red.
|
static |
Handle PNG image data chunk.
image | PNG image |
png | PNG context |
len | Chunk length |
rc | Return status code |
Definition at line 337 of file png.c.
References image::data, DBGC, png_context::deflate, deflate_inflate(), in, len, image::name, png_context::offset, png_context::raw, rc, and strerror().
|
static |
|
static |
|
static |
|
static |
Unfilter byte using the "Average" filter.
current | Filtered current byte |
left | Unfiltered left byte |
above | Unfiltered above byte |
above_left | Unfiltered above-left byte |
current | Unfiltered current byte |
|
static |
Paeth predictor function (defined in RFC 2083)
a | Pixel A |
b | Pixel B |
c | Pixel C |
predictor | Predictor pixel |
Definition at line 430 of file png.c.
Referenced by png_unfilter_paeth().
|
static |
Unfilter byte using the "Paeth" filter.
current | Filtered current byte |
above_left | Unfiltered above-left byte |
above | Unfiltered above byte |
left | Unfiltered left byte |
current | Unfiltered current byte |
Definition at line 460 of file png.c.
References png_paeth_predictor().
|
static |
Unfilter one interlace pass of PNG raw data.
image | PNG image |
png | PNG context |
interlace | Interlace pass |
rc | Return status code |
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.
References assert(), copy_from_user(), copy_to_user(), deflate_chunk::data, DBGC, DBGC2, ENOTSUP, filter, png_interlace::height, image::name, NULL, offset, deflate_chunk::offset, png_interlace::pass, png_filters, png_pixel_len(), png_scanline_len(), and png_context::raw.
Referenced by png_unfilter().
|
static |
Unfilter PNG raw data.
image | PNG image |
png | PNG context |
rc | Return status code |
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.
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().
|
inlinestatic |
Calculate PNG pixel component value.
raw | Raw component value |
alpha | Alpha value |
max | Maximum raw/alpha value |
value | Component value in range 0-255 |
Definition at line 628 of file png.c.
Referenced by png_pixels_pass().
|
static |
Fill one interlace pass of PNG pixels.
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.
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().
|
static |
Fill PNG pixels.
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.
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().
|
static |
Handle PNG image end chunk.
image | PNG image |
png | PNG context |
len | Chunk length |
rc | Return status code |
Definition at line 801 of file png.c.
References DBGC, png_context::deflate, deflate_finished(), EINVAL, len, deflate_chunk::len, image::name, deflate_chunk::offset, png_context::pixbuf, png_pixels(), png_unfilter(), png_context::raw, and rc.
|
static |
Handle PNG chunk.
image | PNG image |
png | PNG context |
type | Chunk type |
len | Chunk length |
rc | Return status code |
Definition at line 871 of file png.c.
References DBGC, ENOTSUP, png_chunk_handler::handle, htonl, len, image::name, png_context::offset, PNG_CHUNK_ANCILLARY, png_chunk_handlers, png_type_name(), type, and png_chunk_handler::type.
Referenced by png_pixbuf().
|
static |
Convert PNG image to pixel buffer.
image | PNG image |
pixbuf | Pixel buffer to fill in |
rc | Return status code |
Definition at line 905 of file png.c.
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().
|
static |
Probe PNG image.
image | PNG image |
rc | Return status code |
Definition at line 987 of file png.c.
References copy_from_user(), image::data, DBGC, ENOEXEC, image::len, memcmp(), image::name, and signature.
struct image_type png_image_type __image_type | ( | PROBE_NORMAL | ) |
PNG image type.
|
static |
|
static |
Number of interlacing passes.
Definition at line 90 of file png.c.
Referenced by png_image_header().
|
static |
PNG filter types.
Definition at line 486 of file png.c.
Referenced by png_unfilter_pass().
|
static |
PNG chunk handlers.
Definition at line 855 of file png.c.
Referenced by png_chunk().