<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:12pt"><div><br></div>
<pre style="" class="default prettyprint prettyprinted"><code><span class="pun">(</span><span class="pln">cffi</span><span class="pun">:</span><span class="pln">defcstruct </span><span class="pun">(</span><span class="pln">cv</span><span class="pun">-</span><span class="pln">size </span><span class="pun">:</span><span class="kwd">class</span><span class="pln"> cv</span><span class="pun">-</span><span class="pln">size</span><span class="pun">-</span><span class="pln">type</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">width </span><span class="pun">:</span><span class="kwd">int</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">height </span><span class="pun">:</span><span class="kwd">int</span><span class="pun">))</span><span class="pln">
</span><span class="pun">(</span><span class="pln">defmethod cffi</span><span class="pun">:</span><span class="pln">translate</span><span class="pun">-</span><span class="kwd">from</span><span class="pun">-</span><span class="pln">foreign </span><span class="pun">(</span><span class="pln">p </span><span class="pun">(</span><span class="pln">type cv</span><span class="pun">-</span><span class="pln">size</span><span class="pun">-</span><span class="pln">type</span><span class="pun">))</span><span class="pln">
</span><span class="pun">(</span><span class="kwd">let</span><span class="pln"> </span><span class="pun">((</span><span class="pln">plist </span><span class="pun">(</span><span class="pln">call</span><span class="pun">-</span><span class="kwd">next</span><span class="pun">-</span><span class="pln">method</span><span class="pun">)))</span><span class="pln">
</span><span class="pun">(</span><span class="pln">make</span><span class="pun">-</span><span class="pln">size </span><span class="pun">:</span><span class="pln">width </span><span class="pun">(</span><span class="pln">getf plist </span><span class="str">'width)
:height (getf plist '</span><span class="pln">height</span><span class="pun">))))</span></code></pre>
<div>and my opencv wrappers for CvGetSize and cvCreateImage, get-size and create-image, are defined like this</div>
<pre style="" class="default prettyprint prettyprinted"><code><span class="pun">;;</span><span class="pln"> </span><span class="typ">CvSize</span><span class="pln"> cvGetSize</span><span class="pun">(</span><span class="kwd">const</span><span class="pln"> </span><span class="typ">CvArr</span><span class="pun">*</span><span class="pln"> arr</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">cffi</span><span class="pun">:</span><span class="pln">defcfun </span><span class="pun">(</span><span class="str">"cvGetSize"</span><span class="pln"> </span><span class="kwd">get</span><span class="pun">-</span><span class="pln">size</span><span class="pun">)</span><span class="pln"> </span><span class="pun">(:</span><span class="kwd">struct</span><span class="pln"> cv</span><span class="pun">-</span><span class="pln">size</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">arr cv</span><span class="pun">-</span><span class="pln">arr</span><span class="pun">))</span><span class="pln">
</span><span class="pun">;;</span><span class="pln"> </span><span class="typ">IplImage</span><span class="pun">*</span><span class="pln"> cvCreateImage</span><span class="pun">(</span><span class="typ">CvSize</span><span class="pln"> size</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> depth</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> channels</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">cffi</span><span class="pun">:</span><span class="pln">defcfun </span><span class="pun">(</span><span class="str">"cvCreateImage"</span><span class="pln"> </span><span class="pun">%</span><span class="pln">create</span><span class="pun">-</span><span class="pln">image</span><span class="pun">)</span><span class="pln"> ipl</span><span class="pun">-</span><span class="pln">image
</span><span class="pun">(</span><span class="pln">size </span><span class="pun">:</span><span class="pln">int64</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">depth </span><span class="pun">:</span><span class="kwd">int</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">channels </span><span class="pun">:</span><span class="kwd">int</span><span class="pun">))</span><span class="pln">
</span><span class="pun">(</span><span class="pln">defun create</span><span class="pun">-</span><span class="pln">image </span><span class="pun">(</span><span class="pln">size depth channels</span><span class="pun">)</span><span class="pln">
</span><span class="str">"Create an image with dimensions given by SIZE, DEPTH bits per
channel, and CHANNELS number of channels."</span><span class="pln">
</span><span class="pun">(</span><span class="kwd">let</span><span class="pln"> </span><span class="pun">((</span><span class="pln">nsize </span><span class="pun">(</span><span class="pln">size</span><span class="pun">-></span><span class="pln">int64 size</span><span class="pun">)))</span><span class="pln">
</span><span class="pun">(%</span><span class="pln">create</span><span class="pun">-</span><span class="pln">image nsize depth channels</span><span class="pun">)))</span></code></pre>
<div>here is the definition of size->int64</div>
<pre style="" class="default prettyprint prettyprinted"><code><span class="pun">(</span><span class="pln">DEFUN SIZE</span><span class="pun">-></span><span class="pln">INT64 </span><span class="pun">(</span><span class="pln">S</span><span class="pun">)</span><span class="pln"> </span><span class="pun">(+</span><span class="pln"> </span><span class="pun">(</span><span class="pln">SIZE</span><span class="pun">-</span><span class="pln">WIDTH S</span><span class="pun">)</span><span class="pln"> </span><span class="pun">(</span><span class="pln">ASH </span><span class="pun">(</span><span class="pln">SIZE</span><span class="pun">-</span><span class="pln">HEIGHT S</span><span class="pun">)</span><span class="pln"> </span><span class="lit">32</span><span class="pun">)))</span><span class="pln">
it converts </span><span class="kwd">get</span><span class="pun">-</span><span class="pln">size output which </span><span class="kwd">is</span><span class="pln"> a structure here</span><span class="pun">:</span><span class="pln">
</span><span class="com">#S(SIZE :WIDTH 640 :HEIGHT 480)</span><span class="pln">
</span><span class="kwd">into</span><span class="pln"> </span><span class="lit">64</span><span class="pun">-</span><span class="pln">bit integer</span><span class="pun">,</span><span class="pln"> which CFFI can handle </span></code></pre>
<div>but i love the idea of the translate-foreign defmethod's</div>
<div>so i was wondering if you can show my how to make the
translate-into-foreign version of the below from method this would
really make my library awesome</div>
<pre style="" class="default prettyprint prettyprinted"><code><span class="pun">(</span><span class="pln">defmethod cffi</span><span class="pun">:</span><span class="pln">translate</span><span class="pun">-</span><span class="kwd">from</span><span class="pun">-</span><span class="pln">foreign </span><span class="pun">(</span><span class="pln">p </span><span class="pun">(</span><span class="pln">type cv</span><span class="pun">-</span><span class="pln">size</span><span class="pun">-</span><span class="pln">type</span><span class="pun">))</span><span class="pln">
</span><span class="pun">(</span><span class="kwd">let</span><span class="pln"> </span><span class="pun">((</span><span class="pln">plist </span><span class="pun">(</span><span class="pln">call</span><span class="pun">-</span><span class="kwd">next</span><span class="pun">-</span><span class="pln">method</span><span class="pun">)))</span><span class="pln">
</span><span class="pun">(</span><span class="pln">make</span><span class="pun">-</span><span class="pln">size </span><span class="pun">:</span><span class="pln">width </span><span class="pun">(</span><span class="pln">getf plist </span><span class="str">'width)
:height (getf plist '</span><span class="pln">height</span><span class="pun">))))</span></code></pre>
<div>I was going to try stuff and add it but for the get-size output
structure, it isnt a plist so not really sure what to put there for the</div>
<pre style="" class="default prettyprint prettyprinted"><code><span class="pun">(</span><span class="kwd">let</span><span class="pln"> </span><span class="pun">((</span><span class="pln">plist </span><span class="pun">(</span><span class="pln">call</span><span class="pun">-</span><span class="kwd">next</span><span class="pun">-</span><span class="pln">method</span><span class="pun">)))</span></code></pre>
<div>part, for the </div>
<pre style="" class="default prettyprint prettyprinted"><code><span class="pln"> </span><span class="pun">(</span><span class="pln">make</span><span class="pun">-</span><span class="pln">size </span><span class="pun">:</span><span class="pln">width </span><span class="pun">(</span><span class="pln">getf plist </span><span class="str">'width)
:height (getf plist '</span><span class="pln">height</span><span class="pun">))))</span></code></pre><br></div></body></html>