@@ -8,7 +8,7 @@ use image::{GenericImageView, ImageEncoder, ImageError, Rgba};
88pub use libharuhishot:: HaruhiShotState ;
99use libharuhishot:: reexport:: Transform ;
1010use libharuhishot:: {
11- CaptureOption , ClipImageViewInfo , ClipRegion , ImageInfo , Position , Region , Size ,
11+ CaptureOption , ClipImageViewInfoArea , ClipRegion , ImageInfo , Position , Region , Size ,
1212} ;
1313
1414use std:: io:: { BufWriter , Write , stdout} ;
@@ -149,9 +149,9 @@ fn capture_area(
149149 let mut min_y = i32:: MAX ;
150150 let mut max_x = i32:: MIN ;
151151 let mut max_y = i32:: MIN ;
152- for view in & views {
153- let Position { x, y } = view. region . absolute_position_real ( ) ;
154- let Size { width, height } = view. region . clip_size_real ( ) ;
152+ for view in & views. areas {
153+ let Position { x, y } = view. region . display_position_real ( ) ;
154+ let Size { width, height } = view. region . display_logical_size ( ) ;
155155
156156 min_x = min_x. min ( x) ;
157157 min_y = min_y. min ( y) ;
@@ -162,7 +162,7 @@ fn capture_area(
162162 let total_height = ( max_y - min_y) as u32 ;
163163
164164 let mut combined_image = image:: RgbaImage :: new ( total_width, total_height) ;
165- for ClipImageViewInfo {
165+ for ClipImageViewInfoArea {
166166 info :
167167 ImageInfo {
168168 data,
@@ -172,7 +172,7 @@ fn capture_area(
172172 ..
173173 } ,
174174 region,
175- } in views
175+ } in views. areas
176176 {
177177 // Load the captured image
178178 let img = image:: ImageBuffer :: from_raw ( img_width, img_height, data) . ok_or (
@@ -200,44 +200,49 @@ fn capture_area(
200200 }
201201 _ => unreachable ! ( ) ,
202202 } ;
203-
204- // we use the relative position to make image
205- let Position { x, y } = region. relative_position_wl ( ) ;
206-
207- let Size { width, height } = region. clip_size_real ( ) ;
208-
209- let subimage = img
210- . view ( x as u32 , y as u32 , width as u32 , height as u32 )
211- . to_image ( ) ;
212- let rgba_img: image:: RgbaImage = subimage;
213-
203+ let Size { width, height } = region. display_logical_size ( ) ;
204+ let img = image:: imageops:: resize (
205+ & img,
206+ width as u32 ,
207+ height as u32 ,
208+ image:: imageops:: FilterType :: Gaussian ,
209+ ) ;
214210 // we use the real position to calculate the position
215- let Position { x, y } = region. absolute_position_real ( ) ;
211+ let Position { x, y } = region. display_position_real ( ) ;
216212 // Calculate the position in he combined image
217213 let offset_x = ( x - min_x) as u32 ;
218214 let offset_y = ( y - min_y) as u32 ;
219215
220216 // Copy the output image to the combined image
221- for ( x, y, pixel) in rgba_img . enumerate_pixels ( ) {
217+ for ( x, y, pixel) in img . enumerate_pixels ( ) {
222218 let target_x = offset_x + x;
223219 let target_y = offset_y + y;
224220 if target_x < total_width && target_y < total_height {
225221 combined_image. put_pixel ( target_x, target_y, * pixel) ;
226222 }
227223 }
228224 }
225+ let clip_region = views. region ;
226+ let image = combined_image
227+ . view (
228+ clip_region. position . x as u32 ,
229+ clip_region. position . y as u32 ,
230+ clip_region. size . width as u32 ,
231+ clip_region. size . height as u32 ,
232+ )
233+ . to_image ( ) ;
229234
230235 if use_stdout {
231236 let mut buff = std:: io:: Cursor :: new ( Vec :: new ( ) ) ;
232- combined_image . write_to ( & mut buff, image:: ImageFormat :: Png ) ?;
237+ image . write_to ( & mut buff, image:: ImageFormat :: Png ) ?;
233238 let content = buff. get_ref ( ) ;
234239 let stdout = stdout ( ) ;
235240 let mut writer = BufWriter :: new ( stdout. lock ( ) ) ;
236241 writer. write_all ( content) ?;
237242 Ok ( HaruhiShotResult :: StdoutSucceeded )
238243 } else {
239244 let file = random_file_path ( ) ;
240- combined_image . save ( & file) ?;
245+ image . save ( & file) ?;
241246 Ok ( HaruhiShotResult :: SaveToFile ( file) )
242247 }
243248}
@@ -253,7 +258,7 @@ fn get_color(state: &mut HaruhiShotState) -> Result<HaruhiShotResult, HaruhiImag
253258 ) ) ?;
254259 waysip_to_region ( info. size ( ) , info. left_top_point ( ) )
255260 } ) ?;
256- let ClipImageViewInfo {
261+ let ClipImageViewInfoArea {
257262 info :
258263 ImageInfo {
259264 data,
@@ -271,7 +276,7 @@ fn get_color(state: &mut HaruhiShotState) -> Result<HaruhiShotResult, HaruhiImag
271276 } ,
272277 ..
273278 } ,
274- } = views. remove ( 0 ) ;
279+ } = views. areas . remove ( 0 ) ;
275280 let image: image:: ImageBuffer < Rgba < u8 > , Vec < u8 > > =
276281 image:: ImageBuffer :: from_raw ( img_width, img_height, data) . unwrap ( ) ;
277282 let img = match transform {
0 commit comments