;;; ;;; autogamma.scm - automatically tweak gamma of dark images ;;; to look good on my monitor (and maybe elsewhere) ;;; ;;; ;;; -------------------------------------------------------------------- ;;; version 0.1 by Jeff Trefftzs ;;; - Initial relase ;;; version 0.2 Raymond Ostertag ;;; - ported to Gimp 2.0 ;;; -------------------------------------------------------------------- ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program; if not, write to the Free Software ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;;; Define the function: (define (script-fu-autogamma inImage inLayer inMonitor) (let* ( (histogram (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) (mean (car histogram)) (stdev (cadr histogram)) (median (caddr histogram)) (pow (/ (- 128 median) 128)) ; raise 10 to this power (gamma (* (exp (* pow (log 10))) inMonitor)) (gamma (cond (( > gamma 10) 10) (t gamma))) ) (gimp-levels inLayer HISTOGRAM-VALUE 0 255 gamma 0 255) ) (gimp-displays-flush) ) (script-fu-register "script-fu-autogamma" _"/Script-Fu/Enhance/Gamma Correction..." "Corrects an image's gamma by centering the gamma slider under the \ median value and multiplying the resulting gamma by a monitor-specific \ constant." "Jeff Trefftzs" "Copyright 2003, Jeff Trefftzs" "ENTER DATE HERE" "RGB* GRAY* INDEXED*" SF-IMAGE "The Image" 0 SF-DRAWABLE "The Layer" 0 SF-ADJUSTMENT "Monitor Correction" '(1.5 .01 10 .1 1 3 1) )