@@ -112,7 +112,8 @@ Image_Option:
112
112
113
113
`.alpha_drop_if_present`
114
114
If the image has an alpha channel, drop it.
115
- You may want to use `.alpha_premultiply` in this case.
115
+ You may want to use `.alpha_
116
+ tiply` in this case.
116
117
117
118
NOTE: For PNG, this also skips handling of the tRNS chunk, if present,
118
119
unless you select `alpha_premultiply`.
@@ -587,6 +588,32 @@ Channel :: enum u8 {
587
588
A = 4 ,
588
589
}
589
590
591
+ // Take a slice of pixels (`[]RGBA_Pixel`, etc), and return an `Image`
592
+ // Don't call `destroy` on the resulting `Image`. Instead, delete the original `pixels` slice.
593
+ pixels_to_image :: proc (pixels: [][$N ]$E , width: int , height: int ) -> (img: Image, ok: bool ) where E == u8 || E == u16 , N >= 1 && N <= 4 {
594
+ if len (pixels) != width * height {
595
+ return {}, false
596
+ }
597
+
598
+ img.height = height
599
+ img.width = width
600
+ img.depth = 8 when E == u8 else 16
601
+ img.channels = N
602
+
603
+ s := transmute (runtime.Raw_Slice)pixels
604
+ d := runtime.Raw_Dynamic_Array{
605
+ data = s.data,
606
+ len = s.len * size_of (E) * N,
607
+ cap = s.len * size_of (E) * N,
608
+ allocator = runtime.nil_allocator (),
609
+ }
610
+ img.pixels = bytes.Buffer{
611
+ buf = transmute ([dynamic ]u8 )d,
612
+ }
613
+
614
+ return img, true
615
+ }
616
+
590
617
// When you have an RGB(A) image, but want a particular channel.
591
618
return_single_channel :: proc (img: ^Image, channel: Channel) -> (res: ^Image, ok: bool ) {
592
619
// Were we actually given a valid image?
0 commit comments