📄 cameramodule.cpp
字号:
cam_start_finder(CAM_object* self, PyObject *args)
{
PyObject* c;
TInt xSize = 0;
TInt ySize = 0;
if (!PyArg_ParseTuple(args, "O(ii)", &c, &xSize, &ySize))
return NULL;
if (c == Py_None)
c = NULL;
else if (!PyCallable_Check(c)) {
PyErr_SetString(PyExc_TypeError, "callable expected");
return NULL;
}
Py_XINCREF(c);
self->myCallBack.iCb = c;
self->callBackSet = ETrue;
self->camera->SetCallBack(self->myCallBack);
Py_BEGIN_ALLOW_THREADS
self->camera->StartViewFinder(xSize, ySize);
Py_END_ALLOW_THREADS
Py_INCREF(Py_None);
return Py_None;
}
/*
* Stop view finder.
*/
extern "C" PyObject *
cam_stop_finder(CAM_object* self, PyObject /**args*/)
{
if (self->callBackSet) {
Py_BEGIN_ALLOW_THREADS
self->camera->StopViewFinder();
Py_END_ALLOW_THREADS
self->camera->UnSetCallBack();
Py_XDECREF(self->myCallBack.iCb);
self->callBackSet = EFalse;
}
Py_INCREF(Py_None);
return Py_None;
}
/*
* Returns the image modes.
*/
extern "C" PyObject *
cam_image_modes(CAM_object* self)
{
return Py_BuildValue("i", self->camera->GetImageModes());
}
/*
* Returns the maximum image size (camera internal).
*/
extern "C" PyObject *
cam_max_image_size(CAM_object* self)
{
return Py_BuildValue("i", self->camera->GetImageSizeMax());
}
/*
* Returns the image size possible with specified color mode and index.
*/
extern "C" PyObject *
cam_image_size(CAM_object* self, PyObject *args)
{
TInt mode;
TInt index;
if (!PyArg_ParseTuple(args, "ii", &mode, &index))
return NULL;
TSize size(0, 0);
self->camera->GetImageSize(size, index, static_cast<CCamera::TFormat>(mode));
return Py_BuildValue("(ii)", size.iWidth, size.iHeight);
}
/*
* Returns the maximum digital zoom supported in the device.
*/
extern "C" PyObject *
cam_max_zoom(CAM_object* self)
{
return Py_BuildValue("i", self->camera->GetMaxZoom());
}
/*
* Returns the flash modes (in bitfield) supported in the device.
*/
extern "C" PyObject *
cam_flash_modes(CAM_object* self)
{
return Py_BuildValue("i", self->camera->GetFlashModes());
}
/*
* Returns the exposure modes (in bitfield) supported in the device.
*/
extern "C" PyObject *
cam_exposure_modes(CAM_object* self)
{
return Py_BuildValue("i", self->camera->GetExpModes());
}
/*
* Returns the white balance modes (in bitfield) supported in the device.
*/
extern "C" PyObject *
cam_white_modes(CAM_object* self)
{
return Py_BuildValue("i", self->camera->GetWhiteModes());
}
/*
* Returns the available cameras.
*/
extern "C" PyObject *
cam_cameras_available(CAM_object* self)
{
return Py_BuildValue("i", CCamera::CamerasAvailable());
}
/*
* Returns the camera handle.
*/
extern "C" PyObject *
cam_handle(CAM_object* self)
{
return Py_BuildValue("i", self->camera->GetHandle());
}
/*
* Return whether there is a photo request ongoing.
*/
extern "C" PyObject *
cam_taking_photo(CAM_object* self)
{
return Py_BuildValue("i", self->camera->TakingPhoto());
}
/*
* Return whether the view finder is on.
*/
extern "C" PyObject *
cam_finder_on(CAM_object* self)
{
return Py_BuildValue("i", self->camera->ViewFinderOn());
}
/*
* Release the camera for other process to use.
*/
extern "C" PyObject *
cam_release(CAM_object* self)
{
self->camera->Release();
Py_INCREF(Py_None);
return Py_None;
}
//////////////TYPE SET CAMERA
extern "C" {
static const PyMethodDef cam_methods[] = {
{"take_photo", (PyCFunction)cam_take_photo, METH_VARARGS | METH_KEYWORDS, NULL},
{"start_finder", (PyCFunction)cam_start_finder, METH_VARARGS, NULL},
{"stop_finder", (PyCFunction)cam_stop_finder, METH_NOARGS, NULL},
{"image_modes", (PyCFunction)cam_image_modes, METH_NOARGS, NULL},
{"max_image_size", (PyCFunction)cam_max_image_size, METH_NOARGS, NULL},
{"image_size", (PyCFunction)cam_image_size, METH_VARARGS, NULL},
{"max_zoom", (PyCFunction)cam_max_zoom, METH_NOARGS, NULL},
{"flash_modes", (PyCFunction)cam_flash_modes, METH_NOARGS, NULL},
{"exposure_modes", (PyCFunction)cam_exposure_modes, METH_NOARGS, NULL},
{"white_balance_modes", (PyCFunction)cam_white_modes, METH_NOARGS, NULL},
{"cameras_available", (PyCFunction)cam_cameras_available, METH_NOARGS, NULL},
{"handle", (PyCFunction)cam_handle, METH_NOARGS, NULL},
{"taking_photo", (PyCFunction)cam_taking_photo, METH_NOARGS, NULL},
{"finder_on", (PyCFunction)cam_finder_on, METH_NOARGS, NULL},
{"release", (PyCFunction)cam_release, METH_NOARGS, NULL},
{NULL, NULL, 0 , NULL} /* sentinel */
};
static PyObject *
cam_getattr(CAM_object *op, char *name)
{
return Py_FindMethod((PyMethodDef*)cam_methods, (PyObject *)op, name);
}
static const PyTypeObject c_cam_type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"_camera.Camera", /*tp_name*/
sizeof(CAM_object), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)cam_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)cam_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
//////////////TYPE SET VIDEO CAMERA
static const PyMethodDef vid_methods[] = {
{"start_record", (PyCFunction)vid_start_record, METH_VARARGS, NULL},
{"stop_record", (PyCFunction)vid_stop_record, METH_NOARGS, NULL},
{NULL, NULL, 0 , NULL} /* sentinel */
};
static PyObject *
vid_getattr(VID_object *op, char *name)
{
return Py_FindMethod((PyMethodDef*)vid_methods, (PyObject *)op, name);
}
static const PyTypeObject c_vid_type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"_camera.Video", /*tp_name*/
sizeof(VID_object), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)vid_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)vid_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
} //extern C
//////////////INIT
extern "C" {
static const PyMethodDef camera_methods[] = {
{"Camera", (PyCFunction)new_cam_object, METH_VARARGS, NULL},
{"Video", (PyCFunction)new_vid_object, METH_VARARGS, NULL},
{NULL, NULL} /* sentinel */
};
DL_EXPORT(void) initcamera(void)
{
PyTypeObject* cam_type = PyObject_New(PyTypeObject, &PyType_Type);
*cam_type = c_cam_type;
cam_type->ob_type = &PyType_Type;
PyTypeObject* vid_type = PyObject_New(PyTypeObject, &PyType_Type);
*vid_type = c_vid_type;
vid_type->ob_type = &PyType_Type;
SPyAddGlobalString("CAMType", (PyObject*)cam_type);
SPyAddGlobalString("VIDType", (PyObject*)vid_type);
PyObject *m, *d;
m = Py_InitModule("_camera", (PyMethodDef*)camera_methods);
d = PyModule_GetDict(m);
PyDict_SetItemString(d,"EColor4K", PyInt_FromLong(CCamera::EFormatFbsBitmapColor4K));
PyDict_SetItemString(d,"EColor64K", PyInt_FromLong(CCamera::EFormatFbsBitmapColor64K));
PyDict_SetItemString(d,"EColor16M", PyInt_FromLong(CCamera::EFormatFbsBitmapColor16M));
PyDict_SetItemString(d,"EFormatExif", PyInt_FromLong(CCamera::EFormatExif));
PyDict_SetItemString(d,"EFormatJpeg", PyInt_FromLong(CCamera::EFormatJpeg));
PyDict_SetItemString(d,"EFlashNone", PyInt_FromLong(CCamera::EFlashNone));
PyDict_SetItemString(d,"EFlashAuto", PyInt_FromLong(CCamera::EFlashAuto));
PyDict_SetItemString(d,"EFlashForced", PyInt_FromLong(CCamera::EFlashForced));
PyDict_SetItemString(d,"EFlashFillIn", PyInt_FromLong(CCamera::EFlashFillIn));
PyDict_SetItemString(d,"EFlashRedEyeReduce", PyInt_FromLong(CCamera::EFlashRedEyeReduce));
PyDict_SetItemString(d,"EExposureAuto", PyInt_FromLong(CCamera::EExposureAuto));
PyDict_SetItemString(d,"EExposureNight", PyInt_FromLong(CCamera::EExposureNight));
PyDict_SetItemString(d,"EExposureBacklight", PyInt_FromLong(CCamera::EExposureBacklight));
PyDict_SetItemString(d,"EExposureCenter", PyInt_FromLong(CCamera::EExposureCenter));
PyDict_SetItemString(d,"EWBAuto", PyInt_FromLong(CCamera::EWBAuto));
PyDict_SetItemString(d,"EWBDaylight", PyInt_FromLong(CCamera::EWBDaylight));
PyDict_SetItemString(d,"EWBCloudy", PyInt_FromLong(CCamera::EWBCloudy));
PyDict_SetItemString(d,"EWBTungsten", PyInt_FromLong(CCamera::EWBTungsten));
PyDict_SetItemString(d,"EWBFluorescent", PyInt_FromLong(CCamera::EWBFluorescent));
PyDict_SetItemString(d,"EWBFlash", PyInt_FromLong(CCamera::EWBFlash));
// video
PyDict_SetItemString(d,"EOpenComplete", PyInt_FromLong(CVideoCamera::EOpenComplete));
PyDict_SetItemString(d,"EPrepareComplete", PyInt_FromLong(CVideoCamera::EPrepareComplete));
PyDict_SetItemString(d,"ERecordComplete", PyInt_FromLong(CVideoCamera::ERecordComplete));
}
} /* extern "C" */
#ifndef EKA2
GLDEF_C TInt E32Dll(TDllReason)
{
return KErrNone;
}
#endif /*EKA2*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -