?? mmicamera.c
字號(hào):
/*
攝像頭模塊與mmi的接口代碼
2004.7.1 WYJ 整理
2004.7.8 WYJ 加入部分驅(qū)動(dòng),基礎(chǔ)版本
2004.7.15 WYJ 完成基本功能
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if defined (NEW_FRAME)
#include "typedefs.h"
#include "vsi.h"
#include "pei.h"
#include "custom.h"
#include "gsm.h"
#else /* NEW_FRAME */
#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"
#endif /* NEW_FRAME */
#include "Mfw_sys.h"
#include "mfw_mfw.h"
#include "mfw_win.h"
#include "mfw_kbd.h"
#include "mfw_edt.h"
#include "mfw_tim.h"
#include "mfw_phb.h"
#include "mfw_sms.h"
#include "mfw_icn.h"
#include "mfw_mnu.h"
#include "mfw_lng.h"
#include "mfw_sat.h"
#include "mfw_kbd.h"
#include "mfw_nm.h"
#include "Mfw_cm.h"
#include "dspl.h"
#include "MmiMmi.h"
#include "MmiMain.h"
#include "MmiDummy.h"
#include "MmiDialogs.h"
#include "MmiLists.h"
#include "MmiCall.h"
#include "MmiMenu.h"
#include "MmiSoftKeys.h"
#include "MmiResources.h"
#include "MmiBlkLangDB.h"
#include "MmiBookUtils.h"
#include "MmiEditor.h"
#include "MmiEditor_i.h"
#include "MmiBookshared.h"
#include "mmiSmsMenu.h"
#include "Mmismssend.h"
#include "mmiutilapi.h"
#include "mmidialogs.h"
#include "mmitextinput.h"
#include "mmisounds_defs.h"
#include "GameDisplay.h" //yangx Add
#include "mmicamera.h"
#include "mmiutilapi.h"
/* camera 驅(qū)動(dòng)接口函數(shù) */
#include "cam_api.h"
/* camera 狀態(tài)變量 */
CAMEXT CamExt;
//extern unsigned long jpg_buf[1024*20];
extern unsigned char jpg_buf[1024*20*4];
// trace
#define TRACE(s) MI_dbgPrintf s
//#define TRACE(s)
// 動(dòng)態(tài)分配空間失敗,暫時(shí)使用靜態(tài)空間
//unsigned char tmpjpg[176*240*4];
extern const unsigned char bm_bkg[];
// capture窗口顯示用圖片 有待擴(kuò)展
/***********************************************************************************
*
* 模塊: 文件管理模塊
*
* 描述: 對(duì)ffs進(jìn)行操作,負(fù)責(zé)camera部分添加刪除記錄等工作
*
* 歷史: 2004.7.1 WYJ 創(chuàng)建
*
***********************************************************************************/
/* 模塊內(nèi)部使用的宏 */
/* 文件接口屬性 */
#define MAX_CAM_FILE 10 // 存儲(chǔ)文件數(shù)量
#define MAX_CAM_CAPACITY (1024*200) // 最大容量暫定100k
#define MAX_CAM_NAME 15 // 最大文件名長度,實(shí)際是6個(gè)漢字
#define CAM_FATH "/cam" // 默認(rèn)路徑
#define CAM_CONFFILE "/cam/filecon"//圖片文件控制管理文件名
#define CAM_OPTION_FILE "/cam/option" //屬性文件
/* 模塊內(nèi)部使用的結(jié)構(gòu)體 */
// 每個(gè)圖片文件信息
typedef struct
{
int jpg_type; // jpg圖片分辨率
int size; // 圖片大小
char flag; // 記錄是否為空,0 表示記錄為空
char file_name[MAX_CAM_NAME]; // 用戶定義的文件名
}Flash_CAMFile;
// 圖片文件信息
typedef struct
{
int capacity; // 當(dāng)前ffs里所有圖片文件容量之和
int file_sum; // 文件數(shù)量
char index[MAX_CAM_FILE]; // cam_file的索引表, 以用戶拍攝順序?yàn)樗饕? Flash_CAMFile cam_file[MAX_CAM_FILE]; // 文件信息數(shù)組
}Flash_CAM;
// camera需保存的參數(shù)
typedef struct
{
CAMU16 m_nCurSize;
CAMU16 m_nJPEGQFactor;
int melody;
}Flash_CAM_OPTION;
typedef struct{
T_MMI_CONTROL mmi_control;
T_MFW_HND parent_win;
T_MFW_HND win;
T_MFW_HND kbd;
UBYTE frame_index;
}CAM_OSD;
CAM_OSD Cam_osd_data;
/* 模塊函數(shù)聲明 */
static int IsCamFfs_Full(int newfile);
static int Add_One_Record(char *name, unsigned char *pPic, int size/*, int jpgtype*/);
static int Delete_One_Record(int index);
static int Delete_All(void);
/* 全局變量的定義 */
Flash_CAM cam_control; //與ffs里圖片文件控制管理文件同步的數(shù)組
Flash_CAM_OPTION cam_option;
/*
* 描述: camera 需要用到的文件系統(tǒng)的初始化,將ffs內(nèi)容讀到變量cam_control
* 若目錄為空,就創(chuàng)建目錄及文件
* 返回: 0:成功
*/
int Cam_Ffs_Init()
{
T_FFS_DIR dir; // no use to user
int status; // 返回值
T_FFS_STAT s; // ffs api 需要
/* 創(chuàng)建目錄 */
status = ffs_opendir(CAM_FATH, &dir);
TRACE(("ffs_opendir: %d", status));
if(status <= EFFS_OK) // 目錄不存在
{
status = ffs_mkdir(CAM_FATH);
TRACE(("ffs_mkdir: %d", status));
}
/* 讀數(shù)據(jù)到cam_control */
status = ffs_stat(CAM_CONFFILE, &s);
TRACE(("ffs_stat(CAM_CONFFILE, s): %d", status));
if(status != EFFS_NOTFOUND) // 文件已存在,讀數(shù)據(jù)
{
status = ffs_fread(CAM_CONFFILE, &cam_control, sizeof(Flash_CAM));
TRACE(("ffs_fread return:%d", status));
}
else // 創(chuàng)建一個(gè)初始化文件
{
memset(&cam_control, 0, sizeof(Flash_CAM));
status = ffs_fwrite(CAM_CONFFILE, &cam_control, sizeof(Flash_CAM));
TRACE(("ffs_fwrite return:%d", status));
}
/* 讀數(shù)據(jù)到cam_option */
status = ffs_stat(CAM_OPTION_FILE, &s);
TRACE(("ffs_stat(CAM_CONFFILE, s): %d", status));
if(status != EFFS_NOTFOUND) // 文件已存在,讀數(shù)據(jù)
{
status = ffs_fread(CAM_OPTION_FILE, &cam_option, sizeof(Flash_CAM_OPTION));
TRACE(("ffs_fread return:%d", status));
CamExt.m_nCurSize = cam_option.m_nCurSize;
CamExt.m_nJPEGQFactor = cam_option.m_nJPEGQFactor;
}
else // 創(chuàng)建一個(gè)初始化文件
{
memset(&cam_control, 0, sizeof(Flash_CAM));
status = ffs_fwrite(CAM_OPTION_FILE, &cam_option, sizeof(Flash_CAM_OPTION));
TRACE(("ffs_fwrite return:%d", status));
}
return 1;
}
/*
* 描述: 判斷camera ffs空間是否已滿,包括文件數(shù)量及總大小
* 返回: 1:滿
*/
static int IsCamFfs_Full(int newfile)
{
if(cam_control.file_sum == MAX_CAM_FILE || cam_control.capacity+newfile > MAX_CAM_CAPACITY)
{
TRACE(("M2C: CamFfs Full"));
return 1;
}
else
{
TRACE(("M2C: CamFfs not Full"));
return 0;
}
}
/*
* 描述: 判斷camera ffs是否為空,刪除時(shí)用到
* 返回: 1:空
*/
static int IsCamFfs_Empty(void)
{
if(cam_control.file_sum)
return 0;
else
return 1;
}
/*
* 描述: 添加一張圖片記錄
* 返回: -1: 磁盤滿 -2: 磁盤操作有錯(cuò) 0:成功
*/
static int Add_One_Record(char * name, unsigned char * pPic, int size/*, int jpgtype*/)
{
char ffsname[20]; // ffs文件名
int i, j;
int status;
// 檢查
if(IsCamFfs_Full(size))
return -1;
// 找一個(gè)空位
i = find_One_Space();
if(i == -1)
return -1;
/* 添加一條圖片記錄 */
/* 寫ffs圖片文件 */
memset(ffsname, 0, sizeof(ffsname));
sprintf(ffsname, "%s/%02d.jpg", CAM_FATH, i);
status = ffs_fwrite(ffsname, pPic, size);
TRACE(("ffs_fwrite return:%d", status));
if(status != EFFS_OK)
return -2;
/* 更新 cam_control 數(shù)據(jù) */
cam_control.index[cam_control.file_sum] = i;
cam_control.cam_file[i].size = size;
// cam_control.cam_file[i].jpg_type = jpgtype; //Marked by Cathy
memcpy(cam_control.cam_file[i].file_name, name, MAX_CAM_NAME);
cam_control.cam_file[i].flag = 1;
cam_control.file_sum++;
cam_control.capacity += size;
status = ffs_fwrite(CAM_CONFFILE, &cam_control, sizeof(Flash_CAM));
TRACE(("ffs_fwrite return:%d", status));
if(status != EFFS_OK)
return -2;
return 0;
}
/*
* 描述: 刪除一張圖片
* 參數(shù): 索引index: 0 - cam_control.file_sum
* 返回: 0:成功
*/
static int Delete_One_Record(int index)
{
int i;
int file_pos; // 要?jiǎng)h除的cam_file文件序號(hào)
char ffsname[20]; // ffs文件名
int status;
file_pos = cam_control.index[index];
/* 修改索引表 */
for(i=0; i<MAX_CAM_FILE-index-1; i++)
cam_control.index[index+i] = cam_control.index[index+i+1];
/* 刪除圖片文件 */
cam_control.cam_file[file_pos].flag = 0;
memset(ffsname, 0, sizeof(ffsname));
sprintf(ffsname, "%s/%02d.jpg", CAM_FATH, file_pos);
status = ffs_remove(ffsname);
TRACE(("ffs_remove return:%d", status));
/* 修改總?cè)萘考皥D片數(shù)量 */
cam_control.capacity -= cam_control.cam_file[file_pos].size;
cam_control.file_sum--;
/* 寫ffs操作 */
status = ffs_fwrite(CAM_CONFFILE, &cam_control, sizeof(Flash_CAM));
TRACE(("ffs_fwrite return:%d", status));
return 0;
}
/*
* 描述: 刪除所有圖片文件
* 返回: 0:成功
*/
static int Delete_All(void)
{
int i;
int status;
char ffsname[20]; // ffs文件名
/* 刪除所有圖片文件 */
for(i=0; i<cam_control.file_sum; i++)
{
memset(ffsname, 0, sizeof(ffsname));
sprintf(ffsname, "%s/%02d.jpg", CAM_FATH, cam_control.index[i]);
status = ffs_remove(ffsname);
TRACE(("ffs_remove return:%d", status));
}
/* 初始化控制文件 */
memset(&cam_control, 0, sizeof(Flash_CAM));
status = ffs_fwrite(CAM_CONFFILE, &cam_control, sizeof(Flash_CAM));
TRACE(("ffs_fwrite return:%d", status));
return 0;
}
/*
* 描述: 找到一個(gè)cam_control.cam_file 里的空位
* 返回: -1:沒有空間 其他:索引位置
*/
int find_One_Space()
{
int i;
for(i=0; i<MAX_CAM_FILE; i++)
{
if(cam_control.cam_file[i].flag == 0)
return i;
}
return -1;
}
/***********************************************************************************
*
* 模塊: 驅(qū)動(dòng)接口模塊
*
* 描述: 提供給mmi驅(qū)動(dòng)的接口
*
* 歷史: 2004.7.1 WYJ 創(chuàng)建
*
***********************************************************************************/
/* 設(shè)置Camera狀態(tài) */
#define M2C_START_PREVIEW 1 // 開始預(yù)覽
#define M2C_STOP_PREVIEW 2 // 停止預(yù)覽
#define M2C_CAPTURE 3 // 捕獲一幅圖片
#define M2C_SWITCH_OFF 4 // 關(guān)camera
#define M2C_SWITCH_ON 5 // 開camera
/* 對(duì)底層進(jìn)行操作 */
Boolean CaptureJpeg(void); //added by cathy
static int M2C_Set_Camera_State(int state);
static int M2C_Disp_Saved_Pic(int index);
static int M2C_Disp_Captured_Pic(void);
static int M2C_Get_Captured_Size(void);
static int M2C_Get_Captured_Pic(unsigned char *p/*, int size*/);
static void M2C_Control_Refresh(int flag);
/*
* 描述: 調(diào)用底層接口,對(duì)camera狀態(tài)進(jìn)行操作
* 返回: 1: 成功
*/
static int M2C_Set_Camera_State(int state)
{
PREVIEWINFO prvinfo;
char name[] = {'P','h','o','t','o','\0'};
int i;
UINT32 addr1,addr2;
switch(state)
{
case M2C_SWITCH_ON:
TRACE(("M2C: switch on"));
//Camera_OnEnterCamera(); //Marked by Cathy
return 1;
case M2C_START_PREVIEW:
TRACE(("M2C: start preview"));
//Camera_PreviewOn(); //Marked by Cathy
// Overlay_Windows_Update(0,0,0,0,0);
CamPreview_On();
//end cathy
// M2C_Control_Refresh(R2D_REFRESH_DISABLE);
return 1;
case M2C_STOP_PREVIEW:
TRACE(("M2C: stop preview"));
// Camera_OnExitCamera(); //Marked by Cathy
CamPreview_Off();
Exit_Camera_Mode();
// M2C_Control_Refresh(R2D_REFRESH_ENABLE);
return 1;
case M2C_CAPTURE:
TRACE(("M2C: start capture"));
//Camera_StillCapture(); //Marked by Cathy
Camera_OnCapture();
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -