-
Notifications
You must be signed in to change notification settings - Fork 627
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
Creating a new PixelImage
type.
#2262
Comments
These are answered together. Because it is more strongly typed. Note that subpixel types are not specific to Also, the borrowed Following #1523, |
Ah ok, I think I can see the use-case: let byte_vec: Vec<u8> = from_external_function();
let image: Image<Rgb<u8>, Vec<u8>> = Image {
width,
height,
phantom: PhantomData,
pixels: byte_vec,
}; Is that right? In which case couldn't the user just use let byte_vec: Vec<u8> = from_external_function();
let rgb_vec: Vec<Rgb<u8>> = bytemuck::cast_vec(byte_vec);
let image: Image<Rgb<u8>> = Image {
width,
height,
pixels: rgb_vec,
};
I see two options here:
struct PixelImage {pixels: Vec<P>}
struct PixelImageWithMetadata {pixel_image: PixelImage, metadata: ImageMetadata}
struct PixelImage {pixels: Vec<P>, metadata: Option<ImageMetadata>,}
// With an enum variant on ImageMetadata itself.
struct PixelImage {pixels: Vec<P>, metadata: ImageMetadata::Unknown,} I don't feel too strongly either way between these two options as I feel like I could make either option work for all use-cases, the only slight downside to option |
I'm rather new to this wonderful crate so excuse my lack of knowledge. Adding metadata to the I would be more in favor of having a new type, which holds the |
The main information I was thinking about was color-space information. Perhaps Some core operations require this information for accurate color-conversion, such as if you were to convert an This type of conversion could be implemented on There's also the potential scenario where you may or may not know the color-space information about an image at run-time, this would require a hybrid type somewhere between struct PixelImagePossiblyWithMetadata {
pixels: Vec<P>,
metadata: Option<ImageMetadata>,
} This might be a useful type for applying best-effort color-space conversions between image pixel formats. |
I used metadata for:
So there can be a lot of application-specific metadata, and not all of it will be useful to everyone. Therefore I suggest having something like extensions in the HTTP crate: https://docs.rs/http/latest/http/struct.Extensions.html |
I suppose the alternative to using a type-map like struct ImageMetadata {
color_space_info: Option<ColorSpaceInfo>,
original_file_size: Option<u32>,
original_image_dimensions: Option<(u32, u32)>,
loop_count: Option<u32>,
file_modification_timestamp: Option<u64>,
decoder_info: Option<DecoderInfo>,
}
struct DecoderInfo {
filetype: FileType,
decoder_name: String,
decoder_version: String,
}
type ColorSpaceInfo = image_canvas::Color; Using the very comprehensive This struct would likely grow as people requested different types of metadata (like GPS info), but this could be done backwards-compatibly if we made all the fields private and used a builder-style API for it. Alternatively, we could make breaking changes by expanding it but teach people to use |
From #1523 it was discussed that renaming
ImageBuffer
toPixelImage
or similar would be beneficial to emphasize the strong dependence onPixel
types likeRgb
andLuma
over other formats, especially compressed formats like.jpg
represented as[u8]
.Since we are renaming it I though it might be a good idea to discuss some other related design choices of the
PixelImage
type.At the moment
ImageBuffer
is defined as:I have several questions when looking at this:
Container
toDeref<Target=[P::Subpixel]>
rather thanDeref<Target=[P]>
which is more strongly typed?Container
rather than usingVec<P>
whenDeref<Target[P::Subpixel]>
is a required bound for nearly all methods?Dependent on the answers to these questions, I would like to add an new type to the library:
If we need a borrowed version of
PixelImage
we could create that also with animpl Borrow + impl Deref<>
:One yet unresolved question about this new type (from #1523) is:
ImageMetadata
struct to it?And then slowly deprecate and replace the old
ImageBuffer
type withPixelImage
over the next few releases. What do you think?The text was updated successfully, but these errors were encountered: