Recover camera session failures once with low-resolution native YUV
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import com.gorios.lanvoice.expression.*
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
fun cameraPixelsCheck() {
|
||||
fun plane(bytes: IntArray,row: Int,pixel: Int,offset: Int=0)=CameraPixelPlane(
|
||||
ByteBuffer.wrap(bytes.map { it.toByte() }.toByteArray()).apply { position(offset) },row,pixel)
|
||||
val rgba=plane(intArrayOf(99,10,20,30,255,40,50,60,128,99,99,70,80,90,255,100,110,120,255,99,99),10,4,1)
|
||||
check(CameraPixelConverter.argb(listOf(rgba),false,0,0,2,2).toList()==
|
||||
listOf(0xff0a141e.toInt(),0x8028323c.toInt(),0xff46505a.toInt(),0xff646e78.toInt()))
|
||||
check(CameraPixelConverter.argb(listOf(rgba),false,1,1,1,1).single()==0xff646e78.toInt())
|
||||
check(rgba.bytes.position()==1)
|
||||
val luma=plane(intArrayOf(16,235,99,99,81,145,99,99),4,1)
|
||||
val chroma=plane(intArrayOf(128,99,128,99),4,2)
|
||||
val pixels=CameraPixelConverter.argb(listOf(luma,chroma,chroma),true,0,0,2,2)
|
||||
check(pixels[0]==0xff000000.toInt() && pixels[1]==0xffffffff.toInt())
|
||||
check((pixels[2] and 0xffffff)==0x4c4c4c && (pixels[3] and 0xffffff)==0x969696)
|
||||
// Shared interleaved chroma buffers, each view starts at its own channel.
|
||||
val uv=ByteBuffer.wrap(byteArrayOf(90,240.toByte(),99,99))
|
||||
val u=CameraPixelPlane(uv.duplicate(),4,2);val v=CameraPixelPlane(uv.duplicate().apply { position(1) },4,2)
|
||||
val red=CameraPixelConverter.argb(listOf(plane(IntArray(4) {81},2,1),u,v),true,1,1,1,1).single()
|
||||
check((red ushr 16 and 255)==255 && (red ushr 8 and 255)==0 && (red and 255)==0)
|
||||
check(uv.position()==0 && v.bytes.position()==1)
|
||||
for(block in listOf<()->Unit>(
|
||||
{CameraPixelConverter.argb(listOf(rgba),true,0,0,2,2)},
|
||||
{CameraPixelConverter.argb(listOf(rgba),false,0,0,4000,4000)},
|
||||
{CameraPixelConverter.argb(listOf(rgba),false,-1,0,1,1)},
|
||||
{CameraPixelConverter.argb(listOf(rgba),false,0,0,2,3)},
|
||||
{CameraPixelConverter.argb(listOf(plane(intArrayOf(1),1,1)),false,0,0,1,1)}
|
||||
)) check(runCatching(block).isFailure)
|
||||
println("PASS: production RGBA/native YUV local conversion, row/pixel strides/crop/plane offsets/shared chroma/BT601/clamp, buffer positions and malformed/bounded allocation rejection; no real camera")
|
||||
}
|
||||
Reference in New Issue
Block a user