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
//! Image manipulation effects in HSL, LCh and HSV.

extern crate image;
extern crate rand;
use image::{GenericImageView};
use palette::{Hsl, Lch, Shade, Pixel, Saturate, Srgba, Hue, Hsv};
use crate::{PhotonImage, helpers};
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

/// Apply gamma correction. 
// #[wasm_bindgen]
// pub fn gamma_correction(mut photon_image: &mut PhotonImage, red: f32, green: f32,  blue: f32) {
//     let img = helpers::dyn_image_from_raw(&photon_image);
//     let (width, height) = img.dimensions();
//     let mut img = img.to_rgba();

//     // Initialize gamma arrays 
//     let mut gammaR: Vec<u8> = vec![];
//     let mut gammaG: Vec<u8> = vec![];
//     let mut gammaB: Vec<u8> = vec![];

//     let MAX_VALUE_INT = 255;
//     let MAX_VALUE_FLT = 255.0;
//     let REVERSE = 1.0;

//     // Set values within gamma arrays
//     for i in 0..256 {
//         gammaR[i] = min(MAX_VALUE_INT, ((MAX_VALUE_FLT * ((i as f32 / MAX_VALUE_FLT) as u32).powf(REVERSE / red) + 0.5 ) as u8));
//         gammaG[i] = min(MAX_VALUE_INT, ((MAX_VALUE_FLT * ((i as f32 / MAX_VALUE_FLT) as u32).powf(REVERSE / green) + 0.5 ) as u8);
//         gammaB[i] = min(MAX_VALUE_INT, ((MAX_VALUE_FLT * ((i as f32 / MAX_VALUE_FLT) as u32).powf(REVERSE / blue) + 0.5 ) as u8);

//     }

//     for x in 0..width {
//         for y in 0..height {
//             let px_data = img.get_pixel(x, y).data;
            
//             let r_val = px_data[0];
//             let g_val = px_data[1];
//             let b_val = px_data[2];

//             px_data[0] = gammaR[r_val as usize];
//             px_data[1] = gammaG[g_val as usize];
//             px_data[2] = gammaB[b_val as usize];
            
//             img.put_pixel(x, y, px);
//             }
//         }
//     photon_image.raw_pixels = img.to_vec();
// }

/// Image manipulation effects in the LCh colour space
/// 
/// Effects include:
/// * **saturate** - Saturation increase.
/// * **desaturate** - Desaturate the image.
/// * **shift_hue** - Hue rotation by a specified number of degrees.
/// * **darken** - Decrease the brightness.
/// * **lighten** - Increase the brightness.
/// 
/// # Arguments
/// * `photon_image` - A PhotonImage.
/// * `mode` - The effect desired to be applied. Choose from: `saturate`, `desaturate`, `shift_hue`, `darken`, `lighten`
/// * `amt` - A float value from 0 to 1 which represents the amount the effect should be increased by.
/// # Example
/// ```
/// // For example to increase the saturation by 10%:
/// use photon::color_spaces::lch;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// lch(&mut img, "saturate", 0.1);
/// ```
#[wasm_bindgen]
pub fn lch(mut photon_image: &mut PhotonImage, mode: &str, amt: f32) {
    let img = helpers::dyn_image_from_raw(&photon_image);
    let (width, height) = img.dimensions();
    let mut img = img.to_rgba();
    for x in 0..width {
        for y in 0..height {
            let px_data = img.get_pixel(x, y).data;
            let lch_colour: Lch = Srgba::from_raw(&px_data)
                .into_format()
                .into_linear()
                .into();

            let new_color = match mode {
                // Match a single value
                "desaturate" => lch_colour.desaturate(amt),
                "saturate" => lch_colour.saturate(amt),
                "lighten" => lch_colour.lighten(amt), 
                "darken" => lch_colour.darken(amt),
                "shift_hue" => lch_colour.shift_hue(amt * 360.0),
                _ => lch_colour.saturate(amt),
            };
            
            img.put_pixel(x, y, image::Rgba {
                data: Srgba::from_linear(new_color.into()).into_format().into_raw()
            });
            }
        }
    photon_image.raw_pixels = img.to_vec();
}

/// Image manipulation effects in the HSL colour space.
/// 
/// Effects include:
/// * **saturate** - Saturation increase.
/// * **desaturate** - Desaturate the image.
/// * **shift_hue** - Hue rotation by a specified number of degrees.
/// * **darken** - Decrease the brightness.
/// * **lighten** - Increase the brightness.
/// 
/// # Arguments
/// * `photon_image` - A PhotonImage.
/// * `mode` - The effect desired to be applied. Choose from: `saturate`, `desaturate`, `shift_hue`, `darken`, `lighten`
/// * `amt` - A float value from 0 to 1 which represents the amount the effect should be increased by.
/// # Example
/// ```
/// // For example to increase the saturation by 10%:
/// use photon::color_spaces::hsl;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// hsl(&mut img, "saturate", 0.1);
/// ``` 
#[wasm_bindgen]
pub fn hsl(mut photon_image: &mut PhotonImage, mode: &str, amt: f32) {
    // The function logic is kept separate from other colour spaces for now, 
    // since other HSL-specific logic may be implemented here, which isn't available in other colour spaces
    let mut img = helpers::dyn_image_from_raw(&photon_image).to_rgba();
    let (width, height) = img.dimensions();
        for x in 0..width {
            for y in 0..height {
                let px_data = img.get_pixel(x, y).data;

                let colour = Srgba::from_raw(&px_data).into_format();

                let hsl_colour = Hsl::from(colour);
                
                let new_color = match mode {
                    // Match a single value
                    "desaturate" => hsl_colour.desaturate(amt),
                    "saturate" => hsl_colour.saturate(amt),
                    "lighten" => hsl_colour.lighten(amt), 
                    "darken" => hsl_colour.darken(amt),
                    "shift_hue" => hsl_colour.shift_hue(amt * 360.0),
                    _ => hsl_colour.saturate(amt),
                };

                img.put_pixel(x, y, image::Rgba {
                    data: Srgba::from_linear(new_color.into()).into_format().into_raw()
                });
            }
        }

    photon_image.raw_pixels = img.to_vec();
}

/// Image manipulation in the HSV colour space. 
/// 
/// Effects include:
/// * **saturate** - Saturation increase.
/// * **desaturate** - Desaturate the image.
/// * **shift_hue** - Hue rotation by a specified number of degrees.
/// * **darken** - Decrease the brightness.
/// * **lighten** - Increase the brightness.
/// 
/// # Arguments
/// * `photon_image` - A PhotonImage.
/// * `mode` - The effect desired to be applied. Choose from: `saturate`, `desaturate`, `shift_hue`, `darken`, `lighten`
/// * `amt` - A float value from 0 to 1 which represents the amount the effect should be increased by.
/// 
/// # Example
/// ```
/// // For example to increase the saturation by 10%:
/// use photon::color_spaces::hsv;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// hsv(&mut img, "saturate", 0.1);
/// ```
#[wasm_bindgen]
pub fn hsv(photon_image: &mut PhotonImage, mode: &str, amt: f32) {
    let img = helpers::dyn_image_from_raw(&photon_image);
    let mut img  = img.to_rgba();

    let (width, height) = img.dimensions();

        for x in 0..width {
            for y in 0..height {
                let px_data = img.get_pixel(x, y).data;

                let color = Srgba::from_raw(&px_data).into_format();

                let hsv_colour = Hsv::from(color);

                let new_color = match mode {
                    // Match a single value
                    "desaturate" => hsv_colour.desaturate(amt),
                    "saturate" => hsv_colour.saturate(amt),
                    "lighten" => hsv_colour.lighten(amt), 
                    "darken" => hsv_colour.darken(amt),
                    "shift_hue" => hsv_colour.shift_hue(amt * 360.0),
                    _ => hsv_colour.saturate(amt),
                };

                img.put_pixel(x, y, image::Rgba {
                    data: Srgba::from_linear(new_color.into()).into_format().into_raw()
                });
            }
        }
    photon_image.raw_pixels = img.to_vec();
}

/// Shift hue by a specified number of degrees in the HSL colour space.
/// # Arguments
/// * `img` - A PhotonImage.
/// * `mode` - The number of degrees to shift the hue by, or hue rotate by.
/// 
/// # Example
/// ```
/// // For example to hue rotate/shift the hue by 120 degrees in the HSL colour space:
/// use photon::color_spaces::hue_rotate_hsl;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// hue_rotate_hsl(&mut img, 120);
/// ``` 
#[wasm_bindgen]
pub fn hue_rotate_hsl(img: &mut PhotonImage, degrees: f32) {
    hsl(img, "shift_hue", degrees);
}

/// Shift hue by a specified number of degrees in the HSV colour space.
/// # Arguments
/// * `img` - A PhotonImage.
/// * `mode` - The number of degrees to shift the hue by, or hue rotate by.
/// 
/// # Example
/// ```
/// // For example to hue rotate/shift the hue by 120 degrees in the HSV colour space:
/// use photon::color_spaces::hue_rotate_hsv;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// hue_rotate_hsv(&mut img, 120);
/// ``` 
#[wasm_bindgen]
pub fn hue_rotate_hsv(img: &mut PhotonImage, degrees: f32) {
    hsv(img, "shift_hue", degrees);
}

/// Shift hue by a specified number of degrees in the LCh colour space.
/// # Arguments
/// * `img` - A PhotonImage.
/// * `mode` - The number of degrees to shift the hue by, or hue rotate by.
/// 
/// # Example
/// ```
/// // For example to hue rotate/shift the hue by 120 degrees in the HSL colour space:
/// use photon::color_spaces::hue_rotate_lch;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// hue_rotate_lch(&mut img, 120);
/// ``` 
#[wasm_bindgen]
pub fn hue_rotate_lch(img: &mut PhotonImage, degrees: f32) {
    lch(img, "shift_hue", degrees)
}

/// Increase the image's saturation by converting each pixel's colour to the HSL colour space
/// and increasing the colour's saturation. 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to increase the saturation by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Increasing saturation by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to increase saturation by 10% in the HSL colour space:
/// use photon::color_spaces::saturate_hsl;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// saturate_hsl(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn saturate_hsl(img: &mut PhotonImage, level: f32) {

    return hsl(img, "saturate", level);
}

/// Increase the image's saturation in the LCh colour space.
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to increase the saturation by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Increasing saturation by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to increase saturation by 40% in the Lch colour space:
/// use photon::color_spaces::saturate_lch;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// saturate_lch(&mut img, 0.4);
/// ``` 
#[wasm_bindgen]
pub fn saturate_lch(img: &mut PhotonImage, level: f32) {
    return lch(img, "saturate", level);
}

/// Increase the image's saturation in the HSV colour space.
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level by which to increase the saturation by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Increasing saturation by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to increase saturation by 30% in the HSV colour space:
/// use photon::color_spaces::saturate_hsv;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// saturate_hsv(&mut img, 0.3);
/// ``` 
#[wasm_bindgen]
pub fn saturate_hsv(img: &mut PhotonImage, level: f32) {
    return hsv(img, "saturate", level);
}

/// Lighten an image by a specified amount in the LCh colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to lighten the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Lightening by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to lighten an image by 10% in the LCh colour space:
/// use photon::color_spaces::lighten_lch;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// lighten_lch(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn lighten_lch(img: &mut PhotonImage, level: f32) {
    return lch(img, "lighten", level);
}

/// Lighten an image by a specified amount in the HSL colour space.
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to lighten the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Lightening by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to lighten an image by 10% in the HSL colour space:
/// use photon::color_spaces::lighten_hsl;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// lighten_hsl(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn lighten_hsl(img: &mut PhotonImage, level: f32) {
    return hsl(img, "lighten", level);
}

/// Lighten an image by a specified amount in the HSV colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to lighten the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Lightening by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to lighten an image by 10% in the HSV colour space:
/// use photon::color_spaces::lighten_hsv;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// lighten_hsv(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn lighten_hsv(img: &mut PhotonImage, level: f32) {
    return hsv(img, "lighten", level);
}

/// Darken the image by a specified amount in the LCh colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to darken the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Darkening by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to darken an image by 10% in the LCh colour space:
/// use photon::color_spaces::darken_lch;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// darken_lch(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn darken_lch(img: &mut PhotonImage, level: f32) {
    return lch(img, "darken", level);
}

/// Darken the image by a specified amount in the HSL colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to darken the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Darkening by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to darken an image by 10% in the HSL colour space:
/// use photon::color_spaces::darken_hsl;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// darken_hsl(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn darken_hsl(img: &mut PhotonImage, level: f32) {
    return hsl(img, "darken", level);
}

/// Darken the image's colours by a specified amount in the HSV colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to darken the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Darkening by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to darken an image by 10% in the HSV colour space:
/// use photon::color_spaces::darken_hsv;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// darken_hsv(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn darken_hsv(img: &mut PhotonImage, level: f32) {
    return hsv(img, "darken", level);
}

/// Desaturate the image by a specified amount in the HSV colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to desaturate the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Desaturating by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to desaturate an image by 10% in the HSV colour space:
/// use photon::color_spaces::desaturate_hsv;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/mountains.PNG");
/// 
/// desaturate_hsv(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn desaturate_hsv(img: &mut PhotonImage, level: f32) {
    return hsv(img, "desaturate", level);
}

/// Desaturate the image by a specified amount in the HSL colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to desaturate the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Desaturating by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to desaturate an image by 10% in the LCh colour space:
/// use photon::color_spaces::desaturate_hsl;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// desaturate_hsl(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn desaturate_hsl(img: &mut PhotonImage, level: f32) {
    return hsl(img, "desaturate", level);
}

/// Desaturate the image by a specified amount in the LCh colour space.
/// 
/// # Arguments
/// * `img` - A PhotonImage.
/// * `level` - Float value from 0 to 1 representing the level to which to desaturate the image by.
/// The `level` must be from 0 to 1 in floating-point, `f32` format. 
/// Desaturating by 80% would be represented by a `level` of 0.8
/// 
/// # Example
/// ```
/// // For example to desaturate an image by 10% in the LCh colour space:
/// use photon::color_spaces::desaturate_lch;
/// 
/// // Open the image. A PhotonImage is returned.
/// let img: PhotonImage = open_image("images/flowers.PNG");
/// 
/// desaturate_lch(&mut img, 0.1);
/// ``` 
#[wasm_bindgen]
pub fn desaturate_lch(img: &mut PhotonImage, level: f32) {
    return lch(img, "desaturate", level);
}

// #[wasm_bindgen]
// pub fn selective_color_convert(mut photon_image: &mut PhotonImage, ref_color:Rgb, new_color:Rgb, fraction: f32) {
//     let img = helpers::dyn_image_from_raw(&photon_image);
//     let (_width, _height) = img.dimensions();
//     let mut img = img.to_rgba();
//     for x in 0.._width {
//         for y in 0.._height {
//             let mut px = img.get_pixel(x, y);

//             // Reference colour to compare the current pixel's colour to
//             let lab: Lab = Srgb::new(ref_color.r as f32 / 255.0, ref_color.g as f32 / 255.0, ref_color.b as f32 / 255.0).into();
      
//             // Convert the current pixel's colour to the l*a*b colour space
//             let r_val: f32 = px.data[0] as f32 / 255.0;
//             let g_val: f32 = px.data[1] as f32 / 255.0;
//             let b_val: f32 = px.data[2] as f32 / 255.0;

//             let px_lab: Lab = Srgb::new(r_val, g_val, b_val).into();

//             let sim = color_sim(lab, px_lab);
//             if sim > 0 && sim < 40 {
//                 let newr = (((new_color.r - ref_color.r) as f32) * fraction + new_color.r as f32) as u8;
//                 let newg = (((new_color.g - ref_color.g) as f32) * fraction + new_color.g as f32) as u8;
//                 let newb = (((new_color.b - ref_color.b) as f32) * fraction + new_color.b as f32) as u8;
            
//                 img.put_pixel(x, y, image::Rgba([newr, newg, newb, 255]));
//             }
//         }
//     }
//     photon_image.raw_pixels = img.to_vec();
// }

// pub fn correct(img: &DynamicImage, mode: &'static str, colour_space: &'static str, amt: f32) -> DynamicImage {
//     let mut img  = img.to_rgb();

//     let (width, height) = img.dimensions();

//         for x in 0..width {
//             for y in 0..height {
//                 let px_data = img.get_pixel(x, y).data;

//                 let colour_to_cspace;
//                 if colour_space == "hsv" {
//                     colour_to_cspace: Hsv = Srgb::from_raw(&px_data).into_format();
//                 }
//                 else if colour_space == "hsl" {
//                     colour_to_cspace = Hsl::from(color);
//                 }
//                 else {
//                     colour_to_cspace = Lch::from(color);
//                 }
            
//                 let new_color  = match mode {
//                     // Match a single value
//                     "desaturate" => colour_to_cspace.desaturate(amt),
//                     "saturate" => colour_to_cspace.saturate(amt),
//                     "lighten" => colour_to_cspace.lighten(amt), 
//                     "darken" => colour_to_cspace.darken(amt),
//                     _ => colour_to_cspace.saturate(amt),
//                 };

//                 img.put_pixel(x, y, image::Rgb {
//                     data: Srgb::from_linear(new_color.into()).into_format().into_raw()
//                 });
//             }
//         }

//     let dynimage = image::ImageRgb8(img);
//     return dynimage;
// }