Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions YUViewLib/src/common/Formatting.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#pragma once

#include "Size.h"
#include "Typedef.h"

#include <sstream>
Expand Down
45 changes: 45 additions & 0 deletions YUViewLib/src/common/Offset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

struct Offset
{
Offset() = default;
Offset(int x, int y) : x(x), y(y) {}

bool operator==(const Offset &other) const { return this->x == other.x && this->y == other.y; }
bool operator!=(const Offset &other) const { return this->x != other.x || this->y != other.y; }

int x{};
int y{};
};
60 changes: 60 additions & 0 deletions YUViewLib/src/common/Size.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

struct Size
{
static constexpr unsigned MAX_DIMENSION = 100000;

constexpr Size(unsigned width, unsigned height) : width(width), height(height) {}
constexpr Size() = default;

constexpr bool operator==(const Size &other) const
{
return this->width == other.width && this->height == other.height;
}
constexpr bool operator!=(const Size &other) const
{
return this->width != other.width || this->height != other.height;
}

explicit operator bool() const { return this->isValid(); }
constexpr bool isValid() const
{
return this->width > 0 && this->width < MAX_DIMENSION && //
this->height > 0 && this->height < MAX_DIMENSION;
}

unsigned width{};
unsigned height{};
};
29 changes: 0 additions & 29 deletions YUViewLib/src/common/Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,6 @@ struct Ratio
int den{};
};

struct Size
{
constexpr Size(unsigned width, unsigned height) : width(width), height(height) {}
constexpr Size() = default;

constexpr bool operator==(const Size &other) const
{
return this->width == other.width && this->height == other.height;
}
constexpr bool operator!=(const Size &other) const
{
return this->width != other.width || this->height != other.height;
}
explicit operator bool() const { return this->isValid(); }
constexpr bool isValid() const { return this->width > 0 && this->height > 0; }
unsigned width{};
unsigned height{};
};

struct Offset
{
Offset(int x, int y) : x(x), y(y) {}
Offset() = default;
bool operator==(const Offset &other) const { return this->x == other.x && this->x == other.x; }
bool operator!=(const Offset &other) const { return this->x != other.x || this->y != other.y; }
int x{};
int y{};
};

// A list of value pair lists, where every list has a string (title)
class ValuePairListSets : public QList<QPair<QString, QStringPairList>>
{
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/dataSource/DataSourceLocalFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ getLastWriteTime(const std::filesystem::path &filePath) noexcept
{
return {std::filesystem::last_write_time(filePath)};
}
catch (const std::exception &e)
catch (const std::exception &)
{
return {};
}
Expand Down
1 change: 1 addition & 0 deletions YUViewLib/src/decoder/decoderTarga.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#pragma once

#include <common/Size.h>
#include <common/Typedef.h>

#include <optional>
Expand Down
2 changes: 2 additions & 0 deletions YUViewLib/src/ffmpeg/AVCodecContextWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#pragma once

#include "FFMpegLibrariesTypes.h"

#include <common/Size.h>
#include <common/Typedef.h>

namespace FFmpeg
Expand Down
2 changes: 2 additions & 0 deletions YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#pragma once

#include "FFMpegLibrariesTypes.h"

#include <common/Size.h>
#include <common/Typedef.h>

namespace FFmpeg
Expand Down
10 changes: 6 additions & 4 deletions YUViewLib/src/ffmpeg/AVFrameWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#pragma once

#include "FFMpegLibrariesTypes.h"

#include <common/Size.h>
#include <common/Typedef.h>

namespace FFmpeg
Expand All @@ -47,9 +49,9 @@ class AVFrameWrapper

void clear();

uint8_t * getData(int component);
uint8_t *getData(int component);
int getLineSize(int component);
AVFrame * getFrame() const;
AVFrame *getFrame() const;
int getWidth();
int getHeight();
Size getSize();
Expand All @@ -64,7 +66,7 @@ class AVFrameWrapper
void update();

// These are private. Use "update" to update them from the AVFormatContext
uint8_t * data[AV_NUM_DATA_POINTERS]{};
uint8_t *data[AV_NUM_DATA_POINTERS]{};
int linesize[AV_NUM_DATA_POINTERS]{};
int width{};
int height{};
Expand All @@ -81,7 +83,7 @@ class AVFrameWrapper
int quality{};
AVDictionary *metadata{};

AVFrame * frame{};
AVFrame *frame{};
LibraryVersion libVer{};
};

Expand Down
18 changes: 15 additions & 3 deletions YUViewLib/src/filesource/FileSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,20 @@ int64_t FileSource::readBytes(QByteArray &targetBuffer, int64_t startPos, int64_
if (!this->isOk())
return 0;

if (startPos < 0 || nrBytes <= 0)
return 0;

if (targetBuffer.size() < nrBytes)
targetBuffer.resize(nrBytes);
{
try
{
targetBuffer.resize(nrBytes);
}
catch (const std::bad_alloc &)
{
return 0;
}
}

#if FILESOURCE_DEBUG_SIMULATESLOWLOADING && !NDEBUG
QThread::msleep(50);
Expand Down Expand Up @@ -133,7 +145,7 @@ std::optional<int64_t> FileSource::getFileSize() const
const auto size = std::filesystem::file_size(this->fullFilePath);
return static_cast<int64_t>(size);
}
catch (const std::filesystem::filesystem_error &e)
catch (const std::filesystem::filesystem_error &)
{
return {};
}
Expand Down Expand Up @@ -177,7 +189,7 @@ void FileSource::clearFileCache()

LPCWSTR file = this->fullFilePath.wstring().c_str();
HANDLE hFile =
CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
CloseHandle(hFile);

this->srcFile.setFileName(this->fullFilePath);
Expand Down
10 changes: 5 additions & 5 deletions YUViewLib/src/filesource/FileSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ enum class InputFormat
};

constexpr EnumMapper<InputFormat, 5> InputFormatMapper = {
std::make_pair(InputFormat::Invalid, "Invalid"),
std::make_pair(InputFormat::AnnexBHEVC, "AnnexBHEVC"),
std::make_pair(InputFormat::AnnexBAVC, "AnnexBAVC"),
std::make_pair(InputFormat::AnnexBVVC, "AnnexBVVC"),
std::make_pair(InputFormat::Libav, "Libav")};
std::make_pair(InputFormat::Invalid, "Invalid"),
std::make_pair(InputFormat::AnnexBHEVC, "AnnexBHEVC"),
std::make_pair(InputFormat::AnnexBAVC, "AnnexBAVC"),
std::make_pair(InputFormat::AnnexBVVC, "AnnexBVVC"),
std::make_pair(InputFormat::Libav, "Libav")};

/* The FileSource class provides functions for accessing files. Besides the reading of
* certain blocks of the file, it also directly provides information on the file for the
Expand Down
1 change: 1 addition & 0 deletions YUViewLib/src/filesource/FrameFormatGuess.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#pragma once

#include <common/Size.h>
#include <common/Typedef.h>
#include <video/PixelFormat.h>

Expand Down
7 changes: 6 additions & 1 deletion YUViewLib/src/playlistitem/playlistItemRawFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,18 @@ void playlistItemRawFile::loadRawData(int frameIdx)
return;

auto nrBytes = this->video->getBytesPerFrame();
if (nrBytes < 0)
return;

// Load the raw data for the given frameIdx from file and set it in the video
int64_t fileStartPos;
if (this->isY4MFile)
fileStartPos = this->y4mFrameIndices.at(frameIdx);
else
fileStartPos = frameIdx * nrBytes;
fileStartPos = static_cast<int64_t>(frameIdx) * nrBytes;

if (fileStartPos < 0)
return;

DEBUG_RAWFILE("playlistItemRawFile::loadRawData Start loading frame " << frameIdx << " bytes "
<< int(nrBytes));
Expand Down
2 changes: 2 additions & 0 deletions YUViewLib/src/statistics/StatisticsData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#pragma once

#include <common/Size.h>

#include "FrameTypeData.h"
#include "StatisticsType.h"

Expand Down
4 changes: 2 additions & 2 deletions YUViewLib/src/video/FrameHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ QLayout *FrameHandler::createFrameHandlerControls(bool isSizeFixed)
ui.setupUi();

// Set default values
ui.widthSpinBox->setMaximum(100000);
ui.widthSpinBox->setMaximum(Size::MAX_DIMENSION);
ui.widthSpinBox->setValue(frameSize.width);
ui.widthSpinBox->setEnabled(!isSizeFixed);
ui.heightSpinBox->setMaximum(100000);
ui.heightSpinBox->setMaximum(Size::MAX_DIMENSION);
ui.heightSpinBox->setValue(frameSize.height);
ui.heightSpinBox->setEnabled(!isSizeFixed);
ui.frameSizeComboBox->addItems(presetFrameSizes.getFormattedNames());
Expand Down
1 change: 1 addition & 0 deletions YUViewLib/src/video/FrameHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <common/InfoItemAndData.h>
#include <common/SaveUi.h>
#include <common/Size.h>
#include <common/Typedef.h>
#include <common/YUViewDomElement.h>

Expand Down
5 changes: 4 additions & 1 deletion YUViewLib/src/video/rgb/PixelFormatRGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
#pragma once

#include <common/EnumMapper.h>
#include <common/Size.h>
#include <common/Typedef.h>

#include <video/PixelFormat.h>

#include <optional>
#include <string_view>
#include <video/PixelFormat.h>

#include <string>

Expand Down
5 changes: 4 additions & 1 deletion YUViewLib/src/video/yuv/PixelFormatYUV.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
#pragma once

#include <common/EnumMapper.h>
#include <common/Offset.h>
#include <common/Size.h>
#include <common/Typedef.h>

#include <video/PixelFormat.h>

// The YUV_Internals namespace. We use this namespace because of the dialog. We want to be able to
Expand Down Expand Up @@ -239,7 +242,7 @@ class PixelFormatYUV
bool operator!=(const PixelFormatYUV &a) const { return getName() != a.getName(); }
bool operator==(const std::string &a) const { return getName() == a; }
bool operator!=(const std::string &a) const { return getName() != a; }
operator bool() const { return this->isValid(); }
operator bool() const { return this->isValid(); }

private:
// If this is set, the format is defined according to a specific standard and does not
Expand Down
Loading
Loading