(define (compare-downscaling-alternatives w h s i)

  (define (print-percentage-of-white-pixels layer)
    (let (
          (n (car (last-pair (gimp-histogram layer HISTOGRAM-VALUE 255 255) 0)))
          (name (car (gimp-drawable-get-name layer)))
          )
    (gimp-message (string-append "after scaling with " name
                                 ",\nthe percentage of white pixels is "
                                 (number->string (* 100. n)) "% - expected 100%\n"))
    n))

  (define (regular-grid i d w s level op)
    (let ((c (list level level level)))
      (plug-in-grid
        RUN-NONINTERACTIVE i d w s 0 c op w s 0 c op w s 0 c op)))

  (define (prepare-white-layers-with-grid image w h s name)
    (let (
          (layer (car (gimp-layer-new image w h GRAY-IMAGE name 100 NORMAL-MODE)))
         )

      (gimp-image-add-layer
        image layer -1)

      (gimp-drawable-fill
        layer WHITE-FILL)

      (regular-grid
        image layer 2 s 0 255)
    ))

  (define (prepare-white-image-with-grid w h s n)
    (let ((image (car (gimp-image-new w h GRAY))))

      (gimp-image-undo-disable 
        image)

      (while (< 0 n)
        (begin 
          (prepare-white-layers-with-grid image w h s (number->string n))
          (set! n (- n 1))))

      (gimp-image-undo-enable
        image)

      image))

  (let*
    (
     (image   (prepare-white-image-with-grid (* s w) (* s h) s 2))
     (layers  (cadr (gimp-image-get-layers image)))
     (handler (car (gimp-message-get-handler)))
     )
    (gimp-message-set-handler CONSOLE)

    (gimp-drawable-set-name
      (aref layers 0) "gimp-drawable-transform-scale")
    (gimp-drawable-transform-scale
      (aref layers 0)
      0 0 w h
      TRANSFORM-FORWARD
      i
      TRUE
      3
      TRANSFORM-RESIZE-CROP)

    (gimp-drawable-set-name
      (aref layers 1) "gimp-layer-scale-full")
    (gimp-layer-scale-full
      (aref layers 1)
      w h
      FALSE i)

    (gimp-message
      (if (=
            (print-percentage-of-white-pixels (aref layers 0))
            (print-percentage-of-white-pixels (aref layers 1)))
            "success"
            "failure"))

    (gimp-message-set-handler
      handler)

    (gimp-image-resize-to-layers
      image)

    (gimp-image-clean-all
      image)

    (gimp-display-new
      image)

    (gimp-displays-flush)
    )
)

(define (regression-test-000)
  (compare-downscaling-alternatives 13 13 16 INTERPOLATION-NONE))
