Embed Raster in a native application#

Build Raster once, install its native package to a prefix, and use the checked consumers to verify that your application can read and warp a small RGB window. The examples exercise the C ABI, the C++ façade, and Rust without requiring you to reproduce their full source in your application.

The consumers require tests/data/sentinel2_bgr_10m_1001x1001.tif. This fixture is provisioned separately: it is ignored by Git and is absent from a fresh checkout. On the project’s runners, tools/run-merge-gpu.py can copy it from /opt/cugeo/fixtures/cugeo-raster. Use this fixture for the examples because their assertions are specific to it.

Check RGB windows in two layouts#

The fixture is a ClassicTIFF with three UInt16 bands and EPSG:32631. The C consumer opens it, queries dataset and georeference metadata, and plans two host reads. Its padded BIP request reads a 3 × 2 window at (10, 20), and its padded BSQ request reads the adjacent 3 × 2 window at (13, 20). The two requests therefore check the layouts with different pixel values from adjacent windows.

BIP places the three band samples together at each pixel, and BSQ places each band in its own plane. The C example initializes ABI structure sizes with sizeof and supplies caller-owned destinations. It uses the following byte strides.

Destination

Row

Pixel

Band

Minimum extent

Padded BIP

20

6

2

38

Padded BSQ

8

2

18

50

For zero-based row r, column c, and band b, use r * row_stride + c * pixel_stride + b * band_stride to locate the sample in bytes. For example, row 1, column 1, band 0 is at byte offset 26 in the BIP destination and offset 10 in the BSQ destination. The checked values are 801 and 814 respectively, because the requests cover different windows. The consumer checks every value, padding, both completed request results, and the receipt. It then applies a nearest-neighbor identity host warp to the first output and checks the pixels and six valid statuses. Its success string is strict C11 typed read-many and host warp passed.

C++ and Rust consumers#

The C++ consumer exercises the installed façade for dataset I/O and warp with native types and RAII owners. Follow its checks when integrating the façade.

The Rust consumer reads the same (10, 20) window twice into packed BIP arrays. Both arrays must equal the following.

[809, 555, 335, 816, 554, 329, 815, 556, 341,
 803, 555, 330, 801, 550, 331, 791, 543, 333]

It checks a complete Native TIFF receipt with two completed requests, 72 output bytes, and zero conversion bytes. Both request results are completed with zero conversion bytes. Its identity nearest host warp must reproduce the array and return six Valid pixel statuses. The source’s success string is Rust metadata/read-many/affine oracle passed.

Release handles and destinations#

The C example sends both successful and error paths through cleanup. It releases the warp plan with cugeo_raster_plan_release, the read batch plan with cugeo_raster_read_batch_plan_release_v1, and the dataset with cugeo_raster_dataset_release_v1. Its handles start as null and the release functions are exercised as null-safe. The caller owns the output and status buffers and must keep them valid for the operations that use them.

In the C++ consumer, keep the destination storage alive while its views and operations use it. The façade’s RAII owners release their resources at their scope boundary. The Rust example similarly drops its batch and dataset after the synchronous host work completes.