Skip to content

Instantly share code, notes, and snippets.

@joelreymont
Created December 31, 2009 16:35
Show Gist options
  • Save joelreymont/266790 to your computer and use it in GitHub Desktop.
Save joelreymont/266790 to your computer and use it in GitHub Desktop.
;;; Blend a masked source image with a target
(defun cocoa-blend (target source mask offset size)
(declare #.*optimize*
(type fixnum size offset)
(inline fli:dereference (setf fli:dereference)))
(loop for i fixnum from offset below (the fixnum (+ offset size))
for j fixnum from 0 below size do
(let ((dst (fli:dereference target :index i :type '(:unsigned :char)))
(src (fli:dereference source :index j :type '(:unsigned :char)))
(alpha (fli:dereference mask :index j :type '(:unsigned :char))))
(declare (type fixnum dst src alpha))
(when (> alpha 0)
(setf (fli:dereference target :index i :type '(:unsigned :char))
(the fixnum
(truncate (/ (+ (* src alpha) (* dst (- 255 alpha))) 255))))
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment