1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
//! # fimg
//!
//! Provides fast image operations, such as rotation, flipping, and overlaying.
//!
//! ## Organization
//!
//! Image types:
//!
//! - [`Image`]: the main image type.
//! - [`DynImage`]: This is the image type you use when, say, loading a png. You should immediately convert this into a
//! - [`ImageCloner`]: This is... a [`Image`], but about to be cloned. It just allows some simple out-of-place optimizations, that `.clone().op()` dont  allow. (produce with [`Image::cloner`])
//! - [`uninit::Image`]: A uninitialized image. Used for performance optimization.
//!
//! ### Operations
//!
//! Affine:
//! - [`Image::rot_90`]
//! - [`Image::rot_180`]
//! - [`Image::rot_270`]
//! - [`Image::flip_h`]
//! - [`Image::flip_v`]
//!
//! Drawing:
//! - [`Image::box`], [`Image::filled_box`], [`Image::stroked_box`]
//! - [`Image::circle`], [`Image::border_circle`]
//! - [`Image::line`], [`Image::thick_line`]
//! - [`Image::points`]
//! - [`Image::quad`]
//! - [`Image::poly`], [`Image::border_poly`]
//! - [`Image::tri`]
//! - [`Image::text`]
//!
//! Scaling: [`Image::scale`]
//!
//! Misc image ops:
//! - [`Image::repeated`]
//! - [`Image::overlay`](Overlay), [`Image::overlay_at`](OverlayAt), [`Image::overlay_blended`](BlendingOverlay)
//! - [`Image::blur`]
//! - [`Image::crop`]
//!
//! ## feature flags
//!
//! - `scale`: enables the [`scale`] module.
//! - `save`: enables [`Image::save`], via the [`png`](https://crates.io/crates/png) crate.
//! - `text`: enables [`Image::text`], via the [`fontdue`](https://crates.io/crates/fontdue) crate.
//! - `blur`: enables [`Image::blur`], via the [`stackblur`](https://crates.io/crates/stackblur-iter) crate.
//! - `real-show`: [`Image::show`], if the `save` feature is enabled, will, by default, simply open the appropriate image viewing program.
//! if, for some reason, this is inadequate/you dont have a good image viewer, enable the `real-show` feature to make [`Image::show`] open up a window of its own.
//! without the `real-show` feature, [`Image::show`] will save itself to your temp directory, which you may not want.
//! - `term`: [`term::print`]. this enables printing images directly to the terminal, if you don't want to open a window or something. supports `{iterm2, kitty, sixel, fallback}` graphics.
//! - `default`: \[`save`, `scale`\].
#![cfg_attr(all(feature = "term", windows), windows_subsystem = "console")]
#![feature(
    maybe_uninit_write_slice,
    hint_assert_unchecked,
    slice_swap_unchecked,
    generic_const_exprs,
    iter_array_chunks,
    core_intrinsics,
    slice_as_chunks,
    slice_flatten,
    rustc_private,
    portable_simd,
    array_windows,
    doc_auto_cfg,
    const_option,
    array_chunks,
    let_chains,
    try_blocks,
    test
)]
#![warn(
    clippy::undocumented_unsafe_blocks,
    clippy::missing_const_for_fn,
    clippy::missing_safety_doc,
    clippy::suboptimal_flops,
    unsafe_op_in_unsafe_fn,
    clippy::dbg_macro,
    clippy::use_self,
    missing_docs
)]
#![allow(
    clippy::zero_prefixed_literal,
    mixed_script_confusables,
    incomplete_features,
    confusable_idents,
    internal_features
)]
use std::{hint::assert_unchecked, num::NonZeroU32, ops::Range};

mod affine;
#[cfg(feature = "blur")]
mod blur;
pub use sub::{Cropper, SubImage};
pub mod builder;
#[doc(hidden)]
pub mod cloner;
mod convert;
mod drawing;
mod r#dyn;
pub(crate) mod math;
mod overlay;
mod pack;
mod span;
mod sub;
pub mod uninit;
#[cfg(feature = "wgpu-convert")]
mod wgpu_convert;
pub use pack::Pack;
pub mod pixels;
#[cfg(feature = "scale")]
pub mod scale;
#[cfg(any(feature = "save", feature = "real-show"))]
mod show;
#[cfg(feature = "term")]
pub mod term;
pub use cloner::ImageCloner;
pub use overlay::{BlendingOverlay, ClonerOverlay, ClonerOverlayAt, Overlay, OverlayAt};
pub use r#dyn::DynImage;

trait CopyWithinUnchecked {
    /// # Safety
    ///
    /// panicless version of [`[T]::copy_within`](`slice::copy_within`), where the slices cant overlap. this uses `memcpy`.
    /// your slices must be in bounds.
    /// this isnt a public function, so im not going to say exactly what "in bounds" means.
    unsafe fn copy_within_unchecked(&mut self, src: Range<usize>, dest: usize);
}

impl<T> CopyWithinUnchecked for [T] {
    unsafe fn copy_within_unchecked(&mut self, src: Range<usize>, dest: usize) {
        let std::ops::Range { start, end } = src;
        debug_assert!(dest <= self.len() - end - start, "dest is out of bounds");
        #[allow(clippy::multiple_unsafe_ops_per_block)]
        // SAFETY: the caller better be good
        unsafe {
            let ptr = self.as_mut_ptr();
            std::ptr::copy_nonoverlapping(ptr.add(start), ptr.add(dest), end - start)
        };
    }
}

trait At {
    fn at<const C: usize>(self, x: u32, y: u32) -> usize;
}

impl At for (u32, u32) {
    fn at<const C: usize>(self, x: u32, y: u32) -> usize {
        debug_assert!(x < self.0, "x out of bounds");
        debug_assert!(y < self.1, "y out of bounds");
        #[allow(clippy::multiple_unsafe_ops_per_block)]
        // SAFETY: me when uncheck math: 😧 (FIXME)
        let index = unsafe {
            // y * w + x
            let tmp = (y as usize).unchecked_mul(self.0 as usize);
            tmp.unchecked_add(x as usize)
        };
        // SAFETY: 🧐 is unsound? 😖
        unsafe { index.unchecked_mul(C) }
    }
}

impl Image<&[u8], 3> {
    /// Tile self till it fills a new image of size x, y
    /// # Safety
    ///
    /// UB if self's width is not a multiple of x, or self's height is not a multiple of y
    /// ```
    /// # use fimg::Image;
    /// let x: Image<&[u8], 3> = Image::build(8, 8).buf(include_bytes!("../benches/3_8x8.imgbuf"));
    /// let tiled = unsafe { x.repeated(48, 48) }; // repeat 6 times
    /// # assert_eq!(tiled.buffer(), b"\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xf7\xcb\xa4\xf7\xcb\xa4\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xf7\xcb\xa4\xf7\xcb\xa4\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xf7\xcb\xa4\xf7\xcb\xa4\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xf7\xcb\xa4\xf7\xcb\xa4\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d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d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d\xd3\xae\x8d")
    /// ```
    #[must_use = "function does not modify the original image"]
    pub unsafe fn repeated(&self, out_width: u32, out_height: u32) -> Image<Vec<u8>, 3> {
        let mut img = uninit::Image::new(
            out_width.try_into().unwrap(),
            out_height.try_into().unwrap(),
        );
        debug_assert!(out_width % self.width() == 0);
        debug_assert!(out_height % self.height() == 0);
        for y in 0..self.height() {
            // SAFETY: get one row of pixels
            let from = unsafe {
                self.buffer
                    .get_unchecked(self.at(0, y)..self.at(0, y) + (self.width() as usize * 3))
            };
            debug_assert_eq!(from.len(), self.width() as usize * 3);
            let first = (0, y)..(self.width(), y);
            // SAFETY: copy it in
            unsafe { img.write(from, first.clone()) };

            for x in 1..(out_width / self.width()) {
                let section = img.at(x * self.width(), y);
                // SAFETY: copy each row of the image one by one
                unsafe { img.copy_within(first.clone(), section) };
            }
        }

        let first_row = 0..img.at(0, self.height());
        for y in 1..(out_height / self.height()) {
            let this_row = img.at(0, y * self.height());
            // SAFETY: copy entire blocks of image at a time
            unsafe { img.copy_within(first_row.clone(), this_row) };
        }
        // SAFETY: we init
        unsafe { img.assume_init() }
    }
}

/// A image with a variable number of channels, and a nonzero size.
#[derive(Debug, PartialEq, Eq)]
#[repr(C)]
pub struct Image<T, const CHANNELS: usize> {
    /// column order 2d slice/vec
    buffer: T,
    /// image horizontal size
    width: NonZeroU32,
    /// image vertical size
    height: NonZeroU32,
}

impl<T: Clone, const CHANNELS: usize> Clone for Image<T, CHANNELS> {
    /// Returns a duplicate of this image.
    /// ```
    /// # use fimg::Image;
    /// # let i = Image::<Vec<_>, 1>::alloc(5,5);
    /// let new_i = i.clone();
    /// ```
    /// If you find yourself in the pattern of
    /// ```
    /// # use fimg::Image;
    /// # let i = Image::<Vec<_>, 1>::alloc(5,5);
    /// let mut i = i.clone();
    /// unsafe { i.rot_90() };
    /// ```
    /// STOP!
    ///
    /// Instead use
    /// ```
    /// # use fimg::Image;
    /// # let i = Image::<Vec<_>, 1>::alloc(5,5);
    /// let i = unsafe { i.cloner().rot_90() };
    /// ```
    fn clone(&self) -> Self {
        Self {
            buffer: self.buffer.clone(),
            width: self.width,
            height: self.height,
        }
    }
}

impl<T, const CHANNELS: usize> Image<T, CHANNELS> {
    #[inline]
    /// get the height as a [`u32`]
    pub const fn height(&self) -> u32 {
        self.height.get()
    }

    #[inline]
    /// get the width as a [`u32`]
    pub const fn width(&self) -> u32 {
        self.width.get()
    }

    #[inline]
    /// create a new image
    ///
    /// # Safety
    ///
    /// does not check that buffer.len() == w * h * C
    ///
    /// using this with invalid values may result in future UB
    pub const unsafe fn new(width: NonZeroU32, height: NonZeroU32, buffer: T) -> Self {
        Self {
            buffer,
            width,
            height,
        }
    }

    /// consumes the image, returning the image buffer
    pub fn take_buffer(self) -> T {
        self.buffer
    }

    /// returns a immutable reference to the backing buffer
    pub const fn buffer(&self) -> &T {
        &self.buffer
    }

    /// returns a mutable(!) reference to the backing buffer
    ///
    /// # Safety
    ///
    /// please do not change buffer size.
    pub unsafe fn buffer_mut(&mut self) -> &mut T {
        &mut self.buffer
    }

    /// # Safety
    ///
    /// the output index is not guaranteed to be in bounds
    #[inline]
    fn at(&self, x: u32, y: u32) -> usize {
        (self.width(), self.height()).at::<CHANNELS>(x, y)
    }

    /// # Safety
    /// keep the buffer size the same
    unsafe fn map<U, const N: usize, F: FnOnce(&T) -> U>(&self, f: F) -> Image<U, N> {
        // SAFETY: we dont change anything, why check
        unsafe { Image::new(self.width, self.height, f(self.buffer())) }
    }

    unsafe fn mapped<U, const N: usize, F: FnOnce(T) -> U>(self, f: F) -> Image<U, N> {
        // SAFETY: we dont change anything, why check
        unsafe { Image::new(self.width, self.height, f(self.buffer)) }
    }

    /// # Safety
    /// buffer size must be the same.
    unsafe fn map_into<U: From<T>, const N: usize>(self) -> Image<U, N> {
        unsafe { self.mapped(Into::into) }
    }
}

impl<const CHANNELS: usize, T: Clone> Image<&[T], CHANNELS> {
    /// Allocate a new `Image<Vec<T>>` from this imageref.
    pub fn to_owned(&self) -> Image<Vec<T>, CHANNELS> {
        // SAFETY: size not changed
        unsafe { self.map(|b| b.to_vec()) }
    }
}

impl<const CHANNELS: usize, T: Clone> Image<&mut [T], CHANNELS> {
    /// Allocate a new `Image<Vec<T>>` from this mutable imageref.
    pub fn to_owned(&self) -> Image<Vec<T>, CHANNELS> {
        // SAFETY: size not changed
        unsafe { self.map(|b| b.to_vec()) }
    }
}

impl<const CHANNELS: usize> Copy for Image<&[u8], CHANNELS> {}

impl<const CHANNELS: usize> Image<&[u8], CHANNELS> {
    #[inline]
    #[must_use]
    /// Copy this ref image
    pub const fn copy(&self) -> Self {
        Self {
            width: self.width,
            height: self.height,
            buffer: self.buffer,
        }
    }

    /// Create a new immutable image of width x, y.
    ///
    /// # Panics
    ///
    /// if width || height == 0
    ///
    /// ```
    /// # use fimg::Image;
    /// let img = Image::make::<5, 5>();
    /// # let img: Image<_, 4> = img;
    /// ```
    pub const fn make<'a, const WIDTH: u32, const HEIGHT: u32>() -> Image<&'a [u8], CHANNELS>
    where
        [(); CHANNELS * WIDTH as usize * HEIGHT as usize]:,
    {
        Image {
            width: NonZeroU32::new(WIDTH).expect("passed zero width to builder"),
            height: NonZeroU32::new(HEIGHT).expect("passed zero height to builder"),
            buffer: &[0; CHANNELS * WIDTH as usize * HEIGHT as usize],
        }
    }
}

impl<const CHANNELS: usize, const N: usize> Image<[u8; N], CHANNELS> {
    /// Box this array image.
    pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> {
        // SAFETY: size not changed
        unsafe { self.map_into() }
    }
}

impl<const CHANNELS: usize> Image<&[u8], CHANNELS> {
    /// Box this image.
    pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> {
        // SAFETY: size not changed
        unsafe { self.map_into() }
    }
}

impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS> {
    /// Box this owned image.
    pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> {
        // SAFETY: ctor
        unsafe { self.map_into() }
    }
}

impl<const CHANNELS: usize> Image<Box<[u8]>, CHANNELS> {
    /// Unbox this vec image.
    pub fn unbox(self) -> Image<Vec<u8>, CHANNELS> {
        // SAFETY: ctor
        unsafe { self.map_into() }
    }
}

#[macro_export]
/// Create a <code>[Image]<[[u8]; N], C></code> with ease. If your looking for a <code>[Image]<&'static [[u8]]></code>, try [`Image::make`].
///
/// ```
/// let mut i = fimg::make!(4 channels 128 x 128);
/// ```
///
/// Implementation note:
/// This is doable with a const generic fn, but it returns a `fimg::Image<[u8; fimg::::{impl#7}::array::{constant#1}], _>` which means you cant actually type it, so its useless.
macro_rules! make {
    ($channels:literal channels $w:literal x $h: literal) => {
        unsafe {
            $crate::Image::<_, $channels>::new(
                match ::core::num::NonZeroU32::new($w) {
                    ::core::option::Option::Some(n) => n,
                    ::core::option::Option::None => panic!("width is 0"),
                },
                match ::core::num::NonZeroU32::new($h) {
                    ::core::option::Option::Some(n) => n,
                    ::core::option::Option::None => panic!("height is 0"),
                },
                [0_u8; $channels * $w * $h],
            )
        }
    };
}

impl<T, const CHANNELS: usize> Image<T, CHANNELS> {
    /// The size of the underlying buffer.
    #[allow(clippy::len_without_is_empty)]
    pub fn len<U>(&self) -> usize
    where
        T: AsRef<[U]>,
    {
        self.buffer().as_ref().len()
    }

    /// # Safety
    ///
    /// the output index is not guaranteed to be in bounds
    #[inline]
    fn slice<U>(&self, x: u32, y: u32) -> Range<usize>
    where
        T: AsRef<[U]>,
    {
        let index = self.at(x, y);
        debug_assert!(self.len() > index);
        // SAFETY: as long as the buffer isnt wrong, this is 😄
        index..unsafe { index.unchecked_add(CHANNELS) }
    }

    #[inline]
    /// Returns a iterator over every pixel
    pub fn chunked<'a, U: 'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]>
    where
        T: AsRef<[U]>,
    {
        // SAFETY: 0 sized images illegal
        unsafe { assert_unchecked(self.len() >= CHANNELS) };
        // SAFETY: no half pixels!
        unsafe { assert_unchecked(self.len() % CHANNELS == 0) };
        self.buffer().as_ref().array_chunks::<CHANNELS>()
    }

    #[inline]
    /// Flatten the chunks of this image into a slice of slices.
    pub fn flatten<U>(&self) -> &[[U; CHANNELS]]
    where
        T: AsRef<[U]>,
    {
        // SAFETY: buffer cannot have half pixels
        unsafe { self.buffer().as_ref().as_chunks_unchecked::<CHANNELS>() }
    }

    /// Create a mutref to this image
    pub fn as_mut<U>(&mut self) -> Image<&mut [U], CHANNELS>
    where
        T: AsMut<[U]>,
    {
        // SAFETY: construction went okay
        unsafe { Image::new(self.width, self.height, self.buffer.as_mut()) }
    }

    /// Reference this image.
    pub fn as_ref<U>(&self) -> Image<&[U], CHANNELS>
    where
        T: AsRef<[U]>,
    {
        // SAFETY: we got constructed okay, parameters must be valid
        unsafe { Image::new(self.width, self.height, self.buffer().as_ref()) }
    }

    /// Return a pixel at (x, y).
    /// # Safety
    ///
    /// - UB if x, y is out of bounds
    /// - UB if buffer is too small
    #[inline]
    pub unsafe fn pixel<U: Copy>(&self, x: u32, y: u32) -> [U; CHANNELS]
    where
        T: AsRef<[U]>,
    {
        // SAFETY: x and y in bounds, slice is okay
        let ptr = unsafe {
            self.buffer()
                .as_ref()
                .get_unchecked(self.slice(x, y))
                .as_ptr()
                .cast()
        };
        // SAFETY: slice always returns a length of `CHANNELS`, so we `cast()` it for convenience.
        unsafe { *ptr }
    }

    /// Return a mutable reference to a pixel at (x, y).
    /// # Safety
    ///
    /// - UB if x, y is out of bounds
    /// - UB if buffer is too small
    #[inline]
    pub unsafe fn pixel_mut<U: Copy>(&mut self, x: u32, y: u32) -> &mut [U]
    where
        T: AsMut<[U]> + AsRef<[U]>,
    {
        // SAFETY: we have been told x, y is in bounds.
        let idx = self.slice(x, y);
        // SAFETY: slice should always return a valid index
        unsafe { self.buffer.as_mut().get_unchecked_mut(idx) }
    }
}

impl<T: AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
    /// Bytes of this image.
    pub fn bytes(&self) -> &[u8] {
        self.buffer.as_ref()
    }

    /// Procure a [`ImageCloner`].
    #[must_use = "function does not modify the original image"]
    pub fn cloner(&self) -> ImageCloner<'_, CHANNELS> {
        ImageCloner::from(self.as_ref())
    }
}

impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
    #[inline]
    /// Returns a iterator over every pixel, mutably
    pub fn chunked_mut(&mut self) -> impl Iterator<Item = &mut [u8; CHANNELS]> {
        // SAFETY: 0 sized images are not allowed
        unsafe { assert_unchecked(self.len() >= CHANNELS) };
        // SAFETY: buffer cannot have half pixels
        unsafe { assert_unchecked(self.len() % CHANNELS == 0) };
        self.buffer.as_mut().array_chunks_mut::<CHANNELS>()
    }

    #[inline]
    /// Flatten the chunks of this image into a mutable slice of slices.
    pub fn flatten_mut(&mut self) -> &mut [[u8; CHANNELS]] {
        // SAFETY: buffer cannot have half pixels
        unsafe { self.buffer.as_mut().as_chunks_unchecked_mut::<CHANNELS>() }
    }

    /// Set the pixel at x, y
    ///
    /// # Safety
    ///
    /// UB if x, y is out of bounds.
    #[inline]
    pub unsafe fn set_pixel(&mut self, x: u32, y: u32, px: [u8; CHANNELS]) {
        // SAFETY: Caller says that x, y is in bounds
        let out = unsafe { self.pixel_mut(x, y) };
        // SAFETY: px must be CHANNELS long
        unsafe { std::ptr::copy_nonoverlapping(px.as_ptr(), out.as_mut_ptr(), CHANNELS) };
    }
}

impl<const CHANNELS: usize> Image<&mut [u8], CHANNELS> {
    /// Copy this ref image
    pub fn copy(&mut self) -> Image<&mut [u8], CHANNELS> {
        #[allow(clippy::undocumented_unsafe_blocks)]
        unsafe {
            Image::new(self.width, self.height, self.buffer)
        }
    }
}

impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS> {
    /// Allocates a new image. If `width` and `height` are constant, try using [`make`].
    ///
    /// # Panics
    ///
    /// if width || height == 0
    #[must_use]
    pub fn alloc(width: u32, height: u32) -> Self {
        Self {
            width: width.try_into().unwrap(),
            height: height.try_into().unwrap(),
            buffer: vec![0; CHANNELS * width as usize * height as usize],
        }
    }

    /// Consumes and leaks this image, returning a reference to the image.
    #[must_use = "not using the returned reference is a memory leak"]
    pub fn leak(self) -> Image<&'static mut [u8], CHANNELS> {
        // SAFETY: size unchanged
        unsafe { self.mapped(Vec::leak) }
    }
}

impl<const CHANNELS: usize, T: ?Sized> Image<Box<T>, CHANNELS> {
    /// Consumes and leaks this image, returning a reference to the image.
    #[must_use = "not using the returned reference is a memory leak"]
    pub fn leak(self) -> Image<&'static mut T, CHANNELS> {
        // SAFETY: size unchanged
        unsafe { self.mapped(Box::leak) }
    }
}

#[cfg(feature = "save")]
/// Write a png image.
pub trait WritePng {
    /// Write this png image.
    fn write(&self, f: &mut impl std::io::Write) -> std::io::Result<()>;
}

/// Read png.
#[cfg(feature = "save")]
pub trait ReadPng
where
    Self: Sized,
{
    /// Read a png into an image.
    fn read(f: &mut impl std::io::Read) -> std::io::Result<Self>;
}

/// helper macro for defining the save() method.
macro_rules! save {
    ($channels:literal == $clr:ident ($clrhuman:literal)) => {
        #[cfg(feature = "save")]
        impl<T: AsRef<[u8]>> WritePng for Image<T, $channels> {
            #[doc = "Save this "]
            #[doc = $clrhuman]
            #[doc = " image."]
            fn write(&self, f: &mut impl std::io::Write) -> std::io::Result<()> {
                let mut enc = png::Encoder::new(f, self.width(), self.height());
                enc.set_color(png::ColorType::$clr);
                enc.set_depth(png::BitDepth::Eight);
                enc.set_source_gamma(png::ScaledFloat::new(1.0 / 2.2));
                enc.set_source_chromaticities(png::SourceChromaticities::new(
                    (0.31270, 0.32900),
                    (0.64000, 0.33000),
                    (0.30000, 0.60000),
                    (0.15000, 0.06000),
                ));
                let mut writer = enc.write_header()?;
                writer.write_image_data(self.bytes())?;
                Ok(())
            }
        }
        impl<T: AsRef<[u8]>> Image<T, $channels> {
            #[cfg(feature = "save")]
            #[doc = "Save this "]
            #[doc = $clrhuman]
            #[doc = " image."]
            pub fn save(&self, f: impl AsRef<std::path::Path>) {
                self.write(&mut std::io::BufWriter::new(
                    std::fs::File::create(f).unwrap(),
                ))
                .unwrap();
            }
        }
    };
}

macro_rules! read {
    ($n:literal) => {
        #[cfg(feature = "save")]
        impl ReadPng for Image<Box<[u8]>, $n> {
            /// Open a PNG image
            fn read(f: &mut impl std::io::Read) -> std::io::Result<Self> {
                use png::Transformations as T;
                let mut dec = png::Decoder::new(f);
                match $n {
                    1 | 3 => dec.set_transformations(T::STRIP_16 | T::EXPAND),
                    2 | 4 => dec.set_transformations(T::STRIP_16 | T::ALPHA), // alpha implies expand
                    _ => (),
                }
                let mut reader = dec.read_info()?;
                let mut buf = vec![0; reader.output_buffer_size()].into_boxed_slice();
                let info = reader.next_frame(&mut buf)?;
                use png::ColorType::*;
                macro_rules! n {
                    ($x:literal) => {
                        Image::<_, $x>::build(info.width, info.height)
                            .buf(buf)
                            .into()
                    };
                }
                Ok(match info.color_type {
                    Indexed => unreachable!(), // see EXPAND
                    Grayscale => n![1],
                    GrayscaleAlpha => n![2],
                    Rgb => n![3],
                    Rgba => n![4],
                })
            }
        }
    };
}
impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS>
where
    [(); { (CHANNELS <= 4) as usize } - 1]:,
{
    #[cfg(feature = "save")]
    /// Open a PNG image
    pub fn open(f: impl AsRef<std::path::Path>) -> Self {
        let p = std::fs::File::open(f).unwrap();
        let r = &mut std::io::BufReader::new(p);
        use core::intrinsics::transmute_unchecked as t;
        // SAFETY: ... this is idiotic.
        unsafe {
            match CHANNELS {
                1 => t(Image::<Box<_>, 1>::read(r).unwrap().unbox()),
                2 => t(Image::<Box<_>, 2>::read(r).unwrap().unbox()),
                3 => t(Image::<Box<_>, 3>::read(r).unwrap().unbox()),
                4 => t(Image::<Box<_>, 4>::read(r).unwrap().unbox()),
                _ => unreachable!(),
            }
        }
    }
}
read!(1);
read!(2);
read!(3);
read!(4);

save!(3 == Rgb("RGB"));
save!(4 == Rgba("RGBA"));
save!(2 == GrayscaleAlpha("YA"));
save!(1 == Grayscale("Y"));

#[cfg(test)]
macro_rules! img {
    [[$($v:literal),+] [$($v2:literal),+]] => {
        Image::<Vec<u8>, 1>::build(2,2).buf(vec![$($v,)+ $($v2,)+])
    }
}
#[cfg(test)]
use img;