BlyxDocumentation
Browse chapters
Documentation / Workflow recipes

Hoopoe · Check a thumbnail buffer before allocation

Plan a thumbnail and check the decoded pixel buffer against a byte budget.

Check a thumbnail buffer before allocation

Encoded file size gives a poor estimate of decoded thumbnail memory. Account for output dimensions and scanline padding before allocating. A 400×200 image fits into 100×50 pixels. Three channels and four-byte alignment require 15,000 bytes, above the given budget.

Run the framework with your own input

Install Blyx 0.2.1 and a Rust toolchain with a host linker, then run the versioned project. Each positional argument is a number or a comma-separated numerical vector. The CLI accepts up to 16 entries per vector. The imported module accepts longer inputs.

git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-hoopoe.git
cd blyx-hoopoe
blyxc native-run project.blyx -- 400 200 100 100 3 4 14000

API and return values

Returns [output width, output height, aligned stride, bytes, fits budget]. Includes one output buffer with one byte per channel. Decoder and encoder overhead are outside this estimate. Invalid input returns an empty vector.

ArgumentAccepted input
widthpositive exact integer
heightpositive exact integer
box_wpositive exact integer
box_hpositive exact integer
channelspositive exact integer
alignpositive exact integer
memorynonnegative exact integer

Use the libraries independently

The framework vendors the same library source published in these two repositories. Each module has its own package page, input contract and regression suite.

Try the program

Output Ready
Expected output
100
50
300
15000
0
Open in the full playground →

Practice

Change width = 3.0, height = 2.0, box_w = 10.0, box_h = 10.0, memory = 24.0. Predict the result, then run the program.

Hint

Returns [output width, output height, aligned stride, bytes, fits budget]. Includes one output buffer with one byte per channel. Decoder and encoder overhead are outside this estimate.

Worked solution

The result vector is [3, 2, 12, 24, 1]. Compare its fields with the return layout in the API section.

Find

    let width = 400.0;

Replace with

    let width = 3.0;

Find

    let height = 200.0;

Replace with

    let height = 2.0;

Find

    let box_w = 100.0;

Replace with

    let box_w = 10.0;

Find

    let box_h = 100.0;

Replace with

    let box_h = 10.0;

Find

    let memory = 14000.0;

Replace with

    let memory = 24.0;

Output after the change

3
2
12
24
1