1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 /* ---- includes ----------------------------------------------------------- */ 18 19 #include "b_BasicEm/Functions.h" 20 #include "b_BasicEm/Math.h" 21 #include "b_BitFeatureEm/L01Tld1x1Ftr.h" 22 #include "b_BitFeatureEm/Functions.h" 23 24 /* ------------------------------------------------------------------------- */ 25 26 /* ========================================================================= */ 27 /* */ 28 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */ 29 /* */ 30 /* ========================================================================= */ 31 32 /* ------------------------------------------------------------------------- */ 33 34 /* ========================================================================= */ 35 /* */ 36 /* ---- \ghd{ constructor / destructor } ----------------------------------- */ 37 /* */ 38 /* ========================================================================= */ 39 40 /* ------------------------------------------------------------------------- */ 41 42 void bbf_L01Tld1x1Ftr_init( struct bbs_Context* cpA, 43 struct bbf_L01Tld1x1Ftr* ptrA ) 44 { 45 bbf_Feature_init( cpA, &ptrA->baseE ); 46 ptrA->baseE.typeE = ( uint32 )bbf_FT_L01_TLD_1X1_FTR; 47 ptrA->baseE.vpActivityE = bbf_L01Tld1x1Ftr_activity; 48 bbs_UInt32Arr_init( cpA, &ptrA->dataArrE ); 49 ptrA->activityFactorE = 0; 50 } 51 52 /* ------------------------------------------------------------------------- */ 53 54 void bbf_L01Tld1x1Ftr_exit( struct bbs_Context* cpA, 55 struct bbf_L01Tld1x1Ftr* ptrA ) 56 { 57 bbf_Feature_exit( cpA, &ptrA->baseE ); 58 bbs_UInt32Arr_exit( cpA, &ptrA->dataArrE ); 59 ptrA->activityFactorE = 0; 60 } 61 62 /* ------------------------------------------------------------------------- */ 63 64 /* ========================================================================= */ 65 /* */ 66 /* ---- \ghd{ operators } -------------------------------------------------- */ 67 /* */ 68 /* ========================================================================= */ 69 70 /* ------------------------------------------------------------------------- */ 71 72 void bbf_L01Tld1x1Ftr_copy( struct bbs_Context* cpA, 73 struct bbf_L01Tld1x1Ftr* ptrA, 74 const struct bbf_L01Tld1x1Ftr* srcPtrA ) 75 { 76 bbf_Feature_copy( cpA, &ptrA->baseE, &srcPtrA->baseE ); 77 bbs_UInt32Arr_copy( cpA, &ptrA->dataArrE, &srcPtrA->dataArrE ); 78 ptrA->activityFactorE = srcPtrA->activityFactorE; 79 } 80 81 /* ------------------------------------------------------------------------- */ 82 83 flag bbf_L01Tld1x1Ftr_equal( struct bbs_Context* cpA, 84 const struct bbf_L01Tld1x1Ftr* ptrA, 85 const struct bbf_L01Tld1x1Ftr* srcPtrA ) 86 { 87 if( !bbf_Feature_equal( cpA, &ptrA->baseE, &srcPtrA->baseE ) ) return FALSE; 88 if( !bbs_UInt32Arr_equal( cpA, &ptrA->dataArrE, &srcPtrA->dataArrE ) ) return FALSE; 89 if( ptrA->activityFactorE != srcPtrA->activityFactorE ) return FALSE; 90 return TRUE; 91 } 92 93 /* ------------------------------------------------------------------------- */ 94 95 /* ========================================================================= */ 96 /* */ 97 /* ---- \ghd{ query functions } -------------------------------------------- */ 98 /* */ 99 /* ========================================================================= */ 100 101 /* ------------------------------------------------------------------------- */ 102 103 /* ========================================================================= */ 104 /* */ 105 /* ---- \ghd{ modify functions } ------------------------------------------- */ 106 /* */ 107 /* ========================================================================= */ 108 109 /* ------------------------------------------------------------------------- */ 110 111 /* ========================================================================= */ 112 /* */ 113 /* ---- \ghd{ I/O } -------------------------------------------------------- */ 114 /* */ 115 /* ========================================================================= */ 116 117 /* ------------------------------------------------------------------------- */ 118 119 uint32 bbf_L01Tld1x1Ftr_memSize( struct bbs_Context* cpA, 120 const struct bbf_L01Tld1x1Ftr* ptrA ) 121 { 122 uint32 memSizeL = bbs_SIZEOF16( uint32 ) + 123 bbs_SIZEOF16( uint32 ); /* version */ 124 125 memSizeL += bbf_Feature_memSize( cpA, &ptrA->baseE ); 126 memSizeL += bbs_UInt32Arr_memSize( cpA, &ptrA->dataArrE ); 127 memSizeL += bbs_SIZEOF16( ptrA->activityFactorE ); 128 129 return memSizeL; 130 } 131 132 /* ------------------------------------------------------------------------- */ 133 134 uint32 bbf_L01Tld1x1Ftr_memWrite( struct bbs_Context* cpA, 135 const struct bbf_L01Tld1x1Ftr* ptrA, 136 uint16* memPtrA ) 137 { 138 uint32 memSizeL = bbf_L01Tld1x1Ftr_memSize( cpA, ptrA ); 139 memPtrA += bbs_memWrite32( &memSizeL, memPtrA ); 140 memPtrA += bbs_memWriteUInt32( bbf_L01_TLD_1X1_FTR_VERSION, memPtrA ); 141 memPtrA += bbf_Feature_memWrite( cpA, &ptrA->baseE, memPtrA ); 142 memPtrA += bbs_UInt32Arr_memWrite( cpA, &ptrA->dataArrE, memPtrA ); 143 memPtrA += bbs_memWrite32( &ptrA->activityFactorE, memPtrA ); 144 return memSizeL; 145 } 146 147 /* ------------------------------------------------------------------------- */ 148 149 uint32 bbf_L01Tld1x1Ftr_memRead( struct bbs_Context* cpA, 150 struct bbf_L01Tld1x1Ftr* ptrA, 151 const uint16* memPtrA, 152 struct bbs_MemTbl* mtpA ) 153 { 154 uint32 memSizeL, versionL; 155 struct bbs_MemTbl memTblL = *mtpA; 156 struct bbs_MemSeg* espL = bbs_MemTbl_fastestSegPtr( cpA, &memTblL, 0 ); 157 if( bbs_Context_error( cpA ) ) return 0; 158 memPtrA += bbs_memRead32( &memSizeL, memPtrA ); 159 memPtrA += bbs_memReadVersion32( cpA, &versionL, bbf_L01_TLD_1X1_FTR_VERSION, memPtrA ); 160 memPtrA += bbf_Feature_memRead( cpA, &ptrA->baseE, memPtrA ); 161 memPtrA += bbs_UInt32Arr_memRead( cpA, &ptrA->dataArrE, memPtrA, espL ); 162 memPtrA += bbs_memRead32( &ptrA->activityFactorE, memPtrA ); 163 if( memSizeL != bbf_L01Tld1x1Ftr_memSize( cpA, ptrA ) ) 164 { 165 bbs_ERR0( bbs_ERR_CORRUPT_DATA, "uint32 bbf_L01Tld1x1Ftr_memRead( struct bem_ScanGradientMove* ptrA, const uint16* memPtrA ):\n" 166 "size mismatch" ); 167 return 0; 168 } 169 170 return memSizeL; 171 } 172 173 /* ------------------------------------------------------------------------- */ 174 175 /* ========================================================================= */ 176 /* */ 177 /* ---- \ghd{ exec functions } --------------------------------------------- */ 178 /* */ 179 /* ========================================================================= */ 180 181 /* ------------------------------------------------------------------------- */ 182 183 int32 bbf_L01Tld1x1Ftr_activity( const struct bbf_Feature* ptrA, const uint32* patchA ) 184 { 185 const struct bbf_L01Tld1x1Ftr* ptrL = ( struct bbf_L01Tld1x1Ftr* )ptrA; 186 187 int32 iL; 188 189 const uint32* dataPtrL = ptrL->dataArrE.arrPtrE; 190 const uint32* patchL = patchA; 191 192 uint32 bsL = 0; 193 194 for( iL = ptrL->baseE.patchWidthE >> 2; iL > 0; iL-- ) 195 { 196 uint32 vL; 197 vL = ( patchL[ 0 ] ^ dataPtrL[ 0 ] ) & dataPtrL[ 1 ]; 198 bsL += bbf_BIT_SUM_32( vL ); 199 200 vL = ( patchL[ 1 ] ^ dataPtrL[ 2 ] ) & dataPtrL[ 3 ]; 201 bsL += bbf_BIT_SUM_32( vL ); 202 203 vL = ( patchL[ 2 ] ^ dataPtrL[ 4 ] ) & dataPtrL[ 5 ]; 204 bsL += bbf_BIT_SUM_32( vL ); 205 206 vL = ( patchL[ 3 ] ^ dataPtrL[ 6 ] ) & dataPtrL[ 7 ]; 207 bsL += bbf_BIT_SUM_32( vL ); 208 209 dataPtrL += 8; 210 patchL += 4; 211 } 212 213 return bsL * ptrL->activityFactorE; 214 } 215 216 /* ------------------------------------------------------------------------- */ 217 218 /* ========================================================================= */ 219 220