processPhoto method

Uint8List processPhoto(
  1. Uint8List imageBuffer,
  2. AutoFocusType? autofocusType
)

Processes a photo to correct rotation and add metadata.

Args: imageBuffer (Uint8List): The photo as a byte array. autofocusType (AutoFocusType?): The type of autofocus that was used to capture the photo.

Returns: Uint8List: The processed photo as a byte array.

Implementation

Uint8List processPhoto(Uint8List imageBuffer, AutoFocusType? autofocusType) {
  ExifData exif = decodeJpgExif(imageBuffer) ?? ExifData();

  exif.exifIfd.make = "Brilliant Labs";
  exif.exifIfd.model = "Frame";
  exif.exifIfd.software = "Frame Dart SDK";
  if (autofocusType != null) {
    exif.imageIfd.data[0x9207] = IfdValueShort(autofocusType.exifValue);
  }

  exif.imageIfd.data[0x9003] =
      IfdValueAscii(DateTime.now().toIso8601String());

  // Set orientation to rotate 90 degrees clockwise
  exif.imageIfd.orientation = 6;

  // Inject updated EXIF data back into the image
  final updatedImageBuffer = injectJpgExif(imageBuffer, exif);
  if (updatedImageBuffer == null) {
    throw Exception("Failed to inject EXIF data");
  }
  return updatedImageBuffer;
}