File indexing completed on 2025-01-05 03:57:24

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-05-24
0007  * Description : utils to generate video frames.
0008  *
0009  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "frameutils.h"
0016 
0017 // Qt includes
0018 
0019 #include <QColor>
0020 #include <QPainter>
0021 
0022 // Local includes
0023 
0024 #include "dimg.h"
0025 #include "drawdecoding.h"
0026 #include "digikam_config.h"
0027 #include "digikam_debug.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 QImage FrameUtils::makeFramedImage(const QString& file, const QSize& outSize)
0033 {
0034     QImage timg;
0035 
0036     if (!file.isEmpty())
0037     {
0038         qCDebug(DIGIKAM_GENERAL_LOG) << "Load frame from" << file;
0039 
0040         // The Raw decoding settings for DImg loader.
0041         DRawDecoderSettings settings;
0042         settings.halfSizeColorImage    = false;
0043         settings.sixteenBitsImage      = false;
0044         settings.RGBInterpolate4Colors = false;
0045         settings.RAWQuality            = DRawDecoderSettings::BILINEAR;
0046 
0047         DImg dimg(file, nullptr, DRawDecoding(settings));
0048         dimg.exifRotate(file);
0049         timg = dimg.copyQImage();
0050     }
0051 
0052     return makeScaledImage(timg, outSize);
0053 }
0054 
0055 QImage FrameUtils::makeScaledImage(QImage& timg, const QSize& outSize)
0056 {
0057     QImage qimg(outSize, QImage::Format_ARGB32);
0058     qimg.fill(QColor(0, 0, 0, 255));
0059 
0060     if (!timg.isNull())
0061     {
0062         timg = timg.scaled(outSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
0063 
0064         QPainter p(&qimg);
0065         p.drawImage((qimg.width()  / 2) - (timg.width()  / 2),
0066                     (qimg.height() / 2) - (timg.height() / 2),
0067                     timg);
0068     }
0069 
0070     return qimg;
0071 }
0072 
0073 } // namespace Digikam