summaryrefslogtreecommitdiff
path: root/camera/CameraHalCommon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'camera/CameraHalCommon.cpp')
-rw-r--r--camera/CameraHalCommon.cpp102
1 files changed, 97 insertions, 5 deletions
diff --git a/camera/CameraHalCommon.cpp b/camera/CameraHalCommon.cpp
index 7e81a09..ff460f9 100644
--- a/camera/CameraHalCommon.cpp
+++ b/camera/CameraHalCommon.cpp
@@ -16,7 +16,8 @@
#include "CameraHal.h"
-namespace android {
+namespace Ti {
+namespace Camera {
const char CameraHal::PARAMS_DELIMITER []= ",";
@@ -46,7 +47,7 @@ void CameraHal::PPM(const char* str){
ppm.tv_sec = ppm.tv_sec * 1000000;
ppm.tv_sec = ppm.tv_sec + ppm.tv_usec - ppm_start.tv_usec;
- ALOGD("PPM: %s :%ld.%ld ms", str, ( ppm.tv_sec /1000 ), ( ppm.tv_sec % 1000 ));
+ CAMHAL_LOGI("PPM: %s :%ld.%ld ms", str, ( ppm.tv_sec /1000 ), ( ppm.tv_sec % 1000 ));
}
#elif PPM_INSTRUMENTATION_ABS
@@ -76,7 +77,7 @@ void CameraHal::PPM(const char* str){
absolute *= 1000;
absolute += ppm.tv_usec /1000;
- ALOGD("PPM: %s :%llu.%llu ms : %llu ms", str, ( elapsed /1000 ), ( elapsed % 1000 ), absolute);
+ CAMHAL_LOGI("PPM: %s :%llu.%llu ms : %llu ms", str, ( elapsed /1000 ), ( elapsed % 1000 ), absolute);
}
#endif
@@ -109,13 +110,104 @@ void CameraHal::PPM(const char* str, struct timeval* ppm_first, ...){
ppm.tv_sec = ppm.tv_sec * 1000000;
ppm.tv_sec = ppm.tv_sec + ppm.tv_usec - ppm_first->tv_usec;
- ALOGD("PPM: %s :%ld.%ld ms : %llu ms", temp_str, ( ppm.tv_sec /1000 ), ( ppm.tv_sec % 1000 ), absolute);
+ CAMHAL_LOGI("PPM: %s :%ld.%ld ms : %llu ms", temp_str, ( ppm.tv_sec /1000 ), ( ppm.tv_sec % 1000 ), absolute);
va_end(args);
}
#endif
-};
+/** Common utility function definitions used all over the HAL */
+unsigned int CameraHal::getBPP(const char* format) {
+ unsigned int bytesPerPixel;
+
+ // Calculate bytes per pixel based on the pixel format
+ if (strcmp(format, android::CameraParameters::PIXEL_FORMAT_YUV422I) == 0) {
+ bytesPerPixel = 2;
+ } else if (strcmp(format, android::CameraParameters::PIXEL_FORMAT_RGB565) == 0 ||
+ strcmp(format, android::CameraParameters::PIXEL_FORMAT_BAYER_RGGB) == 0) {
+ bytesPerPixel = 2;
+ } else if (strcmp(format, android::CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) {
+ bytesPerPixel = 1;
+ } else {
+ bytesPerPixel = 1;
+ }
+
+ return bytesPerPixel;
+}
+
+void CameraHal::getXYFromOffset(unsigned int *x, unsigned int *y,
+ unsigned int offset, unsigned int stride,
+ const char* format)
+{
+ CAMHAL_ASSERT( x && y && format && (0U < stride) );
+
+ *x = (offset % stride) / getBPP(format);
+ *y = (offset / stride);
+}
+
+const char* CameraHal::getPixelFormatConstant(const char* parametersFormat)
+{
+ const char *pixelFormat = NULL;
+
+ if ( NULL != parametersFormat ) {
+ if ( 0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_YUV422I) ) {
+ CAMHAL_LOGVA("CbYCrY format selected");
+ pixelFormat = (const char *) android::CameraParameters::PIXEL_FORMAT_YUV422I;
+ } else if ( (0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_YUV420SP)) ||
+ (0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_YUV420P)) ) {
+ // TODO(XXX): We are treating YV12 the same as YUV420SP
+ CAMHAL_LOGVA("YUV420SP format selected");
+ pixelFormat = (const char *) android::CameraParameters::PIXEL_FORMAT_YUV420SP;
+ } else if ( 0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_RGB565) ) {
+ CAMHAL_LOGVA("RGB565 format selected");
+ pixelFormat = (const char *) android::CameraParameters::PIXEL_FORMAT_RGB565;
+ } else if ( 0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_BAYER_RGGB) ) {
+ CAMHAL_LOGVA("BAYER format selected");
+ pixelFormat = (const char *) android::CameraParameters::PIXEL_FORMAT_BAYER_RGGB;
+ } else if ( 0 == strcmp(parametersFormat, android::CameraParameters::PIXEL_FORMAT_JPEG) ) {
+ CAMHAL_LOGVA("JPEG format selected");
+ pixelFormat = (const char *) android::CameraParameters::PIXEL_FORMAT_JPEG;
+ } else {
+ CAMHAL_LOGEA("Invalid format, NV12 format selected as default");
+ pixelFormat = (const char *) android::CameraParameters::PIXEL_FORMAT_YUV420SP;
+ }
+ } else {
+ CAMHAL_LOGEA("Preview format is NULL, defaulting to NV12");
+ pixelFormat = (const char *) android::CameraParameters::PIXEL_FORMAT_YUV420SP;
+ }
+
+ return pixelFormat;
+}
+
+size_t CameraHal::calculateBufferSize(const char* parametersFormat, int width, int height)
+{
+ int bufferSize = -1;
+
+ if ( NULL != parametersFormat ) {
+ if ( 0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_YUV422I) ) {
+ bufferSize = width * height * 2;
+ } else if ( (0 == strcmp(parametersFormat, android::CameraParameters::PIXEL_FORMAT_YUV420SP)) ||
+ (0 == strcmp(parametersFormat, android::CameraParameters::PIXEL_FORMAT_YUV420P)) ) {
+ bufferSize = width * height * 3 / 2;
+ } else if ( 0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_RGB565) ) {
+ bufferSize = width * height * 2;
+ } else if ( 0 == strcmp(parametersFormat, (const char *) android::CameraParameters::PIXEL_FORMAT_BAYER_RGGB) ) {
+ bufferSize = width * height * 2;
+ } else {
+ CAMHAL_LOGEA("Invalid format");
+ bufferSize = 0;
+ }
+ } else {
+ CAMHAL_LOGEA("Preview format is NULL");
+ bufferSize = 0;
+ }
+
+ return bufferSize;
+}
+
+
+} // namespace Camera
+} // namespace Ti