展会信息港展会大全

msm7x27a添加camera差值以及添加新拍照分辨率尺寸
来源:互联网   发布日期:2015-09-29 10:15:21   浏览:1873次  

导读:前段时间客户要求在高通7系列上加camera的差值,所以个人研究了一下这个差值的做法。首先贴上要加载的文件的地址:vendor/qcom/android-open/libcamera2/Q...

前段时间客户要求在高通7系列上加camera的差值,所以个人研究了一下这个差值的做法。

首先贴上要加载的文件的地址:

vendor/qcom/android-open/libcamera2/QualcommCameraHardware.cpp

vendor/qcom/proprietary/mm-camera/apps/appslib/snapshot.c

vendor/qcom/proprietary/mm-camera/common/mm_camera_interface.h

1.首先看mm_camera_interface.h

typedef struct {

struct camera_size_type mIn;

struct camera_size_type mOut;

int8_t mEnable;

}interpolaton_info_t;

interpolaton_info_t*p_interpolaton_info;

//添加差值结构体定义interpolaton_info_t并申请变量*p_interpolaton_info。

2. 查看QualcommCameraHardware.cpp

static interpolaton_info_tmInterpolatonInfo;//定义变量

bool QualcommCameraHardware::startCamera()

{

LOGV("startCamera E");

。。。

if (pthread_join(mDeviceOpenThread, NULL) != 0) {

LOGE("openCamera thread exit failed");

return false;

}

mCfgControl.mm_camera_query_parms(CAMERA_PARM_PICT_SIZE, (void **)&picture_sizes, &PICTURE_SIZE_COUNT);

#ifdefHAVE_SW_CAM_IMAGE_INTERPOLATION

/* max pict size supported by cureent yuv sensor is 5M,how to change?

*eg:if(picture_sizes->width == 2592 && picture_sizes->height == 1944)---->8MP

*if(picture_sizes->width == 3200 && picture_sizes->height == 2400)---->12MP

*......

*and so on

*{ 4000, 3000}, // 12MP

*{ 3200, 2400}, // 8MP

*{ 2592, 1944}, // 5MP

*{ 2048, 1536}, // 3MP QXGA

*{ 1920, 1080}, //HD1080

*{ 1600, 1200}, // 2MP UXGA

*{ 1280, 768}, //WXGA

*{ 1280, 720}, //HD720

*{ 1024, 768}, // 1MP XGA

*{ 800, 600}, //SVGA

*{ 800, 480}, // WVGA

*{ 640, 480}, // VGA

*{ 352, 288}, //CIF

*{ 320, 240}, // QVGA

*{ 176, 144} // QCIF

*

*/

memset(&mInterpolatonInfo,0,sizeof(interpolaton_info_t));

if(picture_sizes->width == 640 &&picture_sizes->height == 480)//这里是添加差值的起步点,从拍照640x480开始差值,即30万开始。

{

LOGE("zzb change the supported pict sizes before(%d,%d)",picture_sizes->width,picture_sizes->height);

mInterpolatonInfo.mIn = *picture_sizes;

picture_sizes -= 1;//把拍照的指针向前移一位(根据要求可以移自己想要的位置)

PICTURE_SIZE_COUNT += 1;//这个是和上面的picture_sizes相对应的

mInterpolatonInfo.mOut = *picture_sizes;//这个是差值的输出分辨率

mInterpolatonInfo.mEnable = false;

LOGE("zm change the supported pict sizes after(%d,%d)",picture_sizes->width,picture_sizes->height);

}

#endif

if ((picture_sizes == NULL) || (!PICTURE_SIZE_COUNT)) {

LOGE("startCamera X: could not get snapshot sizes");

return false;

}

。。。

}// END startCamera()

bool QualcommCameraHardware::initImageEncodeParameters(int size)

{

LOGV("%s: E", __FUNCTION__);

memset(&mImageEncodeParms, 0, sizeof(encode_params_t));

int jpeg_quality = mParameters.getInt("jpeg-quality");

bool ret;

#ifdef HAVE_SW_CAM_IMAGE_INTERPOLATION

//zm

mImageEncodeParms.p_interpolaton_info = &mInterpolatonInfo;

#endif

if (jpeg_quality >= 0) {

LOGV("initJpegParameters, current jpeg main img quality =%d",

jpeg_quality);

//Application can pass quality of zero

//when there is no back sensor connected.

//as jpeg quality of zero is not accepted at

//camera stack, pass default value.

if(jpeg_quality == 0) jpeg_quality = 85;

mImageEncodeParms.quality = jpeg_quality;

ret = native_set_parms(CAMERA_PARM_JPEG_MAINIMG_QUALITY, sizeof(int), &jpeg_quality);

if(!ret){

LOGE("initJpegParametersX: failed to set main image quality");

return false;

}

}

。。。

}//ENDinitImageEncodeParameters(int size)

CameraParameters QualcommCameraHardware::getParameters() const

{

LOGV("getParameters: EX");

#ifdef HAVE_SW_CAM_IMAGE_INTERPOLATION

//zm

LOGE("zm:getParameters:state%d,in(%d,%d),out(%d,%d)",mInterpolatonInfo.mEnable,mInterpolatonInfo.mIn.width,mInterpolatonInfo.mIn.height,mInterpolatonInfo.mOut.width,mInterpolatonInfo.mOut.height);

if(mInterpolatonInfo.mEnable)

{

CameraParameters para = mParameters;

para.setPictureSize(mInterpolatonInfo.mOut.width,mInterpolatonInfo.mOut.height);//设置为输出差值分辨率的值

return para;

}

#endif

return mParameters;

}//ENDgetParameters()

status_t QualcommCameraHardware::setPictureSize(const CameraParameters& params)

{

int width, height;

params.getPictureSize(&width, &height);

LOGV("requested picture size %d x %d", width, height);

#ifdef HAVE_SW_CAM_IMAGE_INTERPOLATION

LOGE("zm requested picture size %d x %d", width, height);

//zm

//support 1MP XGA-> SVGA -> WVGAmodify by zhangmin 2013.4.25 {begain

if(width == 1024 && height == 768)//根据要求菜单的拍照分辨率导出差值分辨率的值

//if(mInterpolatonInfo.mOut.width == width && mInterpolatonInfo.mOut.height == height)

{

mInterpolatonInfo.mEnable = true;

width = mInterpolatonInfo.mIn.width;//这个是基值(即差值的起始点)

height = mInterpolatonInfo.mIn.height;

mInterpolatonInfo.mOut.width = 1024;//这个是输出要差值的分辨率

mInterpolatonInfo.mOut.height = 768;

LOGE("zm chg picture size %d x %d", width, height);

}

else if(width == 1280 && height == 960)// output 1280x960

{

mInterpolatonInfo.mEnable = true;

width = mInterpolatonInfo.mIn.width;

height = mInterpolatonInfo.mIn.height;

mInterpolatonInfo.mOut.width = 1280;

mInterpolatonInfo.mOut.height = 960;

LOGE("zm chg picture size %d x %d", width, height);

}

else if(width == 800 && height == 600)

{

mInterpolatonInfo.mEnable = true;

width = mInterpolatonInfo.mIn.width;

height = mInterpolatonInfo.mIn.height;

mInterpolatonInfo.mOut.width = 800;

mInterpolatonInfo.mOut.height = 600;

LOGE("zm 600 chg picture size %d x %d", width, height);

}

else if(width == 800 && height == 480)

{

mInterpolatonInfo.mEnable = true;

width = mInterpolatonInfo.mIn.width;

height = mInterpolatonInfo.mIn.height;

mInterpolatonInfo.mOut.width = 800;

mInterpolatonInfo.mOut.height = 480;

LOGE("zm 480 chg picture size %d x %d", width, height);

}

else

{

mInterpolatonInfo.mEnable = false;

}

//support 1MP XGA-> SVGA -> WVGAmodify by zhangmin 2013.4.25 }end

#endif

// Validate the picture size

for (int i = 0; i < supportedPictureSizesCount; ++i) {

if (width == picture_sizes_ptr[i].width

&& height == picture_sizes_ptr[i].height) {

mParameters.setPictureSize(width, height);

mDimension.picture_width = width;

mDimension.picture_height = height;

return NO_ERROR;

}

}

。。。

}END setPictureSize(const CameraParameters& params)

3. 添加snapshot.c//主要是差值图像的编码

void* encode_thread_func(void *data)

{

mm_camera_status_t status = MM_CAMERA_SUCCESS;

snapshot_context_t* context = (snapshot_context_t *)data;

struct msm_frame* main_frame = NULL;

struct msm_frame* thumb_frame = NULL;

。。。

pthread_mutex_lock(&encode_thread_mutex);

if (context->encode_thread_exit) {

pthread_mutex_unlock(&encode_thread_mutex);

CDBG("%s encode_thread_exit", __func__);

goto encode_func_end;

}

#ifdef HAVE_SW_CAM_IMAGE_INTERPOLATION

//zm

{

common_crop_t * crop1 = (common_crop_t *)main_frame->cropinfo;

CDBG("zzb:buffer %d vaddr %p \n", main_frame->path,(void *)main_frame->buffer);

CDBG("zzb: Scaling params thumb in1_w %d in1_h %d out1_w %d out1_h %d "

"main_img in2_w %d in2_h %d out2_w %d out2_h %d\n",

crop1->in1_w, crop1->in1_h,

crop1->out1_w, crop1->out1_h,

crop1->in2_w, crop1->in2_h,

crop1->out2_w, crop1->out2_h);

}

if(main_frame != NULL && context->encode_params.p_interpolaton_info != NULL && context->encode_params.p_interpolaton_info->mEnable)

{

common_crop_t * crop = (common_crop_t *)main_frame->cropinfo;

CDBG("zzb change the crop info");

if(crop->in2_w==0 && crop->in2_h == 0)

{

crop->in2_w = context->encode_params.p_interpolaton_info->mIn.width;

crop->in2_h = context->encode_params.p_interpolaton_info->mIn.height;

}

crop->out2_w = context->encode_params.p_interpolaton_info->mOut.width;

crop->out2_h = context->encode_params.p_interpolaton_info->mOut.height;

}

#endif

#ifdef_TARGET_7x2x_

status = snapshot_jpeg_encode(context, main_frame, thumb_frame);

#else

status = snapshot_jpeg_encode(context, main_frame);

#endif

。。。

}// Endencode_thread_func(void *data)

这样整个差值添加的就做完了,美妙的差值就实现了!嘿嘿。。。

上面实现了camera的差值,现在又有一个难题,什么呢?还不是客户成天没事做想些东西折腾我们苦逼的工程师,

比如我们差值到720p的了(1280x720),客户觉得预览的黑边太大,要求拍照分辨率为(1280x960)这个是130万的。

肿么办?现在现有的如下

static struct camera_size_type default_picture_sizes[] = {

{ 4000, 3000}, // 12MP

{ 3200, 2400}, // 8MP

{ 2592, 1944}, // 5MP

{ 2048, 1536}, // 3MP QXGA

{ 1920, 1080}, //HD1080

{ 1600, 1200}, // 2MP UXGA

{ 1280, 768}, //WXGA

{ 1280, 720}, //HD720

{ 1024, 768}, // 1MP XGA

{ 800, 600}, //SVGA

{ 800, 480}, // WVGA

{ 640, 480}, // VGA

{ 352, 288}, //CIF

{ 320, 240}, // QVGA

{ 176, 144} // QCIF

};

现在只有1280x768 和 1600x1200,中间少了1280x960。所以我们又要满足人家要求呗,添加。。。

首先在这个数组里面添加一项 1280x960//在文件vendor/qcom/properietary/mm-camera/apps/appslib/mm_camera_inerface.c

然后在packages/apps/Camera/res/values/文件夹下修改arrays.xmlstrings.xml

这两个问价属于camera的菜单项,需要在这里把菜单加进去。

首先修改arrays.xml

红色代表新添加的菜单

<!-- Camera Preferences Picture size dialog box entries -->

<string-array name="pref_camera_picturesize_entries" translatable="false">

<!-- TODO: Change to a better name of the preference.

The first element of the array sould be

"pref_camera_picturesize_entry_2592x1944". However, we are too

late for the translation. Since we show the same label as the

second item, we just use the second one instead.

-->

<item>@string/pref_camera_picturesize_entry_4000x3000</item>

<item>@string/pref_camera_picturesize_entry_3200x2400</item>

<item>@string/pref_camera_picturesize_entry_2592x1936</item>

<item>@string/pref_camera_picturesize_entry_2592x1936</item>

<item>@string/pref_camera_picturesize_entry_2592x1936</item>

<item>@string/pref_camera_picturesize_entry_2048x1536</item>

<item>@string/pref_camera_picturesize_entry_1920x1080</item>

<item>@string/pref_camera_picturesize_entry_1600x1200</item>

<item>@string/pref_camera_picturesize_entry_1280x768</item>

<item>@string/pref_camera_picturesize_entry_1280x720</item>

<item>@string/pref_camera_picturesize_entry_1024x768</item>

<item>@string/pref_camera_picturesize_entry_800x600</item>

<item>@string/pref_camera_picturesize_entry_800x480</item>

<item>@string/pref_camera_picturesize_entry_1280x960</item>

<item>@string/pref_camera_picturesize_entry_640x480</item>

<item>@string/pref_camera_picturesize_entry_352x288</item>

<item>@string/pref_camera_picturesize_entry_320x240</item>

<item>@string/pref_camera_picturesize_entry_176x144</item>

</string-array>

<!-- When launching the camera app first time, we will set the picture

size to the first one in the list that is also supported by the

driver -->

<string-array name="pref_camera_picturesize_entryvalues" translatable="false">

<item>4000x3000</item>

<item>3200x2400</item>

<item>2592x1944</item>

<item>2592x1936</item>

<item>2560x1920</item>

<item>2048x1536</item>

<item>1920x1080</item>

<item>1600x1200</item>

<item>1280x768</item>

<item>1280x720</item>

<item>1024x768</item>

<item>800x600</item>

<item>800x480</item>

<item>1280x960</item>

<item>640x480</item>

<item>352x288</item>

<item>320x240</item>

<item>176x144</item>

</string-array>

<!-- Camera Preferences Picture format dialog box entries -->

其次修改 strings.xml

红色是添加的菜单

<!-- Settings screen, Picture size dialog radio button choices -->

<string name="pref_camera_picturesize_entry_4000x3000">12M Pixels</string>

<string name="pref_camera_picturesize_entry_3200x2400">8M Pixels</string>

<string name="pref_camera_picturesize_entry_2592x1936">5M Pixels</string>

<string name="pref_camera_picturesize_entry_2048x1536">3M Pixels</string>

<string name="pref_camera_picturesize_entry_1920x1080">HD1080</string>

<string name="pref_camera_picturesize_entry_1600x1200">2M Pixels</string>

<string name="pref_camera_picturesize_entry_1280x960">1.3M Pixels</string>

<string name="pref_camera_picturesize_entry_1280x768">WXGA</string>

<string name="pref_camera_picturesize_entry_1280x720">HD720</string>

<string name="pref_camera_picturesize_entry_1024x768">1M Pixels</string>

<string name="pref_camera_picturesize_entry_800x600">SVGA</string>

<string name="pref_camera_picturesize_entry_800x480">WVGA</string>

<string name="pref_camera_picturesize_entry_640x480">VGA</string>

<string name="pref_camera_picturesize_entry_352x288">CIF</string>

<string name="pref_camera_picturesize_entry_320x240">QVGA</string>

<string name="pref_camera_picturesize_entry_176x144">QCIF</string>

这样又有一个神奇的1.3M的菜单显现在你面前。

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港