Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions apps/simple-camera/__tests__/visioncamera.photo.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,51 @@ describe('VisionCamera - Photo', () => {
await session.stop()
})

it('returns captured Photo metadata from capturePhotoToFile', async () => {
const session = await VisionCamera.createCameraSession(false)
const photoOutput = VisionCamera.createPhotoOutput({
targetResolution: CommonResolutions.HD_4_3,
containerFormat: 'jpeg',
quality: 0.8,
qualityPrioritization: 'balanced',
})
await session.configure([
{
input: backDevice,
outputs: [{ output: photoOutput, mirrorMode: 'on' }],
constraints: [],
},
])
await session.start()

try {
photoOutput.outputOrientation = 'left'
const inMemoryPhoto = await photoOutput.capturePhoto(
{ flashMode: 'off', enableShutterSound: false },
{},
)
try {
const photoFile = await photoOutput.capturePhotoToFile(
{ flashMode: 'off', enableShutterSound: false },
{},
)

expect(photoFile.filePath).toMatch(/^\/.*\.(jpeg|jpg)$/)
expect(photoFile.width).toBe(inMemoryPhoto.width)
expect(photoFile.height).toBe(inMemoryPhoto.height)
expect(photoFile.orientation).toBe(inMemoryPhoto.orientation)
expect(photoFile.isMirrored).toBe(inMemoryPhoto.isMirrored)
expect(photoFile.timestamp).toBeGreaterThan(0)
expect(photoFile.isRawPhoto).toBe(inMemoryPhoto.isRawPhoto)
expect(photoFile.containerFormat).toBe(inMemoryPhoto.containerFormat)
} finally {
inMemoryPhoto.dispose()
}
} finally {
await session.stop()
}
})

it('reports supportsDepthDataDelivery on a depth-capable device', async (context) => {
// `supportsDepthDataDelivery` is a per-output property that flips to `true`
// once the photo output is bound to a device that can produce depth data.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.margelo.nitro.camera.extensions.converters

import android.annotation.SuppressLint
import androidx.camera.core.impl.utils.Exif
import com.margelo.nitro.camera.CameraOrientation
import com.margelo.nitro.camera.PhotoContainerFormat
import com.margelo.nitro.camera.PhotoFile
import com.margelo.nitro.camera.extensions.fromDegrees
import java.io.File

@SuppressLint("RestrictedApi")
fun PhotoFile.Companion.fromFile(
file: File,
imageFormat: Int,
timestamp: Double,
isMirrored: Boolean,
): PhotoFile {
val exif = Exif.createFromFile(file)
val containerFormat = PhotoContainerFormat.fromImageFormat(imageFormat)
return PhotoFile(
filePath = file.absolutePath,
width = exif.width.toDouble(),
height = exif.height.toDouble(),
orientation = CameraOrientation.fromDegrees(exif.rotation),
isMirrored = isMirrored,
timestamp = timestamp,
isRawPhoto = containerFormat == PhotoContainerFormat.DNG,
containerFormat = containerFormat,
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.margelo.nitro.camera.hybrids.outputs

import android.media.MediaActionSound
import android.os.SystemClock
import android.util.Log
import androidx.camera.core.CameraInfo
import androidx.camera.core.CameraSelector
Expand All @@ -18,6 +19,7 @@ import com.margelo.nitro.camera.PhotoFile
import com.margelo.nitro.camera.PhotoOutputOptions
import com.margelo.nitro.camera.QualityPrioritization
import com.margelo.nitro.camera.Size
import com.margelo.nitro.camera.extensions.converters.fromFile
import com.margelo.nitro.camera.extensions.converters.toCaptureMode
import com.margelo.nitro.camera.extensions.converters.toFlashMode
import com.margelo.nitro.camera.extensions.converters.toOutputFormat
Expand Down Expand Up @@ -256,38 +258,48 @@ class HybridPhotoOutput(

// 2. Perform Capture
var didFireOnDidCapturePhoto = false
imageCapture.takePicture(
outputFileOptions,
{
callbacks.onWillBeginCapture?.invoke()
if (enableShutterSound) {
shutterSound.play(MediaActionSound.SHUTTER_CLICK)
}
callbacks.onWillCapturePhoto?.invoke()
},
{ progress ->
if (progress == 100) {
// Capture is complete! Saving...
callbacks.onDidCapturePhoto?.invoke()
didFireOnDidCapturePhoto = true
}
},
{ bitmap ->
// Preview Image delivered!
callbacks.onPreviewImageAvailable?.let { onPreviewImageAvailable ->
val image = HybridImage(bitmap)
onPreviewImageAvailable(image)
}
},
)
var timestamp: Double? = null
val result =
imageCapture.takePicture(
outputFileOptions,
{
timestamp = SystemClock.elapsedRealtimeNanos().toDouble() / 1_000_000_000.0
callbacks.onWillBeginCapture?.invoke()
if (enableShutterSound) {
shutterSound.play(MediaActionSound.SHUTTER_CLICK)
}
callbacks.onWillCapturePhoto?.invoke()
},
{ progress ->
if (progress == 100) {
// Capture is complete! Saving...
callbacks.onDidCapturePhoto?.invoke()
didFireOnDidCapturePhoto = true
}
},
{ bitmap ->
// Preview Image delivered!
callbacks.onPreviewImageAvailable?.let { onPreviewImageAvailable ->
val image = HybridImage(bitmap)
onPreviewImageAvailable(image)
}
},
)

if (!didFireOnDidCapturePhoto) {
// Not every device supports progress callbacks, so we just fire it later here
callbacks.onDidCapturePhoto?.invoke()
}

// 3. Return
return@async PhotoFile(file.absolutePath)
val captureTimestamp =
timestamp ?: throw Error("Photo capture did not report when exposure started!")
return@async PhotoFile.fromFile(
file = file,
imageFormat = result.imageFormat,
timestamp = captureTimestamp,
isMirrored = isMirrored,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,15 @@ final class HybridCameraPhotoOutput: HybridCameraPhotoOutputSpec, NativeCameraOu
.await()
let filePath = try await photo.saveToTemporaryFileAsync()
.await()
return PhotoFile(filePath: filePath)
return PhotoFile(
filePath: filePath,
width: photo.width,
height: photo.height,
orientation: photo.orientation,
isMirrored: photo.isMirrored,
timestamp: photo.timestamp,
isRawPhoto: photo.isRawPhoto,
containerFormat: photo.containerFormat)
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading