mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
- Support EXIF extraction from HEIF/HEIC and AVIF images by detecting container format and using correct WIC metadata paths. - Extend supported file extensions to include .heic, .heif, and .avif. - Add unit tests and test data for HEIF/AVIF extraction, with graceful handling if required Windows Store extensions are missing. - Update PowerRename settings UI to show HEIF/AVIF extension status and provide install buttons. - Extend ViewModel to detect/install required extensions and expose status for binding. <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #43758 <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng <yuleng@microsoft.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
86 lines
3.1 KiB
C++
86 lines
3.1 KiB
C++
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
#pragma once
|
|
#include "MetadataTypes.h"
|
|
#include "MetadataResultCache.h"
|
|
#include "PropVariantValue.h"
|
|
#include <wincodec.h>
|
|
#include <atlbase.h>
|
|
|
|
// Forward declarations for unit test friend classes
|
|
namespace WICMetadataExtractorTests
|
|
{
|
|
class ExtractAVIFMetadataTests;
|
|
}
|
|
|
|
namespace PowerRenameLib
|
|
{
|
|
/// <summary>
|
|
/// Metadata path format based on container type
|
|
/// </summary>
|
|
enum class MetadataPathFormat
|
|
{
|
|
JPEG, // Uses /app1/ifd/... paths (JPEG)
|
|
IFD // Uses /ifd/... paths (HEIF, TIFF, etc.)
|
|
};
|
|
|
|
/// <summary>
|
|
/// Windows Imaging Component (WIC) implementation for metadata extraction
|
|
/// Provides efficient batch extraction of all metadata types with built-in caching
|
|
/// </summary>
|
|
class WICMetadataExtractor
|
|
{
|
|
// Friend declarations for unit testing
|
|
friend class WICMetadataExtractorTests::ExtractAVIFMetadataTests;
|
|
|
|
public:
|
|
WICMetadataExtractor();
|
|
~WICMetadataExtractor();
|
|
|
|
// Public metadata extraction methods
|
|
bool ExtractEXIFMetadata(
|
|
const std::wstring& filePath,
|
|
EXIFMetadata& outMetadata);
|
|
|
|
bool ExtractXMPMetadata(
|
|
const std::wstring& filePath,
|
|
XMPMetadata& outMetadata);
|
|
|
|
void ClearCache();
|
|
|
|
private:
|
|
// WIC factory management
|
|
static CComPtr<IWICImagingFactory> GetWICFactory();
|
|
static void InitializeWIC();
|
|
|
|
// WIC operations
|
|
CComPtr<IWICBitmapDecoder> CreateDecoder(const std::wstring& filePath);
|
|
CComPtr<IWICMetadataQueryReader> GetMetadataReader(IWICBitmapDecoder* decoder);
|
|
|
|
bool LoadEXIFMetadata(const std::wstring& filePath, EXIFMetadata& outMetadata);
|
|
bool LoadXMPMetadata(const std::wstring& filePath, XMPMetadata& outMetadata);
|
|
|
|
// Batch extraction methods
|
|
void ExtractAllEXIFFields(IWICMetadataQueryReader* reader, EXIFMetadata& metadata, MetadataPathFormat pathFormat);
|
|
void ExtractGPSData(IWICMetadataQueryReader* reader, EXIFMetadata& metadata, MetadataPathFormat pathFormat);
|
|
void ExtractAllXMPFields(IWICMetadataQueryReader* reader, XMPMetadata& metadata);
|
|
|
|
// Internal container format detection
|
|
MetadataPathFormat GetMetadataPathFormatFromDecoder(IWICBitmapDecoder* decoder);
|
|
|
|
// Field reading helpers
|
|
std::optional<SYSTEMTIME> ReadDateTime(IWICMetadataQueryReader* reader, const std::wstring& path);
|
|
std::optional<std::wstring> ReadString(IWICMetadataQueryReader* reader, const std::wstring& path);
|
|
std::optional<int64_t> ReadInteger(IWICMetadataQueryReader* reader, const std::wstring& path);
|
|
std::optional<double> ReadDouble(IWICMetadataQueryReader* reader, const std::wstring& path);
|
|
|
|
// Helper methods
|
|
std::optional<PropVariantValue> ReadMetadata(IWICMetadataQueryReader* reader, const std::wstring& path);
|
|
|
|
private:
|
|
MetadataResultCache cache;
|
|
};
|
|
}
|