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
//! Utility functions that help reading images, and converting them to [Gray Code](https://en.wikipedia.org/wiki/Gray_code) and back
use crate;
use ;
use Cursor;
/// Open image from the raw data that describes an image file
///
/// # Example
/// ```no_run
/// # use pixelveil::image_utils::open_rgbimage_from_raw;
/// use std::fs::read;
///
/// let image_file_data = read("example.png")?;
/// let img = open_rgbimage_from_raw(image_file_data)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `raw_data: Vec<u8>` — The image file data.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// The possible errors that can be returned are:
/// * `ImageError` if the data that was passed in is not a valid image file format
///
/// # Returns
/// This function returns a `Result<RgbImage, ImageError>`.
/// If `Ok` is returned, the unwrapped value is the opened `RgbImage`.
///
/// # Notes
/// This function is used as an abstraction for image handling in Rust, it does not have a Python wrapper function.
/// Open image from a path
///
/// # Example
/// ```no_run
/// # use pixelveil::image_utils::open_rgbimage_from_path;
/// let img = open_rgbimage_from_path("image.png")?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `path: &str` — The image path.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// The possible errors that can be returned are:
/// * `ImageError` if the path specifies a missing file or one of invalid image format
///
/// # Returns
/// This function returns a `Result<RgbImage, ImageError>`.
/// If `Ok` is returned, the unwrapped value is the opened `RgbImage`.
///
/// # Notes
/// This function is used as an abstraction for image handling in Rust, it does not have a Python wrapper function.
/// Converts a 24-bit RGB pixel from pure binary code to Gray Code as defined [here](https://en.wikipedia.org/wiki/Gray_code)
///
/// # Example
/// ```
/// # use pixelveil::image_utils::pixel_to_gray_code;
/// # use image::Rgb;
/// let mut pixel = Rgb::<u8>([0b1110101, 0b0011000, 0b1010111]);
///
/// pixel_to_gray_code(&mut pixel);
///
/// assert_eq!(pixel, Rgb::<u8>([0b1001111, 0b0010100, 0b1111100]));
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `pixel: &mut Rgb<u8>` — The pixel to convert.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns (), the passed in pixel will be changed instead of constructing a new pixel.
/// Converts a 24-bit RGB pixel from Gray Code to pure binary code as defined [here](https://en.wikipedia.org/wiki/Gray_code)
///
/// # Example
/// ```
/// # use pixelveil::image_utils::pixel_to_binary_code;
/// # use image::Rgb;
/// let mut pixel = Rgb::<u8>([0b10011111, 0b00101001, 0b11111001]);
///
/// pixel_to_binary_code(&mut pixel);
///
/// assert_eq!(pixel, Rgb::<u8>([0b11101010, 0b00110001, 0b10101110]));
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `pixel: &mut Rgb<u8>` — The pixel to convert.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns (), the passed in pixel will be changed instead of constructing a new pixel.
/// Converts an image from pure binary code to Gray Code
///
/// Applies `pixel_to_gray_code` on every pixel in the image.
///
/// # Example
/// ```no_run
/// # use image::RgbImage;
/// # use pixelveil::image_utils::image_to_gray_code;
/// let mut img = RgbImage::new(500, 500);
///
/// image_to_gray_code(&mut img);
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `image: &mut RgbImage` — The image to convert.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns (), the passed in image will be changed instead of constructing a new image.
/// Converts an image from Gray Code to pure binary code
///
/// Applies `pixel_to_binary_code` on every pixel in the image.
///
/// # Example
/// ```no_run
/// # use image::RgbImage;
/// # use pixelveil::image_utils::image_to_binary_code;
/// let mut img = RgbImage::new(500, 500);
///
/// image_to_binary_code(&mut img);
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `image: &mut RgbImage` — The image to convert.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns (), the passed in image will be changed instead of constructing a new image.
/// Export any DynamicImage to a .png file format
///
/// # Example
/// ```
/// # use pixelveil::image_utils::export_image_to_png_bytes;
/// # use image::{DynamicImage, ColorType};
/// let image = DynamicImage::new(500, 500, ColorType::Rgb8);
/// let image_file_bytes = export_image_to_png_bytes(&image);
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `img: &DynamicImage` — The image you want to export.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns a `Vec<u8>` that describes the file bytes in the .png file format
///
/// # Notes
/// This function is used as an abstraction for image handling in Rust, it does not have a Python wrapper function.
/// Convert an RgbImage to a DynamicImage
///
/// # Example
/// ```
/// # use pixelveil::image_utils::rgbimage_to_dynamicimage;
/// # use image::{DynamicImage, RgbImage};
/// let rgb_image = RgbImage::new(500, 500);
/// let dynamic_image = rgbimage_to_dynamicimage(rgb_image);
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `img: RgbImage` — The image you want to convert.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns a DynamicImage that contains the moved RgbImage.
///
/// # Notes
/// This function is used as an abstraction for image handling in Rust, it does not have a Python wrapper function.