@@ -655,9 +655,18 @@ def get_bounds(self) -> QuadBounds:
655655class CensorAction (RectAction ):
656656 def __init__ (self , start : tuple [int , int ], end : tuple [int , int ], background_pixbuf : GdkPixbuf .Pixbuf , options ):
657657 super ().__init__ (start , end , False , options )
658- self .block_size = 8
658+
659+ self .original_scale = 1.0
660+ self .base_block_size = 8
659661 self .background_pixbuf = background_pixbuf
660662
663+ def set_original_scale (self , scale : float ):
664+ self .original_scale = scale
665+
666+ def _get_scaled_block_size (self , current_scale : float ) -> float :
667+ scale_ratio = current_scale / self .original_scale
668+ return self .base_block_size * scale_ratio
669+
661670 def draw (self , cr : cairo .Context , image_to_widget_coords : Callable [[int , int ], tuple [float , float ]], scale : float ):
662671 x1 , y1 = image_to_widget_coords (* self .start )
663672 x2 , y2 = image_to_widget_coords (* self .end )
@@ -668,15 +677,17 @@ def draw(self, cr: cairo.Context, image_to_widget_coords: Callable[[int, int], t
668677 crop = self ._get_image_crop ()
669678 if not crop :
670679 return
671- self ._draw_pixelation (cr , crop , x , y , width , height )
672680
673- def _draw_pixelation (self , cr : cairo .Context , crop : dict , x : float , y : float , width : float , height : float ):
681+ scaled_block_size = self ._get_scaled_block_size (scale )
682+ self ._draw_pixelation (cr , crop , x , y , width , height , scaled_block_size )
683+
684+ def _draw_pixelation (self , cr : cairo .Context , crop : dict , x : float , y : float , width : float , height : float , block_size : float ):
674685 cr .save ()
675686 cr .rectangle (x , y , width , height )
676687 cr .clip ()
677688
678- blocks_x = max (1 , int (width / self . block_size ))
679- blocks_y = max (1 , int (height / self . block_size ))
689+ blocks_x = max (1 , int (width / block_size ))
690+ blocks_y = max (1 , int (height / block_size ))
680691
681692 tiny_surface = cairo .ImageSurface (cairo .FORMAT_ARGB32 , blocks_x , blocks_y )
682693 tiny_cr = cairo .Context (tiny_surface )
0 commit comments