-
Notifications
You must be signed in to change notification settings - Fork 672
feat: Image decoder in the frontend #3971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+406
−15
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
18784b8
feat: Image decoder in the frontend
milesial 48cf8e2
chore: Move away from mod.rs
milesial c4c85dc
tests: offline test
milesial a994a63
chore: make clippy happy
milesial eabe088
tests: clone with LFS
milesial 0732216
feat: Address reviews, better limits
milesial 3c4aa12
tests: Enable LFS
milesial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,69 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use anyhow::Result; | ||
|
|
||
| use super::common::EncodedMediaData; | ||
| use ndarray::{ArrayBase, Dimension, OwnedRepr}; | ||
| mod image; | ||
|
|
||
| pub use image::{ImageDecoder, ImageMetadata}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub enum DecodedMediaMetadata { | ||
| #[allow(dead_code)] // used in followup MR | ||
| Image(ImageMetadata), | ||
| } | ||
|
|
||
| #[derive(Debug, PartialEq, Eq)] | ||
| pub enum DataType { | ||
| UINT8, | ||
| } | ||
|
|
||
| // Decoded media data (image RGB, video frames pixels, ...) | ||
| #[derive(Debug)] | ||
| pub struct DecodedMediaData { | ||
milesial marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #[allow(dead_code)] // used in followup MR | ||
| pub(crate) data: Vec<u8>, | ||
| #[allow(dead_code)] // used in followup MR | ||
| pub(crate) shape: Vec<usize>, | ||
| #[allow(dead_code)] // used in followup MR | ||
| pub(crate) dtype: DataType, | ||
| #[allow(dead_code)] // used in followup MR | ||
| pub(crate) metadata: Option<DecodedMediaMetadata>, | ||
| } | ||
|
|
||
| // convert Array{N}<u8> to DecodedMediaData | ||
| // TODO: Array1<f32> for audio | ||
milesial marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| impl<D: Dimension> From<ArrayBase<OwnedRepr<u8>, D>> for DecodedMediaData { | ||
| fn from(array: ArrayBase<OwnedRepr<u8>, D>) -> Self { | ||
| let shape = array.shape().to_vec(); | ||
| let (data, _) = array.into_raw_vec_and_offset(); | ||
| Self { | ||
| data, | ||
| shape, | ||
| dtype: DataType::UINT8, | ||
| metadata: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| pub trait Decoder: Clone + Send + 'static { | ||
| fn decode(&self, data: EncodedMediaData) -> Result<DecodedMediaData>; | ||
|
|
||
| async fn decode_async(&self, data: EncodedMediaData) -> Result<DecodedMediaData> { | ||
| // light clone (only config params) | ||
| let decoder = self.clone(); | ||
| // compute heavy -> rayon | ||
| let result = tokio_rayon::spawn(move || decoder.decode(data)).await?; | ||
| Ok(result) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)] | ||
| pub struct MediaDecoder { | ||
| #[serde(default)] | ||
| pub image_decoder: ImageDecoder, | ||
| // TODO: video, audio decoders | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.