# # v-emu-ivbs.awk - emulate IrfanView blur / sharpen effect # by uratan! 2021.5.15 # # # generates convolution-matrix for pnmconvol # you can emulate IrfanView's effect by: # +------------------------------------------------------- # |M="sharpen"; P=30; F="matrix.PGM" # blur or sharpen # | # |echo "$M $P $F" | awk -f v-emu-ivbs.awk # |djpeg src.jpg | pnmconvol $F | cjpeg -q 85 > tuned.jpg # |rm $F # +------------------------------------------------------- # # CAUTION: # [1] convolution-matrix is on PGM format but it is not pure PGM image, # see manual page of pnmconvol for detail. # [2] some rounding errors are still remained... # (IrfanView: truncate vs pnmconvol: rounding, maybe...) # [3] "the edge of the image is not converted. simply copied" # is same by both pnmconvol and IrfanView, maybe... # { method = $1; # "blur" or "sharpen" p = $2; # effect settings from 1 to 99 name = $3; # name of matrix file if(method == "blur") { # # blur # f = 0.0 + p / 800; [0, 0.125] # e = 1.0 - 8 * p / 800; [0, 1.0] # #name = sprintf("mat_b%02d.PGM", p); bias = 800; maxv = 2 * bias; f = (bias) + p; e = (bias) + bias - 8 * p; print "P2" > name; print "3 3" > name; print maxv > name; printf("%3d %3d %3d\n", f, f, f) > name; printf("%3d %3d %3d\n", f, e, f) > name; printf("%3d %3d %3d\n", f, f, f) > name; } else { # # sharpen # f = 0.0 - p / 200; [-0.5, 0] # e = 1.0 + 8 * p / 200; [ 1, 5] # #name = sprintf("mat_s%02d.PGM", p); bias = 200; maxv = 2 * bias; f = (bias) - p; e = (bias) + bias + 8 * p; print "P2" > name; print "3 3" > name; print maxv > name; printf("%3d %3d %3d\n", f, f, f) > name; printf("%3d %3d %3d\n", f, e, f) > name; printf("%3d %3d %3d\n", f, f, f) > name; } }