|
|
|
@ -160,6 +160,128 @@ void CPhoneDevice::CPhoneCamera::onDisconnected(ACameraDevice* device)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CPhoneDevice::CJpegCamera::CJpegCamera(CPhoneDevice* dev, int32_t width, int32_t height, const std::string& path, const NdkCamera::CAMERA_PARAMS& params) : CPhoneDevice::CPhoneCamera(dev, width, height, params), m_path(path)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPhoneDevice::CJpegCamera::onImageAvailable(AImageReader* reader)
|
|
|
|
|
{
|
|
|
|
|
ALOGD("onImageAvailable %p", reader);
|
|
|
|
|
|
|
|
|
|
AImage* image = 0;
|
|
|
|
|
media_status_t mstatus = AImageReader_acquireLatestImage(reader, &image);
|
|
|
|
|
|
|
|
|
|
if (mstatus != AMEDIA_OK)
|
|
|
|
|
{
|
|
|
|
|
// error
|
|
|
|
|
// https://stackoverflow.com/questions/67063562
|
|
|
|
|
if (mstatus != AMEDIA_IMGREADER_NO_BUFFER_AVAILABLE)
|
|
|
|
|
{
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "AImageReader_acquireLatestImage error: %d", mstatus);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t* y_data = 0;
|
|
|
|
|
int y_len = 0;
|
|
|
|
|
#if 0
|
|
|
|
|
if (!lightDetected)
|
|
|
|
|
{
|
|
|
|
|
AImage_getPlaneData(image, 0, &y_data, &y_len);
|
|
|
|
|
|
|
|
|
|
lightDetected = true;
|
|
|
|
|
|
|
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
|
uint64_t avgY = std::reduce(y_data, y_data + y_len, 0);
|
|
|
|
|
#else
|
|
|
|
|
uint64_t avgY = std::accumulate(y_data, y_data + y_len, 0);
|
|
|
|
|
#endif
|
|
|
|
|
avgY = avgY / (uint64_t)y_len;
|
|
|
|
|
mResult.avgY = avgY;
|
|
|
|
|
mFinalResult.avgY = avgY;
|
|
|
|
|
#if 1
|
|
|
|
|
if (avgY < 50)
|
|
|
|
|
{
|
|
|
|
|
if (m_params.autoExposure)
|
|
|
|
|
{
|
|
|
|
|
uint8_t aeMode = ACAMERA_CONTROL_AE_MODE_OFF;
|
|
|
|
|
camera_status_t status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_MODE, 1, &aeMode);
|
|
|
|
|
|
|
|
|
|
int32_t sensitivity = (avgY < 5) ? 2000 : (mResult.sensitivity * 60.0 / avgY);
|
|
|
|
|
status = ACaptureRequest_setEntry_i32(capture_request, ACAMERA_SENSOR_SENSITIVITY, 1, &sensitivity);
|
|
|
|
|
|
|
|
|
|
int64_t exposureTime = (avgY < 5) ? 200 * 1000000 : (mResult.exposureTime * 120.0 / avgY);
|
|
|
|
|
status = ACaptureRequest_setEntry_i64(capture_request, ACAMERA_SENSOR_EXPOSURE_TIME, 1, &exposureTime);
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_WARNING, "YUV Light: %u EXPO:%lld => %lld ISO: %u => %u", (uint32_t)avgY,
|
|
|
|
|
mResult.exposureTime, exposureTime, mResult.sensitivity, sensitivity);
|
|
|
|
|
}
|
|
|
|
|
AImage_delete(image);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (m_imagesCaptured == ~0 || m_imagesCaptured != EXPECTED_CAPTURE_IDX)
|
|
|
|
|
{
|
|
|
|
|
// XYLOG(XYLOG_SEVERITY_DEBUG, "m_imagesCaptured=%u wait for next image", m_imagesCaptured);
|
|
|
|
|
// Not Ready Or Taken
|
|
|
|
|
AImage_delete(image);
|
|
|
|
|
if (m_imagesCaptured != ~0)
|
|
|
|
|
{
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "Skip Image index=%u", m_imagesCaptured);
|
|
|
|
|
m_imagesCaptured++;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO, "Photo Taken: AES=%u AFS=%u AWBS=%u", (uint32_t)mFinalResult.aeState, (uint32_t)mFinalResult.awbState, (uint32_t)mFinalResult.afState);
|
|
|
|
|
|
|
|
|
|
mFinalResult.duration = GetMicroTimeStamp() - m_startTime;
|
|
|
|
|
|
|
|
|
|
int32_t format;
|
|
|
|
|
AImage_getFormat(image, &format);
|
|
|
|
|
|
|
|
|
|
if (format == AIMAGE_FORMAT_JPEG)
|
|
|
|
|
{
|
|
|
|
|
int planeCount;
|
|
|
|
|
media_status_t status = AImage_getNumberOfPlanes(image, &planeCount);
|
|
|
|
|
|
|
|
|
|
// LOGI("Info: getNumberOfPlanes() planeCount = %d", planeCount);
|
|
|
|
|
if (!(status == AMEDIA_OK && planeCount == 1))
|
|
|
|
|
{
|
|
|
|
|
// LOGE("Error: getNumberOfPlanes() planeCount = %d", planeCount);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t *data = nullptr;
|
|
|
|
|
int len = 0;
|
|
|
|
|
AImage_getPlaneData(image, 0, &data, &len);
|
|
|
|
|
|
|
|
|
|
FILE *file = fopen(m_path.c_str(), "wb");
|
|
|
|
|
if (file && data && len)
|
|
|
|
|
{
|
|
|
|
|
fwrite(data, 1, len, file);
|
|
|
|
|
fclose(file);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (file)
|
|
|
|
|
fclose(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AImage_delete(image);
|
|
|
|
|
m_imagesCaptured ++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t CPhoneDevice::CJpegCamera::getOutputFormat() const
|
|
|
|
|
{
|
|
|
|
|
return AIMAGE_FORMAT_JPEG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode) : mCameraPowerCount(0), mOtgCount(0), mVersionCode(versionCode)
|
|
|
|
|
{
|
|
|
|
|
mCamera = NULL;
|
|
|
|
@ -1209,6 +1331,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
|
|
|
|
|
if (mPhotoInfo.mediaType == 0)
|
|
|
|
|
{
|
|
|
|
|
mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params);
|
|
|
|
|
// mCamera = new CJpegCamera(this, photoInfo.width, photoInfo.height, mPath, params);
|
|
|
|
|
if (mCamera->open(to_string(mPhotoInfo.cameraId)) == 0)
|
|
|
|
|
{
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: Succeeded to OpenCamera CH=%u PR=%X PHOTOID=%u", (unsigned int)photoInfo.channel, (unsigned int)photoInfo.preset, photoInfo.photoId);
|
|
|
|
@ -1578,9 +1701,9 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
|
|
|
|
|
DrawOutlineText(ft2, mat, it->text, pt, fontSize, scalarWhite, thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector <int> params;
|
|
|
|
|
std::vector<int> params;
|
|
|
|
|
params.push_back(cv::IMWRITE_JPEG_QUALITY);
|
|
|
|
|
params.push_back(mPhotoInfo.quality);
|
|
|
|
|
params.push_back((int)((uint32_t)mPhotoInfo.quality));
|
|
|
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
std::string fullPath = endsWith(mPath, ".jpg") ? mPath : (mPath + CTerminal::BuildPhotoFileName(mPhotoInfo));
|
|
|
|
@ -1872,3 +1995,12 @@ int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPhoneDevice::OpenSensors()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPhoneDevice::CloseSensors()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|