Home | History | Annotate | Download | only in b_APIEm
      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_APIEm/DCR.h"
     20 #include "b_BasicEm/Functions.h"
     21 
     22 /* ------------------------------------------------------------------------- */
     23 
     24 /* ========================================================================= */
     25 /*                                                                           */
     26 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
     27 /*                                                                           */
     28 /* ========================================================================= */
     29 
     30 /* ------------------------------------------------------------------------- */
     31 
     32 /* ========================================================================= */
     33 /*                                                                           */
     34 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
     35 /*                                                                           */
     36 /* ========================================================================= */
     37 
     38 /* ------------------------------------------------------------------------- */
     39 
     40 void bpi_DCR_init( struct bbs_Context* cpA,
     41 				   struct bpi_DCR* ptrA )
     42 {
     43 	ptrA->maxImageWidthE = 0;
     44 	ptrA->maxImageHeightE = 0;
     45 	ptrA->imageDataPtrE = NULL;
     46 	ptrA->imageWidthE = 0;
     47 	ptrA->imageHeightE = 0;
     48 	bts_Int16Vec2D_init( &ptrA->offsE );
     49 	bts_IdCluster2D_init( cpA, &ptrA->mainClusterE );
     50 	bts_IdCluster2D_init( cpA, &ptrA->sdkClusterE );
     51 	ptrA->confidenceE = 0;
     52 	ptrA->approvedE = FALSE;
     53 	ptrA->idE = 0;
     54 	ptrA->roiRectE = bts_Int16Rect_create( 0, 0, 0, 0 );
     55 	bbs_UInt16Arr_init( cpA, &ptrA->cueDataE );
     56 }
     57 
     58 /* ------------------------------------------------------------------------- */
     59 
     60 void bpi_DCR_exit( struct bbs_Context* cpA,
     61 				   struct bpi_DCR* ptrA )
     62 {
     63 	ptrA->maxImageWidthE = 0;
     64 	ptrA->maxImageHeightE = 0;
     65 	ptrA->imageDataPtrE = NULL;
     66 	ptrA->imageWidthE = 0;
     67 	ptrA->imageHeightE = 0;
     68 	bts_Int16Vec2D_exit( &ptrA->offsE );
     69 	bts_IdCluster2D_exit( cpA, &ptrA->mainClusterE );
     70 	bts_IdCluster2D_exit( cpA, &ptrA->sdkClusterE );
     71 	ptrA->confidenceE = 0;
     72 	ptrA->approvedE = FALSE;
     73 	ptrA->idE = 0;
     74 	bbs_UInt16Arr_exit( cpA, &ptrA->cueDataE );
     75 }
     76 
     77 /* ------------------------------------------------------------------------- */
     78 
     79 /* ========================================================================= */
     80 /*                                                                           */
     81 /* ---- \ghd{ operators } -------------------------------------------------- */
     82 /*                                                                           */
     83 /* ========================================================================= */
     84 
     85 /* ------------------------------------------------------------------------- */
     86 
     87 /* ========================================================================= */
     88 /*                                                                           */
     89 /* ---- \ghd{ query functions } -------------------------------------------- */
     90 /*                                                                           */
     91 /* ========================================================================= */
     92 
     93 /* ------------------------------------------------------------------------- */
     94 
     95 /* ========================================================================= */
     96 /*                                                                           */
     97 /* ---- \ghd{ modify functions } ------------------------------------------- */
     98 /*                                                                           */
     99 /* ========================================================================= */
    100 
    101 /* ------------------------------------------------------------------------- */
    102 
    103 void bpi_DCR_create( struct bbs_Context* cpA,
    104 					 struct bpi_DCR* ptrA,
    105 					 uint32 imageWidthA,
    106 					 uint32 imageHeightA,
    107 					 uint32 cueSizeA,
    108 					 struct bbs_MemTbl* mtpA )
    109 {
    110 	struct bbs_MemTbl memTblL = *mtpA;
    111 	struct bbs_MemSeg* espL =
    112             bbs_MemTbl_fastestSegPtr( cpA, &memTblL,
    113                                       bpi_DCR_MAX_CLUSTER_SIZE * bbs_SIZEOF16( struct bts_Int16Vec2D ) );
    114 	if( bbs_Context_error( cpA ) ) return;
    115 
    116 	bts_IdCluster2D_create( cpA, &ptrA->mainClusterE, bpi_DCR_MAX_CLUSTER_SIZE, espL );
    117 	bts_IdCluster2D_size( cpA, &ptrA->mainClusterE, 0 );
    118 	if( bbs_Context_error( cpA ) ) return;
    119 	bts_IdCluster2D_create( cpA, &ptrA->sdkClusterE, bpi_DCR_MAX_SDK_CLUSTER_SIZE, espL );
    120 	bts_IdCluster2D_size( cpA, &ptrA->sdkClusterE, 0 );
    121 	if( bbs_Context_error( cpA ) ) return;
    122 	if( bbs_Context_error( cpA ) ) return;
    123 	bbs_UInt16Arr_create( cpA, &ptrA->cueDataE, cueSizeA, espL );
    124 	bbs_UInt16Arr_size( cpA, &ptrA->cueDataE, 0 );
    125 
    126 	ptrA->maxImageWidthE = imageWidthA;
    127 	ptrA->maxImageHeightE = imageHeightA;
    128 }
    129 
    130 /* ------------------------------------------------------------------------- */
    131 
    132 /* ========================================================================= */
    133 /*                                                                           */
    134 /* ---- \ghd{ I/O } -------------------------------------------------------- */
    135 /*                                                                           */
    136 /* ========================================================================= */
    137 
    138 /* ------------------------------------------------------------------------- */
    139 
    140 /* ========================================================================= */
    141 /*                                                                           */
    142 /* ---- \ghd{ exec functions } --------------------------------------------- */
    143 /*                                                                           */
    144 /* ========================================================================= */
    145 
    146 /* ------------------------------------------------------------------------- */
    147 
    148 void bpi_DCR_assignGrayByteImage( struct bbs_Context* cpA,
    149 								  struct bpi_DCR* ptrA,
    150 								  const void* bufferPtrA,
    151 								  uint32 widthA,
    152 								  uint32 heightA )
    153 {
    154 	bbs_DEF_fNameL( "void bpi_DCR_assignGrayByteImage( struct bbs_Context* cpA, struct bpi_DCR* ptrA, const void* bufferPtrA, uint32 widthA, uint32 heightA )" )
    155 
    156 	if( widthA > ptrA->maxImageWidthE || heightA > ptrA->maxImageHeightE )
    157 	{
    158 		bbs_ERROR5( "%s:\nSize of assigned image (%ix%i) exceeds maximum size defined at DCR initialization (%ix%i).",
    159 				    fNameL,
    160 					widthA, heightA,
    161 					ptrA->maxImageWidthE, ptrA->maxImageHeightE	);
    162 		return;
    163 	}
    164 
    165 	if( ( widthA & 1 ) != 0 )
    166 	{
    167 		bbs_ERROR1( "%s:\nWidth of image must be even.\n", fNameL );
    168 		return;
    169 	}
    170 
    171 	ptrA->imageDataPtrE = ( void* )bufferPtrA;
    172 	ptrA->imageWidthE = widthA;
    173 	ptrA->imageHeightE = heightA;
    174 
    175 	/* reset some data */
    176 	ptrA->roiRectE = bts_Int16Rect_create( 0, 0, widthA, heightA );
    177 	bts_IdCluster2D_size( cpA, &ptrA->mainClusterE, 0 );
    178 	bts_IdCluster2D_size( cpA, &ptrA->sdkClusterE, 0 );
    179 	bbs_UInt16Arr_size( cpA, &ptrA->cueDataE, 0 );
    180 }
    181 
    182 /* ------------------------------------------------------------------------- */
    183 
    184 void bpi_DCR_assignGrayByteImageROI( struct bbs_Context* cpA,
    185 									 struct bpi_DCR* ptrA,
    186 									 const void* bufferPtrA,
    187 									 uint32 widthA,
    188 									 uint32 heightA,
    189 									 const struct bts_Int16Rect* pRectA )
    190 {
    191 	bbs_DEF_fNameL( "void bpi_DCR_assignGrayByteImageROI( struct bpi_DCR* ptrA, const void* bufferPtrA, uint32 widthA, uint32 heightA )" )
    192 
    193 	if( widthA > ptrA->maxImageWidthE || heightA > ptrA->maxImageHeightE )
    194 	{
    195 		bbs_ERROR5( "%s:\nSize of assigned image (%ix%i) exceeds maximum size defined at DCR initialization (%ix%i).",
    196 				    fNameL,
    197 					widthA, heightA,
    198 					ptrA->maxImageWidthE, ptrA->maxImageHeightE	);
    199 		return;
    200 	}
    201 
    202 	if( ( widthA & 1 ) != 0 )
    203 	{
    204 		bbs_ERROR1( "%s:\nWidth of image must be even.\n",
    205 				    fNameL );
    206 		return;
    207 	}
    208 
    209 	if( pRectA->x2E < pRectA->x1E || pRectA->y2E < pRectA->y1E ||
    210 		pRectA->x1E < 0           || pRectA->y1E < 0 ||
    211 		pRectA->x2E > ( int32 )widthA || pRectA->y2E > ( int32 )heightA )
    212 	{
    213 		bbs_ERROR1( "%s:\nInvalid ROI rectangle.\n", fNameL );
    214 		return;
    215 	}
    216 
    217 	ptrA->imageDataPtrE = ( void* )bufferPtrA;
    218 	ptrA->imageWidthE = widthA;
    219 	ptrA->imageHeightE = heightA;
    220 
    221 	/* reset some data */
    222 	ptrA->roiRectE = *pRectA;
    223 	bts_IdCluster2D_size( cpA, &ptrA->mainClusterE, 0 );
    224 	bts_IdCluster2D_size( cpA, &ptrA->sdkClusterE, 0 );
    225 	bbs_UInt16Arr_size( cpA, &ptrA->cueDataE, 0 );
    226 }
    227 
    228 /* ------------------------------------------------------------------------- */
    229 
    230 int32 bpi_DCR_confidence( struct bbs_Context* cpA,
    231 						  const struct bpi_DCR* ptrA )
    232 {
    233 	return ptrA->confidenceE;
    234 }
    235 
    236 /* ------------------------------------------------------------------------- */
    237 
    238 /* ========================================================================= */
    239