2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* ---- includes ----------------------------------------------------------- */
19 #include "b_BasicEm/Functions.h"
20 #include "b_BasicEm/Math.h"
21 #include "b_BitFeatureEm/Sequence.h"
23 /* ------------------------------------------------------------------------- */
25 /* ========================================================================= */
27 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
29 /* ========================================================================= */
31 /* ------------------------------------------------------------------------- */
33 /* ========================================================================= */
35 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
37 /* ========================================================================= */
39 /* ------------------------------------------------------------------------- */
41 void bbf_Sequence_init( struct bbs_Context* cpA,
42 struct bbf_Sequence* ptrA )
44 bbs_memset16( ptrA->ftrPtrArrE, 0, bbs_SIZEOF16( ptrA->ftrPtrArrE ) );
46 bbf_Feature_init( cpA, &ptrA->baseE );
47 ptrA->baseE.typeE = ( uint32 )bbf_FT_SEQUENCE;
48 ptrA->baseE.vpActivityE = bbf_Sequence_activity;
50 bbs_Int32Arr_init( cpA, &ptrA->thrArrE );
51 bbs_UInt16Arr_init( cpA, &ptrA->wgtArrE );
52 bbs_UInt16Arr_init( cpA, &ptrA->dataArrE );
55 /* ------------------------------------------------------------------------- */
57 void bbf_Sequence_exit( struct bbs_Context* cpA,
58 struct bbf_Sequence* ptrA )
61 for( iL = 0; iL < ptrA->sizeE; iL++ ) bbf_featureExit( cpA, ptrA->ftrPtrArrE[ iL ] );
63 bbs_memset16( ptrA->ftrPtrArrE, 0, bbs_SIZEOF16( ptrA->ftrPtrArrE ) );
64 bbf_Feature_exit( cpA, &ptrA->baseE );
66 bbs_Int32Arr_exit( cpA, &ptrA->thrArrE );
67 bbs_UInt16Arr_exit( cpA, &ptrA->wgtArrE );
68 bbs_UInt16Arr_exit( cpA, &ptrA->dataArrE );
71 /* ------------------------------------------------------------------------- */
73 /* ========================================================================= */
75 /* ---- \ghd{ operators } -------------------------------------------------- */
77 /* ========================================================================= */
79 /* ------------------------------------------------------------------------- */
81 void bbf_Sequence_copy( struct bbs_Context* cpA,
82 struct bbf_Sequence* ptrA,
83 const struct bbf_Sequence* srcPtrA )
85 bbs_ERROR0( "bbf_Sequence_copy:\n Function is not available" );
88 /* ------------------------------------------------------------------------- */
90 flag bbf_Sequence_equal( struct bbs_Context* cpA,
91 const struct bbf_Sequence* ptrA,
92 const struct bbf_Sequence* srcPtrA )
94 bbs_ERROR0( "bbf_Sequence_equal:\n Function is not available" );
98 /* ------------------------------------------------------------------------- */
100 /* ========================================================================= */
102 /* ---- \ghd{ query functions } -------------------------------------------- */
104 /* ========================================================================= */
106 /* ------------------------------------------------------------------------- */
108 /* ========================================================================= */
110 /* ---- \ghd{ modify functions } ------------------------------------------- */
112 /* ========================================================================= */
114 /* ------------------------------------------------------------------------- */
116 /* ========================================================================= */
118 /* ---- \ghd{ I/O } -------------------------------------------------------- */
120 /* ========================================================================= */
122 /* ------------------------------------------------------------------------- */
124 uint32 bbf_Sequence_memSize( struct bbs_Context* cpA,
125 const struct bbf_Sequence* ptrA )
128 uint32 memSizeL = bbs_SIZEOF16( uint32 ) +
129 bbs_SIZEOF16( uint32 ); /* version */
131 memSizeL += bbf_Feature_memSize( cpA, &ptrA->baseE );
132 memSizeL += bbs_SIZEOF16( ptrA->sizeE );
133 memSizeL += bbs_Int32Arr_memSize( cpA, &ptrA->thrArrE );
134 memSizeL += bbs_UInt16Arr_memSize( cpA, &ptrA->wgtArrE );
135 for( iL = 0; iL < ptrA->sizeE; iL++ ) memSizeL += bbf_featureMemSize( cpA, ptrA->ftrPtrArrE[ iL ] );
139 /* ------------------------------------------------------------------------- */
141 uint32 bbf_Sequence_memWrite( struct bbs_Context* cpA,
142 const struct bbf_Sequence* ptrA,
146 uint32 memSizeL = bbf_Sequence_memSize( cpA, ptrA );
147 memPtrA += bbs_memWrite32( &memSizeL, memPtrA );
148 memPtrA += bbs_memWriteUInt32( bbf_SEQUENCE_VERSION, memPtrA );
149 memPtrA += bbf_Feature_memWrite( cpA, &ptrA->baseE, memPtrA );
150 memPtrA += bbs_memWrite32( &ptrA->sizeE, memPtrA );
151 memPtrA += bbs_Int32Arr_memWrite( cpA, &ptrA->thrArrE, memPtrA );
152 memPtrA += bbs_UInt16Arr_memWrite( cpA, &ptrA->wgtArrE, memPtrA );
153 for( iL = 0; iL < ptrA->sizeE; iL++ ) memPtrA += bbf_featureMemWrite( cpA, ptrA->ftrPtrArrE[ iL ], memPtrA );
157 /* ------------------------------------------------------------------------- */
159 uint32 bbf_Sequence_memRead( struct bbs_Context* cpA,
160 struct bbf_Sequence* ptrA,
161 const uint16* memPtrA,
162 struct bbs_MemTbl* mtpA )
165 uint32 memSizeL, versionL;
166 struct bbs_MemTbl memTblL = *mtpA;
167 struct bbs_MemSeg* espL = bbs_MemTbl_fastestSegPtr( cpA, &memTblL, 0 );
168 if( bbs_Context_error( cpA ) ) return 0;
169 memPtrA += bbs_memRead32( &memSizeL, memPtrA );
170 memPtrA += bbs_memReadVersion32( cpA, &versionL, bbf_SEQUENCE_VERSION, memPtrA );
171 memPtrA += bbf_Feature_memRead( cpA, &ptrA->baseE, memPtrA );
172 memPtrA += bbs_memRead32( &ptrA->sizeE, memPtrA );
174 if( ptrA->sizeE > bbf_SEQUENCE_MAX_SIZE )
176 bbs_ERROR0( "bbf_Sequence_memRead:\n Sequence size exceeds bbf_SEQUENCE_MAX_SIZE" );
180 memPtrA += bbs_Int32Arr_memRead( cpA, &ptrA->thrArrE, memPtrA, espL );
182 if( versionL >= 101 ) memPtrA += bbs_UInt16Arr_memRead( cpA, &ptrA->wgtArrE, memPtrA, espL );
184 /* check features & allocate data buffer */
186 const uint16* memPtrL = memPtrA;
187 uint32 dataSizeL = 0;
188 for( iL = 0; iL < ptrA->sizeE; iL++ )
190 enum bbf_FeatureType typeL = ( enum bbf_FeatureType )bbs_memPeek32( memPtrL + 4 );
191 dataSizeL += bbf_featureSizeOf16( cpA, typeL );
192 memPtrL += bbs_memPeek32( memPtrL );
194 bbs_UInt16Arr_create( cpA, &ptrA->dataArrE, dataSizeL, espL );
197 /* load features & initialize pointers */
199 uint16* dataPtrL = ptrA->dataArrE.arrPtrE;
200 for( iL = 0; iL < ptrA->sizeE; iL++ )
202 enum bbf_FeatureType typeL = ( enum bbf_FeatureType )bbs_memPeek32( memPtrA + 4 );
203 ptrA->ftrPtrArrE[ iL ] = ( struct bbf_Feature* )dataPtrL;
204 bbf_featureInit( cpA, ptrA->ftrPtrArrE[ iL ], typeL );
205 memPtrA += bbf_featureMemRead( cpA, ptrA->ftrPtrArrE[ iL ], memPtrA, &memTblL );
206 dataPtrL += bbf_featureSizeOf16( cpA, typeL );
210 /* if( memSizeL != bbf_Sequence_memSize( cpA, ptrA ) )
212 bbs_ERR0( bbs_ERR_CORRUPT_DATA, "uint32 bbf_Sequence_memRead( struct bem_ScanGradientMove* ptrA, const uint16* memPtrA ):\n"
221 /* ------------------------------------------------------------------------- */
223 /* ========================================================================= */
225 /* ---- \ghd{ exec functions } --------------------------------------------- */
227 /* ========================================================================= */
229 /* ------------------------------------------------------------------------- */
231 int32 bbf_Sequence_activity( const struct bbf_Feature* ptrA, const uint32* patchA )
233 const struct bbf_Sequence* ptrL = ( struct bbf_Sequence* )ptrA;
237 int32 sizeL = ptrL->sizeE;
240 int32 actSumL = ( -sizeL ) << 20;
242 if( sizeL == 0 ) return 0x10000000; /* 1.0 in 4.28 format */
244 if( ptrL->wgtArrE.sizeE == 0 )
246 for( iL = 0; iL < ptrL->sizeE; iL++ )
249 int32 actL = ptrL->ftrPtrArrE[ iL ]->vpActivityE( ptrL->ftrPtrArrE[ iL ], patchA ) - ptrL->thrArrE.arrPtrE[ iL ];
250 actSumL += ( actL >> 8 );
251 if( actL < 0 ) return ( actSumL / sizeL ) << 7; /* return 4.28 */
256 for( iL = 0; iL < ptrL->sizeE; iL++ )
259 int32 actL = ptrL->ftrPtrArrE[ iL ]->vpActivityE( ptrL->ftrPtrArrE[ iL ], patchA ) - ptrL->thrArrE.arrPtrE[ iL ];
260 int32 wgtL = ptrL->wgtArrE.arrPtrE[ iL ];
261 actL = ( actL >> 16 ) * wgtL + ( ( ( int32 )( actL & 0x0000FFFF ) * wgtL ) >> 16 );
262 actSumL += ( actL >> 8 );
263 if( actL < 0 ) return ( actSumL / sizeL ) << 7; /* return 4.28 */
267 actSumL += sizeL << 20;
269 /* positive activity: ] 0, 1 ] */
270 return ( actSumL / sizeL ) << 7; /* return 4.28 */
273 /* ------------------------------------------------------------------------- */
275 /* ========================================================================= */