File indexing completed on 2025-01-19 03:50:59
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2019-09-26 0007 * Description : A HEIF IO file for DImg framework 0008 * 0009 * SPDX-FileCopyrightText: 2019-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * Other HEIF loader implementions: 0012 * https://github.com/KDE/krita/tree/master/plugins/impex/heif 0013 * https://github.com/jakar/qt-heif-image-plugin 0014 * https://github.com/ImageMagick/ImageMagick/blob/master/coders/heic.c 0015 * https://github.com/GNOME/gimp/blob/master/plug-ins/common/file-heif.c 0016 * 0017 * Specification: https://nokiatech.github.io/heif/technical.html 0018 * 0019 * SPDX-License-Identifier: GPL-2.0-or-later 0020 * 0021 * ============================================================ */ 0022 0023 #ifndef DIGIKAM_DIMG_HEIF_LOADER_H 0024 #define DIGIKAM_DIMG_HEIF_LOADER_H 0025 0026 // Libheif includes 0027 0028 #include <libheif/heif.h> 0029 0030 // Local includes 0031 0032 #include "dimg.h" 0033 #include "dimgloader.h" 0034 0035 using namespace Digikam; 0036 0037 namespace Digikam 0038 { 0039 0040 class DImgHEIFLoader : public DImgLoader 0041 { 0042 0043 public: 0044 0045 explicit DImgHEIFLoader(DImg* const image); 0046 ~DImgHEIFLoader() override; 0047 0048 bool load(const QString& filePath, DImgLoaderObserver* const observer) override; 0049 bool save(const QString& filePath, DImgLoaderObserver* const observer) override; 0050 0051 bool hasAlpha() const override; 0052 bool sixteenBit() const override; 0053 bool isReadOnly() const override; 0054 0055 /** 0056 * Determine libx265 encoder bits depth capability: 8=standard, 10, 12, or more. 0057 * Return -1 if encoder instance is not found. 0058 */ 0059 static int x265MaxBitsDepth(); 0060 0061 private: 0062 0063 bool isHeifSuccess(struct heif_error* const error); 0064 0065 /// Read operations 0066 0067 bool readHEICColorProfile(struct heif_image_handle* const image_handle); 0068 bool readHEICImageByID(struct heif_context* const heif_context, 0069 heif_item_id image_id); 0070 0071 bool readHEICImageByHandle(struct heif_image_handle* image_handle, 0072 struct heif_image* heif_image, bool loadImageData); 0073 0074 /// Save operations 0075 0076 bool saveHEICColorProfile(struct heif_image* const image); 0077 0078 bool saveHEICMetadata(struct heif_context* const heif_context, 0079 struct heif_image_handle* const image_handle); 0080 0081 private: 0082 0083 bool m_sixteenBit; 0084 bool m_hasAlpha; 0085 0086 DImgLoaderObserver* m_observer; 0087 }; 0088 0089 } // namespace Digikam 0090 0091 #endif // DIGIKAM_DIMG_HEIF_LOADER_H