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

📄 isp_yuv_if.c

📁 MTK6225 支持的200W像素的代码
💻 C
📖 第 1 页 / 共 5 页
字号:
* FUNCTION
*	camera_yuv_capture_jpeg_process
*
* DESCRIPTION
*	This function capture one picture and encode it as jpeg file
*
* PARAMETERS
*	isp_data : the parameters for camera capture and jpeg encode process
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 camera_yuv_capture_jpeg_process(void)
{
	kal_uint32 jpeg_file_size = 1;
#if (defined(YUV_SENSOR_SUPPORT))
	volatile kal_uint8 i;
	kal_uint8 capture_retry_flag=0;
	kal_uint16 temp_grab_size;
	MMDI_SCENERIO_ID scene_id=SCENARIO_CAMERA_CAPTURE_JPEG_ID;
	kal_uint32 event_group;

#if (defined(EXIF_SUPPORT))
	exif_cam_para_struct* exif_cam_para_ptr;
 	exif_MTK_para_struct* exif_MTK_para_ptr;
#if (defined(DRV_ISP_6227_SERIES))
 	kal_uint16	exif_header_length;
 	kal_uint16	exif_padding_length=0;
#endif
#endif
#if (defined(DRV_ISP_6228_SERIES)||defined(DRV_ISP_6229_SERIES))
	lcd_frame_update_struct lcd_data;
	memset(&lcd_data, 0, sizeof(lcd_frame_update_struct));	//initial lcd_data
#endif

	ENABLE_CMOS_SESNOR;
   DISABLE_VIEW_FINDER_MODE;
   DISABLE_CAMERA_IDLE_INT;

#if (defined(DRV_ISP_6227_SERIES)||defined(DRV_ISP_6225_SERIES))
	intmem_init((kal_uint32 *) isp_capture_jpeg_data.intmem_start_address,
					isp_capture_jpeg_data.intmem_size);
	extmem_init((kal_uint32 *) isp_capture_jpeg_data.extmem_start_address,
					isp_capture_jpeg_data.extmem_size);
#endif

	/* accoring the zoom factor to calculate the grab window area */
	exposure_window.image_target_width=isp_capture_jpeg_data.target_width;
	exposure_window.image_target_height=isp_capture_jpeg_data.target_height;
	exposure_window.digital_zoom_factor=isp_digital_zoom_factor;

	sensor_config_data.enable_shutter_tansfer=KAL_FALSE;
	sensor_config_data.meta_mode=KAL_FALSE;
	sensor_config_data.enable_flashlight_tansfer=KAL_FALSE;

	image_sensor_func->sensor_capture_setting(&exposure_window,&sensor_config_data);

	/* accoring the zoom factor to calculate the grab window area */
	isp_grab_width= ((exposure_window.exposure_window_width * ISP_MIN_DIGITAL_ZOOM_FACTOR) / isp_digital_zoom_factor)&0xFFFC ;
	isp_grab_height=((exposure_window.exposure_window_height * ISP_MIN_DIGITAL_ZOOM_FACTOR) / isp_digital_zoom_factor)&0xFFFC ;
	isp_grab_start_x=exposure_window.grab_start_x+ (((exposure_window.exposure_window_width-isp_grab_width)>>1)&0xFFFC);
	isp_grab_start_y=exposure_window.grab_start_y+ (((exposure_window.exposure_window_height-isp_grab_height)>>1)&0xFFFE);

	if ((isp_capture_jpeg_data.target_width * exposure_window.exposure_window_height) >=
		 (isp_capture_jpeg_data.target_height * exposure_window.exposure_window_width))
	{	/* x limit */
		temp_grab_size=isp_grab_height;
		isp_grab_height=(isp_grab_width * isp_capture_jpeg_data.target_height/isp_capture_jpeg_data.target_width)&0xFFFE;
		isp_grab_start_y+=(((temp_grab_size-isp_grab_height)>>1)&0xFFFE);
	}
	else
	{	/* y limit */
		temp_grab_size=isp_grab_width;
		isp_grab_width=(isp_grab_height * isp_capture_jpeg_data.target_width/isp_capture_jpeg_data.target_height)&0xFFFE;
		isp_grab_start_x+=(((temp_grab_size-isp_grab_width)>>1)&0xFFFC);
	}

	SET_YUV_TG_GRAB_PIXEL(isp_grab_start_x,isp_grab_width);
	SET_YUV_TG_GRAB_LINE(isp_grab_start_y,isp_grab_height);
	isp_capture_jpeg_data.source_width=isp_grab_width;
	isp_capture_jpeg_data.source_height=isp_grab_height;
#if (defined(DRV_ISP_6228_SERIES)||defined(DRV_ISP_6229_SERIES))
	ipp_capture_jpeg_data.image_src_width	=	isp_capture_jpeg_data.source_width;
	ipp_capture_jpeg_data.image_src_height	=	isp_capture_jpeg_data.source_height;
#endif

	DISABLE_VERTICAL_SUB_SAMPLE;
	DISABLE_HORIZONTAL_SUB_SAMPLE;
#if (defined(DRV_ISP_6227_SERIES))
	jpeg_codec_power_up();
#endif

	kal_set_eg_events(camera_isp_event_id,0,KAL_AND);
	ENABLE_CAMERA_IDLE_INT;
	SET_CAMERA_CAPTURE_MODE;
	SET_CAMERA_FRAME_RATE(0);
	for(i=0;i<camera_oper_data.capture_delay_frame;i++)
	{
	   DISABLE_VIEW_FINDER_MODE;
	   kal_set_eg_events(camera_isp_event_id,0,KAL_AND);
		ENABLE_VIEW_FINDER_MODE;

   	kal_retrieve_eg_events(camera_isp_event_id,CAMERA_ISP_IDLE_EVENT,KAL_OR_CONSUME,
      	                    &event_group,KAL_SUSPEND);
   }
   DISABLE_VIEW_FINDER_MODE;
   DISABLE_CAMERA_IDLE_INT;

#if (defined(EXIF_SUPPORT))
   /* config exif header */
   exif_cam_para_ptr=exif_get_cam_para_struct();
   exif_MTK_para_ptr=exif_get_MTK_para_struct();
#endif

#if (defined(DRV_ISP_6228_SERIES)||defined(DRV_ISP_6229_SERIES))
	open_image_data_path(scene_id);
	config_camera_capture_jpeg_data_path(scene_id,&ipp_capture_jpeg_data);

	if (isp_capture_jpeg_data.display==KAL_TRUE)
	{
		lcd_data.module_id			=	LCD_UPDATE_MODULE_MEDIA;
		lcd_data.lcd_id				=	isp_capture_jpeg_data.lcd_id;
		lcd_data.block_mode_flag	=	KAL_TRUE;
		lcd_data.fb_update_mode		=	LCD_HW_TRIGGER_MODE;
		lcd_data.lcm_start_x			=	isp_capture_jpeg_data.lcm_start_x;
		lcd_data.lcm_start_y			=	isp_capture_jpeg_data.lcm_start_y;
		lcd_data.lcm_end_x			=	isp_capture_jpeg_data.lcm_end_x;
		lcd_data.lcm_end_y			=	isp_capture_jpeg_data.lcm_end_y;
		lcd_data.roi_offset_x		=	isp_capture_jpeg_data.roi_offset_x;
		lcd_data.roi_offset_y		=	isp_capture_jpeg_data.roi_offset_y;
		lcd_data.update_layer		=	isp_capture_jpeg_data.update_layer;
		lcd_data.hw_update_layer	=	isp_capture_jpeg_data.hw_update_layer;
		lcd_data.hw_trigger_src		=	LCD_HW_TRIGGER_IBW2;

		isp_capture_jpeg_data.display=KAL_TRUE;

		lcd_data.roi_background_color	=	0xFFFFFF;
		lcd_data.memory_output			=	KAL_FALSE;
		lcd_data.block_mode_flag		=	KAL_TRUE;
		lcd_data.lcd_block_mode_cb		=	NULL;
#if (defined(TV_OUT_SUPPORT))
		if (isp_capture_jpeg_data.tv_output==KAL_TRUE)
		{
			lcd_data.tv_output								=	KAL_TRUE;
			lcd_data.tv_output_width						=	isp_capture_jpeg_data.tv_output_width;
			lcd_data.tv_output_height						=	isp_capture_jpeg_data.tv_output_height;
			lcd_data.tv_output_offset_x					=	isp_capture_jpeg_data.tv_output_offset_x;
			lcd_data.tv_output_offset_y					=	isp_capture_jpeg_data.tv_output_offset_y;
			lcd_data.tv_output_frame_buffer1_address	=	isp_capture_jpeg_data.tv_output_buffer1_address;
			lcd_data.tv_output_frame_buffer2_address	=	isp_capture_jpeg_data.tv_output_buffer2_address;
			lcd_data.tv_output_frame_buffer_size		=	isp_capture_jpeg_data.tv_output_buffer_size;
		}
		else
		{
			lcd_data.tv_output=KAL_FALSE;
		}
#endif	/* TV_OUT_SUPPORT */
		lcd_fb_update(&lcd_data);
	}

	isp_operation_state=ISP_CAPTURE_JPEG_STATE;

	camera_image_setting(CAM_PARAM_EFFECT,isp_preview_config_data.image_effect);
	if(isp_preview_config_data.image_effect==0)
	{
		camera_image_setting(CAM_PARAM_CONTRAST,isp_preview_config_data.contrast_level);
		camera_image_setting(CAM_PARAM_BRIGHTNESS,isp_preview_config_data.brightness_level);
		camera_image_setting(CAM_PARAM_HUE,isp_preview_config_data.hue_value);
		camera_image_setting(CAM_PARAM_SATURATION,isp_preview_config_data.saturation_value);
	}
	camera_image_setting(CAM_PARAM_WB,isp_preview_config_data.wb_mode);
	camera_image_setting(CAM_PARAM_EXPOSURE,isp_preview_config_data.ev_value);
	camera_image_setting(CAM_PARAM_BANDING,isp_preview_config_data.banding_freq);
	camera_image_setting(CAM_PARAM_NIGHT_MODE,isp_preview_config_data.night_mode);

        // Support burst capture function for MT6228+YUV
	if (isp_capture_jpeg_data.snapshot_number==1)
	{
		SET_CAMERA_CAPTURE_MODE;
	}
	else if (isp_capture_jpeg_data.snapshot_number>1)
	{
		SET_CAMERA_PREVIEW_MODE;
	}
	SET_CAMERA_FRAME_RATE(0);
	ENABLE_VIEW_FINDER_MODE;
	//return;

#elif (defined(DRV_ISP_6227_SERIES))
#if (defined(EXIF_SUPPORT))
/* calculating exif header size and shift the start addres of jpeg encoder*/
	exif_header_length=exif_get_custom_IFD_and_buffer_size(2);

	if(exif_header_length>0)
	{
		jpeg_encode_config_data.jpeg_file_start_address+=exif_header_length;

		if(jpeg_encode_config_data.jpeg_file_start_address % 4 !=0)
		{
			jpeg_encode_config_data.jpeg_file_start_address=((jpeg_encode_config_data.jpeg_file_start_address+4)>>2)<<2;
		}

		exif_padding_length=jpeg_encode_config_data.jpeg_file_start_address-
									(isp_capture_jpeg_data.target_buffer_start_address+exif_header_length);
		jpeg_encode_config_data.jpeg_file_buffer_size-=(jpeg_encode_config_data.jpeg_file_start_address-
																		isp_capture_jpeg_data.target_buffer_start_address);
	}
#endif
   do
   {
	   if(capture_retry_flag==1)
	   {
	   	ENABLE_CMOS_SESNOR;
	   	jpeg_encode_config_data.image_quality=JPEG_ENCODER_POOR_QUALITY;
	  		intmem_init((kal_uint32 *) isp_capture_jpeg_data.intmem_start_address,
						isp_capture_jpeg_data.intmem_size);
			extmem_init((kal_uint32 *) isp_capture_jpeg_data.extmem_start_address,
						isp_capture_jpeg_data.extmem_size);
	   	capture_retry_flag++;
	   }

		mp4_reset();
		config_image_dma(scene_id,jpeg_encode_config_data.image_width,jpeg_encode_config_data.image_height);
		config_jpeg_encoder(&jpeg_encode_config_data);
		config_image_processor(scene_id);
		config_pixel_resizer(scene_id);

		isp_operation_state=ISP_CAPTURE_JPEG_STATE;

		camera_image_setting(CAM_PARAM_EFFECT,isp_preview_config_data.image_effect);
		if(isp_preview_config_data.image_effect==0)
		{
			camera_image_setting(CAM_PARAM_CONTRAST,isp_preview_config_data.contrast_level);
			camera_image_setting(CAM_PARAM_BRIGHTNESS,isp_preview_config_data.brightness_level);
			camera_image_setting(CAM_PARAM_HUE,isp_preview_config_data.hue_value);
			camera_image_setting(CAM_PARAM_SATURATION,isp_preview_config_data.saturation_value);
		}
		camera_image_setting(CAM_PARAM_WB,isp_preview_config_data.wb_mode);
		camera_image_setting(CAM_PARAM_EXPOSURE,isp_preview_config_data.ev_value);
		camera_image_setting(CAM_PARAM_BANDING,isp_preview_config_data.banding_freq);
		camera_image_setting(CAM_PARAM_NIGHT_MODE,isp_preview_config_data.night_mode);

		jpeg_encoder_encode_result=0;
		SET_CAMERA_CAPTURE_MODE;
		SET_CAMERA_FRAME_RATE(0);
		ENABLE_VIEW_FINDER_MODE;

	/* wait until JPEG encode completely */
		for (i=0;i<20;i++)
		{
			kal_sleep_task(20);

			if (jpeg_encoder_encode_result & JPEG_ENCODE_STALL)
			{
				while ((*(volatile unsigned int *) 0x80690000) & 0x10000)
				{
					DISABLE_VIEW_FINDER_MODE;
					*((volatile unsigned int *) 0x80610004) = 0x60000;
					*((volatile unsigned int *) 0x80610004) = 0x6;
					RESET_JPEG_ENCODER;
					ENABLE_JPEG_ENCODER;
					ENABLE_VIEW_FINDER_MODE;
					kal_sleep_task(73);
				}
				jpeg_file_size=0;
			}
			else if (jpeg_encoder_encode_result & JPEG_ENCODE_DONE)
			{
				jpeg_file_size=DRV_Reg32(JPEG_ENCODER_DMA_ADDR_REG)-DRV_Reg32(JPEG_ENCODER_DEST_ADDR_REG);
				kal_sleep_task(15);
				i=100;
			}
		}
		if (i==20)
			jpeg_file_size=0;

		DISABLE_CMOS_SESNOR;
		DISABLE_VIEW_FINDER_MODE;

		RESZ_Stop(scene_id);
		RESZ_Close(scene_id);

		clean_imgprc_coefficient(scene_id);
		IMGPROC_Stop(scene_id);
		IMGPROC_Close(scene_id);

		stop_image_dma(scene_id);
		IMGDMA_Close(scene_id);

		intmem_deinit();
		extmem_deinit();

		if((capture_retry_flag==0)&&(jpeg_file_size==0)&&(jpeg_encode_config_data.image_quality!=JPEG_ENCODER_POOR_QUALITY))
			capture_retry_flag++;
	}while(capture_retry_flag==1);

#if (defined(EXIF_SUPPORT))
	/* Filling Exif header */
	if(exif_header_length>0)
	{
		*((kal_uint8 *)jpeg_encode_config_data.jpeg_file_start_address)=0xFF;
		*((kal_uint8 *)jpeg_encode_config_data.jpeg_file_start_address+1)=0xD8;
		exif_Fillin_Header((kal_uint8 *)jpeg_encode_config_data.jpeg_file_start_address,2);

		/* padding bytes to cover SOI marker generated by JPEG encoder */
		for(i=0;i<exif_padding_length;i++)
			*((kal_uint8 *)(jpeg_encode_config_data.jpeg_file_start_address+1-i))=0x00;

		jpeg_file_size+=(jpeg_encode_config_data.jpeg_file_start_address-jpeg_encode_config_data.jpeg_file_start_address);
	}
#endif

	jpeg_encoder_operation_state=JPEG_ENCODER_STANDBY_STATE;
	isp_operation_state=ISP_STANDBY_STATE;

	jpeg_codec_power_down();

#elif (defined(DRV_ISP_6225_SERIES))
	sw_jpeg_encode_config_data.image_width=isp_capture_jpeg_data.target_width;
	sw_jpeg_encode_config_data.image_height=isp_capture_jpeg_data.target_height;
	sw_jpeg_encode_config_data.image_quality=isp_capture_jpeg_data.image_quality;
	sw_jpeg_encode_config_data.jpeg_file_start_address=isp_capture_jpeg_data.target_buffer_start_address;
	sw_jpeg_encode_config_data.jpeg_file_buffer_size=isp_capture_jpeg_data.target_buffer_size;
	sw_jpeg_encode_config_data.intmem_start_address=isp_capture_jpeg_data.intmem_start_address;
	sw_jpeg_encode_config_data.intmem_size=isp_capture_jpeg_data.intmem_size;

	sw_jpeg_encode_config_data.input_type=IMAGE_FORMAT_YUV420;
	if(isp_capture_jpeg_data.jpeg_gray_mode==0)
		sw_jpeg_encode_config_data.output_type=IMAGE_FORMAT_YUV420;
	else
		sw_jpeg_encode_config_data.output_type=IMAGE_FORMAT_GRAY;
	sw_jpeg_encode_config_data.jpeg_yuv_data[0]=(kal_uint8 *)isp_capture_jpeg_data.y_address;
	sw_jpeg_encode_config_data.jpeg_yuv_data[1]=(kal_uint8 *)isp_capture_jpeg_data.u_address;
	sw_jpeg_encode_config_data.jpeg_yuv_data[2]=(kal_uint8 *)isp_capture_jpeg_data.v_address;
	sw_jpeg_encode_config_data.jpeg_yuv_size[0]=isp_capture_jpeg_data.y_size;
	sw_jpeg_encode_config_data.jpeg_yuv_size[1]=isp_capture_jpeg_data.u_size;
	sw_jpeg_encode_config_data.jpeg_yuv_size[2]=isp_capture_jpeg_data.v_size;

	#ifdef DRV_JPG_ENC_DIRECT_COUPLE_SUPPORT
	sw_jpeg_encode_config_data.memory_output=isp_capture_jpeg_data.memory_output;						/* output another image for LCD output */
	sw_jpeg_encode_config_data.memory_output_type=isp_capture_jpeg_data.memory_output_type;
	sw_jpeg_encode_config_data.memory_output_width=isp_capture_jpeg_data.memory_output_width;				/* image width for LCD output */
	sw_jpeg_encode_config_data.memory_output_height=isp_capture_jpeg_data.memory_output_height;			/* image height for LCD output */
	sw_jpeg_encode_config_data.memory_output_buffer_address=isp_capture_jpeg_data.memory_output_buffer_address;
	sw_jpeg_encode_config_data.memory_output_buffer_size=isp_capture_jpeg_data.memory_output_buffer_size;
	#endif
	
	config_pixel_resizer(scene_id);
	isp_operation_state=ISP_CAPTURE_JPEG_STATE;

	camera_image_setting(CAM_PARAM_EFFECT,isp_preview_config_data.image_effect);
	if(isp_preview_config_data.image_effect==0)
	{
		camera_image_setting(CAM_PARAM_CONTRAST,isp_preview_config_data.contrast_level);
		camera_image_setting(CAM_PARAM_BRIGHTNESS,isp_preview_config_data.brightness_level);
		camera_image_setting(CAM_PARAM_HUE,isp_preview_config_data.hue_value);
		camera_image_setting(CAM_PARAM_SATURATION,isp_preview_config_data.saturation_value);
	}
	camera_image_setting(CAM_PARAM_WB,isp_preview_config_data.wb_mode);
	camera_image_setting(CAM_PARAM_EXPOSURE,isp_preview_config_data.ev_value);
	camera_image_setting(CAM_PARAM_BANDING,isp_preview_config_data.banding_freq);

⌨️ 快捷键说明

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