rawshift-core 0.1.0

Shared core types for rawshift (geometry, pixel samples, metadata model)
Documentation
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
//! Core image structures and types.
//!
//! This module defines the fundamental structures for representing
//! image dimensions, coordinates, and raw image data.

use crate::color::ColorSpace;

/// Compute the maximum pixel value (white level) for a given bit depth, clamped to `u16`.
///
/// Returns `u16::MAX` when `bit_depth >= 16`, and `(1 << bit_depth) - 1` otherwise.
#[inline]
pub fn white_level_from_bit_depth(bit_depth: u8) -> u16 {
    if bit_depth >= 16 {
        u16::MAX
    } else if bit_depth == 0 {
        0
    } else {
        (1u16 << bit_depth) - 1
    }
}

/// Image dimensions.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Size {
    /// Width in pixels
    pub width: u32,
    /// Height in pixels
    pub height: u32,
}

impl Size {
    /// Create a new Size.
    pub fn new(width: u32, height: u32) -> Self {
        Self { width, height }
    }

    /// Check if dimensions are valid (non-zero).
    pub fn is_valid(&self) -> bool {
        self.width > 0 && self.height > 0
    }

    /// Total number of pixels.
    pub fn pixel_count(&self) -> u64 {
        self.width as u64 * self.height as u64
    }
}

/// A point in image coordinates.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Point {
    /// X coordinate
    pub x: u32,
    /// Y coordinate
    pub y: u32,
}

impl Point {
    /// Create a new Point.
    pub fn new(x: u32, y: u32) -> Self {
        Self { x, y }
    }

    /// Origin point (0, 0).
    pub const ORIGIN: Point = Point { x: 0, y: 0 };
}

/// A rectangular region.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Rect {
    /// Origin (top-left corner)
    pub origin: Point,
    /// Size of the rectangle
    pub size: Size,
}

impl Rect {
    /// Create a new Rect.
    pub fn new(origin: Point, size: Size) -> Self {
        Self { origin, size }
    }

    /// Create a rect from coordinates.
    pub fn from_coords(x: u32, y: u32, width: u32, height: u32) -> Self {
        Self {
            origin: Point::new(x, y),
            size: Size::new(width, height),
        }
    }

    /// Right edge (x + width).
    pub fn right(&self) -> u32 {
        self.origin.x.saturating_add(self.size.width)
    }

    /// Bottom edge (y + height).
    pub fn bottom(&self) -> u32 {
        self.origin.y.saturating_add(self.size.height)
    }
}

/// CFA (Color Filter Array) pattern.
///
/// Represents the Bayer pattern used in the camera's sensor.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CfaPattern {
    /// Red-Green / Green-Blue
    Rggb,
    /// Green-Red / Blue-Green
    Grbg,
    /// Blue-Green / Green-Red
    Bggr,
    /// Green-Blue / Red-Green
    Gbrg,
}

impl CfaPattern {
    /// Parse from a 4-element array (row-major 2x2).
    ///
    /// Values: 0=Red, 1=Green, 2=Blue
    pub fn from_array(pattern: [u8; 4]) -> Option<Self> {
        match pattern {
            [0, 1, 1, 2] => Some(CfaPattern::Rggb),
            [1, 0, 2, 1] => Some(CfaPattern::Grbg),
            [2, 1, 1, 0] => Some(CfaPattern::Bggr),
            [1, 2, 0, 1] => Some(CfaPattern::Gbrg),
            _ => None,
        }
    }

    /// Convert to a 4-element array.
    pub fn to_array(self) -> [u8; 4] {
        match self {
            CfaPattern::Rggb => [0, 1, 1, 2],
            CfaPattern::Grbg => [1, 0, 2, 1],
            CfaPattern::Bggr => [2, 1, 1, 0],
            CfaPattern::Gbrg => [1, 2, 0, 1],
        }
    }

    /// Get a human-readable name.
    pub fn name(&self) -> &'static str {
        match self {
            CfaPattern::Rggb => "RGGB",
            CfaPattern::Grbg => "GRBG",
            CfaPattern::Bggr => "BGGR",
            CfaPattern::Gbrg => "GBRG",
        }
    }
}

/// X-Trans CFA pattern (6x6 repeating tile).
///
/// Values: 0=Red, 1=Green, 2=Blue
/// Row-major order, 36 elements total.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct XTransPattern {
    /// 6x6 grid of color indices: 0=Red, 1=Green, 2=Blue
    pub cells: [[u8; 6]; 6],
}

impl XTransPattern {
    /// Standard Fujifilm X-Trans I pattern (as used in RawTherapee/darktable).
    pub fn standard() -> Self {
        Self {
            cells: [
                [1, 2, 1, 1, 0, 1],
                [0, 1, 0, 2, 1, 2],
                [1, 2, 1, 1, 0, 1],
                [1, 0, 1, 2, 1, 2],
                [1, 2, 1, 1, 0, 1],
                [0, 1, 0, 2, 1, 2],
            ],
        }
    }

    /// Get color at absolute sensor position (x, y) using 6x6 tile wrapping.
    ///
    /// Returns 0=Red, 1=Green, 2=Blue.
    #[inline]
    pub fn color_at(&self, x: usize, y: usize) -> u8 {
        self.cells[y % 6][x % 6]
    }
}

/// Raw image data container.
///
/// Holds the decoded raw sensor data along with associated metadata.
/// Use [`RawImageBuilder`] to construct new instances.
#[derive(Debug, Clone)]
pub struct RawImage {
    size: Size,
    active_area: Rect,
    bit_depth: u8,
    cfa_pattern: CfaPattern,
    xtrans_pattern: Option<XTransPattern>,
    black_levels: [u16; 4],
    white_level: u16,
    /// Raw pixel data (16-bit values, one per sensor pixel).
    /// Stored in row-major order: data[y * width + x]
    pub data: Vec<u16>,
    baseline_exposure: Option<f32>,
    default_crop: Option<Rect>,
}

impl RawImage {
    /// Create a new empty RawImage with the given parameters.
    pub fn new(size: Size, active_area: Rect, bit_depth: u8, cfa_pattern: CfaPattern) -> Self {
        let pixel_count = size.pixel_count() as usize;
        Self {
            size,
            active_area,
            bit_depth,
            cfa_pattern,
            xtrans_pattern: None,
            black_levels: [0; 4],
            white_level: white_level_from_bit_depth(bit_depth),
            data: vec![0u16; pixel_count],
            baseline_exposure: None,
            default_crop: None,
        }
    }

    /// Create a builder for constructing a RawImage.
    pub fn builder(
        size: Size,
        active_area: Rect,
        bit_depth: u8,
        cfa_pattern: CfaPattern,
    ) -> RawImageBuilder {
        RawImageBuilder {
            size,
            active_area,
            bit_depth,
            cfa_pattern,
            xtrans_pattern: None,
            black_levels: [0; 4],
            white_level: white_level_from_bit_depth(bit_depth),
            data: None,
            baseline_exposure: None,
            default_crop: None,
        }
    }

    // ── Read accessors ───────────────────────────────────────────────────

    /// Full sensor dimensions.
    pub fn size(&self) -> Size {
        self.size
    }

    /// Sensor width in pixels.
    pub fn width(&self) -> u32 {
        self.size.width
    }

    /// Sensor height in pixels.
    pub fn height(&self) -> u32 {
        self.size.height
    }

    /// Active/crop area (usable image region).
    pub fn active_area(&self) -> Rect {
        self.active_area
    }

    /// Bits per sample (typically 12, 14, or 16).
    pub fn bit_depth(&self) -> u8 {
        self.bit_depth
    }

    /// CFA (Bayer) pattern.
    pub fn cfa_pattern(&self) -> CfaPattern {
        self.cfa_pattern
    }

    /// X-Trans CFA pattern, if applicable.
    pub fn xtrans_pattern(&self) -> Option<&XTransPattern> {
        self.xtrans_pattern.as_ref()
    }

    /// Black level values (per CFA color channel).
    pub fn black_levels(&self) -> &[u16; 4] {
        &self.black_levels
    }

    /// White/saturation level.
    pub fn white_level(&self) -> u16 {
        self.white_level
    }

    /// Baseline exposure offset in EV.
    pub fn baseline_exposure(&self) -> Option<f32> {
        self.baseline_exposure
    }

    /// Default crop rectangle.
    pub fn default_crop(&self) -> Option<Rect> {
        self.default_crop
    }

    // ── Write accessors ──────────────────────────────────────────────────

    /// Set black level values.
    pub fn set_black_levels(&mut self, levels: [u16; 4]) {
        self.black_levels = levels;
    }

    /// Set white/saturation level.
    pub fn set_white_level(&mut self, level: u16) {
        self.white_level = level;
    }

    /// Set baseline exposure offset.
    pub fn set_baseline_exposure(&mut self, ev: Option<f32>) {
        self.baseline_exposure = ev;
    }

    /// Set default crop rectangle.
    pub fn set_default_crop(&mut self, crop: Option<Rect>) {
        self.default_crop = crop;
    }

    /// Set X-Trans pattern.
    pub fn set_xtrans_pattern(&mut self, pattern: Option<XTransPattern>) {
        self.xtrans_pattern = pattern;
    }

    /// Set bit depth.
    pub fn set_bit_depth(&mut self, bit_depth: u8) {
        self.bit_depth = bit_depth;
    }

    // ── Pixel access ─────────────────────────────────────────────────────

    /// Get pixel value at (x, y).
    pub fn get_pixel(&self, x: u32, y: u32) -> Option<u16> {
        if x < self.size.width && y < self.size.height {
            let idx = (y as usize) * (self.size.width as usize) + (x as usize);
            Some(self.data[idx])
        } else {
            None
        }
    }

    /// Set pixel value at (x, y).
    pub fn set_pixel(&mut self, x: u32, y: u32, value: u16) {
        if x < self.size.width && y < self.size.height {
            let idx = (y as usize) * (self.size.width as usize) + (x as usize);
            self.data[idx] = value;
        }
    }
}

/// Builder for constructing [`RawImage`] instances.
pub struct RawImageBuilder {
    size: Size,
    active_area: Rect,
    bit_depth: u8,
    cfa_pattern: CfaPattern,
    xtrans_pattern: Option<XTransPattern>,
    black_levels: [u16; 4],
    white_level: u16,
    data: Option<Vec<u16>>,
    baseline_exposure: Option<f32>,
    default_crop: Option<Rect>,
}

impl RawImageBuilder {
    /// Set black level values.
    pub fn black_levels(mut self, levels: [u16; 4]) -> Self {
        self.black_levels = levels;
        self
    }

    /// Set white/saturation level.
    pub fn white_level(mut self, level: u16) -> Self {
        self.white_level = level;
        self
    }

    /// Set X-Trans pattern.
    pub fn xtrans_pattern(mut self, pattern: XTransPattern) -> Self {
        self.xtrans_pattern = Some(pattern);
        self
    }

    /// Set baseline exposure offset in EV.
    pub fn baseline_exposure(mut self, ev: f32) -> Self {
        self.baseline_exposure = Some(ev);
        self
    }

    /// Set default crop rectangle.
    pub fn default_crop(mut self, crop: Rect) -> Self {
        self.default_crop = Some(crop);
        self
    }

    /// Set pixel data.
    pub fn data(mut self, data: Vec<u16>) -> Self {
        self.data = Some(data);
        self
    }

    /// Build the RawImage.
    pub fn build(self) -> RawImage {
        let data = self
            .data
            .unwrap_or_else(|| vec![0u16; self.size.pixel_count() as usize]);
        RawImage {
            size: self.size,
            active_area: self.active_area,
            bit_depth: self.bit_depth,
            cfa_pattern: self.cfa_pattern,
            xtrans_pattern: self.xtrans_pattern,
            black_levels: self.black_levels,
            white_level: self.white_level,
            data,
            baseline_exposure: self.baseline_exposure,
            default_crop: self.default_crop,
        }
    }
}

/// A simple container for RGB image data.
#[derive(Debug, Clone)]
pub struct RgbImage {
    size: Size,
    /// Interleaved RGB data (R, G, B, R, G, B...)
    pub data: Vec<u16>,
    baseline_exposure: Option<f32>,
    default_crop: Option<Rect>,
    color_space: ColorSpace,
}

impl RgbImage {
    /// Create a new RgbImage with an unknown color space.
    ///
    /// Use [`with_color_space`](Self::with_color_space) or
    /// [`set_color_space`](Self::set_color_space) when the space is known.
    pub fn new(width: u32, height: u32, data: Vec<u16>) -> Self {
        Self {
            size: Size::new(width, height),
            data,
            baseline_exposure: None,
            default_crop: None,
            color_space: ColorSpace::Unknown,
        }
    }

    /// Create a new RgbImage tagged with a known color space.
    pub fn with_color_space(
        width: u32,
        height: u32,
        data: Vec<u16>,
        color_space: ColorSpace,
    ) -> Self {
        Self {
            size: Size::new(width, height),
            data,
            baseline_exposure: None,
            default_crop: None,
            color_space,
        }
    }

    // ── Read accessors ───────────────────────────────────────────────────

    /// Image dimensions.
    pub fn size(&self) -> Size {
        self.size
    }

    /// Image width in pixels.
    pub fn width(&self) -> u32 {
        self.size.width
    }

    /// Image height in pixels.
    pub fn height(&self) -> u32 {
        self.size.height
    }

    /// Baseline exposure offset in EV.
    pub fn baseline_exposure(&self) -> Option<f32> {
        self.baseline_exposure
    }

    /// Default crop rectangle.
    pub fn default_crop(&self) -> Option<Rect> {
        self.default_crop
    }

    /// The color space the RGB samples are in.
    pub fn color_space(&self) -> ColorSpace {
        self.color_space
    }

    // ── Write accessors ──────────────────────────────────────────────────

    /// Set baseline exposure offset.
    pub fn set_baseline_exposure(&mut self, ev: Option<f32>) {
        self.baseline_exposure = ev;
    }

    /// Set the color space tag for the RGB samples.
    pub fn set_color_space(&mut self, color_space: ColorSpace) {
        self.color_space = color_space;
    }

    /// Set default crop rectangle.
    pub fn set_default_crop(&mut self, crop: Option<Rect>) {
        self.default_crop = crop;
    }

    /// Set image dimensions (used by orientation transforms).
    pub fn set_size(&mut self, size: Size) {
        self.size = size;
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_white_level_from_bit_depth() {
        assert_eq!(white_level_from_bit_depth(0), 0);
        assert_eq!(white_level_from_bit_depth(1), 1);
        assert_eq!(white_level_from_bit_depth(8), 255);
        assert_eq!(white_level_from_bit_depth(12), 4095);
        assert_eq!(white_level_from_bit_depth(14), 16383);
        assert_eq!(white_level_from_bit_depth(15), 32767);
        // bit_depth >= 16 clamps to u16::MAX
        assert_eq!(white_level_from_bit_depth(16), u16::MAX);
        assert_eq!(white_level_from_bit_depth(32), u16::MAX);
        assert_eq!(white_level_from_bit_depth(255), u16::MAX);
    }

    #[test]
    fn test_size() {
        let size = Size::new(100, 200);
        assert_eq!(size.pixel_count(), 20000);
        assert!(size.is_valid());

        let empty = Size::new(0, 100);
        assert!(!empty.is_valid());
    }

    #[test]
    fn test_cfa_pattern() {
        assert_eq!(CfaPattern::from_array([0, 1, 1, 2]), Some(CfaPattern::Rggb));
        assert_eq!(CfaPattern::Rggb.to_array(), [0, 1, 1, 2]);
        assert_eq!(CfaPattern::Rggb.name(), "RGGB");
    }

    #[test]
    fn test_raw_image() {
        let size = Size::new(10, 10);
        let active = Rect::from_coords(0, 0, 10, 10);
        let mut img = RawImage::new(size, active, 14, CfaPattern::Rggb);

        img.set_pixel(5, 5, 1000);
        assert_eq!(img.get_pixel(5, 5), Some(1000));
        assert_eq!(img.get_pixel(100, 100), None);
    }

    #[test]
    fn test_raw_image_pixel_access() {
        let size = Size::new(4, 4);
        let active = Rect::from_coords(0, 0, 4, 4);
        let mut img = RawImage::new(size, active, 14, CfaPattern::Rggb);

        // Set several pixels and verify get_pixel returns correct values
        img.set_pixel(0, 0, 100);
        img.set_pixel(3, 0, 200);
        img.set_pixel(0, 3, 300);
        img.set_pixel(3, 3, 400);
        img.set_pixel(2, 1, 500);

        assert_eq!(img.get_pixel(0, 0), Some(100));
        assert_eq!(img.get_pixel(3, 0), Some(200));
        assert_eq!(img.get_pixel(0, 3), Some(300));
        assert_eq!(img.get_pixel(3, 3), Some(400));
        assert_eq!(img.get_pixel(2, 1), Some(500));

        // Out-of-bounds returns None
        assert_eq!(img.get_pixel(4, 0), None);
        assert_eq!(img.get_pixel(0, 4), None);
        assert_eq!(img.get_pixel(u32::MAX, u32::MAX), None);
    }

    #[test]
    fn test_rgb_image_indexing() {
        // RgbImage stores interleaved RGB: R G B R G B ...
        let data = vec![
            100u16, 200, 300, // pixel 0: R=100, G=200, B=300
            400, 500, 600, // pixel 1: R=400, G=500, B=600
        ];
        let img = RgbImage::new(2, 1, data.clone());

        assert_eq!(img.data[0], 100, "pixel 0 R");
        assert_eq!(img.data[1], 200, "pixel 0 G");
        assert_eq!(img.data[2], 300, "pixel 0 B");
        assert_eq!(img.data[3], 400, "pixel 1 R");
        assert_eq!(img.data[4], 500, "pixel 1 G");
        assert_eq!(img.data[5], 600, "pixel 1 B");

        assert_eq!(img.width(), 2);
        assert_eq!(img.height(), 1);
        assert_eq!(img.data.len(), 6);
    }

    #[test]
    fn test_size_pixel_count() {
        let s = Size::new(1920, 1080);
        assert_eq!(s.pixel_count(), 1920 * 1080);

        // Zero dimension
        let s = Size::new(0, 100);
        assert_eq!(s.pixel_count(), 0);

        // Large dimensions (check u64 doesn't overflow)
        let s = Size::new(10000, 10000);
        assert_eq!(s.pixel_count(), 100_000_000u64);
    }

    #[test]
    fn test_rect_dimensions() {
        let r = Rect::from_coords(10, 20, 100, 200);
        assert_eq!(r.origin.x, 10);
        assert_eq!(r.origin.y, 20);
        assert_eq!(r.size.width, 100);
        assert_eq!(r.size.height, 200);
        assert_eq!(r.right(), 110);
        assert_eq!(r.bottom(), 220);
    }

    #[test]
    fn test_raw_image_builder() {
        let size = Size::new(10, 10);
        let active = Rect::from_coords(0, 0, 10, 10);
        let img = RawImage::builder(size, active, 14, CfaPattern::Rggb)
            .black_levels([100, 100, 100, 100])
            .white_level(16383)
            .build();

        assert_eq!(img.size(), size);
        assert_eq!(img.active_area(), active);
        assert_eq!(img.bit_depth(), 14);
        assert_eq!(img.cfa_pattern(), CfaPattern::Rggb);
        assert_eq!(*img.black_levels(), [100, 100, 100, 100]);
        assert_eq!(img.white_level(), 16383);
        assert_eq!(img.data.len(), 100);
    }

    #[test]
    fn test_raw_image_builder_with_data() {
        let size = Size::new(2, 2);
        let active = Rect::from_coords(0, 0, 2, 2);
        let img = RawImage::builder(size, active, 14, CfaPattern::Rggb)
            .data(vec![1000, 2000, 3000, 4000])
            .build();

        assert_eq!(img.data, vec![1000, 2000, 3000, 4000]);
    }

    #[test]
    fn test_rgb_image_accessors() {
        let img = RgbImage::new(100, 200, vec![0u16; 100 * 200 * 3]);
        assert_eq!(img.width(), 100);
        assert_eq!(img.height(), 200);
        assert_eq!(img.size(), Size::new(100, 200));
        assert_eq!(img.baseline_exposure(), None);
        assert_eq!(img.default_crop(), None);
    }

    #[test]
    fn test_raw_image_setters() {
        let size = Size::new(4, 4);
        let active = Rect::from_coords(0, 0, 4, 4);
        let mut img = RawImage::new(size, active, 14, CfaPattern::Rggb);

        img.set_black_levels([100, 100, 100, 100]);
        assert_eq!(*img.black_levels(), [100, 100, 100, 100]);

        img.set_white_level(4095);
        assert_eq!(img.white_level(), 4095);

        img.set_baseline_exposure(Some(-0.8));
        assert_eq!(img.baseline_exposure(), Some(-0.8));

        let crop = Rect::from_coords(1, 1, 2, 2);
        img.set_default_crop(Some(crop));
        assert_eq!(img.default_crop(), Some(crop));

        img.set_xtrans_pattern(Some(XTransPattern::standard()));
        assert!(img.xtrans_pattern().is_some());
    }
}