55
66
77def apply_cartoon_filter (img , drawable ):
8- # see https://developer.gimp.org/api/2.0/libgimp/index.html
8+ # docs
9+ # https://developer.gimp.org/api/2.0/libgimp/index.html
10+ # https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpenums.html#GimpLayerModeEffects
11+ pdb .gimp_image_undo_group_start (img )
912 # step 1: duplicate layer two times
1013 # layer2
1114 layer2 = pdb .gimp_layer_copy (drawable , False )
@@ -24,22 +27,23 @@ def apply_cartoon_filter(img, drawable):
2427 pdb .plug_in_edge (img , layer3 , 1 , 0 , 0 )
2528
2629 # step 3: adjust curves
27- # see https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpcolor.html#gimp-curves-spline
30+ # https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpcolor.html#gimp-curves-spline
2831 pdb .gimp_curves_spline (layer3 , 0 , 6 ,
2932 [0 , 0 ,
3033 130 , 255 ,
3134 255 , 255 ])
3235
3336 # step 4: adjust levels
34- # see https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpcolor.html#gimp-levels
37+ # https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpcolor.html#gimp-levels
3538 pdb .gimp_levels (layer3 , 0 , 0 , 130 , 1.0 , 0 , 255 )
3639
3740 # step 5: merge layers down
3841 pdb .gimp_image_merge_down (img , layer3 , 0 )
3942 # set layer2 mode to GIMP_OVERLAY_MODE (23)
40- # see https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpenums.html#GimpLayerModeEffects
41- pdb .gimp_layer_set_mode (img .layers [0 ], 23 )
42- pdb .gimp_image_merge_down (img , img .layers [0 ], 0 )
43+ layer2 = pdb .gimp_image_get_active_drawable (img )
44+ pdb .gimp_layer_set_mode (layer2 , 23 )
45+ pdb .gimp_image_merge_down (img , layer2 , 0 )
46+ pdb .gimp_image_undo_group_end (img )
4347
4448
4549register (
0 commit comments