use of android.util.Size in project android_frameworks_base by ResurrectionRemix.
the class StaticMetadata method getPreCorrectedActiveArraySizeChecked.
/**
* Get and check pre-correction active array size.
*/
public Rect getPreCorrectedActiveArraySizeChecked() {
Key<Rect> key = CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE;
Rect activeArray = getValueFromKeyNonNull(key);
if (activeArray == null) {
return new Rect(0, 0, 0, 0);
}
Size pixelArraySize = getPixelArraySizeChecked();
checkTrueForKey(key, "values left/top are invalid", activeArray.left >= 0 && activeArray.top >= 0);
checkTrueForKey(key, "values width/height are invalid", activeArray.width() <= pixelArraySize.getWidth() && activeArray.height() <= pixelArraySize.getHeight());
return activeArray;
}
use of android.util.Size in project android_frameworks_base by ResurrectionRemix.
the class CameraTestUtils method getSortedSizesForFormat.
/**
* Get sorted (descending order) size list for given format. Remove the sizes larger than
* the bound. If the bound is null, don't do the size bound filtering.
*/
public static List<Size> getSortedSizesForFormat(String cameraId, CameraManager cameraManager, int format, Size bound) throws CameraAccessException {
Comparator<Size> comparator = new SizeComparator();
Size[] sizes = getSupportedSizeForFormat(format, cameraId, cameraManager);
List<Size> sortedSizes = null;
if (bound != null) {
sortedSizes = new ArrayList<Size>(/*capacity*/
1);
for (Size sz : sizes) {
if (comparator.compare(sz, bound) <= 0) {
sortedSizes.add(sz);
}
}
} else {
sortedSizes = Arrays.asList(sizes);
}
assertTrue("Supported size list should have at least one element", sortedSizes.size() > 0);
Collections.sort(sortedSizes, comparator);
// Make it in descending order.
Collections.reverse(sortedSizes);
return sortedSizes;
}
use of android.util.Size in project android_frameworks_base by ResurrectionRemix.
the class CameraMetadataTest method testReadWriteSize.
@SmallTest
public void testReadWriteSize() {
// int32 x n
checkKeyGetAndSet("android.jpeg.thumbnailSize", Size.class, new Size(123, 456));
// int32 x 2 x n
checkKeyGetAndSet("android.scaler.availableJpegSizes", Size[].class, new Size[] { new Size(123, 456), new Size(0xDEAD, 0xF00D), new Size(0xF00, 0xB00) });
}
use of android.util.Size in project android_frameworks_base by ResurrectionRemix.
the class RequestThreadManager method calculatePictureSize.
/**
* Find a JPEG size (that is supported by the legacy camera device) which is equal to or larger
* than all of the configured {@code JPEG} outputs (by both width and height).
*
* <p>If multiple supported JPEG sizes are larger, select the smallest of them which
* still satisfies the above constraint.</p>
*
* <p>As a result, the returned size is guaranteed to be usable without needing
* to upscale any of the outputs. If only one {@code JPEG} surface is used,
* then no scaling/cropping is necessary between the taken picture and
* the {@code JPEG} output surface.</p>
*
* @param callbackOutputs a non-{@code null} list of {@code Surface}s with any image formats
* @param params api1 parameters (used for reading only)
*
* @return a size large enough to fit all of the configured {@code JPEG} outputs, or
* {@code null} if the {@code callbackOutputs} did not have any {@code JPEG}
* surfaces.
*/
private Size calculatePictureSize(List<Surface> callbackOutputs, List<Size> callbackSizes, Camera.Parameters params) {
/*
* Find the largest JPEG size (if any), from the configured outputs:
* - the api1 picture size should be set to the smallest legal size that's at least as large
* as the largest configured JPEG size
*/
if (callbackOutputs.size() != callbackSizes.size()) {
throw new IllegalStateException("Input collections must be same length");
}
List<Size> configuredJpegSizes = new ArrayList<>();
Iterator<Size> sizeIterator = callbackSizes.iterator();
for (Surface callbackSurface : callbackOutputs) {
Size jpegSize = sizeIterator.next();
if (!LegacyCameraDevice.containsSurfaceId(callbackSurface, mJpegSurfaceIds)) {
// Ignore non-JPEG callback formats
continue;
}
configuredJpegSizes.add(jpegSize);
}
if (!configuredJpegSizes.isEmpty()) {
/*
* Find the largest configured JPEG width, and height, independently
* of the rest.
*
* The rest of the JPEG streams can be cropped out of this smallest bounding
* rectangle.
*/
int maxConfiguredJpegWidth = -1;
int maxConfiguredJpegHeight = -1;
for (Size jpegSize : configuredJpegSizes) {
maxConfiguredJpegWidth = jpegSize.getWidth() > maxConfiguredJpegWidth ? jpegSize.getWidth() : maxConfiguredJpegWidth;
maxConfiguredJpegHeight = jpegSize.getHeight() > maxConfiguredJpegHeight ? jpegSize.getHeight() : maxConfiguredJpegHeight;
}
Size smallestBoundJpegSize = new Size(maxConfiguredJpegWidth, maxConfiguredJpegHeight);
List<Size> supportedJpegSizes = ParameterUtils.convertSizeList(params.getSupportedPictureSizes());
/*
* Find the smallest supported JPEG size that can fit the smallest bounding
* rectangle for the configured JPEG sizes.
*/
List<Size> candidateSupportedJpegSizes = new ArrayList<>();
for (Size supportedJpegSize : supportedJpegSizes) {
if (supportedJpegSize.getWidth() >= maxConfiguredJpegWidth && supportedJpegSize.getHeight() >= maxConfiguredJpegHeight) {
candidateSupportedJpegSizes.add(supportedJpegSize);
}
}
if (candidateSupportedJpegSizes.isEmpty()) {
throw new AssertionError("Could not find any supported JPEG sizes large enough to fit " + smallestBoundJpegSize);
}
Size smallestSupportedJpegSize = Collections.min(candidateSupportedJpegSizes, new SizeAreaComparator());
if (!smallestSupportedJpegSize.equals(smallestBoundJpegSize)) {
Log.w(TAG, String.format("configureOutputs - Will need to crop picture %s into " + "smallest bound size %s", smallestSupportedJpegSize, smallestBoundJpegSize));
}
return smallestSupportedJpegSize;
}
return null;
}
use of android.util.Size in project android_frameworks_base by ResurrectionRemix.
the class OutputConfiguration method setDeferredSurface.
/**
* Set the deferred surface to this OutputConfiguration.
*
* <p>
* The deferred surface must be obtained from either from {@link android.view.SurfaceView} by
* calling {@link android.view.SurfaceHolder#getSurface}, or from
* {@link android.graphics.SurfaceTexture} via
* {@link android.view.Surface#Surface(android.graphics.SurfaceTexture)}). After the deferred
* surface is set, the application must finish the deferred surface configuration via
* {@link CameraCaptureSession#finishDeferredConfiguration} before submitting a request with
* this surface target.
* </p>
*
* @param surface The deferred surface to be set.
* @throws IllegalArgumentException if the Surface is invalid.
* @throws IllegalStateException if a Surface was already set to this deferred
* OutputConfiguration.
* @hide
*/
public void setDeferredSurface(@NonNull Surface surface) {
checkNotNull(surface, "Surface must not be null");
if (mSurface != null) {
throw new IllegalStateException("Deferred surface is already set!");
}
// This will throw IAE is the surface was abandoned.
Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
if (!surfaceSize.equals(mConfiguredSize)) {
Log.w(TAG, "Deferred surface size " + surfaceSize + " is different with pre-configured size " + mConfiguredSize + ", the pre-configured size will be used.");
}
mSurface = surface;
}
Aggregations