Skip to content

Add support for HEIC_ULTRAHDR #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

epeevs
Copy link
Contributor

@epeevs epeevs commented Jun 5, 2025

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @epeevs, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello team,

Gemini here, providing a summary of this pull request authored by @epeevs. The primary goal of this PR is to introduce support for capturing images in the HEIC UltraHDR format within the sample application, leveraging the Camera2 API. This builds upon the existing UltraHDR capture sample by making it more generic and adding a specific implementation for HEIC.

The changes involve adding a new sample entry in the demo list, creating a new class specifically for HEIC UltraHDR capture that extends the existing UltraHDR sample class, and modifying the base UltraHDR sample class to be more flexible regarding the output format and handle orientation correctly for HEIC images using Camera2 controls rather than ExifInterface. The project's SDK versions have also been updated to accommodate the new API constants.

Highlights

  • New Sample Added: A new sample demo entry, "HEIC UltraHDR Image Capture", has been added to the main sample list. This new sample specifically demonstrates capturing images in the HEIC UltraHDR format using Camera2.
  • HEIC UltraHDR Implementation: A new class, Camera2HeicUltraHDRCapture, is introduced. This class extends the existing Camera2UltraHDRCapture and overrides the image format to ImageFormat.HEIC_ULTRAHDR. This sample requires Android 15 (Baklava) or higher.
  • Base UltraHDR Sample Refactoring: The base Camera2UltraHDRCapture class has been refactored to be open and use a protected ULTRAHDR_FORMAT property, allowing subclasses (like the new HEIC one) to specify the desired format. It defaults to ImageFormat.JPEG_R for backward compatibility with the original UltraHDR sample.
  • Orientation Handling for HEIC: The method for handling image orientation has been updated. The use of ExifInterface for setting orientation metadata is removed, as it's not suitable for HEIC. Instead, the Camera2 control path (CaptureRequest.JPEG_ORIENTATION) is used, which is the recommended approach for various formats, including HEIC.
  • SDK Version Update: The compileSdk and targetSdk versions for the camera2 sample module have been updated from 35 to 36.

Changelog

Click here to see the changelog
  • app/src/main/java/com/example/platform/app/SampleDemo.kt
    • Imported the new Camera2HeicUltraHDRCapture class (line 27).
    • Added a new ComposableSampleDemo entry for "HEIC UltraHDR Image Capture" with id "ultrahdr-heic-image-capture", linking to Camera2HeicUltraHDRCapture and setting minSdk to BAKLAVA (lines 213-221).
  • samples/camera/camera2/build.gradle.kts
    • Updated compileSdk from 35 to 36 (line 25).
    • Updated targetSdk from 35 to 36 (line 29).
  • samples/camera/camera2/src/main/java/com/example/platform/camera/imagecapture/Camera2HeicUltraHDRCapture.kt
    • Added a new file defining Camera2HeicUltraHDRCapture (lines 1-26).
    • This class extends Camera2UltraHDRCapture and overrides ULTRAHDR_FORMAT to ImageFormat.HEIC_ULTRAHDR (line 25).
    • Annotated the class with @RequiresApi(Build.VERSION_CODES.BAKLAVA) (line 23).
  • samples/camera/camera2/src/main/java/com/example/platform/camera/imagecapture/Camera2UltraHDRCapture.kt
    • Removed the import for ExifInterface (line 51).
    • Removed the @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) annotation and made the class open (line 78).
    • Introduced a protected open property ULTRAHDR_FORMAT defaulting to ImageFormat.JPEG_R (line 85).
    • Used ULTRAHDR_FORMAT instead of hardcoded ImageFormat.JPEG_R when setting up the ImageReader (lines 306, 312).
    • Removed the code that used ExifInterface to save orientation metadata (lines 330-333).
    • Added a comment explaining the change in orientation handling for HEIC (lines 327-329).
    • Used ULTRAHDR_FORMAT instead of hardcoded ImageFormat.JPEG_R in the canEncodeUltraHDR check (line 356).
    • Added request.set(CaptureRequest.JPEG_ORIENTATION, relativeOrientation.value ?: 0) to the capture request to handle orientation via Camera2 controls (line 500).
    • Modified the createFile function to accept the image format and use the appropriate file extension (.jpg or .heic) (lines 637-643).
    • Updated the call to createFile to pass the ULTRAHDR_FORMAT (line 586).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


New format arrives,
HEIC UltraHDR takes flight,
Camera sees the light.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively introduces support for HEIC UltraHDR image capture. The approach of extending the existing Camera2UltraHDRCapture class is sound, and the necessary API changes (like using CaptureRequest.JPEG_ORIENTATION instead of EXIF manipulation for HEIC) are correctly implemented. The SDK version updates and new sample demo registration are also appropriate.

Overall, the changes are well-done and enhance the camera sample capabilities. I have one suggestion for improving the robustness of the file creation logic for future extensions.

Summary of Findings

  • File Extension Handling in createFile: The createFile method determines file extensions based on the image format. The current else case defaults to .heic, which is fine for this PR but could be problematic if other non-HEIC UltraHDR formats are supported in the future via subclassing. A more explicit handling of known formats and a clearer strategy for unknown ones would improve robustness. (Commented with medium severity)
  • Copyright Year: The new file samples/camera/camera2/src/main/java/com/example/platform/camera/imagecapture/Camera2HeicUltraHDRCapture.kt has a copyright year of 2025. Typically, this is the year of creation (e.g., 2024) or matches the project's existing files (e.g., Camera2UltraHDRCapture.kt uses 2023). Please verify if 2025 is intentional or a typo. (Not commented due to review settings: low severity)
  • KDoc Documentation: Consider adding KDoc comments to the new class Camera2HeicUltraHDRCapture and its overridden ULTRAHDR_FORMAT property. Also, the newly open base class Camera2UltraHDRCapture and its ULTRAHDR_FORMAT property could benefit from KDocs explaining their roles and extensibility. This would improve code clarity and maintainability. (Not commented due to review settings: low severity)

Merge Readiness

The pull request is in good shape and introduces a valuable feature. I recommend addressing the medium-severity comment regarding file extension handling in createFile to enhance future maintainability. Once that's considered, the PR should be ready for merging. As an AI reviewer, I am not authorized to approve pull requests; please ensure further review and approval from authorized team members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant