mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
Transcode heic/heif images
This commit is contained in:
@@ -196,8 +196,12 @@ export async function autoOrientJPEG(
|
||||
return attachment;
|
||||
}
|
||||
|
||||
// If we haven't downloaded the attachment yet, we won't have the data
|
||||
if (!attachment.data) {
|
||||
// If we haven't downloaded the attachment yet, we won't have the data.
|
||||
// All images go through handleImageAttachment before being sent and thus have
|
||||
// already been scaled to level, oriented, stripped of exif data, and saved
|
||||
// in high quality format. If we want to send the image in HQ we can return
|
||||
// the attachement as-is. Otherwise we'll have to further scale it down.
|
||||
if (!attachment.data || sendHQImages) {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
@@ -205,10 +209,7 @@ export async function autoOrientJPEG(
|
||||
attachment.data,
|
||||
attachment.contentType
|
||||
);
|
||||
const xcodedDataBlob = await scaleImageToLevel(
|
||||
dataBlob,
|
||||
sendHQImages || isIncoming
|
||||
);
|
||||
const xcodedDataBlob = await scaleImageToLevel(dataBlob, isIncoming);
|
||||
const xcodedDataArrayBuffer = await blobToArrayBuffer(xcodedDataBlob);
|
||||
|
||||
// IMPORTANT: We overwrite the existing `data` `ArrayBuffer` losing the original
|
||||
|
||||
+21
-17
@@ -3,20 +3,28 @@
|
||||
|
||||
export type MIMEType = string & { _mimeTypeBrand: never };
|
||||
|
||||
export const APPLICATION_OCTET_STREAM = 'application/octet-stream' as MIMEType;
|
||||
export const APPLICATION_JSON = 'application/json' as MIMEType;
|
||||
export const AUDIO_AAC = 'audio/aac' as MIMEType;
|
||||
export const AUDIO_MP3 = 'audio/mp3' as MIMEType;
|
||||
export const IMAGE_GIF = 'image/gif' as MIMEType;
|
||||
export const IMAGE_JPEG = 'image/jpeg' as MIMEType;
|
||||
export const IMAGE_PNG = 'image/png' as MIMEType;
|
||||
export const IMAGE_WEBP = 'image/webp' as MIMEType;
|
||||
export const IMAGE_ICO = 'image/x-icon' as MIMEType;
|
||||
export const IMAGE_BMP = 'image/bmp' as MIMEType;
|
||||
export const VIDEO_MP4 = 'video/mp4' as MIMEType;
|
||||
export const VIDEO_QUICKTIME = 'video/quicktime' as MIMEType;
|
||||
export const LONG_MESSAGE = 'text/x-signal-plain' as MIMEType;
|
||||
export const stringToMIMEType = (value: string): MIMEType => {
|
||||
return value as MIMEType;
|
||||
};
|
||||
|
||||
export const APPLICATION_OCTET_STREAM = stringToMIMEType(
|
||||
'application/octet-stream'
|
||||
);
|
||||
export const APPLICATION_JSON = stringToMIMEType('application/json');
|
||||
export const AUDIO_AAC = stringToMIMEType('audio/aac');
|
||||
export const AUDIO_MP3 = stringToMIMEType('audio/mp3');
|
||||
export const IMAGE_GIF = stringToMIMEType('image/gif');
|
||||
export const IMAGE_JPEG = stringToMIMEType('image/jpeg');
|
||||
export const IMAGE_PNG = stringToMIMEType('image/png');
|
||||
export const IMAGE_WEBP = stringToMIMEType('image/webp');
|
||||
export const IMAGE_ICO = stringToMIMEType('image/x-icon');
|
||||
export const IMAGE_BMP = stringToMIMEType('image/bmp');
|
||||
export const VIDEO_MP4 = stringToMIMEType('video/mp4');
|
||||
export const VIDEO_QUICKTIME = stringToMIMEType('video/quicktime');
|
||||
export const LONG_MESSAGE = stringToMIMEType('text/x-signal-plain');
|
||||
|
||||
export const isHeic = (value: string): boolean =>
|
||||
value === 'image/heic' || value === 'image/heif';
|
||||
export const isGif = (value: string): value is MIMEType =>
|
||||
value === 'image/gif';
|
||||
export const isJPEG = (value: string): value is MIMEType =>
|
||||
@@ -31,7 +39,3 @@ export const isAudio = (value: string): value is MIMEType =>
|
||||
Boolean(value) && value.startsWith('audio/') && !value.endsWith('aiff');
|
||||
export const isLongMessage = (value: unknown): value is MIMEType =>
|
||||
value === LONG_MESSAGE;
|
||||
|
||||
export const fromString = (value: string): MIMEType => {
|
||||
return value as MIMEType;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user