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
use photon_rs::PhotonImage; pub fn uniform(img: &PhotonImage, padding: u32) -> PhotonImage { let image_buffer = img.get_raw_pixels(); let img_width = img.get_width(); let img_height = img.get_height(); let mut img_padded_buffer = Vec::<u8>::new(); let width_padded: u32 = img_width + 2 * padding; let height_padded: u32 = img_height + 2 * padding; for _ in 0..((width_padded + 1) * padding) { img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(255); } for i in (0..image_buffer.len()).step_by(4) { if (i / 4) % img_width as usize == 0 && i != 0 { for _ in (0..2 * padding).step_by(1) { img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(255); } } img_padded_buffer.push(image_buffer[i]); img_padded_buffer.push(image_buffer[i + 1]); img_padded_buffer.push(image_buffer[i + 2]); img_padded_buffer.push(image_buffer[i + 3]); } for _ in 0..((width_padded + 1) * padding) { img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(255); } PhotonImage::new(img_padded_buffer, width_padded, height_padded) } pub fn left(img: &PhotonImage, padding: u32) -> PhotonImage { let image_buffer = img.get_raw_pixels(); let img_width = img.get_width(); let img_height = img.get_height(); let mut img_padded_buffer = Vec::<u8>::new(); let width_padded: u32 = img_width + padding; for i in 0..img_height as usize { let img_slice = image_buffer[(i * 4 * img_width as usize)..(i + 1) * 4 * img_width as usize].to_owned(); for _ in 0..padding { img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(255); } for x in img_slice { img_padded_buffer.push(x); } } PhotonImage::new(img_padded_buffer, width_padded, img_height) } pub fn right(img: &PhotonImage, padding: u32) -> PhotonImage { let image_buffer = img.get_raw_pixels(); let img_width = img.get_width(); let img_height = img.get_height(); let mut img_padded_buffer = Vec::<u8>::new(); let width_padded: u32 = img_width + padding; for i in 0..img_height as usize { let img_slice = image_buffer[(i * 4 * img_width as usize)..(i + 1) * 4 * img_width as usize].to_owned(); for x in img_slice { img_padded_buffer.push(x); } for _ in 0..padding { img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(255); } } PhotonImage::new(img_padded_buffer, width_padded, img_height) } pub fn top(img: &PhotonImage, padding: u32) -> PhotonImage { let image_buffer = img.get_raw_pixels(); let img_width = img.get_width(); let img_height = img.get_height(); let height_padded: u32 = img_height + padding; let mut img_padded_buffer: Vec<u8> = Vec::<u8>::new(); for _ in 0..(padding * img_width) { img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(255); } for i in (0..image_buffer.len()).step_by(4) { img_padded_buffer.push(image_buffer[i]); img_padded_buffer.push(image_buffer[i + 1]); img_padded_buffer.push(image_buffer[i + 2]); img_padded_buffer.push(image_buffer[i + 3]); } PhotonImage::new(img_padded_buffer, img_width, height_padded) } pub fn bottom(img: &PhotonImage, padding: u32) -> PhotonImage { let image_buffer = img.get_raw_pixels(); let img_width = img.get_width(); let img_height = img.get_height(); let height_padded: u32 = img_height + padding; let mut img_padded_buffer: Vec<u8> = Vec::<u8>::new(); for i in (0..image_buffer.len()).step_by(4) { img_padded_buffer.push(image_buffer[i]); img_padded_buffer.push(image_buffer[i + 1]); img_padded_buffer.push(image_buffer[i + 2]); img_padded_buffer.push(image_buffer[i + 3]); } for _ in 0..(padding * img_width) { img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(0); img_padded_buffer.push(255); } PhotonImage::new(img_padded_buffer, img_width, height_padded) }