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

📄 still.c

📁 dm270 source code
💻 C
📖 第 1 页 / 共 2 页
字号:

	OSD_winEnable( OSD_VID_WIN0, TRUE);


	UART_sendString( UART0, "\r\n Creating thumbnail. Please wait ..." );

	// create YUV-thumbnail using preview engine
	PREV_setConfig( &prevConfig_createThumbnail );
	PREV_enable(TRUE);
	while(PREV_isEnabled() )
		;

	
	// create JPEG-thumbnail using DSP.
	{
		Uint16 cmd;
		
		// reset DSP
		DSPC_reset();

		// clear ARM-DSP communication area
		ARMDSP_clearReg();

		// load image pipe code to DSP side
		DSPLoadCode(jpeg_encode);

		// wait for DSP to be ready
		do {
			ARMDSP_getArmCmd(&cmd, NULL, 0);
		} while( cmd != 0x777 ) ;

		// clear DSP HINT interrupt
		INTC_clearIRQ( INT_DSP );

		// send command to start image pipe
		ARMDSP_sendDspCmd(JPEG_ENCODE, (Uint16*)&JpegEncCmd, sizeof(JpegEncCmd)/2);

		// wait for jpeg encode to complete
		INTC_waitForInt(INT_DSP, 0);

		// get execution status
		ARMDSP_getDspReply(&cmd, (Uint16*)&JpegEncReply, sizeof(JpegEncReply)/2 );

		if(    (cmd & 0xFFF) != JPEG_ENCODE  
			|| (cmd & DSP_CMD_COMPLETE ) != DSP_CMD_COMPLETE 
			|| (cmd & DSP_CMD_INVALID_CMD ) || (cmd & DSP_CMD_INVALID_PARAM ) ) 
		{
			sprintf( UART_outBuff, "\r\n E_DEVICE : Jpeg Encode. Execution status [0x%x] \r\n",
				cmd );
			UART_sendString( UART0,  UART_outBuff );
		}
	}

	UART_sendString( UART0, " Done." );

	thumbSize = MAKE_WORD32(JpegEncReply.BitstreamSizeHigh, JpegEncReply.BitstreamSizeLow);
	sprintf( UART_outBuff, "\r\n Thumbnail Jpeg image size is %ld bytes.", thumbSize );
	UART_sendString( UART0,  UART_outBuff );

	UART_sendString( UART0, "\r\n Applying EXIF wrapper. Please wait..." );
	
	// EXIF wrapper
	jpg_addr   = (Uint8*)JPEG_DATA_ADDR;
	jpg_size   = jpegSize;
	thumb_addr = (Uint8*)THUMB_JPEG_DATA_ADDR;
	thumb_size = thumbSize;
	exif_addr  = (Uint8*)((EXIF_HEADER_ADDR + 3)&(~3));
	out_addr   = (Uint8*)EXIF_DATA_ADDR;

	if(EXIFInitParams( &prmExif, jpg_addr, jpg_size, thumb_addr, thumb_size) !=E_PASS ) {
	    UART_sendString( UART0, "\r\n ERROR : EXIF Creation" );
		return;
	}

	if(EXIFMakeHeader( &prmExif, exif_addr, &exif_size)!=E_PASS) {
	    UART_sendString( UART0, "\r\n ERROR : EXIF Creation" );	
		return;
	}

	if( EXIFFreeParams( &prmExif) != E_PASS ) {	
	    UART_sendString( UART0, "\r\n ERROR : EXIF Creation" );	
		return;
	}

	memcpy(out_addr, jpg_addr, 2);		// copy 0xFFD8
	memcpy(out_addr+2, exif_addr, exif_size); // copy EXIF header
	memcpy(out_addr+2+exif_size, jpg_addr+2, jpg_size-2); // copy main JPG image

	out_size=jpg_size+exif_size;

	UART_sendString( UART0, " Done." );

	if(FS_FILE_IO) {
		char fname[40];

		UART_sendString( UART0, "\r\n Saving EXIF file to memory card ... " );
		if( out_size  > maxFileSize ) {
			UART_sendString( UART0, "\r\n"
				   "\r\n ERROR : Cannot save image. Insufficient space on Memory  card." );
			return;
		}
		UART_sendString( UART0, "\r\n"
							   "\r\n Saving Image. Please Wait ... " );

		
		if( NewFileName(fname, &StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
			UART_sendString( UART0, "\r\n"
							        "\r\n ERROR : Memory card access error." );
			return;
		}

		GUI_fileInfoPanelSetInfo(StillCtrl.FileIndex);

		if( STILL_writeFile( fname, (Uint32)out_addr, out_size ) != E_PASS )	{
			UART_sendString( UART0, "\r\n"
						            "\r\n ERROR : Memory card file write error." );	
			return;
		}

		UART_sendString( UART0, "Done." );
		sprintf( UART_outBuff, "\r\n JPEG FILE : %s ", fname );
		UART_sendString( UART0, UART_outBuff );

		
	}

	UART_sendString( UART0, "\r\n Done.  " );
}

static PREV_ConfigData	prevConfig_jpegDecode = {
	FALSE,							// ccdcInputWidth8bits;
	FALSE,							// alawEnable;
	TRUE,							// oneShotEnable;
	TRUE,							// resizeOnlyEnable;
	TRUE,							// sdramInputEnable;
	FALSE,							// burstAlignModeEnable;
	FALSE,							// writeEnableValid;
	(char*)CCD_RAW_DATA_ADDR,		// *readAddress;
	(char*)OSD_VIDEO_WIN0_ADDR,		// *writeAddress;
	0,								// hstart;
	0,								// vstart;
	0,								// inputPixelsH;
	0,								// inputLinesV;
	640,							// outputPixelsH;
	480								// outputLinesV;
};

static OSD_WinConfigData		vwin0Config_jpegDecode;
static OSD_VideoWinModeData		vwin0Mode_jpegDecode;

void STILL_PLAYBACK_run() {
	Uint32 jpeg_size;
	char fname[40];

	UART_sendString( UART0, "\r\n Decoding JPEG Image. Please wait ... " );

	// stop AE/AWB
	AEWBDemoStop();

	// stop CCDC, PREV, AEWB
	CCDC_enable( FALSE, FALSE );
	PREV_enable( FALSE );

	while(PREV_isEnabled() )
		;

	if( FS_FILE_IO ) {

		UART_sendString( UART0, "\r\n Loading Image. Please Wait ... " );

		if( GenFileName(fname, StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
			UART_sendString( UART0, "\r\n ERROR : File Access");
			return;
		}

		if( STILL_readFile( fname, JPEG_DATA_ADDR, &jpeg_size) != E_PASS ) {
			UART_sendString( UART0, "\r\n ERROR : File Read");
			return;
		}

		UART_sendString( UART0, "Done.");

		sprintf( UART_outBuff, "\r\n FILE : %s ", fname );

		UART_sendString( UART0, UART_outBuff );

		GUI_fileInfoPanelSetInfo(StillCtrl.FileIndex);
	}

	// start JPEG decode on DSP side
	{
		Uint16 cmd;

		// reset DSP
		DSPC_reset();

		// clear ARM-DSP communication area
		ARMDSP_clearReg();

		// load jpeg decode code to DSP side
		DSPLoadCode(ti_image_pipe);

		// wait for DSP to be ready
		do {
			ARMDSP_getArmCmd(&cmd, NULL, 0);
		} while( cmd != 0x777 ) ;

		// clear DSP HINT interrupt
		INTC_clearIRQ( INT_DSP );

		// send command to start JPEG decode
		ARMDSP_sendDspCmd(JPEG_DECODE, (Uint16*)&JpegDecCmd, sizeof(JpegDecCmd)/2 );

		// wait for JPEG decode to complete
		INTC_waitForInt(INT_DSP, 0);

		// get execution status
		ARMDSP_getDspReply(&cmd, (Uint16*)&JpegDecReply, sizeof(JpegDecReply)/2 );

		if(    (cmd & 0xFFF) != JPEG_DECODE
			|| (cmd & DSP_CMD_COMPLETE ) != DSP_CMD_COMPLETE 
			|| (cmd & DSP_CMD_INVALID_CMD ) || (cmd & DSP_CMD_INVALID_PARAM ) ) 
		{
			sprintf( UART_outBuff, "\r\n E_DEVICE : JPEG decode. Execution status [0x%x] \r\n",
				cmd );
			UART_sendString( UART0,  UART_outBuff );
			//return;
		}
	}

	// resize and display
	prevConfig_jpegDecode.inputPixelsH = JpegDecReply.DecImageWidth;
	prevConfig_jpegDecode.inputLinesV  = JpegDecReply.DecImageHeight;

	// adjust for aspect ratio
	if(prevConfig_jpegDecode.inputPixelsH >= prevConfig_jpegDecode.inputLinesV ) {
		prevConfig_jpegDecode.outputPixelsH = 720;
		prevConfig_jpegDecode.outputLinesV =  
				((Uint32)prevConfig_jpegDecode.outputPixelsH*prevConfig_jpegDecode.inputLinesV)/prevConfig_jpegDecode.inputPixelsH;

		if(prevConfig_jpegDecode.outputLinesV>480) {
			prevConfig_jpegDecode.outputLinesV = 480;
			prevConfig_jpegDecode.outputPixelsH = 
				((Uint32)prevConfig_jpegDecode.outputLinesV*prevConfig_jpegDecode.inputPixelsH)/prevConfig_jpegDecode.inputLinesV;
		}
	} else {
		prevConfig_jpegDecode.outputLinesV = 480;
		prevConfig_jpegDecode.outputPixelsH = 
				((Uint32)prevConfig_jpegDecode.outputLinesV*prevConfig_jpegDecode.inputPixelsH)/prevConfig_jpegDecode.inputLinesV;

		if(prevConfig_jpegDecode.outputPixelsH>720) {
			prevConfig_jpegDecode.outputPixelsH = 720;
			prevConfig_jpegDecode.outputLinesV =  
				((Uint32)prevConfig_jpegDecode.outputPixelsH*prevConfig_jpegDecode.inputLinesV)/prevConfig_jpegDecode.inputPixelsH;
		}
	}

	prevConfig_jpegDecode.outputPixelsH = (prevConfig_jpegDecode.outputPixelsH+15)&0xFFF0;
	prevConfig_jpegDecode.hstart        = JpegDecCmd.DisplayWidth;
	PREV_setConfig( &prevConfig_jpegDecode );

	vwin0Config_jpegDecode.address = (char*)OSD_VIDEO_WIN0_ADDR;
	vwin0Config_jpegDecode.offset  = prevConfig_jpegDecode.outputPixelsH*2;
	vwin0Config_jpegDecode.width   = prevConfig_jpegDecode.outputPixelsH;
	vwin0Config_jpegDecode.height  = prevConfig_jpegDecode.outputLinesV/2;
	vwin0Config_jpegDecode.startX  = (720-vwin0Config_jpegDecode.width)/2;
	vwin0Config_jpegDecode.startY  = (240-vwin0Config_jpegDecode.height)/2;
	vwin0Config_jpegDecode.displayMode = OSD_FRAME_MODE;
	vwin0Config_jpegDecode.hzoom   = OSD_NO_ZOOM;
	vwin0Config_jpegDecode.vzoom   = OSD_NO_ZOOM;

	OSD_setWinConfig(OSD_VID_WIN0, &vwin0Config_jpegDecode );	

	vwin0Mode_jpegDecode.expandFilterEnable = FALSE;
	vwin0Mode_jpegDecode.hexpand = FALSE;
	vwin0Mode_jpegDecode.vexpand = FALSE;

	OSD_setVideoWinMode( &vwin0Mode_jpegDecode ); 

	CLKC_moduleSelectClockSource(CLK_CCDC, CLKC_SYSCLK);
	CCDC_enable( TRUE, FALSE);
	PREV_enable( TRUE );
	
	
	OSD_winEnable( OSD_VID_WIN0, TRUE);

	GUI_slideShowPanelImageDimSet( JpegDecReply.ImageWidth, JpegDecReply.ImageHeight );
	GUI_slideShowPanelSetState(&SLIDESHOW_BUTTON_PAUSE);

	UART_sendString( UART0, " Done.  " );
}


STATUS STILL_writeFile( char *fname, Uint32 jpeg_addr, Uint32 size ) {
	FILE_ID *fp;

	fp = FILE_open(fname, "wb", 0 );
	if( fp == NULL )
		return E_DEVICE;

	profile_clear_all();
	profile_start(10);
	
	FILE_write( fp, (char*)jpeg_addr, size );

	profile_end(10);

	FILE_close(fp, 0);
	return E_PASS;
}

STATUS STILL_readFile( char *fname, Uint32 jpeg_addr, Uint32 *size ) {
	FILE_ID *fp;
	

	fp = FILE_open(fname, "rb", 0 );
	if( fp == NULL )
		return E_DEVICE;

	profile_clear(11);
	profile_start(11);

	*size = 0;
	while(1) {
		*size += FILE_read( fp, (char*)jpeg_addr, MB);
		if(FILE_eof(fp)) 
			break;
		
		jpeg_addr += MB;
	}

	profile_end(11);
	

	FILE_close(fp, 0);
	return E_PASS;
}

/*-----------------------------------------------------------------------------\
@RoutineName :: STILL_nextFile

@Description ::
    Goto next Image file in device

@Parameters  ::
    NONE

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/
STATUS STILL_nextFile() {
	char fname[40];

    if( GetNextIndex(&StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
		if( GetFirstIndex(&StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
				UART_sendString( UART0, "\r\n  E_DEVICE : JPEG files not found.");
				return E_DEVICE;
		}
	}

	if( GenFileName(fname, StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
        UART_sendString( UART0, "\r\n  E_DEVICE : File Access");
        return E_DEVICE;
    }

	return E_PASS;
}

/*-----------------------------------------------------------------------------\
@RoutineName :: STILL_prevFile

@Description ::
    Goto Previous Image file in device

@Parameters  ::
    NONE

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/
STATUS STILL_prevFile() {
    char fname[40];

    if( GetPrevIndex(&StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
		if( GetLastIndex(&StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
				UART_sendString( UART0, "\r\n  E_DEVICE : JPEG files not found.");
				return E_DEVICE;
		}
	}

	if( GenFileName(fname, StillCtrl.FileIndex, IMG_FILE) != E_PASS ) {
        UART_sendString( UART0, "\r\n  E_DEVICE : File Access");
        return E_DEVICE;
    }

	return E_PASS;
}

/*-----------------------------------------------------------------------------\
@RoutineName :: STILL_firstFile

@Description ::
    Goto First Image file in device

@Parameters  ::
    NONE

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/
STATUS STILL_firstFile() {
    return GetFirstIndex(&StillCtrl.FileIndex, IMG_FILE);
}

/*-----------------------------------------------------------------------------\
@RoutineName :: STILL_lastFile

@Description ::
    Goto Last Image file in device

@Parameters  ::
    NONE

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/
STATUS STILL_lastFile() {
    return GetLastIndex(&StillCtrl.FileIndex, IMG_FILE);
}

⌨️ 快捷键说明

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