diff --git a/YUViewLib/src/common/Formatting.h b/YUViewLib/src/common/Formatting.h index 6696de333..381e4a9b3 100644 --- a/YUViewLib/src/common/Formatting.h +++ b/YUViewLib/src/common/Formatting.h @@ -32,6 +32,7 @@ #pragma once +#include "Size.h" #include "Typedef.h" #include diff --git a/YUViewLib/src/common/Offset.h b/YUViewLib/src/common/Offset.h new file mode 100644 index 000000000..f61d40731 --- /dev/null +++ b/YUViewLib/src/common/Offset.h @@ -0,0 +1,45 @@ +/* This file is part of YUView - The YUV player with advanced analytics toolset + * + * 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 . + */ + +#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{}; +}; diff --git a/YUViewLib/src/common/Size.h b/YUViewLib/src/common/Size.h new file mode 100644 index 000000000..796e9ad84 --- /dev/null +++ b/YUViewLib/src/common/Size.h @@ -0,0 +1,60 @@ +/* This file is part of YUView - The YUV player with advanced analytics toolset + * + * 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 . + */ + +#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{}; +}; diff --git a/YUViewLib/src/common/Typedef.h b/YUViewLib/src/common/Typedef.h index 155e6f11d..82e54d918 100644 --- a/YUViewLib/src/common/Typedef.h +++ b/YUViewLib/src/common/Typedef.h @@ -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> { diff --git a/YUViewLib/src/dataSource/DataSourceLocalFile.cpp b/YUViewLib/src/dataSource/DataSourceLocalFile.cpp index 34becf6a1..f89370dfd 100644 --- a/YUViewLib/src/dataSource/DataSourceLocalFile.cpp +++ b/YUViewLib/src/dataSource/DataSourceLocalFile.cpp @@ -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 {}; } diff --git a/YUViewLib/src/decoder/decoderTarga.h b/YUViewLib/src/decoder/decoderTarga.h index 2a19b808f..b8a639936 100644 --- a/YUViewLib/src/decoder/decoderTarga.h +++ b/YUViewLib/src/decoder/decoderTarga.h @@ -32,6 +32,7 @@ #pragma once +#include #include #include diff --git a/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h b/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h index 760f6a171..b01611bbc 100644 --- a/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h +++ b/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h @@ -33,6 +33,8 @@ #pragma once #include "FFMpegLibrariesTypes.h" + +#include #include namespace FFmpeg diff --git a/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h b/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h index 3542e11bb..898783f0c 100644 --- a/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h +++ b/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h @@ -33,6 +33,8 @@ #pragma once #include "FFMpegLibrariesTypes.h" + +#include #include namespace FFmpeg diff --git a/YUViewLib/src/ffmpeg/AVFrameWrapper.h b/YUViewLib/src/ffmpeg/AVFrameWrapper.h index 72b3998fc..0fbe050f4 100644 --- a/YUViewLib/src/ffmpeg/AVFrameWrapper.h +++ b/YUViewLib/src/ffmpeg/AVFrameWrapper.h @@ -33,6 +33,8 @@ #pragma once #include "FFMpegLibrariesTypes.h" + +#include #include namespace FFmpeg @@ -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(); @@ -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{}; @@ -81,7 +83,7 @@ class AVFrameWrapper int quality{}; AVDictionary *metadata{}; - AVFrame * frame{}; + AVFrame *frame{}; LibraryVersion libVer{}; }; diff --git a/YUViewLib/src/filesource/FileSource.cpp b/YUViewLib/src/filesource/FileSource.cpp index e5df613a9..68f82ccab 100644 --- a/YUViewLib/src/filesource/FileSource.cpp +++ b/YUViewLib/src/filesource/FileSource.cpp @@ -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); @@ -133,7 +145,7 @@ std::optional FileSource::getFileSize() const const auto size = std::filesystem::file_size(this->fullFilePath); return static_cast(size); } - catch (const std::filesystem::filesystem_error &e) + catch (const std::filesystem::filesystem_error &) { return {}; } @@ -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); diff --git a/YUViewLib/src/filesource/FileSource.h b/YUViewLib/src/filesource/FileSource.h index c9b89875d..389b19564 100644 --- a/YUViewLib/src/filesource/FileSource.h +++ b/YUViewLib/src/filesource/FileSource.h @@ -55,11 +55,11 @@ enum class InputFormat }; constexpr EnumMapper 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 diff --git a/YUViewLib/src/filesource/FrameFormatGuess.h b/YUViewLib/src/filesource/FrameFormatGuess.h index 104ccd306..edb8f621b 100644 --- a/YUViewLib/src/filesource/FrameFormatGuess.h +++ b/YUViewLib/src/filesource/FrameFormatGuess.h @@ -32,6 +32,7 @@ #pragma once +#include #include #include