Home | History | Annotate | Download | only in AKFS_APIs_8975
      1 /******************************************************************************
      2  * $Id: AKFS_Device.c 580 2012-03-29 09:56:21Z yamada.rj $
      3  ******************************************************************************
      4  *
      5  * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
      6  *
      7  * Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *      http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  */
     19 #include "AKFS_Device.h"
     20 
     21 int16 AKFS_InitBuffer(
     22 	const	int16	ndata,		/*!< Size of vector buffer */
     23 			AKFVEC	vdata[]		/*!< Vector buffer */
     24 )
     25 {
     26 	int i;
     27 
     28 	/* size check */
     29 	if (ndata <= 0) {
     30 		return AKFS_ERROR;
     31 	}
     32 
     33 	for (i=0; i<ndata; i++) {
     34 		vdata[i].u.x = AKFS_INIT_VALUE_F;
     35 		vdata[i].u.y = AKFS_INIT_VALUE_F;
     36 		vdata[i].u.z = AKFS_INIT_VALUE_F;
     37 	}
     38 
     39 	return AKFS_SUCCESS;
     40 }
     41 
     42 int16 AKFS_BufShift(
     43 	const	int16	len,	/*!< size of buffer */
     44 	const	int16	shift,	/*!< shift size */
     45 			AKFVEC	v[] /*!< buffer */
     46 )
     47 {
     48 	int16 i;
     49 
     50 	if((shift < 1) || (len < shift)) {
     51 		return AKFS_ERROR;
     52 	}
     53 	for (i = len-1; i >= shift; i--) {
     54 		v[i] = v[i-shift];
     55 	}
     56 	return AKFS_SUCCESS;
     57 }
     58 
     59 int16 AKFS_Rotate(
     60 	const	AKFS_PATNO	pat,
     61 			AKFVEC*		vec
     62 )
     63 {
     64 	AKFLOAT tmp;
     65 	switch(pat){
     66 		/* Obverse */
     67 		case PAT1:
     68 			/* This is Android default */
     69 			break;
     70 		case PAT2:
     71 			tmp = vec->u.x;
     72 			vec->u.x = vec->u.y;
     73 			vec->u.y = -tmp;
     74 			break;
     75 		case PAT3:
     76 			vec->u.x = -(vec->u.x);
     77 			vec->u.y = -(vec->u.y);
     78 			break;
     79 		case PAT4:
     80 			tmp = vec->u.x;
     81 			vec->u.x = -(vec->u.y);
     82 			vec->u.y = tmp;
     83 			break;
     84 		/* Reverse */
     85 		case PAT5:
     86 			vec->u.x = -(vec->u.x);
     87 			vec->u.z = -(vec->u.z);
     88 			break;
     89 		case PAT6:
     90 			tmp = vec->u.x;
     91 			vec->u.x = vec->u.y;
     92 			vec->u.y = tmp;
     93 			vec->u.z = -(vec->u.z);
     94 			break;
     95 		case PAT7:
     96 			vec->u.y = -(vec->u.y);
     97 			vec->u.z = -(vec->u.z);
     98 			break;
     99 		case PAT8:
    100 			tmp = vec->u.x;
    101 			vec->u.x = -(vec->u.y);
    102 			vec->u.y = -tmp;
    103 			vec->u.z = -(vec->u.z);
    104 			break;
    105 		default:
    106 			return AKFS_ERROR;
    107 	}
    108 
    109 	return AKFS_SUCCESS;
    110 }
    111 
    112