16acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn/*M///////////////////////////////////////////////////////////////////////////////////////
26acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
36acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
46acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
56acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  By downloading, copying, installing or using the software you agree to this license.
66acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  If you do not agree to this license, do not download, install,
76acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  copy or use the software.
86acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
96acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
106acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//                        Intel License Agreement
116acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//                For Open Source Computer Vision Library
126acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
136acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// Copyright (C) 2000, Intel Corporation, all rights reserved.
146acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// Third party copyrights are property of their respective owners.
156acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
166acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// Redistribution and use in source and binary forms, with or without modification,
176acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// are permitted provided that the following conditions are met:
186acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
196acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//   * Redistribution's of source code must retain the above copyright notice,
206acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     this list of conditions and the following disclaimer.
216acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
226acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//   * Redistribution's in binary form must reproduce the above copyright notice,
236acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     this list of conditions and the following disclaimer in the documentation
246acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     and/or other materials provided with the distribution.
256acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
266acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//   * The name of Intel Corporation may not be used to endorse or promote products
276acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     derived from this software without specific prior written permission.
286acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
296acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// This software is provided by the copyright holders and contributors "as is" and
306acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// any express or implied warranties, including, but not limited to, the implied
316acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// warranties of merchantability and fitness for a particular purpose are disclaimed.
326acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// In no event shall the Intel Corporation or contributors be liable for any direct,
336acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// indirect, incidental, special, exemplary, or consequential damages
346acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// (including, but not limited to, procurement of substitute goods or services;
356acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// loss of use, data, or profits; or business interruption) however caused
366acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// and on any theory of liability, whether in contract, strict liability,
376acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// or tort (including negligence or otherwise) arising in any way out of
386acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// the use of this software, even if advised of the possibility of such damage.
396acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
406acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//M*/
416acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn#include "_cvaux.h"
426acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn#include <assert.h>
436acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
446acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
456acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennstatic CvStatus
466acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennicvMorphEpilines8uC3( uchar * first_pix,        /* raster epiline from image 1      */
476acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      uchar * second_pix,       /* raster epiline from image 2      */
486acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      uchar * dst_pix,  /* raster epiline from dest image   */
496acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      /* (it's an output parameter)       */
506acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      float alpha,      /* relative position of camera      */
516acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *first,       /* first sequence of runs           */
526acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int first_runs,   /* it's length                      */
536acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *second,      /* second sequence of runs          */
546acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int second_runs, int *first_corr, /* corr data for the 1st seq        */
556acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *second_corr, /* corr data for the 2nd seq        */
566acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int dst_len )
576acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
586acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
596acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    float alpha1;               /* alpha - 1.0 */
606acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int s, s1;                  /* integer variant of alpha and alpha1 ( 0 <= s,s1 <= 256 ) */
616acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int curr;                   /* current index in run's array */
626acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
636acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    float begLine;              /* begin of current run */
646acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    float endLine;              /* end   of current run */
656acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
666acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    float begCorr;              /* begin of correspondence destination of run */
676acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    float endCorr;              /* end   of correspondence destination of run */
686acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
696acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int begDestLine;            /* begin of current destanation of run */
706acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int endDestLine;            /* end   of current destanation of run */
716acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int begLineIndex;
726acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int endLineIndex;
736acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int indexImg1;
746acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    float step = 0;
756acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int n;
766acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
776acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    memset( dst_pix, 0, dst_len );
786acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    alpha1 = (float) (1.0 - alpha);
796acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
806acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    s = (int) (alpha * 256);
816acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    s1 = 256 - s;
826acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
836acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    /* --------------Create first line------------- */
846acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
856acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    begLineIndex = first[0];
866acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    begLine = (float) begLineIndex;
876acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
886acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    curr = 0;
896acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
906acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    for( n = 0; n < first_runs; n++ )
916acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {                           /* for each run */
926acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
936acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begCorr = (float) first_corr[curr];
946acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        curr++;
956acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endCorr = (float) first_corr[curr];
966acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        curr++;
976acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endLineIndex = first[curr];
986acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endLine = (float) endLineIndex;
996acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1006acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begDestLine = (int) (alpha * begLine + alpha1 * begCorr);
1016acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endDestLine = (int) (alpha * endLine + alpha1 * endCorr);
1026acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1036acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        indexImg1 = begDestLine * 3;
1046acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1056acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        step = 0;
1066acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( endDestLine != begDestLine )
1076acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            step = (endLine - begLine) / ((float) (endDestLine - begDestLine));
1086acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1096acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( begCorr != endCorr )
1106acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        {
1116acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1126acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            for( ; begDestLine < endDestLine; begDestLine++ )
1136acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            {
1146acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* for each pixel */
1156acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1166acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex = (int) begLine;
1176acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex *= 3;
1186acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1196acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend R */
1206acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] = (uchar) (((int) (first_pix[begLineIndex]) * s) >> 8);
1216acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1226acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
1236acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1246acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend G */
1256acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] = (uchar) (((int) (first_pix[begLineIndex + 1]) * s) >> 8);
1266acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1276acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
1286acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1296acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend B */
1306acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] = (uchar) (((int) (first_pix[begLineIndex + 2]) * s) >> 8);
1316acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1326acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
1336acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1346acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLine += step;
1356acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1366acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            }                   /* for */
1376acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        }
1386acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        else
1396acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        {
1406acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1416acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            for( ; begDestLine < endDestLine; begDestLine++ )
1426acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            {
1436acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* for each pixel */
1446acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1456acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex = (int) begLine;
1466acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex *= 3;
1476acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1486acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend R */
1496acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] = first_pix[begLineIndex];
1506acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
1516acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1526acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend G */
1536acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] = first_pix[begLineIndex + 1];
1546acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
1556acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1566acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend B */
1576acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] = first_pix[begLineIndex + 2];
1586acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1596acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
1606acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1616acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLine += step;
1626acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1636acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            }                   /* for */
1646acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        }                       /* if */
1656acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1666acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begLineIndex = endLineIndex;
1676acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begLine = endLine;
1686acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1696acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1706acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }                           /* for each runs in first line */
1716acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1726acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    begLineIndex = second[0];
1736acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    begLine = (float) begLineIndex;
1746acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1756acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    curr = 0;
1766acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1776acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    /* --------------Create second line------------- */
1786acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    curr = 0;;
1796acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    for( n = 0; n < second_runs; n++ )
1806acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {                           /* for each run */
1816acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1826acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begCorr = (float) second_corr[curr];
1836acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        curr++;
1846acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endCorr = (float) second_corr[curr];
1856acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        curr++;
1866acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endLineIndex = second[curr];
1876acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endLine = (float) endLineIndex;
1886acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1896acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begDestLine = (int) (alpha1 * begLine + alpha * begCorr);
1906acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        endDestLine = (int) (alpha1 * endLine + alpha * endCorr);
1916acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1926acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        indexImg1 = begDestLine * 3;
1936acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1946acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        step = 0;
1956acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if (endDestLine != begDestLine)
1966acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            step = (endLine - begLine) / ((float) (endDestLine - begDestLine));
1976acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1986acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( begCorr != endCorr )
1996acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        {
2006acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2016acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            for( ; begDestLine < endDestLine; begDestLine++ )
2026acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            {
2036acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* for each pixel */
2046acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2056acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex = (int) begLine;
2066acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex *= 3;
2076acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2086acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend R */
2096acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] =
2106acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                    (uchar) (dst_pix[indexImg1] +
2116acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                             (uchar) (((unsigned int) (second_pix[begLineIndex]) * s1) >> 8));
2126acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2136acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
2146acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2156acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend G */
2166acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] =
2176acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                    (uchar) (dst_pix[indexImg1] +
2186acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                             (uchar) (((unsigned int) (second_pix[begLineIndex + 1]) * s1) >>
2196acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      8));
2206acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2216acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
2226acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2236acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend B */
2246acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] =
2256acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                    (uchar) (dst_pix[indexImg1] +
2266acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                             (uchar) (((unsigned int) (second_pix[begLineIndex + 2]) * s1) >>
2276acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      8));
2286acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2296acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
2306acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2316acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLine += step;
2326acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2336acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            }                   /* for */
2346acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        }
2356acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        else
2366acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        {
2376acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2386acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            for( ; begDestLine < endDestLine; begDestLine++ )
2396acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            {
2406acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* for each pixel */
2416acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2426acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex = (int) begLine;
2436acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLineIndex *= 3;
2446acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2456acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend R */
2466acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] = (uchar) (dst_pix[indexImg1] + second_pix[begLineIndex]);
2476acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
2486acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2496acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend G */
2506acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] =
2516acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                    (uchar) (dst_pix[indexImg1] + second_pix[begLineIndex + 1]);
2526acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
2536acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2546acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /* Blend B */
2556acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                dst_pix[indexImg1] =
2566acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                    (uchar) (dst_pix[indexImg1] + second_pix[begLineIndex + 2]);
2576acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                /*assert(indexImg1 < dst_len); */
2586acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2596acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                indexImg1++;
2606acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2616acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                begLine += step;
2626acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2636acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            }                   /* for */
2646acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        }                       /* if */
2656acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2666acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begLineIndex = endLineIndex;
2676acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        begLine = endLine;
2686acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2696acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }                           /* for each runs in second line */
2706acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2716acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return CV_NO_ERR;
2726acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2736acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}                               /* icvMorphEpilines8uC3 */
2746acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2756acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2766acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn/*======================================================================================*/
2776acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2786acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennstatic CvStatus
2796acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennicvMorphEpilines8uC3Multi( int lines,   /* number of lines                              */
2806acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           uchar * first_pix,   /* raster epilines from the first image         */
2816acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *first_num,      /* numbers of pixel in first line               */
2826acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           uchar * second_pix,  /* raster epilines from the second image        */
2836acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *second_num,     /* numbers of pixel in second line              */
2846acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           uchar * dst_pix,     /* raster epiline from the destination image    */
2856acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           /* (it's an output parameter)                   */
2866acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *dst_num,        /* numbers of pixel in output line              */
2876acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           float alpha, /* relative position of camera                  */
2886acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *first,  /* first sequence of runs                       */
2896acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *first_runs,     /* it's length                                  */
2906acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *second, /* second sequence of runs                      */
2916acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *second_runs, int *first_corr,   /* correspond information for the 1st seq       */
2926acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                           int *second_corr )   /* correspond information for the 2nd seq       */
2936acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2946acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    CvStatus error;
2956acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currLine;
2966acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currFirstPix = 0;
2976acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    //int currFirstNum = 0;
2986acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currSecondPix = 0;
2996acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    //int currSecondNum = 0;
3006acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currDstPix = 0;
3016acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currFirst = 0;
3026acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    //int currFirstRuns = 0;
3036acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currSecond = 0;
3046acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    //int currSecondRuns = 0;
3056acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currFirstCorr = 0;
3066acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int currSecondCorr = 0;
3076acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3086acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( lines < 1 ||
3096acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        first_pix == 0 ||
3106acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        first_num == 0 ||
3116acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        second_pix == 0 ||
3126acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        second_num == 0 ||
3136acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        dst_pix == 0 ||
3146acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        dst_num == 0 ||
3156acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        alpha < 0 ||
3166acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        alpha > 1 ||
3176acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        first == 0 ||
3186acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        first_runs == 0 ||
3196acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        second == 0 || second_runs == 0 || first_corr == 0 || second_corr == 0 )
3206acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        return CV_BADFACTOR_ERR;
3216acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3226acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    for( currLine = 0; currLine < lines; currLine++ )
3236acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
3246acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3256acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        error = icvMorphEpilines8uC3( &(first_pix[currFirstPix]),
3266acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      &(second_pix[currSecondPix]),
3276acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      &(dst_pix[currDstPix]),
3286acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      alpha,
3296acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      &(first[currFirst]),
3306acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      first_runs[currLine],
3316acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      &(second[currSecond]),
3326acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      second_runs[currLine],
3336acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      &(first_corr[currFirstCorr]),
3346acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                      &(second_corr[currSecondCorr]), dst_num[currLine] * 3 );
3356acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3366acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3376acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( error != CV_NO_ERR )
3386acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            return CV_NO_ERR;
3396acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3406acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        currFirstPix += first_num[currLine] * 3;
3416acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        currSecondPix += second_num[currLine] * 3;
3426acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        currDstPix += dst_num[currLine] * 3;
3436acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        currFirst += (first_runs[currLine] * 2) + 1;
3446acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        currSecond += (second_runs[currLine] * 2) + 1;
3456acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        currFirstCorr += first_runs[currLine] * 2;
3466acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        currSecondCorr += second_runs[currLine] * 2;
3476acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3486acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }                           /* for */
3496acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3506acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return CV_NO_ERR;
3516acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3526acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}                               /* icvMorphEpilines8uC3Multi */
3536acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3546acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3556acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3566acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3576acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn/*======================================================================================*/
3586acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3596acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennCV_IMPL void
3606acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RenncvMorphEpilinesMulti( int lines,        /* number of lines             */
3616acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      uchar * first_pix,        /* raster epilines from the first image      */
3626acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *first_num,   /* numbers of pixel in first line            */
3636acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      uchar * second_pix,       /* raster epilines from the second image     */
3646acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *second_num,  /* numbers of pixel in second line           */
3656acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      uchar * dst_pix,  /* raster epiline from the destination image */
3666acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      /* (it's an output parameter)                */
3676acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *dst_num,     /* numbers of pixel in output line           */
3686acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      float alpha,      /* relative position of camera               */
3696acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *first,       /* first sequence of runs                    */
3706acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *first_runs,  /* it's length                               */
3716acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *second,      /* second sequence of runs                   */
3726acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *second_runs, int *first_corr,        /* correspond information for the 1st seq    */
3736acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                      int *second_corr  /* correspond information for the 2nd seq     */
3746acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn     )
3756acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
3766acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    CV_FUNCNAME( "cvMorphEpilinesMulti" );
3776acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    __BEGIN__;
3786acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3796acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    IPPI_CALL( icvMorphEpilines8uC3Multi( lines,        /* number of lines                           */
3806acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          first_pix,    /* raster epilines from the first image      */
3816acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          first_num,    /* numbers of pixel in first line            */
3826acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          second_pix,   /* raster epilines from the second image     */
3836acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          second_num,   /* numbers of pixel in second line           */
3846acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          dst_pix,      /* raster epiline from the destination image */
3856acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          /* (it's an output parameter)                   */
3866acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          dst_num,      /* numbers of pixel in output line           */
3876acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          alpha,        /* relative position of camera               */
3886acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          first,        /* first sequence of runs                    */
3896acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          first_runs,   /* it's length                               */
3906acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          second,       /* second sequence of runs                   */
3916acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          second_runs, first_corr,      /* correspond information for the 1st seq    */
3926acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                                          second_corr   /* correspond information for the 2nd seq     */
3936acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                ));
3946acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    __END__;
3956acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
3966acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
397