⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isp_device_if.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		return ERR_PARA_SIZE_OVER_MEM;				
		
	/* Check Max 32 blocks per row */
	if((defect_data->block_width_factor)>DEFECT_MAX_BLOACK_PER_ROW)
		return ERR_PARA_SIZE_OVER_BLOCK;
		
    /* Check Max defect and search Num */		
    if((defect_data->max_defect_num)>=MAX_DEFECT_NUM)
        return ERR_OVER_MAX_DEFECT_NUM;
	if((defect_data->max_search_num)>DEFECT_MAX_SEARCH_NUM)	
		return ERR_OVER_MAX_SEARCH_NUM;
        
	return 1;	
}

kal_int32 camera_defectpixel_process(	kal_uint8	defect_mode, defectpixel_para_struct *defect_data, 
													kal_uint32 	isp_debug_buffer, kal_uint32 isp_debug_buffer_size)
{
	kal_uint16	block_width, block_height, grap_height_offset;	
	kal_uint8	cap_col_count, shading_en = KAL_FALSE;
	kal_uint32	i;
	kal_int32	ret = 1;
    kal_uint16	defect_width_num=0, defect_height_num=0;		
    defect_current_mode = defect_mode;
	if( (defect_data->defect_type_select == DEFECT_TYPE_BLACK_PIXEL_ONLY)||
		(defect_data->defect_type_select == DEFECT_TYPE_WHITE_PIXEL_ONLY)||
		((defect_data->defect_type_select==DEFECT_TYPE_BOTH_BW)&&
 	  	 (defect_data->defect_type==DEFECT_TYPE_BLACK_PIXEL)) ||
		((defect_data->defect_type_select==DEFECT_TYPE_BOTH_WB)&&
		 (defect_data->defect_type==DEFECT_TYPE_WHITE_PIXEL)) )
	{
	    if( defect_mode==DEFECT_MODE_CAPTURE ) 				    
		defect_operation_state = DEFECT_START_STATE;		
		else
		defect_operation_pv_state = DEFECT_START_STATE;		
		clear_defect_para(defect_mode);		            
	}	
	
	if((defect_data->max_search_num)>DEFECT_MAX_SEARCH_NUM)	
		return ERR_OVER_MAX_SEARCH_NUM;
	
	/* Make sure shading disable */
	if(((REG_ISP_SHADING_CTRL1)&REG_SHADING_ENABLE_BIT)>0)
	    shading_en = KAL_TRUE;
	DISABLE_SHADING_COMPENSATION;
	/* Set ISP Gain as 1X*/
	isp_pregain = BASEGAIN;
	ae_set_isp_pregain();
	
	/* Init Parameter */		
	memcpy(&defectpixel_data, defect_data, sizeof(defectpixel_para_struct));		
	if(defect_mode==DEFECT_MODE_CAPTURE)
	{
		// init defectpixel_cap_data;		
		memcpy(&defectpixel_cap_data, defect_data, sizeof(defectpixel_para_struct));				
		if((defect_data->max_defect_num)>=MAX_DEFECT_NUM)
            return ERR_OVER_MAX_DEFECT_NUM;
	}
	else	// preview
	{
		// init defectpixel_pv_data;				
		memcpy(&defectpixel_pv_data, defect_data, sizeof(defectpixel_para_struct));						
		if((defect_data->max_defect_num)>=MAX_PV_DEFECT_NUM)
            return ERR_OVER_MAX_DEFECT_NUM;		
	}
	
	grap_width = defectpixel_data.image_width ;
	grap_height = defectpixel_data.image_height;

	/* Calculate defect total width/hwight */		
	defect_width_num = defectpixel_data.block_width_factor;
	defect_height_num = defectpixel_data.block_height_factor;		
	block_width = ((defectpixel_data.image_width)/defect_width_num)&0xFFFC;
	block_height = ((defectpixel_data.image_height)/defect_height_num)&0xFFFC; 
	// Max 32 blocks per row
	if(defect_width_num>DEFECT_MAX_BLOACK_PER_ROW)
		return ERR_PARA_SIZE_OVER_BLOCK;
	
	/* Define Area1 and Area2 and Thred*/
	area1_min_x = ((defect_width_num>>2)-1)*block_width;		
	area1_min_y = ((defect_height_num>>2)-1)*block_height;		
	area1_max_x = (((defect_width_num*3)>>2)-1)*block_width;
	area1_max_y = (((defect_height_num*3)>>2)-1)*block_height;	
    defectpixel_data.threshold_area1 = (defectpixel_data.threshold_area1<<7)/100;    
    defectpixel_data.threshold_area2 = (defectpixel_data.threshold_area2<<7)/100;        

	cap_col_count = (isp_debug_buffer_size/grap_width)/block_height;		
	if(cap_col_count<1)
		return ERR_PARA_SIZE_OVER_MEM;
	else if(cap_col_count>defectpixel_data.block_height_factor)	
	    cap_col_count = defectpixel_data.block_height_factor;
	grap_height = cap_col_count*block_height;	
	block_pixel_count = (((defectpixel_data.image_width)*(defectpixel_data.image_height))/(defect_width_num*defect_height_num))>>2;
	
	if(defectpixel_data.defect_type == DEFECT_TYPE_BLACK_PIXEL)		
	{
        switch_cap_en = KAL_TRUE;
        grap_height_offset = 0;
        SET_RAW_DATA_R_OFFSET_ADJ(0);
        SET_RAW_DATA_GR_OFFSET_ADJ(0);
        SET_RAW_DATA_B_OFFSET_ADJ(0);
        SET_RAW_DATA_GB_OFFSET_ADJ(0);                                    	        
				
        // Find defect pixel in this frame												
        camera_defect_raw_capture(	0, 0, grap_width, grap_height, isp_debug_buffer);			
        for(i=0;i<cap_col_count;i++)
        {
		    if((grap_height_offset+block_height)==defectpixel_data.image_height)
		    {
				ret = camera_defect_find_black_pixel(	block_width, (kal_uint16)(block_height-defectpixel_data.boarder_len), grap_height_offset, 
											 	(isp_debug_buffer+(grap_width*(block_height)*i)));
		    }
		    else
		    {
				ret = camera_defect_find_black_pixel(	block_width, block_height, grap_height_offset, 
											 	(isp_debug_buffer+(grap_width*(block_height)*i)));
			}
		    grap_height_offset = grap_height_offset + block_height;
			if(ret<0)
				break;
		}
		if((ret>0)&&((grap_height_offset+defectpixel_data.boarder_len)<(defectpixel_data.image_height)))
		{
			camera_defect_raw_capture(	0, grap_height_offset, grap_width, (kal_uint16)((defectpixel_data.image_height)-grap_height_offset), isp_debug_buffer);
			
			// Find defect pixel in this frame												
            block_pixel_count = ( block_width*((defectpixel_data.image_height)-grap_height_offset-defectpixel_data.boarder_len) )>>2;
			ret = camera_defect_find_black_pixel(	block_width, (kal_uint16)((defectpixel_data.image_height)-grap_height_offset-defectpixel_data.boarder_len), 
			        grap_height_offset, isp_debug_buffer);
		}
	}
	else
	{
        switch_cap_en = KAL_TRUE;	        
    	grap_height_offset = 0;
        /* Set OB as thred */	    	    
        SET_RAW_DATA_R_NEG_SIGN;
        SET_RAW_DATA_GR_NEG_SIGN;
        SET_RAW_DATA_B_NEG_SIGN;
        SET_RAW_DATA_GB_NEG_SIGN;            
        if(defectpixel_data.threshold_area1>31)
            defectpixel_data.threshold_area1 = 31;
        SET_RAW_DATA_R_OFFSET_ADJ(defectpixel_data.threshold_area1<<2);
        SET_RAW_DATA_GR_OFFSET_ADJ(defectpixel_data.threshold_area1<<2);
        SET_RAW_DATA_B_OFFSET_ADJ(defectpixel_data.threshold_area1<<2);
        SET_RAW_DATA_GB_OFFSET_ADJ(defectpixel_data.threshold_area1<<2);                                    
		// Find defect pixel in this frame												
		camera_defect_raw_capture(	0, 0, grap_width, grap_height,isp_debug_buffer);			
		for(i=0;i<cap_col_count;i++)
		{
		    if((grap_height_offset+block_height)==defectpixel_data.image_height)
		    {
				ret = camera_defect_find_white_pixel(	block_width, (kal_uint16)(block_height-defectpixel_data.boarder_len), grap_height_offset, 
												 	(isp_debug_buffer+(grap_width*(block_height)*i)));				        
		    }
		    else
		    {
				ret = camera_defect_find_white_pixel(	block_width, block_height, grap_height_offset, 
												 	(isp_debug_buffer+(grap_width*(block_height)*i)));
			}
		    grap_height_offset = grap_height_offset + block_height;
			if(ret<0)
				break;                												
		}	
		if((ret>0)&&((grap_height_offset+defectpixel_data.boarder_len)<(defectpixel_data.image_height)))
		{
			camera_defect_raw_capture(	0, grap_height_offset, grap_width, (kal_uint16)((defectpixel_data.image_height)-grap_height_offset), isp_debug_buffer);
			
			// Find defect pixel in this frame												
            block_pixel_count = ( block_width*((defectpixel_data.image_height)-grap_height_offset-defectpixel_data.boarder_len) )>>2;
			ret = camera_defect_find_white_pixel(	block_width, (kal_uint16)((defectpixel_data.image_height)-grap_height_offset-defectpixel_data.boarder_len), 
			        grap_height_offset, isp_debug_buffer);
		}
	}

	/* Sorting candidate pixels */	
	if(ret>0)
	{
		if((defectpixel_data.defect_type_select == DEFECT_TYPE_BLACK_PIXEL_ONLY)||		
			(defectpixel_data.defect_type_select == DEFECT_TYPE_WHITE_PIXEL_ONLY)|| 
			((defectpixel_data.defect_type_select==DEFECT_TYPE_BOTH_BW)&&
			 (defectpixel_data.defect_type==DEFECT_TYPE_WHITE_PIXEL)) ||
			((defectpixel_data.defect_type_select==DEFECT_TYPE_BOTH_WB)&&
			 (defectpixel_data.defect_type==DEFECT_TYPE_BLACK_PIXEL)) )	
		{			
			camera_defect_sort_pixel(defect_mode, defectpixel_data.search_mode_select, defectpixel_data.defect_type_select);
			
			if( defect_mode==DEFECT_MODE_CAPTURE ) 			
			{
			    defect_operation_state = DEFECT_FINISH_STATE;			
				ret = defectpixel_result.defect_num;		
			}
			else
			{
			    defect_operation_pv_state = DEFECT_FINISH_STATE;								
				ret = defectpixel_pv_result.defect_num;		
		    }				
		}				
		else
		{
	        if(defect_mode==DEFECT_MODE_CAPTURE)		    
			defect_operation_state = DEFECT_PROCESS_STATE;	
            else			    
			defect_operation_pv_state = DEFECT_PROCESS_STATE;	
			ret = ERR_STATE_UNDER_PROCESSING;
		}
	}
		
	/* Restore shading status */
	if(shading_en == KAL_TRUE)
	{
    	ENABLE_SHADING_COMPENSATION;
	}	
	return ret;
}

kal_int32 get_defectpixel_info(kal_uint8 defect_mode, defectpixel_para_struct **defect_data, defectpixel_result_struct **defect_result)
{
	/* defect_mode: Load preview mode or Load Capture Mode */
	if( defect_mode==DEFECT_MODE_CAPTURE ) 	
	{
		*defect_data = &defectpixel_cap_data;
		*defect_result = &defectpixel_result;
		if(defect_operation_state==DEFECT_FINISH_STATE)
			return defectpixel_result.defect_num;		
		else if(defect_operation_state==DEFECT_PROCESS_STATE)
			return ERR_STATE_UNDER_PROCESSING;
		else
			return ERR_STATE_INIT_PROCESS;
	}
	else
	{
		*defect_data = &defectpixel_pv_data;
		*defect_result = &defectpixel_pv_result;
		if(defect_operation_pv_state==DEFECT_FINISH_STATE)
			return defectpixel_pv_result.defect_num;		
		else if(defect_operation_pv_state==DEFECT_PROCESS_STATE)
			return ERR_STATE_UNDER_PROCESSING;
		else
			return ERR_STATE_INIT_PROCESS;						
	}

	return ERR_STATE_UNKNOWN_MODE;		
}

/* Store in NVRAM */
void copy_calibration_result_to_camera_defect(nvram_camera_defect_struct *p_cam_defect)
{
	kal_uint32 i;
	if( p_cam_defect !=NULL ) 
	{
		//capture , defect_num should <=255
		for(i=0;i<defectpixel_result.defect_num;i++)			
		{
			p_cam_defect->defect[i] = (defectpixel_result.pixel_list[i].pos_x)|(defectpixel_result.pixel_list[i].pos_y<<16);
		}
		if(i>=MAX_DEFECT_NUM)
            p_cam_defect->defect[MAX_DEFECT_NUM-1] = 0xFFFFFFFF;				
        else
		p_cam_defect->defect[i] = 0xFFFFFFFF;		
		//preview , defect_num should <=239
		for(i=MAX_DEFECT_NUM;i<defectpixel_pv_result.defect_num+MAX_DEFECT_NUM;i++)			
		{
			p_cam_defect->defect[i] = (defectpixel_pv_result.pixel_list[i-MAX_DEFECT_NUM].pos_x)|(defectpixel_pv_result.pixel_list[i-MAX_DEFECT_NUM].pos_y<<16);
		}
		if(i>=(MAX_DEFECT_NUM+MAX_PV_DEFECT_NUM))		
            p_cam_defect->defect[MAX_DEFECT_NUM+MAX_PV_DEFECT_NUM-1] = 0xFFFFFFFF;						
        else            
		p_cam_defect->defect[i] = 0xFFFFFFFF;		
	}
}

void pixellist_to_camera_defect(kal_uint8 defect_mode, const defectpixel_result_struct *defect_result, nvram_camera_defect_struct *p_cam_defect)
{
	kal_uint32 i;
	if( defect_mode==DEFECT_MODE_CAPTURE ) 
	{   // defect_num should <= 255
		for(i=0;i<defect_result->defect_num;i++)			
		{
			p_cam_defect->defect[i] = ( ((defect_result->pixel_list[i].pos_y<<16)&0xFFFF0000) | (defect_result->pixel_list[i].pos_x&0x0000FFFF) );
		}
		// Last pixel: pos_x=pos_y=0xFFFF 
		if(i>=MAX_DEFECT_NUM)
            p_cam_defect->defect[MAX_DEFECT_NUM-1] = 0xFFFFFFFF;				
        else		
		p_cam_defect->defect[i] = 0xFFFFFFFF;
		return;
	}
	else
	{   // defect_num should <= 239
		for(i=MAX_DEFECT_NUM;i<defect_result->defect_num+MAX_DEFECT_NUM;i++)			
		{
			p_cam_defect->defect[i] = ( ((defect_result->pixel_list[i-MAX_DEFECT_NUM].pos_y<<16)&0xFFFF0000) | (defect_result->pixel_list[i-MAX_DEFECT_NUM].pos_x&0x0000FFFF) );
		}
		// Last pixel: pos_x=pos_y=0xFFFF 
		if(i>=(MAX_DEFECT_NUM+MAX_PV_DEFECT_NUM))		
            p_cam_defect->defect[MAX_DEFECT_NUM+MAX_PV_DEFECT_NUM-1] = 0xFFFFFFFF;						
        else            		
		p_cam_defect->defect[i] = 0xFFFFFFFF;
		return;
	}
}

/* Load from NVRAM */
void camera_defect_to_pixellist(kal_uint8 defect_mode, const nvram_camera_defect_struct *p_cam_defect, defectpixel_result_struct *defect_result)
{	
	kal_uint32 i;
	if( defect_mode==DEFECT_MODE_CAPTURE ) 
	{
		for(i=0;i<MAX_DEFECT_NUM;i++)			
		{
			defect_result->pixel_list[i].pos_x = ((p_cam_defect->defect[i])&0xFFFF);						
			defect_result->pixel_list[i].pos_y = ((p_cam_defect->defect[i])>>16)&0xFFFF;
			defect_result->pixel_list[i].pixel_diff = 0xFF;
			defect_result->pixel_list[i].area_id = 0xFF;			
			// Last pixel: pos_x=pos_y=0xFFFF, pixel_diff=area_id=0xFF			
			if(p_cam_defect->defect[i] == 0xFFFFFFFF)	
				break;
		}
		defect_result->defect_num = i;
		defect_result->search_num = 0xFFFF;
		return;
	}
	else
	{
		for(i=MAX_DEFECT_NUM;i<MAX_DEFECT_NUM+MAX_PV_DEFECT_NUM;i++)			
		{
			defect_result->pixel_list[i-MAX_DEFECT_NUM].pos_x = ((p_cam_defect->defect[i])&0xFFFF);						
			defect_result->pixel_list[i-MAX_DEFECT_NUM].pos_y = ((p_cam_defect->defect[i])>>16)&0xFFFF;
			defect_result->pixel_list[i-MAX_DEFECT_NUM].pixel_diff = 0xFF;
			defect_result->pixel_list[i-MAX_DEFECT_NUM].area_id = 0xFF;			
			// Last pixel: pos_x=pos_y=0xFFFF, pixel_diff=area_id=0xFF			
			if(p_cam_defect->defect[i] == 0xFFFFFFFF)	
				break;
		}
		defect_result->defect_num = i-MAX_DEFECT_NUM;
		defect_result->search_num = 0xFFFF;
		return;
	}
}

#endif

#endif  // defined(ISP_SUPPORT)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -