Skip to content

Commit 206b81d

Browse files
author
Christian Feldmann
committed
Add test cases for RGB conversion. Next, RGB565.
1 parent fe2d010 commit 206b81d

29 files changed

+634
-256
lines changed

YUViewLib/src/common/Functions.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ std::string toLower(const std::string_view str)
198198
return lowercaseStr;
199199
}
200200

201+
std::vector<std::string_view> splitString(const std::string_view str, const char delimiter)
202+
{
203+
std::vector<std::string_view> result;
204+
size_t start = 0;
205+
size_t end = str.find(delimiter);
206+
while (end != std::string_view::npos)
207+
{
208+
result.emplace_back(str.substr(start, end - start));
209+
start = end + 1;
210+
end = str.find(delimiter, start);
211+
}
212+
result.emplace_back(str.substr(start));
213+
return result;
214+
}
215+
201216
ByteVector readData(std::istream &istream, const size_t nrBytes)
202217
{
203218
ByteVector data;
@@ -225,11 +240,11 @@ std::optional<unsigned> toUnsigned(const std::string_view text)
225240
std::optional<int> toInt(const std::string_view text)
226241
{
227242
int value{};
228-
const auto result = std::from_chars(text.data(), text.data() + text.size(), value);
243+
const auto result = std::from_chars(text.data(), text.end(), value);
229244

230245
if (result.ec != std::errc())
231246
return {};
232-
const auto allCharactersParsed = (result.ptr == &(*text.end()));
247+
const auto allCharactersParsed = (result.ptr == text.end());
233248
if (!allCharactersParsed)
234249
return {};
235250

YUViewLib/src/common/Functions.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <istream>
3838
#include <optional>
39+
#include <vector>
3940

4041
namespace functions
4142
{
@@ -77,8 +78,11 @@ template <size_t N> QStringList toQStringList(const std::array<std::string_view,
7778
return list;
7879
}
7980

80-
std::string toLower(const std::string_view str);
81-
ByteVector readData(std::istream &istream, const size_t nrBytes);
81+
std::string toLower(const std::string_view str);
82+
std::optional<int> toInt(const std::string_view str);
83+
std::vector<std::string_view> splitString(const std::string_view str, const char delimiter);
84+
85+
ByteVector readData(std::istream &istream, const size_t nrBytes);
8286

8387
template <typename T> unsigned clipToUnsigned(T val)
8488
{

YUViewLib/src/handler/ItemMemoryHandler.cpp

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/* This file is part of YUView - The YUV player with advanced analytics toolset
2-
* <https://github.com/IENT/YUView>
3-
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4-
*
5-
* This program is free software; you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation; either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* In addition, as a special exception, the copyright holders give
11-
* permission to link the code of portions of this program with the
12-
* OpenSSL library under certain conditions as described in each
13-
* individual source file, and distribute linked combinations including
14-
* the two.
15-
*
16-
* You must obey the GNU General Public License in all respects for all
17-
* of the code used other than OpenSSL. If you modify file(s) with this
18-
* exception, you may extend this exception to your version of the
19-
* file(s), but you are not obligated to do so. If you do not wish to do
20-
* so, delete this exception statement from your version. If you delete
21-
* this exception statement from all source files in the program, then
22-
* also delete it here.
23-
*
24-
* This program is distributed in the hope that it will be useful,
25-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27-
* GNU General Public License for more details.
28-
*
29-
* You should have received a copy of the GNU General Public License
30-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31-
*/
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
3232

3333
#include "ItemMemoryHandler.h"
3434

@@ -48,26 +48,32 @@ namespace itemMemoryHandler
4848

4949
struct ItemData
5050
{
51-
QString filePath;
52-
QDateTime itemChangedLast;
53-
QString format;
54-
QString toString() const { return QString("File: %1 Last Changed: %2 Format: %3").arg(filePath).arg(itemChangedLast.toString("yy-M-d H-m-s")).arg(format); }
51+
QString filePath;
52+
QDateTime itemChangedLast;
53+
std::string format;
54+
QString toString() const
55+
{
56+
return QString("File: %1 Last Changed: %2 Format: %3")
57+
.arg(filePath)
58+
.arg(itemChangedLast.toString("yy-M-d H-m-s"))
59+
.arg(format);
60+
}
5561
};
5662

5763
QList<ItemData> getAllValidItems()
5864
{
59-
QSettings settings;
65+
QSettings settings;
6066
QList<ItemData> validItems;
61-
auto timeYesterday = QDateTime::currentDateTime().addDays(-2);
67+
auto timeYesterday = QDateTime::currentDateTime().addDays(-2);
6268

6369
auto size = settings.beginReadArray("itemMemory");
64-
for (int i = 0; i < size; ++i)
70+
for (int i = 0; i < size; ++i)
6571
{
6672
settings.setArrayIndex(i);
6773
ItemData data;
68-
data.filePath = settings.value("filePath").toString();
74+
data.filePath = settings.value("filePath").toString();
6975
data.itemChangedLast = settings.value("dateChanged").toDateTime();
70-
data.format = settings.value("format").toString();
76+
data.format = settings.value("format").toString().toStdString();
7177
if (data.itemChangedLast >= timeYesterday)
7278
{
7379
validItems.append(data);
@@ -86,22 +92,22 @@ QList<ItemData> getAllValidItems()
8692
void writeNewItemList(QList<ItemData> newItemList)
8793
{
8894
QSettings settings;
89-
settings.remove("itemMemory"); // Delete the old list
95+
settings.remove("itemMemory"); // Delete the old list
9096

9197
settings.beginWriteArray("itemMemory");
92-
for (int i = 0; i < newItemList.size(); ++i)
98+
for (int i = 0; i < newItemList.size(); ++i)
9399
{
94100
const auto &item = newItemList[i];
95101
settings.setArrayIndex(i);
96102
settings.setValue("filePath", item.filePath);
97103
settings.setValue("dateChanged", QVariant(item.itemChangedLast));
98-
settings.setValue("format", item.format);
104+
settings.setValue("format", QString::fromStdString(item.format));
99105
DEBUG_MEMORY("writeNewItemList Written item " << item.toString());
100106
}
101107
settings.endArray();
102108
}
103109

104-
void itemMemoryAddFormat(QString filePath, QString format)
110+
void itemMemoryAddFormat(const QString &filePath, const std::string &format)
105111
{
106112
auto validItems = getAllValidItems();
107113

@@ -111,8 +117,8 @@ void itemMemoryAddFormat(QString filePath, QString format)
111117
if (validItems[i].filePath == filePath)
112118
{
113119
validItems[i].itemChangedLast = QDateTime::currentDateTime();
114-
validItems[i].format = format;
115-
itemUpdated = true;
120+
validItems[i].format = format;
121+
itemUpdated = true;
116122
DEBUG_MEMORY("itemMemoryAddFormat Modified item " << validItems[i].toString());
117123
break;
118124
}
@@ -121,17 +127,17 @@ void itemMemoryAddFormat(QString filePath, QString format)
121127
if (!itemUpdated)
122128
{
123129
ItemData newItem;
124-
newItem.filePath = filePath;
130+
newItem.filePath = filePath;
125131
newItem.itemChangedLast = QDateTime::currentDateTime();
126-
newItem.format = format;
132+
newItem.format = format;
127133
validItems.append(newItem);
128134
DEBUG_MEMORY("itemMemoryAddFormat Added new item " << newItem.toString());
129135
}
130-
136+
131137
writeNewItemList(validItems);
132138
}
133139

134-
QString itemMemoryGetFormat(QString filePath)
140+
std::optional<std::string> itemMemoryGetFormat(const QString &filePath)
135141
{
136142
auto validItems = getAllValidItems();
137143

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/* This file is part of YUView - The YUV player with advanced analytics toolset
2-
* <https://github.com/IENT/YUView>
3-
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4-
*
5-
* This program is free software; you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation; either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* In addition, as a special exception, the copyright holders give
11-
* permission to link the code of portions of this program with the
12-
* OpenSSL library under certain conditions as described in each
13-
* individual source file, and distribute linked combinations including
14-
* the two.
15-
*
16-
* You must obey the GNU General Public License in all respects for all
17-
* of the code used other than OpenSSL. If you modify file(s) with this
18-
* exception, you may extend this exception to your version of the
19-
* file(s), but you are not obligated to do so. If you do not wish to do
20-
* so, delete this exception statement from your version. If you delete
21-
* this exception statement from all source files in the program, then
22-
* also delete it here.
23-
*
24-
* This program is distributed in the hope that it will be useful,
25-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27-
* GNU General Public License for more details.
28-
*
29-
* You should have received a copy of the GNU General Public License
30-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31-
*/
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
3232

3333
#pragma once
3434

@@ -40,7 +40,7 @@ namespace itemMemoryHandler
4040
/* Simple memory that uses QSettings to save the format for a file.
4141
* Entries older then 48 hours are automatically deleted.
4242
*/
43-
void itemMemoryAddFormat(QString filePath, QString format);
44-
QString itemMemoryGetFormat(QString filePath);
43+
void itemMemoryAddFormat(const QString &filePath, const std::string &format);
44+
std::optional<std::string> itemMemoryGetFormat(const QString &filePath);
4545

4646
} // namespace itemMemoryHandler

YUViewLib/src/playlistitem/playlistItemRawFile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ playlistItemRawFile::playlistItemRawFile(const QString &rawFilePath,
122122
if (!this->parseY4MFile())
123123
return;
124124
}
125-
else if (!pixelFormatFromMemory.isEmpty())
125+
else if (!pixelFormatFromMemory)
126126
{
127127
// Use the format that we got from the memory. Don't do any auto detection.
128-
this->video->setFormatFromString(pixelFormatFromMemory);
128+
this->video->setFormatFromString(*pixelFormatFromMemory);
129129
}
130130
else if (!frameSize.isValid() && sourcePixelFormat.isEmpty())
131131
{
@@ -563,9 +563,9 @@ void playlistItemRawFile::slotVideoPropertiesChanged()
563563
{
564564
DEBUG_RAWFILE("playlistItemRawFile::slotVideoPropertiesChanged");
565565

566-
auto currentPixelFormat = video->getFormatAsString();
567-
if (currentPixelFormat != this->pixelFormatAfterLoading)
568-
itemMemoryHandler::itemMemoryAddFormat(this->properties().name, currentPixelFormat);
566+
const auto currentPixelFormat = video->getFormatAsString();
567+
if (currentPixelFormat && currentPixelFormat != this->pixelFormatAfterLoading)
568+
itemMemoryHandler::itemMemoryAddFormat(this->properties().name, *currentPixelFormat);
569569
}
570570

571571
ValuePairListSets playlistItemRawFile::getPixelValues(const QPoint &pixelPos, int frameIdx)

YUViewLib/src/playlistitem/playlistItemRawFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class playlistItemRawFile : public playlistItemWithVideo
6464
// Create a new playlistItemRawFile from the playlist file entry. Return nullptr if parsing
6565
// failed.
6666
static playlistItemRawFile *newplaylistItemRawFile(const YUViewDomElement &root,
67-
const QString & playlistFilePath);
67+
const QString &playlistFilePath);
6868

6969
virtual bool canBeUsedInProcessing() const override { return true; }
7070

@@ -116,5 +116,5 @@ private slots:
116116
bool isY4MFile{};
117117
QList<uint64_t> y4mFrameIndices;
118118

119-
QString pixelFormatAfterLoading{};
119+
std::optional<std::string> pixelFormatAfterLoading{};
120120
};

0 commit comments

Comments
 (0)