-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Open the PR up as a draft until you feel it is ready for a proper review. Do not make PR:s from your own `main` branch, as that makes it difficult for reviewers to add their own fixes. Add any improvements to the branch as new commits to make it easier for reviewers to follow the progress. All commits will be squashed to a single commit once the PR is merged into `main`. Make sure you mention any issues that this PR closes in the description, as well as any other related issues. To get an auto-generated PR description you can put "copilot:summary" or "copilot:walkthrough" anywhere. --> ### Added support for logging NV12 encoded images via the existing log_image_file api. As promissed a while back :) ```py from rerun import ImageFormat import rerun as rr rr.log_image_file("NV12 image", img_bytes=bytes(frame), img_format=ImageFormat.NV12(width=1920, height=1080)) ``` ![NV12 image example](https://github.com/rerun-io/rerun/assets/59307111/de8ef517-d84f-4130-8946-4ea787f0181e) The raw (encoded) image data is stored in an R8Uint texture. The contents of the texture get decoded in the `rectangle_fs.wgsl` via the decoder written in `decodings.wgsl`. Other [YUV](https://gist.github.com/Jim-Bar/3cbba684a71d1a9d468a6711a6eddbeb) image formats could be added easily, following the NV12 implementation with slight modifications to the decoder. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3541) (if applicable) - [PR Build Summary](https://build.rerun.io/pr/3541) - [Docs preview](https://rerun.io/preview/fc13dd7aa9ae329b3e5100f8bb70c32f2d1b8add/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/fc13dd7aa9ae329b3e5100f8bb70c32f2d1b8add/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/) --------- Co-authored-by: Andreas Reich <[email protected]>
- Loading branch information
Showing
34 changed files
with
790 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#import <./types.wgsl> | ||
|
||
|
||
/// Loads an RGBA texel from a texture holding an NV12 encoded image at the given screen space coordinates. | ||
fn decode_nv12(texture: texture_2d<u32>, coords: IVec2) -> Vec4 { | ||
let texture_dim = Vec2(textureDimensions(texture).xy); | ||
let uv_offset = u32(floor(texture_dim.y / 1.5)); | ||
let uv_row = u32(coords.y / 2); | ||
var uv_col = u32(coords.x / 2) * 2u; | ||
|
||
let y = max(0.0, (f32(textureLoad(texture, UVec2(coords), 0).r) - 16.0)) / 219.0; | ||
let u = (f32(textureLoad(texture, UVec2(u32(uv_col), uv_offset + uv_row), 0).r) - 128.0) / 224.0; | ||
let v = (f32(textureLoad(texture, UVec2((u32(uv_col) + 1u), uv_offset + uv_row), 0).r) - 128.0) / 224.0; | ||
|
||
// Specifying the color standard should be exposed in the future (https://github.com/rerun-io/rerun/pull/3541) | ||
// BT.601 (aka. SDTV, aka. Rec.601). wiki: https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.601_conversion | ||
let r = clamp(y + 1.402 * v, 0.0, 1.0); | ||
let g = clamp(y - (0.344 * u + 0.714 * v), 0.0, 1.0); | ||
let b = clamp(y + 1.772 * u, 0.0, 1.0); | ||
// BT.709 (aka. HDTV, aka. Rec.709). wiki: https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion | ||
// let r = clamp(y + 1.5748 * v, 0.0, 1.0); | ||
// let g = clamp(y + u * -0.1873 + v * -0.4681, 0.0, 1.0); | ||
// let b = clamp(y + u * 1.8556, 0.0 , 1.0); | ||
return Vec4(r, g, b, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.