fix: preserve EXIF make and model for imported photos

This commit is contained in:
Hinnka committed 2026-08-01 13:00:59 +08:00
1 parent 811ad4ef24
commit 70da1c9b6c
5 files changed
+36 -4

No files matched your search

@@ -2007,6 +2007,7 @@ object GalleryManager {
cfaCorrectionMode = metadata.rawCfaCorrectionMode,
effectiveFocalLengthMm = captureInfo.focalLength,
effectiveFocalLength35mm = captureInfo.focalLength35mm,
captureInfo = captureInfo,
dngProfilePreparationOptions = rawDngProfilePreparationOptions(
context = context,
metadata = metadata,
@@ -3549,6 +3550,7 @@ object GalleryManager {
captureMetadataResult = captureMetadataResult,
effectiveFocalLengthMm = captureInfo.focalLength,
effectiveFocalLength35mm = captureInfo.focalLength35mm,
captureInfo = captureInfo,
outputStream = outputStream,
rotation = rotation,
thumbnail = thumbnail,
@@ -148,12 +148,18 @@ data class MediaMetadata(
/**
* 将元数据转换为 CaptureInfo,用于写入 EXIF
*
* CaptureInfo.model 使用其 EXIF 安全设备型号默认值,不复用边框水印的 deviceModel。
* 导入照片的 deviceModel 来自原图 EXIF,应优先保留;本机照片仍使用
* EXIF 安全的设备型号,不复用边框水印展示名称。
*/
fun toCaptureInfo(): com.hinnka.mycamera.camera.CaptureInfo {
return com.hinnka.mycamera.camera.CaptureInfo(
iso = iso,
make = brand ?: Build.MANUFACTURER,
model = if (isImported) {
deviceModel?.takeIf { it.isNotBlank() } ?: DeviceUtil.exifModel
} else {
DeviceUtil.exifModel
},
captureTime = dateTaken ?: System.currentTimeMillis(),
imageWidth = width,
imageHeight = height,
@@ -164,7 +170,7 @@ data class MediaMetadata(
software = software ?: "PhotonCamera",
latitude = latitude,
longitude = longitude,
altitude = altitude
altitude = altitude,
)
}
@@ -9,6 +9,7 @@ import android.media.Image
import android.util.Log
import android.util.Size
import com.hinnka.mycamera.camera.AspectRatio
import com.hinnka.mycamera.camera.CaptureInfo
import com.hinnka.mycamera.model.SafeImage
import com.hinnka.mycamera.processor.GpuLinearRgbSource
import com.hinnka.mycamera.raw.DngProfileGainTableMap
@@ -319,6 +320,7 @@ object RawProcessor {
cfaCorrectionMode: String? = null,
effectiveFocalLengthMm: Float? = null,
effectiveFocalLength35mm: Int? = null,
captureInfo: CaptureInfo,
dngProfilePreparationOptions: RawDngProfilePreparationOptions? = null,
): Boolean {
if (!isRawImage(image)) {
@@ -339,6 +341,7 @@ object RawProcessor {
cfaCorrectionMode = cfaCorrectionMode,
effectiveFocalLengthMm = effectiveFocalLengthMm,
effectiveFocalLength35mm = effectiveFocalLength35mm,
captureInfo = captureInfo,
dngProfilePreparationOptions = dngProfilePreparationOptions,
defaultCrop = resolveCameraRawDefaultCrop(
width = image.width,
@@ -409,6 +412,7 @@ object RawProcessor {
cfaCorrectionMode: String?,
effectiveFocalLengthMm: Float?,
effectiveFocalLength35mm: Int?,
captureInfo: CaptureInfo,
dngProfilePreparationOptions: RawDngProfilePreparationOptions?,
defaultCrop: Rect,
): Boolean {
@@ -447,6 +451,7 @@ object RawProcessor {
cfaCorrectionMode = cfaCorrectionMode,
effectiveFocalLengthMm = effectiveFocalLengthMm,
effectiveFocalLength35mm = effectiveFocalLength35mm,
captureInfo = captureInfo,
dngProfilePreparationOptions = dngProfilePreparationOptions,
defaultCrop = defaultCrop,
)
@@ -631,6 +636,7 @@ object RawProcessor {
captureMetadataResult: CaptureResult? = null,
effectiveFocalLengthMm: Float? = null,
effectiveFocalLength35mm: Int? = null,
captureInfo: CaptureInfo,
outputStream: java.io.OutputStream,
rotation: Int = 0,
thumbnail: Bitmap? = null,
@@ -732,6 +738,7 @@ object RawProcessor {
captureMetadataResult = captureMetadataResult ?: captureResult,
effectiveFocalLengthMm = effectiveFocalLengthMm,
effectiveFocalLength35mm = effectiveFocalLength35mm,
captureInfo = captureInfo,
orientation = orientation,
cfaPattern = resolvedCfaPattern,
blackLevel = blackLevel,
@@ -9,6 +9,7 @@ import android.hardware.camera2.params.ColorSpaceTransform
import android.hardware.camera2.params.LensShadingMap
import android.os.Build
import android.os.SystemClock
import com.hinnka.mycamera.camera.CaptureInfo
import com.hinnka.mycamera.raw.DngProfileGainTableMap
import com.hinnka.mycamera.raw.DngProfileToneCurve
import com.hinnka.mycamera.raw.DngCameraRawProfileXmp
@@ -265,6 +266,7 @@ object SuperResolutionDngWriter {
captureMetadataResult: CaptureResult = captureResult,
effectiveFocalLengthMm: Float? = null,
effectiveFocalLength35mm: Int? = null,
captureInfo: CaptureInfo,
orientation: Int,
cfaPattern: Int,
blackLevel: FloatArray,
@@ -378,6 +380,7 @@ object SuperResolutionDngWriter {
captureMetadataResult = captureMetadataResult,
effectiveFocalLengthMm = effectiveFocalLengthMm,
effectiveFocalLength35mm = effectiveFocalLength35mm,
captureInfo = captureInfo,
orientation = orientation,
cfaPattern = cfaPattern,
blackLevel = encodedBlackLevel,
@@ -432,6 +435,7 @@ object SuperResolutionDngWriter {
captureMetadataResult: CaptureResult,
effectiveFocalLengthMm: Float?,
effectiveFocalLength35mm: Int?,
captureInfo: CaptureInfo,
orientation: Int,
cfaPattern: Int,
blackLevel: FloatArray,
@@ -506,6 +510,7 @@ object SuperResolutionDngWriter {
val lensModel = DeviceUtil.buildExifLensModel(
focalLength35mm = focalLength35mm,
aperture = aperture,
model = captureInfo.model,
)
val exifWhiteBalance = captureMetadataResult.get(CaptureResult.CONTROL_AWB_MODE)?.let { awbMode ->
if (awbMode == CameraMetadata.CONTROL_AWB_MODE_AUTO) 0 else 1
@@ -577,8 +582,8 @@ object SuperResolutionDngWriter {
add(shortArray(TAG_BITS_PER_SAMPLE, IntArray(samplesPerPixel) { 16 }))
add(short(TAG_COMPRESSION, compression.tagValue))
add(short(TAG_PHOTOMETRIC_INTERPRETATION, imageLayout.photometricInterpretation))
add(ascii(TAG_MAKE, Build.MANUFACTURER.ifBlank { "Android" }))
add(ascii(TAG_MODEL, DeviceUtil.exifModel))
add(ascii(TAG_MAKE, captureInfo.make))
add(ascii(TAG_MODEL, captureInfo.model))
add(long(TAG_STRIP_OFFSETS, 0))
add(short(TAG_ORIENTATION, orientation))
add(short(TAG_SAMPLES_PER_PIXEL, samplesPerPixel))
@@ -29,6 +29,18 @@ class MediaMetadataTest {
assertEquals(100, metadata.merge(raw).iso)
}
@Test
fun importedCaptureInfoKeepsSourceExifMakeAndModel() {
val captureInfo = MediaMetadata(
brand = "FUJIFILM",
deviceModel = "X-T5",
isImported = true,
).toCaptureInfo()
assertEquals("FUJIFILM", captureInfo.make)
assertEquals("X-T5", captureInfo.model)
}
private fun rawMetadata(iso: Int): RawMetadata {
return RawMetadata(
width = 4000,