File indexing completed on 2025-01-05 03:56:32

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 28/08/2021
0007  * Description : Writer of focus points to exiftool data
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2021 by Phuoc Khanh Le <phuockhanhnk94 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "focuspoints_writer.h"
0017 
0018 // Qt includes
0019 
0020 #include <QScopedPointer>
0021 
0022 // Local includes
0023 
0024 #include "exiftoolparser.h"
0025 #include "digikam_debug.h"
0026 
0027 namespace Digikam
0028 {
0029 
0030 class Q_DECL_HIDDEN FocusPointsWriter::Private
0031 {
0032 public:
0033 
0034     explicit Private()
0035       : exifTool(nullptr)
0036     {
0037     };
0038 
0039     ExifToolParser* exifTool;
0040     QString         path;
0041 };
0042 
0043 FocusPointsWriter::FocusPointsWriter(QObject* const parent, const QString& path)
0044     : QObject(parent),
0045       d      (new Private)
0046 {
0047     d->exifTool = new ExifToolParser(this);
0048     d->exifTool->load(path);
0049     d->path     = path;
0050 }
0051 
0052 FocusPointsWriter::~FocusPointsWriter()
0053 {
0054     delete d;
0055 }
0056 
0057 void FocusPointsWriter::writeFocusPoint(const FocusPoint& point)
0058 {
0059     ExifToolParser::ExifToolData newTags;
0060 
0061     QPointF pos = point.getCenterPosition();
0062     QSizeF size = point.getSize();
0063 
0064     newTags.insert(QLatin1String("xmp:RegionAreaX"),
0065                    QVariantList() << QString::number(pos.x())
0066                                   << QString()
0067                                   << QString::fromUtf8("Region Area X"));
0068 
0069     newTags.insert(QLatin1String("xmp:RegionAreaY"),
0070                    QVariantList() << QString::number(pos.y())
0071                                   << QString()
0072                                   << QString::fromUtf8("Region Area Y"));
0073 
0074     newTags.insert(QLatin1String("xmp:RegionAreaH"),
0075                    QVariantList() << QString::number(size.height())
0076                                   << QString()
0077                                   << QString::fromUtf8("Region Area Height"));
0078 
0079     newTags.insert(QLatin1String("xmp:RegionAreaW"),
0080                    QVariantList() << QString::number(size.width())
0081                                   << QString()
0082                                   << QString::fromUtf8("Region Area Width"));
0083 
0084     newTags.insert(QLatin1String("xmp:RegionDescription"),
0085                    QVariantList() << QString::fromUtf8("digikam customized auto focus point")
0086                                   << QString()
0087                                   << QString::fromUtf8("Region description"));
0088 
0089     d->exifTool->applyChanges(d->path, newTags);
0090 }
0091 
0092 void FocusPointsWriter::writeFocusPoint(const QRectF& rectF)
0093 {
0094     FocusPoint point
0095     {
0096         static_cast<float> (rectF.topLeft().x() + 0.5 * rectF.width()),
0097         static_cast<float> (rectF.topLeft().y() + 0.5 * rectF.height()),
0098         static_cast<float> (rectF.width()), static_cast<float>(rectF.height())
0099     };
0100 
0101     writeFocusPoint(point);
0102 }
0103 
0104 } // namespace Digikam
0105 
0106 #include "moc_focuspoints_writer.cpp"