Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 4f45e7bdfd4a5ff17f5f8eaab90d017f > files > 1446

albumshaper-2.1-6mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AlbumShaper: pointillism.cpp File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>pointillism.cpp File Reference</h1><code>#include &lt;qimage.h&gt;</code><br>
<code>#include &lt;qstring.h&gt;</code><br>
<code>#include &lt;cstdlib&gt;</code><br>
<code>#include &lt;time.h&gt;</code><br>
<code>#include &quot;<a class="el" href="pointillism_8h_source.html">pointillism.h</a>&quot;</code><br>
<code>#include &quot;<a class="el" href="blackWhite_8h_source.html">blackWhite.h</a>&quot;</code><br>
<code>#include &quot;<a class="el" href="manipulationOptions_8h_source.html">manipulationOptions.h</a>&quot;</code><br>

<p>
<div class="dynheader">
Include dependency graph for pointillism.cpp:</div>
<div class="dynsection">
</div>

<p>
<a href="pointillism_8cpp_source.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pointillism_8cpp.html#3bcd2957d75fcb33f41acca28c8bbc63">pickRandomPixelWithinBlock</a> (int <a class="el" href="blur_8cpp.html#2474a5474cbff19523a51eb1de01cda4">width</a>, int <a class="el" href="blur_8cpp.html#d12fc34ce789bce6c8a05d8a17138534">height</a>, int blockX, int blockY, int BLOCK_SIZE, int &amp;x, int &amp;y)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pointillism_8cpp.html#47cbb848e72d65594ce31821a72ae15e">pixelValid</a> (QImage *image, int x, int y)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">double&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pointillism_8cpp.html#3899ac9e3314758c9e2531f614675f37">computeLocalGrayVal</a> (QImage *image, int x, int y)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pointillism_8cpp.html#81f112ac02150cd015a661348261aa4a">drawDotAt</a> (QImage *image, int x, int y, int)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">QImage *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pointillism_8cpp.html#0337653a2cbb1e1547d58ac6d7b8f395">pointillismEffect</a> (QString filename, <a class="el" href="classManipulationOptions.html">ManipulationOptions</a> *)</td></tr>

</table>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="3899ac9e3314758c9e2531f614675f37"></a><!-- doxytag: member="pointillism.cpp::computeLocalGrayVal" ref="3899ac9e3314758c9e2531f614675f37" args="(QImage *image, int x, int y)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">double computeLocalGrayVal           </td>
          <td>(</td>
          <td class="paramtype">QImage *&nbsp;</td>
          <td class="paramname"> <em>image</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>y</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

<p>Definition at line <a class="el" href="pointillism_8cpp_source.html#l00067">67</a> of file <a class="el" href="pointillism_8cpp_source.html">pointillism.cpp</a>.</p>

<p>Referenced by <a class="el" href="pointillism_8cpp_source.html#l00109">pointillismEffect()</a>.</p>
<div class="fragment"><pre class="fragment"><a name="l00068"></a>00068 {
<a name="l00069"></a>00069   <span class="keywordtype">int</span> weights[3][3] = { {1,2,1}, {2,4,2}, {1,2,1} };
<a name="l00070"></a>00070   
<a name="l00071"></a>00071   <span class="keywordtype">int</span> divisorSum = 0;
<a name="l00072"></a>00072   <span class="keywordtype">double</span> sum = 0;
<a name="l00073"></a>00073   <span class="keywordtype">int</span> xp, yp;
<a name="l00074"></a>00074   <span class="keywordflow">for</span>(yp = QMAX( y-1, 0); yp &lt; QMIN( image-&gt;height()-1, y+1 ); yp++)
<a name="l00075"></a>00075   {
<a name="l00076"></a>00076     uchar* scanLine = image-&gt;scanLine(yp);
<a name="l00077"></a>00077     
<a name="l00078"></a>00078     <span class="keywordflow">for</span>(xp = QMAX( x-1, 0); xp&lt; QMIN( image-&gt;width()-1, x+1 ); xp++)
<a name="l00079"></a>00079     {
<a name="l00080"></a>00080       <span class="comment">//compute dx and dy values</span>
<a name="l00081"></a>00081       <span class="keywordtype">int</span> dx = xp - x;
<a name="l00082"></a>00082       <span class="keywordtype">int</span> dy = yp - y;
<a name="l00083"></a>00083       
<a name="l00084"></a>00084       <span class="comment">//compute weight index</span>
<a name="l00085"></a>00085       <span class="keywordtype">int</span> weightX = dx+1;
<a name="l00086"></a>00086       <span class="keywordtype">int</span> weightY = dy+1;
<a name="l00087"></a>00087       
<a name="l00088"></a>00088       <span class="comment">//update sum and divisor count      </span>
<a name="l00089"></a>00089       sum+= (weights[weightX][weightY] * qGray( *((QRgb*)scanLine+xp) ) );
<a name="l00090"></a>00090       divisorSum+= weights[weightX][weightY];
<a name="l00091"></a>00091     }
<a name="l00092"></a>00092   }
<a name="l00093"></a>00093   
<a name="l00094"></a>00094   <span class="comment">//return weighted average  </span>
<a name="l00095"></a>00095   <span class="keywordflow">return</span> sum/divisorSum; 
<a name="l00096"></a>00096 }
</pre></div>
<p>

</div>
</div><p>
<a class="anchor" name="81f112ac02150cd015a661348261aa4a"></a><!-- doxytag: member="pointillism.cpp::drawDotAt" ref="81f112ac02150cd015a661348261aa4a" args="(QImage *image, int x, int y, int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void drawDotAt           </td>
          <td>(</td>
          <td class="paramtype">QImage *&nbsp;</td>
          <td class="paramname"> <em>image</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>y</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

<p>Definition at line <a class="el" href="pointillism_8cpp_source.html#l00098">98</a> of file <a class="el" href="pointillism_8cpp_source.html">pointillism.cpp</a>.</p>

<p>Referenced by <a class="el" href="pointillism_8cpp_source.html#l00109">pointillismEffect()</a>.</p>
<div class="fragment"><pre class="fragment"><a name="l00099"></a>00099 {
<a name="l00100"></a>00100   <span class="comment">//TODO: antialias over grid, for now</span>
<a name="l00101"></a>00101   <span class="comment">//just update this pixel value</span>
<a name="l00102"></a>00102   uchar* scanLine = image-&gt;scanLine(y);
<a name="l00103"></a>00103   QRgb* rgb = ((QRgb*)scanLine+x);
<a name="l00104"></a>00104   <span class="keywordtype">int</span> red = qRed(*rgb);
<a name="l00105"></a>00105   red = (int) (0.6*red);
<a name="l00106"></a>00106   *rgb = qRgb( red, red, red);
<a name="l00107"></a>00107 }
</pre></div>
<p>

</div>
</div><p>
<a class="anchor" name="3bcd2957d75fcb33f41acca28c8bbc63"></a><!-- doxytag: member="pointillism.cpp::pickRandomPixelWithinBlock" ref="3bcd2957d75fcb33f41acca28c8bbc63" args="(int width, int height, int blockX, int blockY, int BLOCK_SIZE, int &amp;x, int &amp;y)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void pickRandomPixelWithinBlock           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>width</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>height</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>blockX</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>blockY</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>BLOCK_SIZE</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int &amp;&nbsp;</td>
          <td class="paramname"> <em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int &amp;&nbsp;</td>
          <td class="paramname"> <em>y</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

<p>Definition at line <a class="el" href="pointillism_8cpp_source.html#l00042">42</a> of file <a class="el" href="pointillism_8cpp_source.html">pointillism.cpp</a>.</p>

<p>Referenced by <a class="el" href="pointillism_8cpp_source.html#l00109">pointillismEffect()</a>.</p>
<div class="fragment"><pre class="fragment"><a name="l00046"></a>00046 {
<a name="l00047"></a>00047   <span class="keywordtype">int</span> dx = rand() % BLOCK_SIZE;
<a name="l00048"></a>00048   <span class="keywordtype">int</span> dy = rand() % BLOCK_SIZE;
<a name="l00049"></a>00049   x = blockX*BLOCK_SIZE + dx;
<a name="l00050"></a>00050   y = blockY*BLOCK_SIZE + dy;
<a name="l00051"></a>00051   
<a name="l00052"></a>00052   <span class="keywordflow">if</span>(x &lt; 0) x = 0;
<a name="l00053"></a>00053   <span class="keywordflow">if</span>(y &lt; 0) y = 0;
<a name="l00054"></a>00054   <span class="keywordflow">if</span>(x &gt;= <a class="code" href="blur_8cpp.html#2474a5474cbff19523a51eb1de01cda4">width</a> ) x = <a class="code" href="blur_8cpp.html#2474a5474cbff19523a51eb1de01cda4">width</a>-1;
<a name="l00055"></a>00055   <span class="keywordflow">if</span>(y &gt;= <a class="code" href="blur_8cpp.html#d12fc34ce789bce6c8a05d8a17138534">height</a>) y = <a class="code" href="blur_8cpp.html#d12fc34ce789bce6c8a05d8a17138534">height</a>-1;  
<a name="l00056"></a>00056 }
</pre></div>
<p>

</div>
</div><p>
<a class="anchor" name="47cbb848e72d65594ce31821a72ae15e"></a><!-- doxytag: member="pointillism.cpp::pixelValid" ref="47cbb848e72d65594ce31821a72ae15e" args="(QImage *image, int x, int y)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool pixelValid           </td>
          <td>(</td>
          <td class="paramtype">QImage *&nbsp;</td>
          <td class="paramname"> <em>image</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>y</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

<p>Definition at line <a class="el" href="pointillism_8cpp_source.html#l00058">58</a> of file <a class="el" href="pointillism_8cpp_source.html">pointillism.cpp</a>.</p>

<p>References <a class="el" href="blur_8cpp_source.html#l00079">height</a>, and <a class="el" href="blur_8cpp_source.html#l00079">width</a>.</p>
<div class="fragment"><pre class="fragment"><a name="l00059"></a>00059 {
<a name="l00060"></a>00060   <span class="keywordflow">return</span> (
<a name="l00061"></a>00061           x &gt;= 0 &amp;&amp;
<a name="l00062"></a>00062           y &gt;= 0 &amp;&amp;
<a name="l00063"></a>00063           x &lt; image-&gt;<a class="code" href="blur_8cpp.html#2474a5474cbff19523a51eb1de01cda4">width</a>() &amp;&amp;
<a name="l00064"></a>00064           x &lt; image-&gt;<a class="code" href="blur_8cpp.html#d12fc34ce789bce6c8a05d8a17138534">height</a>() );
<a name="l00065"></a>00065 }
</pre></div>
<p>

</div>
</div><p>
<a class="anchor" name="0337653a2cbb1e1547d58ac6d7b8f395"></a><!-- doxytag: member="pointillism.cpp::pointillismEffect" ref="0337653a2cbb1e1547d58ac6d7b8f395" args="(QString filename, ManipulationOptions *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">QImage* pointillismEffect           </td>
          <td>(</td>
          <td class="paramtype">QString&nbsp;</td>
          <td class="paramname"> <em>filename</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classManipulationOptions.html">ManipulationOptions</a> *&nbsp;</td>
          <td class="paramname"></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

<p>Definition at line <a class="el" href="pointillism_8cpp_source.html#l00109">109</a> of file <a class="el" href="pointillism_8cpp_source.html">pointillism.cpp</a>.</p>

<p>References <a class="el" href="blackWhite_8cpp_source.html#l00060">blackWhiteEffect()</a>, <a class="el" href="pointillism_8cpp_source.html#l00067">computeLocalGrayVal()</a>, <a class="el" href="pointillism_8cpp_source.html#l00098">drawDotAt()</a>, <a class="el" href="redEye__internal_8h_source.html#l00037">editedImage</a>, <a class="el" href="blur_8cpp_source.html#l00079">height</a>, <a class="el" href="pointillism_8cpp_source.html#l00042">pickRandomPixelWithinBlock()</a>, and <a class="el" href="blur_8cpp_source.html#l00079">width</a>.</p>

<p>Referenced by <a class="el" href="editingInterface_8cpp_source.html#l00834">EditingInterface::applyEffect()</a>.</p>
<div class="fragment"><pre class="fragment"><a name="l00110"></a>00110 {
<a name="l00111"></a>00111   <span class="comment">//intialize seed using current time</span>
<a name="l00112"></a>00112   srand( <span class="keywordtype">unsigned</span>(time(NULL)) );
<a name="l00113"></a>00113 
<a name="l00114"></a>00114   <span class="comment">//load original image and convert to grayscale</span>
<a name="l00115"></a>00115   QImage* originalImage = <a class="code" href="blackWhite_8cpp.html#81188751080c22115720554f1ce6a30f">blackWhiteEffect</a>( filename, NULL );
<a name="l00116"></a>00116   
<a name="l00117"></a>00117   <span class="comment">//construct edited image</span>
<a name="l00118"></a>00118   QImage* <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a> = <span class="keyword">new</span> QImage( originalImage-&gt;width(),
<a name="l00119"></a>00119                                     originalImage-&gt;height(),
<a name="l00120"></a>00120                                     originalImage-&gt;depth() );
<a name="l00121"></a>00121 
<a name="l00122"></a>00122   <span class="comment">//fill with white since we'll be drawing black/color dots on top</span>
<a name="l00123"></a>00123   editedImage-&gt;fill( qRgb(255,255,255) );
<a name="l00124"></a>00124 
<a name="l00125"></a>00125   <span class="comment">//break image into BLOCK_SIZE x BLOCK_SIZE blocks. iterate over</span>
<a name="l00126"></a>00126   <span class="comment">//each block and pick a random pixel within. Local</span>
<a name="l00127"></a>00127   <span class="comment">//average gray value in edited image is &gt; originalImage + thresh</span>
<a name="l00128"></a>00128   <span class="comment">//then draw a dot at pixel. continue doing this for each block</span>
<a name="l00129"></a>00129   <span class="comment">//and repeat until ???</span>
<a name="l00130"></a>00130   <span class="keyword">const</span> <span class="keywordtype">int</span> BLOCK_SIZE = 8;
<a name="l00131"></a>00131 
<a name="l00132"></a>00132   <span class="comment">//compute image size in blocks</span>
<a name="l00133"></a>00133   <span class="keywordtype">int</span> blocksWide = editedImage-&gt;width() / BLOCK_SIZE;
<a name="l00134"></a>00134   <span class="keywordflow">if</span>(blocksWide*BLOCK_SIZE &lt; editedImage-&gt;<a class="code" href="blur_8cpp.html#2474a5474cbff19523a51eb1de01cda4">width</a>())
<a name="l00135"></a>00135   { blocksWide++; }
<a name="l00136"></a>00136   
<a name="l00137"></a>00137   <span class="keywordtype">int</span> blocksTall = editedImage-&gt;height() / BLOCK_SIZE;
<a name="l00138"></a>00138   <span class="keywordflow">if</span>(blocksTall*BLOCK_SIZE &lt; editedImage-&gt;<a class="code" href="blur_8cpp.html#d12fc34ce789bce6c8a05d8a17138534">height</a>())
<a name="l00139"></a>00139   { blocksTall++; }
<a name="l00140"></a>00140 
<a name="l00141"></a>00141   <span class="comment">//iterate over image say 100 times, we'll need to fix this outer loop to be smarter?</span>
<a name="l00142"></a>00142   <span class="keywordtype">int</span> bx,by,x,y;
<a name="l00143"></a>00143   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;10; i++)
<a name="l00144"></a>00144   {
<a name="l00145"></a>00145     <span class="comment">//iterate over all blocks</span>
<a name="l00146"></a>00146     <span class="keywordflow">for</span>(bx=0; bx&lt;blocksWide; bx++)
<a name="l00147"></a>00147     {
<a name="l00148"></a>00148       <span class="keywordflow">for</span>(by=0; by&lt;blocksTall; by++)
<a name="l00149"></a>00149       {
<a name="l00150"></a>00150         <span class="comment">//pick random pixel within block</span>
<a name="l00151"></a>00151         <a class="code" href="pointillism_8cpp.html#3bcd2957d75fcb33f41acca28c8bbc63">pickRandomPixelWithinBlock</a>( editedImage-&gt;width(),
<a name="l00152"></a>00152                                     editedImage-&gt;height(),
<a name="l00153"></a>00153                                     bx, by,
<a name="l00154"></a>00154                                     BLOCK_SIZE,
<a name="l00155"></a>00155                                     x, y );
<a name="l00156"></a>00156         
<a name="l00157"></a>00157         <span class="keywordtype">double</span> curGrayVal = <a class="code" href="pointillism_8cpp.html#3899ac9e3314758c9e2531f614675f37">computeLocalGrayVal</a>( editedImage, x, y );
<a name="l00158"></a>00158         <span class="keywordtype">double</span> goalGrayVal = <a class="code" href="pointillism_8cpp.html#3899ac9e3314758c9e2531f614675f37">computeLocalGrayVal</a>( originalImage, x, y );
<a name="l00159"></a>00159 
<a name="l00160"></a>00160         <span class="comment">//too bright -&gt; draw dot</span>
<a name="l00161"></a>00161         <span class="keywordflow">if</span>( curGrayVal &gt; goalGrayVal )
<a name="l00162"></a>00162         { <a class="code" href="pointillism_8cpp.html#81f112ac02150cd015a661348261aa4a">drawDotAt</a>( editedImage, x, y, 5 ); }
<a name="l00163"></a>00163       }
<a name="l00164"></a>00164     }
<a name="l00165"></a>00165   }
<a name="l00166"></a>00166 
<a name="l00167"></a>00167   <span class="comment">//free grayscale form of original image</span>
<a name="l00168"></a>00168   <span class="keyword">delete</span> originalImage;
<a name="l00169"></a>00169   originalImage = NULL;
<a name="l00170"></a>00170   
<a name="l00171"></a>00171   <span class="comment">//return pointer to edited image</span>
<a name="l00172"></a>00172   <span class="keywordflow">return</span> editedImage;      
<a name="l00173"></a>00173 }
</pre></div>
<p>

</div>
</div><p>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Aug 23 02:34:31 2009 for AlbumShaper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>