added the decoder and began to configure it

created new variables and initiated them with calues from the .info

added some questions
This commit is contained in:
Schwingel0206 2023-06-08 20:01:39 +02:00
parent 83318d8035
commit 65e422e547
1 changed files with 46 additions and 8 deletions

View File

@ -1,15 +1,53 @@
use std::path::Path; use std::path::Path;
use crate::image::Image; use crate::image::Image;
use std::fs::File;
pub fn image_loader(path: &Path) -> Image<f32> {
let vec: Vec<(f32, f32, f32, f32)> = vec![ /* !!!Fragen!!!
- was ist .unwrap()
- was ist ein IDAT chunk (bei read.info() in der doku)
- was ist .output_buffer_size()
- was ist .next_frame
- kann ich srgb nutzen für dir rgba values bzw für den rgb teil
- woher ziehe ich den alpha channel
- ist makierter teil kommplet nötig
*/
pub fn image_loader(path: &Path) -> Image<f32>
{
//marker1
// The decoder is a build for reader and can be used to set various decoding options
// via `Transformations`. The default output transformation is `Transformations::IDENTITY`.
//open a path in the decoder to look into the img
let decoder = png::Decoder::new(File::open(path).unwrap());
let mut reader = decoder.read_info().unwrap();
// Allocate the output buffer.
let mut buf = vec![0; reader.output_buffer_size()];
// Read the next frame. An APNG might contain multiple frames.
let info = reader.next_frame(&mut buf).unwrap();
let bit_depth = reader.info().bit_depth;
let color_type = reader.info().color_type;
let width = reader.info().width;
let height = reader.info().height;
// Grab the bytes of the image.
let bytes = &buf[..info.buffer_size()];
// Inspect more details of the last read frame.
let in_animation = reader.info().frame_control.is_some();
//marker1
let vec: Vec<(f32, f32, f32, f32)> = vec!
[
(-33.0, 7732.0, 2564355.0, -79.0), (-33.0, 7732.0, 2564355.0, -79.0),
(1.0, 79.0, 255.0, 1.05), (1.0, 79.0, 255.0, 1.05),
(300.0, 300.0, 300.0, 300.0), (300.0, 300.0, 300.0, 300.0),
]; ];
let image: Image<f32> = Image::new(1, 3, vec); let image: Image<f32> = Image::new(1, 3, vec, path.to_path_buf());
image image
} }