Created
December 31, 2009 16:35
-
-
Save joelreymont/266790 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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