mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
fix(server): use srgb pipeline for srgb images (#4101)
* added color-related exif fields * remove metadata check, conditional pipe colorspace * check exif metadata for srgb * added migration * updated e2e fixture * uncased srgb check, search substrings * extracted exif logic into separate function * handle images with no bit depth or color metadata * added unit tests
This commit is contained in:
parent
9676412875
commit
56cf9464af
7 changed files with 155 additions and 17 deletions
|
|
@ -42,9 +42,11 @@ interface ImmichTags extends Tags {
|
|||
MotionPhotoVersion?: number;
|
||||
MotionPhotoPresentationTimestampUs?: number;
|
||||
MediaGroupUUID?: string;
|
||||
ImagePixelDepth?: string;
|
||||
}
|
||||
|
||||
const exifDate = (dt: ExifDateTime | string | undefined) => (dt instanceof ExifDateTime ? dt?.toDate() : null);
|
||||
// exiftool returns strings when it fails to parse non-string values, so this is used where a string is not expected
|
||||
const validate = <T>(value: T): T | null => (typeof value === 'string' ? null : value ?? null);
|
||||
|
||||
export class MetadataExtractionProcessor {
|
||||
|
|
@ -289,6 +291,8 @@ export class MetadataExtractionProcessor {
|
|||
<ExifEntity>{
|
||||
// altitude: tags.GPSAltitude ?? null,
|
||||
assetId: asset.id,
|
||||
bitsPerSample: this.getBitsPerSample(tags),
|
||||
colorspace: tags.ColorSpace ?? null,
|
||||
dateTimeOriginal: exifDate(firstDateTime(tags)) ?? asset.fileCreatedAt,
|
||||
exifImageHeight: validate(tags.ImageHeight),
|
||||
exifImageWidth: validate(tags.ImageWidth),
|
||||
|
|
@ -306,10 +310,29 @@ export class MetadataExtractionProcessor {
|
|||
model: tags.Model ?? null,
|
||||
modifyDate: exifDate(tags.ModifyDate) ?? asset.fileModifiedAt,
|
||||
orientation: validate(tags.Orientation)?.toString() ?? null,
|
||||
profileDescription: tags.ProfileDescription || tags.ProfileName || null,
|
||||
projectionType: tags.ProjectionType ? String(tags.ProjectionType).toUpperCase() : null,
|
||||
timeZone: tags.tz,
|
||||
},
|
||||
tags,
|
||||
];
|
||||
}
|
||||
|
||||
getBitsPerSample(tags: ImmichTags): number | null {
|
||||
const bitDepthTags = [
|
||||
tags.BitsPerSample,
|
||||
tags.ComponentBitDepth,
|
||||
tags.ImagePixelDepth,
|
||||
tags.BitDepth,
|
||||
tags.ColorBitDepth,
|
||||
// `numericTags` doesn't parse values like '12 12 12'
|
||||
].map((tag) => (typeof tag === 'string' ? Number.parseInt(tag) : tag));
|
||||
|
||||
let bitsPerSample = bitDepthTags.find((tag) => typeof tag === 'number' && !Number.isNaN(tag)) ?? null;
|
||||
if (bitsPerSample && bitsPerSample >= 24 && bitsPerSample % 3 === 0) {
|
||||
bitsPerSample /= 3; // converts per-pixel bit depth to per-channel
|
||||
}
|
||||
|
||||
return bitsPerSample;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue