看我的,或许可以参考使用:/*
* Update the changed direction of y.
* There are 4 blocks in one byte,each block own 2 bits.
*
* @block_index: which jepg block?
* @delta_y: y changed.
*/
void update_y_direction(int block_index, int delta_y)
{
int i;
unsigned char level;
level = whichlevel(delta_y);
switch (level) {
case 0:
/* NO changing. Update all of the table */
for (i = 0; i < ALARM_SENSITY_LEVEL_MAX; i++) {
SET_BYTE_BITS(last_y_direction[i][block_index / 4],
(block_index % 4) << 1, 2, BLK_Y_NO_CHANGE);
}
break;
#ifdef USING_ALARM_LV5
case ALARM_SENSITY_LV5:
SET_BYTE_BITS(last_y_direction[ALARM_SENSITY_LV5 - 1][block_index / 4],
(block_index % 4) << 1, 2, delta_y > 0 ? BLK_Y_INCREASED : BLK_Y_DECREASED);
#endif
#ifdef USING_ALARM_LV4
case ALARM_SENSITY_LV4:
SET_BYTE_BITS(last_y_direction[ALARM_SENSITY_LV4 - 1][block_index / 4],
(block_index % 4) << 1, 2, delta_y > 0 ? BLK_Y_INCREASED : BLK_Y_DECREASED);
#endif
#ifdef USING_ALARM_LV3
case ALARM_SENSITY_LV3:
SET_BYTE_BITS(last_y_direction[ALARM_SENSITY_LV3 - 1][block_index / 4],
(block_index % 4) << 1, 2, delta_y > 0 ? BLK_Y_INCREASED : BLK_Y_DECREASED);
#endif
#ifdef USING_ALARM_LV2
case ALARM_SENSITY_LV2:
SET_BYTE_BITS(last_y_direction[ALARM_SENSITY_LV2 - 1][block_index / 4],
(block_index % 4) << 1, 2, delta_y > 0 ? BLK_Y_INCREASED : BLK_Y_DECREASED);
#endif
#ifdef USING_ALARM_LV1
case ALARM_SENSITY_LV1:
SET_BYTE_BITS(last_y_direction[ALARM_SENSITY_LV1 - 1][block_index / 4],
(block_index % 4) << 1, 2, delta_y > 0 ? BLK_Y_INCREASED : BLK_Y_DECREASED);
#endif
break;
default:
; /* WARNING! */
}
}
|