17f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/*
27f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
37f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project *
47f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
57f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * you may not use this file except in compliance with the License.
67f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * You may obtain a copy of the License at
77f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project *
87f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
97f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project *
107f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software
117f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
127f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * See the License for the specific language governing permissions and
147f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * limitations under the License.
157f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project */
167f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
177f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- includes ----------------------------------------------------------- */
187f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
197f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project#include "b_APIEm/Functions.h"
207f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project#include "b_BasicEm/Memory.h"
217f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
227f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
237f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- related objects  --------------------------------------------------- */
247f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
257f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- typedefs ----------------------------------------------------------- */
267f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
277f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- constants ---------------------------------------------------------- */
287f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
297f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */
307f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
317f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */
327f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/*                                                                           */
337f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ external functions } ----------------------------------------- */
347f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/*                                                                           */
357f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */
367f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
377f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */
387f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
397f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectvoid bpi_normalizeSimilarities( struct bbs_Context* cpA,
407f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project							    const int32* rawSimArrA,
417f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project							    const int32* rawIdArrA,
427f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								uint32 rawSizeA,
437f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								const int32* refSimArrA,
447f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								const int32* refIdArrA,
457f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								uint32 refSizeA,
467f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								enum bpi_SimType simTypeA,
477f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								int32* outSimArrA )
487f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{
497f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	/* 8.24 */
507f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	int32 refSimL = 0;
517f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	uint32 iL, jL, kL;
527f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	int32* outPtrL = outSimArrA;
537f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	const int32* rawPtrL = rawSimArrA;
547f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
557f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	switch( simTypeA )
567f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	{
577f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_RAW_SIM:
587f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
597f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* nothing to do */
607f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
617f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
627f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
637f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_SUB_MEAN:
647f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
657f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 shiftL = 0;
667f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 roundL = 0;
677f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			refSimL = 0;
687f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < refSizeA; iL++ )
697f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
707f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				refSimL += ( refSimArrA[ iL ] + roundL ) >> shiftL;
717f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( refSimL > 0x40000000 )
727f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
737f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					refSimL = ( refSimL + 1 ) >> 1;
747f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					shiftL++;
757f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					roundL = ( int32 )1 << ( shiftL - 1 );
767f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
777f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
787f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			refSimL = ( refSimL / refSizeA ) << shiftL;
797f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
807f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
817f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
827f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_SUB_MAX_2:
837f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
847f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 maxL = 0;
857f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			uint32 maxIndexL = 0;
867f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 idL = 0;
877f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
887f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* find raw maximum */
897f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < rawSizeA; iL++ )
907f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
917f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( maxL < rawSimArrA[ iL ] )
927f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
937f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					maxL = refSimArrA[ iL ];
947f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					maxIndexL = iL;
957f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
967f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
977f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
987f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* consider id of maximum equal to probe id */
997f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			idL = rawIdArrA[ maxIndexL ];
1007f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1017f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* find maximum similarity in ref array of different id */
1027f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < refSizeA; iL++ )
1037f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
1047f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( refIdArrA[ iL ] != idL )
1057f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
1067f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					refSimL = ( refSimL > refSimArrA[ iL ] ) ? refSimL : refSimArrA[ iL ];
1077f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
1087f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
1097f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
1107f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
1117f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1127f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_SUB_16_MAX_2:
1137f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
1147f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 maxL = 0;
1157f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			uint32 maxIndexL = 0;
1167f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 idL = 0;
1177f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1187f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 maxSimArrL[ 16 ];
1197f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			bbs_memset32( maxSimArrL, ( uint32 )-1, bbs_SIZEOF32( maxSimArrL ) );
1207f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1217f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* find raw maximum */
1227f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < rawSizeA; iL++ )
1237f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
1247f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( maxL < rawSimArrA[ iL ] )
1257f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
1267f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					maxL = rawSimArrA[ iL ];
1277f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					maxIndexL = iL;
1287f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
1297f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
1307f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1317f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* consider id of maximum equal to probe id */
1327f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			idL = rawIdArrA[ maxIndexL ];
1337f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1347f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* find 16 maximum similarities of different id in ref array */
1357f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < refSizeA; iL++ )
1367f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
1377f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( refIdArrA[ iL ] != idL )
1387f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
1397f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					int32 simL = refSimArrA[ iL ];
1407f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					for( jL = 0; jL < 16; jL++ )
1417f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					{
1427f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project						if( simL > maxSimArrL[ jL ] ) break;
1437f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					}
1447f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					for( kL = 15; kL > jL; kL-- )
1457f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					{
1467f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project						maxSimArrL[ kL ] = maxSimArrL[ kL - 1 ];
1477f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					}
1487f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					if( jL < 16 ) maxSimArrL[ jL ] = simL;
1497f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
1507f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
1517f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1527f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			refSimL = 0;
1537f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( jL = 0; jL < 16; jL++ )
1547f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
1557f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( maxSimArrL[ jL ] == -1 ) break;
1567f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				refSimL += maxSimArrL[ jL ];
1577f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
1587f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1597f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			if( jL > 0 )
1607f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
1617f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				refSimL /= jL;
1627f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
1637f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
1647f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
1657f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1667f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		default:
1677f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
1687f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			bbs_ERROR1( "void bpi_Identifier_normalizeSimilarities(): simTypeA '%i' is handled", simTypeA );
1697f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			return;
1707f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
1717f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	}
1727f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1737f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	/* refSimL -= 1.0 */
1747f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	refSimL -= ( (uint32)1 << 24 );
1757f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1767f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	for( iL = rawSizeA; iL > 0; iL-- )
1777f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	{
1787f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		*outPtrL++ = ( *rawPtrL++ - refSimL + 1 ) >> 1;
1797f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	}
1807f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1817f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project}
1827f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1837f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */
1847f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1857f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectint32 bpi_normalizedSimilarity( struct bbs_Context* cpA,
1867f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project							    int32 rawSimA,
1877f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project							    int32 rawIdA,
1887f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								const int32* refSimArrA,
1897f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								const int32* refIdArrA,
1907f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								uint32 refSizeA,
1917f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project								enum bpi_SimType simTypeA )
1927f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{
1937f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	/* 8.24 */
1947f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	int32 refSimL = 0;
1957f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	uint32 iL, jL, kL;
1967f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
1977f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	switch( simTypeA )
1987f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	{
1997f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_RAW_SIM:
2007f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
2017f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* nothing to do */
2027f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			return rawSimA; /* return without adjustment of value range */
2037f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
2047f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2057f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_SUB_MEAN:
2067f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
2077f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 shiftL = 0;
2087f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 roundL = 0;
2097f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			refSimL = 0;
2107f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < refSizeA; iL++ )
2117f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
2127f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				refSimL += ( refSimArrA[ iL ] + roundL ) >> shiftL;
2137f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( refSimL > 0x40000000 )
2147f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
2157f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					refSimL = ( refSimL + 1 ) >> 1;
2167f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					shiftL++;
2177f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					roundL = ( int32 )1 << ( shiftL - 1 );
2187f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
2197f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
2207f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			refSimL = ( refSimL / refSizeA ) << shiftL;
2217f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
2227f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
2237f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2247f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_SUB_MAX_2:
2257f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
2267f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* find maximum similarity in ref array of different rawIdA */
2277f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < refSizeA; iL++ )
2287f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
2297f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( refIdArrA[ iL ] != rawIdA )
2307f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
2317f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					refSimL = ( refSimL > refSimArrA[ iL ] ) ? refSimL : refSimArrA[ iL ];
2327f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
2337f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
2347f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
2357f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
2367f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2377f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		case bpi_SUB_16_MAX_2:
2387f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
2397f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 maxSimArrL[ 16 ];
2407f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			int32 idL = rawIdA;
2417f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			bbs_memset32( maxSimArrL, ( uint32 )-1, bbs_SIZEOF32( maxSimArrL ) );
2427f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2437f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			/* find 16 maximum similarities of different id in ref array */
2447f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( iL = 0; iL < refSizeA; iL++ )
2457f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
2467f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( refIdArrA[ iL ] != idL )
2477f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				{
2487f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					int32 simL = refSimArrA[ iL ];
2497f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					for( jL = 0; jL < 16; jL++ )
2507f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					{
2517f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project						if( simL > maxSimArrL[ jL ] ) break;
2527f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					}
2537f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					for( kL = 15; kL > jL; kL-- )
2547f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					{
2557f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project						maxSimArrL[ kL ] = maxSimArrL[ kL - 1 ];
2567f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					}
2577f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project					if( jL < 16 ) maxSimArrL[ jL ] = simL;
2587f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				}
2597f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
2607f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2617f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			refSimL = 0;
2627f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			for( jL = 0; jL < 16; jL++ )
2637f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
2647f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				if( maxSimArrL[ jL ] == -1 ) break;
2657f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				refSimL += maxSimArrL[ jL ];
2667f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
2677f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2687f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			if( jL > 0 )
2697f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			{
2707f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project				refSimL /= jL;
2717f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			}
2727f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
2737f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
2747f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2757f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		default:
2767f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		{
2777f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project			bbs_ERROR1( "void bpi_Identifier_normalizeSimilarities(): simTypeA '%i' is handled", simTypeA );
2787f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		}
2797f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		break;
2807f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	}
2817f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2827f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	/* refSimL -= 1.0 */
2837f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	refSimL -= ( (uint32)1 << 24 );
2847f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	return ( rawSimA - refSimL + 1 ) >> 1;
2857f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project}
2867f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2877f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */
2887f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2897f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectuint32 bpi_memWriteCsa16( uint16* memPtrA, uint32 memSizeA, uint16 chkSumA )
2907f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{
2917f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	uint16* memPtrL = memPtrA - memSizeA + 1;
2927f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	uint32 iL;
2937f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	uint16 sumL = 0;
2947f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	uint16 csaL = 0;
2957f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
2967f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	bbs_memWrite16( &csaL, memPtrA );
2977f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	for( iL = 0; iL < memSizeA; iL++ )
2987f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	{
2997f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		uint16 valL = 0;
3007f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		memPtrL += bbs_memRead16( &valL, memPtrL );
3017f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project		sumL += valL;
3027f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	}
3037f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	csaL = chkSumA - sumL;
3047f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
3057f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	return bbs_memWrite16( &csaL, memPtrA );
3067f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project}
3077f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
3087f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */
3097f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
3107f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectuint32 bpi_memReadCsa16( const uint16* memPtrA )
3117f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{
3127f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project	return bbs_SIZEOF16( uint16 );
3137f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project}
3147f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
3157f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */
3167f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project
317