;Helper functions for bicubic-resize (defun C0(t2) 0) (defun C1(t2) (+(* -2.0(* t2 t2 t2)) (* 3.0 t2 t2))) (defun C2(t2) (+(-(* 2.0(* t2 t2 t2)) (* 3.0 t2 t2))1.0)) (defun C3(t2) 0) (defun array-to-list(array) (let ((x (first(array-dimensions array))) (y (second(array-dimensions array)))) (let ((retval (list))) (dotimes (y1 y) (let ((temp-row (list))) (dotimes (x1 x) (push (aref array x1 y1) temp-row)) (push (reverse temp-row) retval))) (reverse retval)))) (defun bicubic-resize(n d f MAX-PIXEL) "Perform an enlargement (or reduction) on a bitmap, which is represented as a list of lists. Each list entry is a row of pixel colours. The magnification factor is n/d, so n=12 and d=2 would increase the bitmap by a factor of 6. It returns a 2d array with the enlarged image which will need converting back to a list. This hasn't been tested with any operation but enlargement. f is the input list of rows (lists) of pixels. For more information see http://mysite.verizon.net/~vze2vrva/design.html" (let ((MAX-OUT-WIDTH (* (length(first f)) (/ n d))) (MAX-OUT-HEIGHT (* (length f) (/ n d))) (MAX-IN-WIDTH (length(first f))) (in-width (length(first f))) (in-height (length f))(MAX-IN-HEIGHT (length f))) (let ((MAX-OUT-DIMENSION (if (> MAX-OUT-WIDTH MAX-OUT-HEIGHT) MAX-OUT-WIDTH MAX-OUT-HEIGHT))) (let ((out-width MAX-OUT-WIDTH) (out-height MAX-OUT-HEIGHT) (c (make-array (list 4 MAX-OUT-DIMENSION))) (h (make-array MAX-IN-WIDTH)) (x) (larger-out-dimension)) (setf larger-out-dimension (if (> out-width out-height) out-width out-height)) (let ((LARRAY (make-array larger-out-dimension)) (x) (g (make-array (list MAX-OUT-WIDTH MAX-OUT-HEIGHT)))) (dotimes (k larger-out-dimension) (setf (elt LARRAY k) (floor(/(* k d)n)))) (dotimes (k n) (setf x (/(REM(* k d)n)n)) (setf (aref c 0 k) (C0 x)) (setf (aref c 1 k) (C1 x)) (setf (aref c 2 k) (C2 x)) (setf (aref c 3 k) (C3 x))) (let ((k n)) (while (< k larger-out-dimension) (dotimes (l 4) (setf (aref c l k) (aref c l (REM k n)))) (incf k))) (dotimes (k out-height) (dotimes (j in-width) (setf (elt h j) 0.0) (dotimes (l 4) (let ((index (floor(-(+(elt LARRAY k)l)1)))) (if-progn (and (>= index 0) (< index in-height)) (incf (elt h j) (*(pixat f j index) (aref c (- 3 l) k))))))) (dotimes (m out-width) (setf x 0.5) (dotimes (l 4) (let ((index (floor(-(+(elt LARRAY m)l)1)))) (if-progn (and (>= index 0) (< index in-width)) (incf x (* (elt h index) (aref c (- 3 l) m)))))) (if (<= x 0.0) (setf (aref g m k) 0) (if (>= x MAX-PIXEL) (setf (aref g m k) MAX-PIXEL) (setf (aref g m k) (round x)))))) (array-to-list g))))))