;;; divider.scm
;;; Time-stamp: <1997/12/07 22:47:39 narazaki@InetQ.or.jp>
;;; Author: Shuji Narazaki <narazaki@inetq.or.jp>
;;; Version: 0.1

;;; Comment:
;;; Code:
(define (script-fu-divider img drw x-divide y-divide)
  (if (< x-divide 1)
      (set! x-divide 1))
  (if (< y-divide 1)
      (set! y-divide 1))
  (let ((nimage (* x-divide y-divide))
	(cropped-width (/ (car (gimp-image-width img)) x-divide))
	(cropped-height (/ (car (gimp-image-height img)) y-divide))
	(new-image #f)
	(x-index 0)
	(y-index 0)
	(offset-x 0)
	(offset-y 0))
    (while (< y-index y-divide)
      (set! x-index 0)
      (set! offset-y (* cropped-height y-index))
      (while (< x-index x-divide)
	(set! offset-x (* cropped-width x-index))
	(set! new-image (car (gimp-channel-ops-duplicate img)))
	(gimp-crop new-image cropped-width cropped-height
		   offset-x offset-y)
	(gimp-display-new new-image) 
	(set! x-index (+ x-index 1)))
      (set! y-index (+ y-index 1)))
    (gimp-displays-flush)))

(script-fu-register
 "script-fu-divider"
 "<Image>/Script-Fu/Utils/Divide image"
 "Crop"
 "Shuji Narazaki <narazaki@inetq.or.jp>"
 "Shuji Narazaki"
 "1997"
 ""
 SF-IMAGE "Image to analyze" 0
 SF-DRAWABLE "Drawable to analyze" 0
 SF-VALUE "num. of x divides" "1"
 SF-VALUE "num. of y divides" "1"
)

;;; Local Variables:
;;; mode:scheme
;;; End:
;;; divider.scm ends here