SurfaceTexture size, how is it defined?
Asked Answered
A

1

7

I'm using SurfaceTexture to draw preview of camera and need to know the size of the texture + what happens in the process.

Let's say the supported camera preview sizes by device are:

1280 720, 1024 576, 960 720, 800 600, 800 480, 768 576, 736 552, etc..

It's obvious that there's mismatch between these sizes and standard texture sizes 2048x2048, 2048x1024, 1024x1024...

I can think of following situations that follow, but I'm uncertain:

1,  surface texture is in size of selected preview size, eg 1280 x 720, but that is not pow2 format and could mean compatibility problems

1, surface texture is in size of selected preview size, eg 1280 x 720, but that is not pow2 format and could mean compatibility problems

2, surface texture is contained within next size of pow2 format, untransformed, for example 1280x720 would be contained within 2048 x 1024 texture, no stretching, part of the texture remains unused

2, surface texture is contained within next size of pow2 format, untransformed, for example 1280x720 would be contained within 2048 x 1024 texture, no stretching, part of the texture remains unused.

3, surface texture is sized up to fit next pow2 texture (perhaps even sized down), image proportions are lost, and also quality suffers. eg 1280 x 720 stretched across 2048 x 1024.

3, surface texture is sized up to fit next pow2 texture (perhaps even sized down), image proportions are lost, and also quality suffers. eg 1920 x 1080 stretched across 2048 x 2048.

4, some other possibility?

How is the camera preview being mapped to the texture and how is the texture size defined in the end?

Artemis answered 11/6, 2014 at 12:36 Comment(2)
I would guess it can be any of the three, depending on vendor specific implementation. You should use SurfaceTexture.getTransformMatrix to get mapping for texture coordinates (s, t). And this transformation can do mapping for each situation.Dodgem
Thanks for the idea. The reason I'm asking is because I'm losing quality somewhere along the way, compared to stock camera. I'm getting slightly jagged edges, as if it was gone through other lossy transformation (yes I am using linear filter). Perhaps my 1280x720 preview size is feeding through 1024px texture. If I had a way to check the texture size, it could confirm whether its true or not. I checked the getTransformMatrix before as well as opengl projection and these seem to be without any relative transformation (all (s, t) coords either 1 or 0)Artemis
A
7

Actually when you are previewing you have buffers that you can set to "keep" the "big" resolution.

Size mPreviewSize;

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);

String cameraId = manager.getCameraIdList()[0];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
mPreviewSize = map.getOutputSizes(SurfaceTexture.class)[0];

SurfaceTexture texture = mTextureView.getSurfaceTexture();
// We configure the size of default buffer to be the size of camera
// preview we want.
texture.setDefaultBufferSize(mPreviewSize.getWidth(),mPreviewSize.getHeight());
Anticyclone answered 21/9, 2015 at 11:26 Comment(2)
What is mPreviewSize in this case? I want it set to the maximum camera resolution my device can support.Kolyma
On the linemPreviewSize = map.getOutputSizes(SurfaceTexture.class)[0]; it sets it to the maximum that the camera supportsAnticyclone

© 2022 - 2024 — McMap. All rights reserved.