am e65066d3: am 7a193899: am 96990d0c: Merge "Fix DngCreator default crop calculations." into mnc-dr-dev

* commit 'e65066d30eb52d2ef938501890ba4cf99d8f1b7b':
  Fix DngCreator default crop calculations.
This commit is contained in:
Ruben Brunk
2015-08-28 22:05:46 +00:00
committed by Android Git Automerger

View File

@@ -755,48 +755,31 @@ uint32_t DirectStripSource::getIfd() const {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** /**
* Given a buffer crop rectangle relative to the pixel array size, and the pre-correction active * Calculate the default crop relative to the "active area" of the image sensor (this active area
* array crop rectangle for the camera characteristics, set the default crop rectangle in the * will always be the pre-correction active area rectangle), and set this.
* TiffWriter relative to the buffer crop rectangle origin.
*/ */
static status_t calculateAndSetCrop(JNIEnv* env, const CameraMetadata& characteristics, static status_t calculateAndSetCrop(JNIEnv* env, const CameraMetadata& characteristics,
uint32_t bufWidth, uint32_t bufHeight, sp<TiffWriter> writer) { sp<TiffWriter> writer) {
camera_metadata_ro_entry entry = camera_metadata_ro_entry entry =
characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
uint32_t xmin = static_cast<uint32_t>(entry.data.i32[0]);
uint32_t ymin = static_cast<uint32_t>(entry.data.i32[1]);
uint32_t width = static_cast<uint32_t>(entry.data.i32[2]); uint32_t width = static_cast<uint32_t>(entry.data.i32[2]);
uint32_t height = static_cast<uint32_t>(entry.data.i32[3]); uint32_t height = static_cast<uint32_t>(entry.data.i32[3]);
const uint32_t margin = 8; // Default margin recommended by Adobe for interpolation. const uint32_t margin = 8; // Default margin recommended by Adobe for interpolation.
// Crop based on pre-correction array for pixel array if (width < margin * 2 || height < margin * 2) {
uint32_t aLeft = xmin; ALOGE("%s: Cannot calculate default crop for image, pre-correction active area is too"
uint32_t aTop = ymin; "small: h=%" PRIu32 ", w=%" PRIu32, __FUNCTION__, height, width);
uint32_t aRight = xmin + width; jniThrowException(env, "java/lang/IllegalStateException",
uint32_t aBottom = ymin + height; "Pre-correction active area is too small.");
return BAD_VALUE;
// 8 pixel border crop for pixel array dimens
uint32_t bLeft = margin;
uint32_t bTop = margin;
uint32_t bRight = bufWidth - margin;
uint32_t bBottom = bufHeight - margin;
// Set the crop to be the intersection of the two rectangles
uint32_t defaultCropOrigin[] = {std::max(aLeft, bLeft), std::max(aTop, bTop)};
uint32_t defaultCropSize[] = {std::min(aRight, bRight) - defaultCropOrigin[0],
std::min(aBottom, bBottom) - defaultCropOrigin[1]};
// If using buffers with pre-correction array dimens, switch to 8 pixel border crop
// relative to the pixel array dimens
if (bufWidth == width && bufHeight == height) {
defaultCropOrigin[0] = xmin + margin;
defaultCropOrigin[1] = ymin + margin;
defaultCropSize[0] = width - margin;
defaultCropSize[1] = height - margin;
} }
uint32_t defaultCropOrigin[] = {margin, margin};
uint32_t defaultCropSize[] = {width - defaultCropOrigin[0] - margin,
height - defaultCropOrigin[1] - margin};
BAIL_IF_INVALID_R(writer->addEntry(TAG_DEFAULTCROPORIGIN, 2, defaultCropOrigin, BAIL_IF_INVALID_R(writer->addEntry(TAG_DEFAULTCROPORIGIN, 2, defaultCropOrigin,
TIFF_IFD_0), env, TAG_DEFAULTCROPORIGIN, writer); TIFF_IFD_0), env, TAG_DEFAULTCROPORIGIN, writer);
BAIL_IF_INVALID_R(writer->addEntry(TAG_DEFAULTCROPSIZE, 2, defaultCropSize, BAIL_IF_INVALID_R(writer->addEntry(TAG_DEFAULTCROPSIZE, 2, defaultCropSize,
@@ -1565,17 +1548,24 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
{ {
// Set dimensions // Set dimensions
if (calculateAndSetCrop(env, characteristics, imageWidth, imageHeight, writer) != OK) { if (calculateAndSetCrop(env, characteristics, writer) != OK) {
return nullptr; return nullptr;
} }
camera_metadata_entry entry = camera_metadata_entry entry =
characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
BAIL_IF_EMPTY_RET_NULL_SP(entry, env, TAG_DEFAULTCROPSIZE, writer); BAIL_IF_EMPTY_RET_NULL_SP(entry, env, TAG_ACTIVEAREA, writer);
uint32_t xmin = static_cast<uint32_t>(entry.data.i32[0]); uint32_t xmin = static_cast<uint32_t>(entry.data.i32[0]);
uint32_t ymin = static_cast<uint32_t>(entry.data.i32[1]); uint32_t ymin = static_cast<uint32_t>(entry.data.i32[1]);
uint32_t width = static_cast<uint32_t>(entry.data.i32[2]); uint32_t width = static_cast<uint32_t>(entry.data.i32[2]);
uint32_t height = static_cast<uint32_t>(entry.data.i32[3]); uint32_t height = static_cast<uint32_t>(entry.data.i32[3]);
// If we only have a buffer containing the pre-correction rectangle, ignore the offset
// relative to the pixel array.
if (imageWidth == width && imageHeight == height) {
xmin = 0;
ymin = 0;
}
uint32_t activeArea[] = {ymin, xmin, ymin + height, xmin + width}; uint32_t activeArea[] = {ymin, xmin, ymin + height, xmin + width};
BAIL_IF_INVALID_RET_NULL_SP(writer->addEntry(TAG_ACTIVEAREA, 4, activeArea, TIFF_IFD_0), BAIL_IF_INVALID_RET_NULL_SP(writer->addEntry(TAG_ACTIVEAREA, 4, activeArea, TIFF_IFD_0),
env, TAG_ACTIVEAREA, writer); env, TAG_ACTIVEAREA, writer);