Skip to content

Commit 029022e

Browse files
committed
feat(misc): use uz literals instead of (size_t) casts
1 parent 16f37af commit 029022e

File tree

7 files changed

+13
-20
lines changed

7 files changed

+13
-20
lines changed

include/tev/Ipc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class IpcPacket {
151151
IStream(std::span<const char> data) : mData{data} {
152152
uint32_t size;
153153
*this >> size;
154-
if ((size_t)size != data.size()) {
154+
if (size != data.size()) {
155155
throw std::runtime_error{"Trying to read IPC packet with incorrect size."};
156156
}
157157
}

include/tev/ThreadPool.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ class ThreadPool {
163163

164164
size_t numThreads() const { return mNumThreads; }
165165

166-
std::recursive_mutex& taskQueueMutex() { return mTaskQueueMutex; }
167-
168166
private:
169167
bool mShuttingDown = false;
170168

src/Image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ Task<HeapArray<float>> Image::getRgbaHdrImageData(
11941194
const size_t nColorChannels = alphaChannel ? (channels.size() - 1) : channels.size();
11951195

11961196
const auto numPixels = (size_t)imageRegion.size().x() * imageRegion.size().y();
1197-
const auto nColorChannelsToSave = std::min(nColorChannels, (size_t)3);
1197+
const auto nColorChannelsToSave = std::min(nColorChannels, 3uz);
11981198

11991199
// Flatten image into vector
12001200
HeapArray<float> result{4 * numPixels};
@@ -1224,7 +1224,7 @@ Task<HeapArray<float>> Image::getRgbaHdrImageData(
12241224
// Divide alpha out if needed (for storing in non-premultiplied formats)
12251225
if (divideAlpha) {
12261226
co_await ThreadPool::global().parallelForAsync(
1227-
(size_t)0,
1227+
0uz,
12281228
numPixels,
12291229
numPixels * 4,
12301230
[&result](size_t j) {

src/ImageCanvas.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -818,19 +818,19 @@ Task<shared_ptr<CanvasStatistics>> ImageCanvas::computeCanvasStatistics(
818818
}
819819

820820
const auto result = make_shared<CanvasStatistics>();
821-
const size_t nColorChannels = alphaChannel ? (flattened.size() - 1) : flattened.size();
821+
const auto nColorChannels = alphaChannel ? (flattened.size() - 1) : flattened.size();
822822
result->nChannels = (int)nColorChannels;
823823

824824
result->histogramColors.resize(nColorChannels);
825825
for (size_t i = 0; i < nColorChannels; ++i) {
826826
string rgba[] = {"R", "G", "B", "A"};
827-
string colorName = nColorChannels == 1 ? "L" : rgba[std::min(i, (size_t)3)];
827+
string colorName = nColorChannels == 1 ? "L" : rgba[std::min(i, 3uz)];
828828
result->histogramColors[i] = Channel::color(colorName, false);
829829
}
830830

831831
const auto regionSize = region.size();
832-
const size_t numPixels = region.area();
833-
const size_t numSamples = nColorChannels * numPixels;
832+
const auto numPixels = region.area();
833+
const auto numSamples = nColorChannels * numPixels;
834834

835835
// If we have 3 color channels, apply alpha, the inspection chroma, and transfer function
836836
if (nColorChannels >= 3) {
@@ -928,7 +928,7 @@ Task<shared_ptr<CanvasStatistics>> ImageCanvas::computeCanvasStatistics(
928928
result->minimum = stats.minimum;
929929

930930
// The more pixels we have, the finer we can make the histogram without becoming noisy
931-
// const size_t numBins = clamp(numPixels / 512, (size_t)16, (size_t)512);
931+
// const size_t numBins = clamp(numPixels / 512, 16uz, 512uz);
932932
const size_t numBins = 400;
933933
result->histogram.resize(numBins * nColorChannels);
934934

@@ -961,7 +961,7 @@ Task<shared_ptr<CanvasStatistics>> ImageCanvas::computeCanvasStatistics(
961961
{
962962
const size_t approxCost = numSamples *
963963
8; // constant factor to represent the increased workload of log/exp and somewhat random memory writes
964-
const size_t numTasks = nextMultiple(ThreadPool::global().nTasks<size_t>(0, numPixels, approxCost), (size_t)nColorChannels);
964+
const size_t numTasks = nextMultiple(ThreadPool::global().nTasks<size_t>(0, numPixels, approxCost), nColorChannels);
965965
const size_t numTasksPerChannel = numTasks / nColorChannels;
966966

967967
vector<float> perTaskHistograms(numBins * nColorChannels * numTasks);

src/imageio/ExrImageSaver.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ class StdOStream : public Imf::OStream {
7171
};
7272

7373
Task<void> ExrImageSaver::save(ostream& oStream, const fs::path& path, span<const float> data, const Vector2i& imageSize, int nChannels) const {
74-
const vector<string> channelNames = {
75-
"R",
76-
"G",
77-
"B",
78-
"A",
79-
};
74+
const vector<string> channelNames = {"R", "G", "B", "A"};
8075

8176
if (nChannels <= 0 || nChannels > 4) {
8277
throw ImageSaveError{fmt::format("Invalid number of channels {}.", nChannels)};

src/imageio/HeifImageLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ Task<vector<ImageData>> HeifImageLoader::load(
405405
// 1 thread per 4 million samples (rgba megapixel) seems to be a good heuristic for parallel decoding. Spawning threads is *really*
406406
// expensive, so even taking into account that decoding does quite a bit of processing per sample, we still need a much larger chunk
407407
// size than our task-based thread pool. Would be better if libheif exposed a way for us to supply a custom thread pool, but oh well.
408-
return clamp(numSamples / (1024 * 1024 * 4), (size_t)1, (size_t)thread::hardware_concurrency());
408+
return clamp(numSamples / (1024 * 1024 * 4), 1uz, (size_t)thread::hardware_concurrency());
409409
};
410410

411411
const auto decodeImageHandle =

src/imageio/TiffImageLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ Task<void> linearizeAndNormalizeRawDng(
614614
const float val = rgbaView[c, i];
615615

616616
// Lerp the transfer function
617-
const size_t idx = clamp((size_t)(val * maxVal), (size_t)0, maxIdx - 1);
617+
const size_t idx = clamp((size_t)(val * maxVal), 0uz, maxIdx - 1);
618618
const float w = val * maxIdx - idx;
619619
rgbaView[c, i] = (1.0f - w) * linTable[idx] * scale + w * linTable[idx + 1] * scale;
620620
}
@@ -1339,7 +1339,7 @@ Task<void> postprocessRgb(
13391339
const float val = rgbaView[c, i];
13401340

13411341
// Lerp the transfer function
1342-
const size_t idx = clamp((size_t)(val * maxIdx) + transferRangeBlack[c], (size_t)0, transferFunction[c].size() - 2);
1342+
const size_t idx = clamp((size_t)(val * maxIdx) + transferRangeBlack[c], 0uz, transferFunction[c].size() - 2);
13431343
const float w = val * maxIdx - idx - transferRangeBlack[c];
13441344
rgbaView[c, i] = ((1.0f - w) * (float)transferFunction[c][idx] + w * (float)transferFunction[c][idx + 1] -
13451345
transferRangeBlack[c]) *

0 commit comments

Comments
 (0)