Skip to content

Commit

Permalink
First set of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Oct 6, 2024
1 parent cd82d37 commit d4dee4f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,16 @@
#include <QString>

/*
* An info item has a name, a text and an optional toolTip. These are used to show them in the
* fileInfoWidget. For example: ["File Name", "file.yuv"] or ["Number Frames", "123"] Another option
* is to show a button. If the user clicks on it, the callback function infoListButtonPressed() for
* the corresponding playlist item is called.
* An info item has a name, a text and an optional description. These are used to show them in the
* fileInfoWidget. For example: ["File Name", "file.yuv"] or ["Number Frames", "123"].
*/
struct InfoItem
{
InfoItem(const QString &name,
const QString &text,
const QString &toolTip = QString(),
bool button = false,
int buttonID = -1)
: name(name), text(text), button(button), buttonID(buttonID), toolTip(toolTip)
{
}
QString name{};
QString text{};
bool button{};
int buttonID{};
QString toolTip{};
std::string name{};
std::string text{};
std::string description{};

InfoItem(std::string &&name, std::string &&text) : name(std::move(name)), text(std::move(text)) {}
};

struct InfoData
Expand Down
16 changes: 8 additions & 8 deletions YUViewLib/src/decoder/decoderHM.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#include <QLibrary>

#include <common/FileInfo.h>
#include <common/InfoItemAndData.h>
#include <decoder/decoderBase.h>
#include <decoder/externalHeader/libHMDecoder.h>
#include <video/yuv/videoHandlerYUV.h>
Expand All @@ -51,11 +51,11 @@ struct LibraryFunctionsHM
void (*libHMDec_set_SEI_Check)(libHMDec_context *, bool check_hash){};
void (*libHMDec_set_max_temporal_layer)(libHMDec_context *, int max_layer){};
libHMDec_error (*libHMDec_push_nal_unit)(libHMDec_context *decCtx,
const void * data8,
const void *data8,
int length,
bool eof,
bool & bNewPicture,
bool & checkOutputPictures){};
bool &bNewPicture,
bool &checkOutputPictures){};

// Get a picture and retrive information on the picture
libHMDec_picture *(*libHMDec_get_picture)(libHMDec_context *){};
Expand All @@ -77,8 +77,8 @@ struct LibraryFunctionsHM
libHMDec_BlockValue *(*libHMDEC_get_internal_info)(libHMDec_context *,
libHMDec_picture *pic,
unsigned int typeIdx,
unsigned int & nrValues,
bool & callAgain){};
unsigned int &nrValues,
bool &callAgain){};
libHMDec_error (*libHMDEC_clear_internal_info)(libHMDec_context *decCtx){};
};

Expand Down Expand Up @@ -107,7 +107,7 @@ class decoderHM : public decoderBaseSingleLib
private:
// A private constructor that creates an uninitialized decoder library.
// Used by checkLibraryFile to check if a file can be used as a this decoder.
decoderHM(){};
decoderHM() {};

// Return the possible names of the HM library
QStringList getLibraryNames() const override;
Expand Down Expand Up @@ -150,7 +150,7 @@ class decoderHM : public decoderBaseSingleLib
QByteArray currentOutputBuffer;
void copyImgToByteArray(
libHMDec_picture *src,
QByteArray & dst); // Copy the raw data from the de265_image source *src to the byte array
QByteArray &dst); // Copy the raw data from the de265_image source *src to the byte array
#endif

LibraryFunctionsHM lib;
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/decoder/decoderVTM.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#include <QLibrary>

#include <common/FileInfo.h>
#include <common/InfoItemAndData.h>

#include "decoderBase.h"
#include "externalHeader/libVTMDecoder.h"
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/decoder/decoderVVDec.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#include <QLibrary>

#include <common/FileInfo.h>
#include <common/InfoItemAndData.h>
#include <decoder/decoderBase.h>
#include <decoder/externalHeader/vvdec/vvdec.h>
#include <video/yuv/videoHandlerYUV.h>
Expand Down
41 changes: 24 additions & 17 deletions YUViewLib/src/filesource/FileSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include <common/Typedef.h>

#include <format>

#include <QDateTime>
#include <QDir>
#include <QSettings>
Expand All @@ -55,26 +57,21 @@ FileSource::FileSource()
&FileSource::fileSystemWatcherFileChanged);
}

bool FileSource::openFile(const QString &filePath)
bool FileSource::openFile(const std::string &filePath)
{
// Check if the file exists
this->fileInfo.setFile(filePath);
if (!this->fileInfo.exists() || !this->fileInfo.isFile())
if (!std::filesystem::is_regular_file(filePath))
return false;

if (this->isFileOpened && this->srcFile.isOpen())
this->srcFile.close();

// open file for reading
this->srcFile.setFileName(filePath);
this->srcFile.setFileName(QString::fromStdString(filePath));
this->isFileOpened = this->srcFile.open(QIODevice::ReadOnly);
if (!this->isFileOpened)
return false;

// Save the full file path
this->fullFilePath = filePath;

// Install a watcher for the file (if file watching is active)
this->updateFileWatchSetting();
this->fileChanged = false;

Expand Down Expand Up @@ -115,27 +112,37 @@ int64_t FileSource::readBytes(QByteArray &targetBuffer, int64_t startPos, int64_
return this->srcFile.read(targetBuffer.data(), nrBytes);
}

QList<InfoItem> FileSource::getFileInfoList() const
std::vector<InfoItem> FileSource::getFileInfoList() const
{
QList<InfoItem> infoList;

if (!this->isFileOpened)
return infoList;
return {};

std::vector<InfoItem> infoList;
infoList.emplace_back("File Path", this->fullFilePath);
infoList.emplace_back("Time Modified", std::format())


infoList.append(InfoItem("File Path", this->fileInfo.absoluteFilePath()));
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
auto createdtime = this->fileInfo.created().toString("yyyy-MM-dd hh:mm:ss");
#else
auto createdtime = this->fileInfo.birthTime().toString("yyyy-MM-dd hh:mm:ss");
#endif
infoList.append(InfoItem("Time Created", createdtime));
infoList.append(
InfoItem("Time Modified", this->fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss")));
infoList.append(InfoItem("Nr Bytes", QString("%1").arg(this->fileInfo.size())));
infoList.emplace_back("Time Created", createdtime.toStdString());
infoList.emplace_back("Time Modified",
this->fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss"));
infoList.emplace_back("Nr Bytes", QString("%1").arg(this->fileInfo.size()));

return infoList;
}

int64_t FileSource::getFileSize() const
{
if (!this->isFileOpened)
return -1;

return !isFileOpened ? -1 : fileInfo.size();
}

QString FileSource::getAbsoluteFilePath() const
{
return this->isFileOpened ? this->fileInfo.absoluteFilePath() : QString();
Expand Down
22 changes: 10 additions & 12 deletions YUViewLib/src/filesource/FileSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#include <QMutexLocker>
#include <QString>

#include <common/FileInfo.h>
#include <common/EnumMapper.h>
#include <common/InfoItemAndData.h>
#include <common/Typedef.h>

enum class InputFormat
Expand Down Expand Up @@ -70,14 +70,13 @@ class FileSource : public QObject
public:
FileSource();

virtual bool openFile(const QString &filePath);
virtual bool openFile(const std::string &filePath);

virtual QList<InfoItem> getFileInfoList() const;
int64_t getFileSize() const { return !isFileOpened ? -1 : fileInfo.size(); }
QString getAbsoluteFilePath() const;
QFileInfo getFileInfo() const { return this->fileInfo; }
QFile *getQFile() { return &this->srcFile; }
bool getAndResetFileChangedFlag();
virtual std::vector<InfoItem> getFileInfoList() const;
int64_t getFileSize() const;
std::string getAbsoluteFilePath() const;
QFile *getQFile() { return &this->srcFile; }
bool getAndResetFileChangedFlag();

// Return true if the file could be opened and is ready for use.
bool isOk() const { return this->isFileOpened; }
Expand Down Expand Up @@ -107,10 +106,9 @@ private slots:
void fileSystemWatcherFileChanged(const QString &) { fileChanged = true; }

protected:
QString fullFilePath{};
QFileInfo fileInfo;
QFile srcFile;
bool isFileOpened{};
std::string fullFilePath{};
QFile srcFile;
bool isFileOpened{};

private:
QFileSystemWatcher fileWatcher{};
Expand Down
8 changes: 4 additions & 4 deletions YUViewLib/src/video/FrameHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#pragma once

#include <common/FileInfo.h>
#include <common/InfoItemAndData.h>
#include <common/SaveUi.h>
#include <common/Typedef.h>
#include <common/YUViewDomElement.h>
Expand Down Expand Up @@ -94,7 +94,7 @@ class FrameHandler : public QObject
// Calculate the difference of this FrameHandler to another FrameHandler. This
// function can be overloaded by more specialized video items. For example the videoHandlerYUV
// overloads this and calculates the difference directly on the YUV values (if possible).
virtual QImage calculateDifference(FrameHandler * item2,
virtual QImage calculateDifference(FrameHandler *item2,
const int frameIdxItem0,
const int frameIdxItem1,
QList<InfoItem> &differenceInfoList,
Expand All @@ -115,9 +115,9 @@ class FrameHandler : public QObject
// playlistItemYUVSource). If a second FrameHandler item is provided, the difference values will
// be drawn. For the second item, a second frame index must be provided (set markDifference if you
// want only differing values to be marked).
virtual void drawPixelValues(QPainter * painter,
virtual void drawPixelValues(QPainter *painter,
const int frameIdx,
const QRect & videoRect,
const QRect &videoRect,
const double zoomFactor,
FrameHandler *item2 = nullptr,
const bool markDifference = false,
Expand Down

0 comments on commit d4dee4f

Please sign in to comment.