MCPcopy Create free account
hub / github.com/android/ndk-samples / MatchCaptureSizeRequest

Method MatchCaptureSizeRequest

camera/basic/src/main/cpp/camera_manager.cpp:166–222  ·  view source on GitHub ↗

* Find a compatible camera modes: * 1) the same aspect ration as the native display window, which should be a * rotated version of the physical device * 2) the smallest resolution in the camera mode list * This is to minimize the later color space conversion workload. */

Source from the content-addressed store, hash-verified

164 * This is to minimize the later color space conversion workload.
165 */
166bool NDKCamera::MatchCaptureSizeRequest(ANativeWindow* display,
167 ImageFormat* resView,
168 ImageFormat* resCap) {
169 DisplayDimension disp(ANativeWindow_getWidth(display),
170 ANativeWindow_getHeight(display));
171 if (cameraOrientation_ == 90 || cameraOrientation_ == 270) {
172 disp.Flip();
173 }
174
175 ACameraMetadata* metadata;
176 CALL_MGR(
177 getCameraCharacteristics(cameraMgr_, activeCameraId_.c_str(), &metadata));
178 ACameraMetadata_const_entry entry;
179 CALL_METADATA(getConstEntry(
180 metadata, ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, &entry));
181 // format of the data: format, width, height, input?, type int32
182 bool foundIt = false;
183 DisplayDimension foundRes(4000, 4000);
184 DisplayDimension maxJPG(0, 0);
185
186 for (uint32_t i = 0; i < entry.count; i += 4) {
187 int32_t input = entry.data.i32[i + 3];
188 int32_t format = entry.data.i32[i + 0];
189 if (input) continue;
190
191 if (format == AIMAGE_FORMAT_YUV_420_888 || format == AIMAGE_FORMAT_JPEG) {
192 DisplayDimension res(entry.data.i32[i + 1], entry.data.i32[i + 2]);
193 if (!disp.IsSameRatio(res)) continue;
194 if (format == AIMAGE_FORMAT_YUV_420_888 && foundRes > res) {
195 foundIt = true;
196 foundRes = res;
197 } else if (format == AIMAGE_FORMAT_JPEG && res > maxJPG) {
198 maxJPG = res;
199 }
200 }
201 }
202
203 if (foundIt) {
204 resView->width = foundRes.org_width();
205 resView->height = foundRes.org_height();
206 resCap->width = maxJPG.org_width();
207 resCap->height = maxJPG.org_height();
208 } else {
209 LOGW("Did not find any compatible camera resolution, taking 640x480");
210 if (disp.IsPortrait()) {
211 resView->width = 480;
212 resView->height = 640;
213 } else {
214 resView->width = 640;
215 resView->height = 480;
216 }
217 *resCap = *resView;
218 }
219 resView->format = AIMAGE_FORMAT_YUV_420_888;
220 resCap->format = AIMAGE_FORMAT_JPEG;
221 return foundIt;
222}
223

Callers 1

CreateCameraMethod · 0.45

Calls 5

FlipMethod · 0.45
IsSameRatioMethod · 0.45
org_widthMethod · 0.45
org_heightMethod · 0.45
IsPortraitMethod · 0.45

Tested by

no test coverage detected