-
-
Notifications
You must be signed in to change notification settings - Fork 5
Image Decoders
NyxOS decodes PNG, BMP and GIF into RGBA in the kernel, on top of a from-scratch DEFLATE implementation. The whole pipeline exists so Selene Browser can draw the pictures on a real web page.
See also: Selene Browser, GUI Subsystem, Shell
Every decoder produces the same thing, so callers stay format-agnostic:
typedef struct {
uint32_t width, height;
uint8_t* pixels; // RGBA, 4 bytes per pixel, width*height*4, kmalloc'd
} image_t;Selene picks a decoder from the content, holds an image_t, and draws it without caring which format it came from.
The decompression core PNG's IDAT stream needs, implemented against RFC 1951 and RFC 1950.
int inflate_raw (const uint8_t* src, uint32_t srclen,
uint8_t* dst, uint32_t dstcap, uint32_t* outlen);
int zlib_inflate(const uint8_t* src, uint32_t srclen,
uint8_t* dst, uint32_t dstcap, uint32_t* outlen);| Function | Handles |
|---|---|
inflate_raw |
Raw DEFLATE — stored, fixed-Huffman and dynamic-Huffman blocks |
zlib_inflate |
The zlib wrapper: 2-byte header, DEFLATE body, and a verified trailing Adler-32 |
Both return 0 on success and a negative code on a corrupt stream or an output overflow.
Self-test: deflatetest — fixed, dynamic and stored blocks, plus a zlib case with Adler-32.
int png_decode(const uint8_t* src, uint32_t srclen, image_t* img);
void png_free(image_t* img);| Supported | Not supported |
|---|---|
| 8-bit depth | 16-bit depth |
| Colour types: grayscale, RGB, palette, gray+alpha, RGBA | Interlaced (Adam7) images |
| All five scanline filters: None, Sub, Up, Average, Paeth |
Self-test: pngtest — an embedded PNG of each colour type, exercising every filter type.
int bmp_decode(const uint8_t* src, uint32_t srclen, image_t* img);Uncompressed (BI_RGB) BITMAPINFOHEADER bitmaps — the shapes still found on the web:
- 24-bit BGR
- 32-bit BGRX
- 8-bit palette
- Bottom-up and top-down row order
Self-test: bmptest — 24/32/8-bit plus a top-down image, against expected RGBA.
int gif_decode(const uint8_t* src, uint32_t srclen, image_t* img);Decodes the first frame of a GIF87a or GIF89a, including a real LZW decompressor:
- Global and local colour tables
- LZW decompression with dictionary growth and clear codes
- Interlaced images
- A transparent colour index
Animation is not supported — subsequent frames are ignored.
Self-test: giftest — a basic palette image, transparency, an interlaced image, and one that grows the LZW dictionary.
Every decoder kmallocs img->pixels. Release it with png_free(&img) (or kfree(img.pixels)). Selene frees decoded images when a page is replaced or a tab closes.
Selene caps a per-image download at 512 KB and decodes at most 8 images per page load, which bounds what a hostile or merely enormous page can allocate.
deflatetest
pngtest
bmptest
giftestEach prints a per-case pass/fail line and returns non-zero on failure.
v5.9.81 added inflate, v5.9.82 PNG, v5.9.83 wired real images into Selene, v5.9.84 made loading lazy and progressive, v5.9.85 added BMP and generalised the pipeline behind image_t, and v5.9.86 added GIF. See Version History.
- Selene Browser - the consumer of these decoders
- GUI Subsystem - how decoded images reach the screen
- Shell - the self-test commands
- RFC 1950 - zlib format - IETF
- RFC 1951 - DEFLATE - IETF
- PNG Specification (Third Edition) - W3C
- GIF89a Specification - CompuServe
NyxOS v6.4.363 · GPL v2 · GitHub · uselessalter on Discord · nyxos@inbox.lv
NyxOS Wiki
Getting started
Kernel
Storage & network
Graphics & apps
Userspace
HOWTO
- HOWTO-Add-a-system-call
- HOWTO-Write-a-userspace-program
- HOWTO-Add-a-shell-command
- HOWTO-Add-a-GUI-application
Reference
- Syscall-Reference
- Command-Reference
- Hardware-Reference
- Format-Reference
- Kernel-Data-Structures
- Source-Tree-Reference
Project