Merge "Camera: Destroy jpeg handle in 'encodeGrayscaleJpeg'" into qt-dev

am: 62a6173c54

Change-Id: If1225d50ab797edd0f21462739e194753ae775cd
gugelfrei
Emilian Peev 5 years ago committed by android-build-merger
commit 91c9dcb862

@ -58,8 +58,8 @@ DepthCompositeStream::DepthCompositeStream(wp<CameraDeviceBase> device,
entry = staticInfo.find(ANDROID_LENS_INTRINSIC_CALIBRATION); entry = staticInfo.find(ANDROID_LENS_INTRINSIC_CALIBRATION);
if (entry.count == 5) { if (entry.count == 5) {
mInstrinsicCalibration.reserve(5); mIntrinsicCalibration.reserve(5);
mInstrinsicCalibration.insert(mInstrinsicCalibration.end(), entry.data.f, mIntrinsicCalibration.insert(mIntrinsicCalibration.end(), entry.data.f,
entry.data.f + 5); entry.data.f + 5);
} else { } else {
ALOGW("%s: Intrinsic calibration absent from camera characteristics!", __FUNCTION__); ALOGW("%s: Intrinsic calibration absent from camera characteristics!", __FUNCTION__);
@ -323,12 +323,12 @@ status_t DepthCompositeStream::processInputFrame(const InputFrame &inputFrame) {
depthPhoto.mMaxJpegSize = maxDepthJpegSize; depthPhoto.mMaxJpegSize = maxDepthJpegSize;
// The camera intrinsic calibration layout is as follows: // The camera intrinsic calibration layout is as follows:
// [focalLengthX, focalLengthY, opticalCenterX, opticalCenterY, skew] // [focalLengthX, focalLengthY, opticalCenterX, opticalCenterY, skew]
if (mInstrinsicCalibration.size() == 5) { if (mIntrinsicCalibration.size() == 5) {
memcpy(depthPhoto.mInstrinsicCalibration, mInstrinsicCalibration.data(), memcpy(depthPhoto.mIntrinsicCalibration, mIntrinsicCalibration.data(),
sizeof(depthPhoto.mInstrinsicCalibration)); sizeof(depthPhoto.mIntrinsicCalibration));
depthPhoto.mIsInstrinsicCalibrationValid = 1; depthPhoto.mIsIntrinsicCalibrationValid = 1;
} else { } else {
depthPhoto.mIsInstrinsicCalibrationValid = 0; depthPhoto.mIsIntrinsicCalibrationValid = 0;
} }
// The camera lens distortion contains the following lens correction coefficients. // The camera lens distortion contains the following lens correction coefficients.
// [kappa_1, kappa_2, kappa_3 kappa_4, kappa_5] // [kappa_1, kappa_2, kappa_3 kappa_4, kappa_5]

@ -124,7 +124,7 @@ private:
ssize_t mMaxJpegSize; ssize_t mMaxJpegSize;
std::vector<std::tuple<size_t, size_t>> mSupportedDepthSizes; std::vector<std::tuple<size_t, size_t>> mSupportedDepthSizes;
std::vector<float> mInstrinsicCalibration, mLensDistortion; std::vector<float> mIntrinsicCalibration, mLensDistortion;
bool mIsLogicalCamera; bool mIsLogicalCamera;
void* mDepthPhotoLibHandle; void* mDepthPhotoLibHandle;
process_depth_photo_frame mDepthPhotoProcess; process_depth_photo_frame mDepthPhotoProcess;

@ -61,6 +61,13 @@ using dynamic_depth::Pose;
using dynamic_depth::Profile; using dynamic_depth::Profile;
using dynamic_depth::Profiles; using dynamic_depth::Profiles;
template<>
struct std::default_delete<jpeg_compress_struct> {
inline void operator()(jpeg_compress_struct* cinfo) const {
jpeg_destroy_compress(cinfo);
}
};
namespace android { namespace android {
namespace camera3 { namespace camera3 {
@ -118,16 +125,16 @@ status_t encodeGrayscaleJpeg(size_t width, size_t height, uint8_t *in, void *out
bool mSuccess; bool mSuccess;
} dmgr; } dmgr;
jpeg_compress_struct cinfo = {}; std::unique_ptr<jpeg_compress_struct> cinfo = std::make_unique<jpeg_compress_struct>();
jpeg_error_mgr jerr; jpeg_error_mgr jerr;
// Initialize error handling with standard callbacks, but // Initialize error handling with standard callbacks, but
// then override output_message (to print to ALOG) and // then override output_message (to print to ALOG) and
// error_exit to set a flag and print a message instead // error_exit to set a flag and print a message instead
// of killing the whole process. // of killing the whole process.
cinfo.err = jpeg_std_error(&jerr); cinfo->err = jpeg_std_error(&jerr);
cinfo.err->output_message = [](j_common_ptr cinfo) { cinfo->err->output_message = [](j_common_ptr cinfo) {
char buffer[JMSG_LENGTH_MAX]; char buffer[JMSG_LENGTH_MAX];
/* Create the message */ /* Create the message */
@ -135,7 +142,7 @@ status_t encodeGrayscaleJpeg(size_t width, size_t height, uint8_t *in, void *out
ALOGE("libjpeg error: %s", buffer); ALOGE("libjpeg error: %s", buffer);
}; };
cinfo.err->error_exit = [](j_common_ptr cinfo) { cinfo->err->error_exit = [](j_common_ptr cinfo) {
(*cinfo->err->output_message)(cinfo); (*cinfo->err->output_message)(cinfo);
if(cinfo->client_data) { if(cinfo->client_data) {
auto & dmgr = *static_cast<CustomJpegDestMgr*>(cinfo->client_data); auto & dmgr = *static_cast<CustomJpegDestMgr*>(cinfo->client_data);
@ -144,12 +151,12 @@ status_t encodeGrayscaleJpeg(size_t width, size_t height, uint8_t *in, void *out
}; };
// Now that we initialized some callbacks, let's create our compressor // Now that we initialized some callbacks, let's create our compressor
jpeg_create_compress(&cinfo); jpeg_create_compress(cinfo.get());
dmgr.mBuffer = static_cast<JOCTET*>(out); dmgr.mBuffer = static_cast<JOCTET*>(out);
dmgr.mBufferSize = maxOutSize; dmgr.mBufferSize = maxOutSize;
dmgr.mEncodedSize = 0; dmgr.mEncodedSize = 0;
dmgr.mSuccess = true; dmgr.mSuccess = true;
cinfo.client_data = static_cast<void*>(&dmgr); cinfo->client_data = static_cast<void*>(&dmgr);
// These lambdas become C-style function pointers and as per C++11 spec // These lambdas become C-style function pointers and as per C++11 spec
// may not capture anything. // may not capture anything.
@ -171,28 +178,28 @@ status_t encodeGrayscaleJpeg(size_t width, size_t height, uint8_t *in, void *out
dmgr.mEncodedSize = dmgr.mBufferSize - dmgr.free_in_buffer; dmgr.mEncodedSize = dmgr.mBufferSize - dmgr.free_in_buffer;
ALOGV("%s:%d Done with jpeg: %zu", __FUNCTION__, __LINE__, dmgr.mEncodedSize); ALOGV("%s:%d Done with jpeg: %zu", __FUNCTION__, __LINE__, dmgr.mEncodedSize);
}; };
cinfo.dest = reinterpret_cast<struct jpeg_destination_mgr*>(&dmgr); cinfo->dest = static_cast<struct jpeg_destination_mgr*>(&dmgr);
cinfo.image_width = width; cinfo->image_width = width;
cinfo.image_height = height; cinfo->image_height = height;
cinfo.input_components = 1; cinfo->input_components = 1;
cinfo.in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
// Initialize defaults and then override what we want // Initialize defaults and then override what we want
jpeg_set_defaults(&cinfo); jpeg_set_defaults(cinfo.get());
jpeg_set_quality(&cinfo, jpegQuality, 1); jpeg_set_quality(cinfo.get(), jpegQuality, 1);
jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE); jpeg_set_colorspace(cinfo.get(), JCS_GRAYSCALE);
cinfo.raw_data_in = 0; cinfo->raw_data_in = 0;
cinfo.dct_method = JDCT_IFAST; cinfo->dct_method = JDCT_IFAST;
cinfo.comp_info[0].h_samp_factor = 1; cinfo->comp_info[0].h_samp_factor = 1;
cinfo.comp_info[1].h_samp_factor = 1; cinfo->comp_info[1].h_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1; cinfo->comp_info[2].h_samp_factor = 1;
cinfo.comp_info[0].v_samp_factor = 1; cinfo->comp_info[0].v_samp_factor = 1;
cinfo.comp_info[1].v_samp_factor = 1; cinfo->comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].v_samp_factor = 1; cinfo->comp_info[2].v_samp_factor = 1;
jpeg_start_compress(&cinfo, TRUE); jpeg_start_compress(cinfo.get(), TRUE);
if (exifOrientation != ExifOrientation::ORIENTATION_UNDEFINED) { if (exifOrientation != ExifOrientation::ORIENTATION_UNDEFINED) {
std::unique_ptr<ExifUtils> utils(ExifUtils::create()); std::unique_ptr<ExifUtils> utils(ExifUtils::create());
@ -204,19 +211,19 @@ status_t encodeGrayscaleJpeg(size_t width, size_t height, uint8_t *in, void *out
if (utils->generateApp1()) { if (utils->generateApp1()) {
const uint8_t* exifBuffer = utils->getApp1Buffer(); const uint8_t* exifBuffer = utils->getApp1Buffer();
size_t exifBufferSize = utils->getApp1Length(); size_t exifBufferSize = utils->getApp1Length();
jpeg_write_marker(&cinfo, JPEG_APP0 + 1, static_cast<const JOCTET*>(exifBuffer), jpeg_write_marker(cinfo.get(), JPEG_APP0 + 1, static_cast<const JOCTET*>(exifBuffer),
exifBufferSize); exifBufferSize);
} else { } else {
ALOGE("%s: Unable to generate App1 buffer", __FUNCTION__); ALOGE("%s: Unable to generate App1 buffer", __FUNCTION__);
} }
} }
for (size_t i = 0; i < cinfo.image_height; i++) { for (size_t i = 0; i < cinfo->image_height; i++) {
auto currentRow = static_cast<JSAMPROW>(in + i*width); auto currentRow = static_cast<JSAMPROW>(in + i*width);
jpeg_write_scanlines(&cinfo, &currentRow, /*num_lines*/1); jpeg_write_scanlines(cinfo.get(), &currentRow, /*num_lines*/1);
} }
jpeg_finish_compress(&cinfo); jpeg_finish_compress(cinfo.get());
actualSize = dmgr.mEncodedSize; actualSize = dmgr.mEncodedSize;
if (dmgr.mSuccess) { if (dmgr.mSuccess) {
@ -430,12 +437,12 @@ extern "C" int processDepthPhotoFrame(DepthPhotoInputFrame inputFrame, size_t de
return BAD_VALUE; return BAD_VALUE;
} }
// It is not possible to generate an imaging model without instrinsic calibration. // It is not possible to generate an imaging model without intrinsic calibration.
if (inputFrame.mIsInstrinsicCalibrationValid) { if (inputFrame.mIsIntrinsicCalibrationValid) {
// The camera intrinsic calibration layout is as follows: // The camera intrinsic calibration layout is as follows:
// [focalLengthX, focalLengthY, opticalCenterX, opticalCenterY, skew] // [focalLengthX, focalLengthY, opticalCenterX, opticalCenterY, skew]
const dynamic_depth::Point<double> focalLength(inputFrame.mInstrinsicCalibration[0], const dynamic_depth::Point<double> focalLength(inputFrame.mIntrinsicCalibration[0],
inputFrame.mInstrinsicCalibration[1]); inputFrame.mIntrinsicCalibration[1]);
size_t width = inputFrame.mMainJpegWidth; size_t width = inputFrame.mMainJpegWidth;
size_t height = inputFrame.mMainJpegHeight; size_t height = inputFrame.mMainJpegHeight;
if (switchDimensions) { if (switchDimensions) {
@ -444,9 +451,9 @@ extern "C" int processDepthPhotoFrame(DepthPhotoInputFrame inputFrame, size_t de
} }
const Dimension imageSize(width, height); const Dimension imageSize(width, height);
ImagingModelParams imagingParams(focalLength, imageSize); ImagingModelParams imagingParams(focalLength, imageSize);
imagingParams.principal_point.x = inputFrame.mInstrinsicCalibration[2]; imagingParams.principal_point.x = inputFrame.mIntrinsicCalibration[2];
imagingParams.principal_point.y = inputFrame.mInstrinsicCalibration[3]; imagingParams.principal_point.y = inputFrame.mIntrinsicCalibration[3];
imagingParams.skew = inputFrame.mInstrinsicCalibration[4]; imagingParams.skew = inputFrame.mIntrinsicCalibration[4];
// The camera lens distortion contains the following lens correction coefficients. // The camera lens distortion contains the following lens correction coefficients.
// [kappa_1, kappa_2, kappa_3 kappa_4, kappa_5] // [kappa_1, kappa_2, kappa_3 kappa_4, kappa_5]

@ -39,8 +39,8 @@ struct DepthPhotoInputFrame {
size_t mMaxJpegSize; size_t mMaxJpegSize;
uint8_t mJpegQuality; uint8_t mJpegQuality;
uint8_t mIsLogical; uint8_t mIsLogical;
float mInstrinsicCalibration[5]; float mIntrinsicCalibration[5];
uint8_t mIsInstrinsicCalibrationValid; uint8_t mIsIntrinsicCalibrationValid;
float mLensDistortion[5]; float mLensDistortion[5];
uint8_t mIsLensDistortionValid; uint8_t mIsLensDistortionValid;
DepthPhotoOrientation mOrientation; DepthPhotoOrientation mOrientation;
@ -57,8 +57,8 @@ struct DepthPhotoInputFrame {
mMaxJpegSize(0), mMaxJpegSize(0),
mJpegQuality(100), mJpegQuality(100),
mIsLogical(0), mIsLogical(0),
mInstrinsicCalibration{0.f}, mIntrinsicCalibration{0.f},
mIsInstrinsicCalibrationValid(0), mIsIntrinsicCalibrationValid(0),
mLensDistortion{0.f}, mLensDistortion{0.f},
mIsLensDistortionValid(0), mIsLensDistortionValid(0),
mOrientation(DepthPhotoOrientation::DEPTH_ORIENTATION_0_DEGREES) {} mOrientation(DepthPhotoOrientation::DEPTH_ORIENTATION_0_DEGREES) {}

Loading…
Cancel
Save