VulpesOS/gaia/apps/camera/js/lib/prepare-preview-blob.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

53 lines
1.2 KiB
JavaScript
Executable file

define(function(require, exports, module) {
'use strict';
/**
* Module Dependencies
*/
var parseJpegMetadata = require('jpegMetaDataParser');
/**
* Exports
*/
module.exports = function(blob, done) {
parseJpegMetadata(blob, onJpegParsed);
function onJpegParsed(metadata) {
metadata.blob = blob;
if (!metadata.preview) {
done(metadata);
return;
}
// If we found an EXIF preview,
// and can determine its size, then
// we can display it instead of the
// big image and save memory and time.
var start = metadata.preview.start;
var end = metadata.preview.end;
var previewBlob = blob.slice(start, end, 'image/jpeg');
parseJpegMetadata(previewBlob, onSuccess, onError);
// If we parsed the preview image, add its
// dimensions to the metadata.preview
// object, and then let the MediaFrame
// object display the preview instead of
// the full-size image.
function onSuccess(previewMetadata) {
metadata.preview.width = previewMetadata.width;
metadata.preview.height = previewMetadata.height;
done(metadata);
}
// If we couldn't parse the preview image,
// just display full-size.
function onError() {
done(metadata);
}
}
};
});