Skip to content

Commit

Permalink
Merge pull request #551 from LebedevRI/misc
Browse files Browse the repository at this point in the history
Some misc C++20 cleanups
  • Loading branch information
LebedevRI authored Nov 9, 2023
2 parents 4fa2d5f + 1ac23c7 commit d93e9e3
Show file tree
Hide file tree
Showing 32 changed files with 100 additions and 114 deletions.
1 change: 1 addition & 0 deletions bench/librawspeed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function(add_rs_bench src)
target_link_libraries(${BENCHNAME} PUBLIC rawspeed_bench)

rawspeed_add_test(NAME ${BENCHNAME}-Dummy COMMAND ${BENCHNAME} --help)
set_tests_properties(${BENCHNAME}-Dummy PROPERTIES LABELS "benchmark;dummy")

rawspeed_add_test(NAME ${BENCHNAME} COMMAND ${BENCHNAME} --benchmark_min_time=0)
set_tests_properties(${BENCHNAME} PROPERTIES LABELS "benchmark")
Expand Down
1 change: 1 addition & 0 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ macro(add_fuzz_target__base fuzzer)
set(ALL_FUZZERS "${ALL_FUZZERS}" CACHE INTERNAL "" FORCE)

rawspeed_add_test(NAME fuzzers/${fuzzer} COMMAND ${fuzzer} -help=1)
set_tests_properties(fuzzers/${fuzzer} PROPERTIES LABELS "fuzz;dummy")
endmacro()

if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND RAWSPEED_FUZZ_BUILD))
Expand Down
3 changes: 0 additions & 3 deletions src/librawspeed/adt/BitIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ struct BitMSBIterator {
invariant(a.bitsPat == b.bitsPat && "Comparing unrelated iterators.");
return a.bitIdx == b.bitIdx;
}
friend bool operator!=(const BitMSBIterator& a, const BitMSBIterator& b) {
return !(a == b);
}
};

} // namespace rawspeed
6 changes: 0 additions & 6 deletions src/librawspeed/adt/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class iPoint2D {
constexpr bool operator==(const iPoint2D& rhs) const {
return x == rhs.x && y == rhs.y;
}
constexpr bool operator!=(const iPoint2D& rhs) const {
return !operator==(rhs);
}

constexpr bool operator>(const iPoint2D& rhs) const {
return x > rhs.x && y > rhs.y;
Expand Down Expand Up @@ -222,8 +219,5 @@ class iRectangle2D {
inline bool operator==(const iRectangle2D& a, const iRectangle2D b) {
return std::tie(a.pos, a.dim) == std::tie(b.pos, b.dim);
}
inline bool operator!=(const iRectangle2D& a, const iRectangle2D b) {
return !(a == b);
}

} // namespace rawspeed
4 changes: 2 additions & 2 deletions src/librawspeed/decoders/ArwDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ RawImage ArwDecoder::decodeRawInternal() {
return mRaw;
}

if (hints.has("srf_format"))
if (hints.contains("srf_format"))
return decodeSRF(raw);

ThrowRDE("No image data found");
Expand Down Expand Up @@ -266,7 +266,7 @@ void ArwDecoder::DecodeUncompressed(const TiffIFD* raw) const {

const Buffer buf(mFile.getSubView(off, c2));

if (hints.has("sr2_format")) {
if (hints.contains("sr2_format")) {
UncompressedDecompressor u(ByteStream(DataBuffer(buf, Endianness::little)),
mRaw,
iRectangle2D({0, 0}, iPoint2D(width, height)),
Expand Down
10 changes: 5 additions & 5 deletions src/librawspeed/decoders/Cr2Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ iPoint2D Cr2Decoder::getSubSampling() const {
}

int Cr2Decoder::getHue() const {
if (hints.has("old_sraw_hue"))
if (hints.contains("old_sraw_hue"))
return (mRaw->metadata.subsampling.y * mRaw->metadata.subsampling.x);

if (!mRootIFD->hasEntryRecursive(static_cast<TiffTag>(0x10))) {
Expand All @@ -335,7 +335,7 @@ int Cr2Decoder::getHue() const {
if (uint32_t model_id =
mRootIFD->getEntryRecursive(static_cast<TiffTag>(0x10))->getU32();
model_id >= 0x80000281 || model_id == 0x80000218 ||
(hints.has("force_new_sraw_hue"))) {
(hints.contains("force_new_sraw_hue"))) {
return ((mRaw->metadata.subsampling.y * mRaw->metadata.subsampling.x) -
1) >>
1;
Expand All @@ -360,7 +360,7 @@ void Cr2Decoder::sRawInterpolate() {
sraw_coeffs[1] = (wb->getU16(offset + 1) + wb->getU16(offset + 2) + 1) >> 1;
sraw_coeffs[2] = wb->getU16(offset + 3);

if (hints.has("invert_sraw_wb")) {
if (hints.contains("invert_sraw_wb")) {
sraw_coeffs[0] = static_cast<int>(
1024.0F / (static_cast<float>(sraw_coeffs[0]) / 1024.0F));
sraw_coeffs[2] = static_cast<int>(
Expand All @@ -386,8 +386,8 @@ void Cr2Decoder::sRawInterpolate() {
sraw_coeffs, hue);

/* Determine sRaw coefficients */
bool isOldSraw = hints.has("sraw_40d");
bool isNewSraw = hints.has("sraw_new");
bool isOldSraw = hints.contains("sraw_40d");
bool isNewSraw = hints.contains("sraw_new");

int version;
if (isOldSraw)
Expand Down
4 changes: 2 additions & 2 deletions src/librawspeed/decoders/CrwDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ RawImage CrwDecoder::decodeRawInternal() {
assert(decTable != nullptr);
uint32_t dec_table = decTable->getU32();

bool lowbits = !hints.has("no_decompressed_lowbits");
bool lowbits = !hints.contains("no_decompressed_lowbits");

CrwDecompressor c(mRaw, dec_table, lowbits, rawData->getData());
mRaw->createData();
Expand Down Expand Up @@ -177,7 +177,7 @@ void CrwDecoder::decodeMetaDataInternal(const CameraMetaData* meta) {
int offset = hints.get("wb_offset", 120);

std::array<uint16_t, 2> key = {{0x410, 0x45f3}};
if (!hints.has("wb_mangle"))
if (!hints.contains("wb_mangle"))
key[0] = key[1] = 0;

offset /= 2;
Expand Down
2 changes: 1 addition & 1 deletion src/librawspeed/decoders/KdcDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Buffer KdcDecoder::getInputBuffer() const {
ThrowRDE("Offset is too large.");

// Offset hardcoding gotten from dcraw
if (hints.has("easyshare_offset_hack"))
if (hints.contains("easyshare_offset_hack"))
off = off < 0x15000 ? 0x15000 : 0x17000;

return mFile.getSubView(off);
Expand Down
2 changes: 1 addition & 1 deletion src/librawspeed/decoders/MrwDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void MrwDecoder::decodeMetaDataInternal(const CameraMetaData* meta) {
auto id = rootIFD->getID();
setMetaData(meta, id.make, id.model, "", iso);

if (hints.has("swapped_wb")) {
if (hints.contains("swapped_wb")) {
mRaw->metadata.wbCoeffs[0] = wb_coeffs[2];
mRaw->metadata.wbCoeffs[1] = wb_coeffs[0];
mRaw->metadata.wbCoeffs[2] = wb_coeffs[1];
Expand Down
2 changes: 1 addition & 1 deletion src/librawspeed/decoders/NakedDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void NakedDecoder::parseHints() {
const auto& model = cam->model.c_str();

auto parseHint = [&cHints, &make, &model](const std::string& name) {
if (!cHints.has(name))
if (!cHints.contains(name))
ThrowRDE("%s %s: couldn't find %s", make, model, name.c_str());

return cHints.get(name, 0U);
Expand Down
10 changes: 5 additions & 5 deletions src/librawspeed/decoders/NefDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ RawImage NefDecoder::decodeRawInternal() {
}
}

if (compression == 1 || (hints.has("force_uncompressed")) ||
if (compression == 1 || (hints.contains("force_uncompressed")) ||
NEFIsUncompressed(raw)) {
DecodeUncompressed();
return mRaw;
Expand Down Expand Up @@ -283,19 +283,19 @@ void NefDecoder::DecodeUncompressed() const {
iPoint2D size(width, slice.h);
iPoint2D pos(0, offY);

if (hints.has("coolpixmangled")) {
if (hints.contains("coolpixmangled")) {
UncompressedDecompressor u(in, mRaw, iRectangle2D(pos, size),
width * bitPerPixel / 8, 12, BitOrder::MSB32);
u.readUncompressedRaw();
} else {
if (hints.has("coolpixsplit")) {
if (hints.contains("coolpixsplit")) {
readCoolpixSplitRaw(in, size, pos, width * bitPerPixel / 8);
} else {
if (in.getSize() % size.y != 0)
ThrowRDE("Inconsistent row size");
const auto inputPitchBytes = in.getSize() / size.y;
BitOrder bo = (mRootIFD->rootBuffer.getByteOrder() == Endianness::big) ^
hints.has("msb_override")
hints.contains("msb_override")
? BitOrder::MSB
: BitOrder::LSB;
UncompressedDecompressor u(in, mRaw, iRectangle2D(pos, size),
Expand Down Expand Up @@ -601,7 +601,7 @@ void NefDecoder::decodeMetaDataInternal(const CameraMetaData* meta) {
}
}

if (hints.has("nikon_wb_adjustment")) {
if (hints.contains("nikon_wb_adjustment")) {
mRaw->metadata.wbCoeffs[0] *= 256 / 527.0;
mRaw->metadata.wbCoeffs[2] *= 256 / 317.0;
}
Expand Down
8 changes: 4 additions & 4 deletions src/librawspeed/decoders/RafDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ RawImage RafDecoder::decodeRawInternal() {
counts->getU32(), width, height);
}

double_width = hints.has("double_width_unpacked");
double_width = hints.contains("double_width_unpacked");
const uint32_t real_width = double_width ? 2U * width : width;

mRaw->dim = iPoint2D(real_width, height);
Expand All @@ -167,7 +167,7 @@ RawImage RafDecoder::decodeRawInternal() {
u.readUncompressedRaw();
} else {
iPoint2D pos(0, 0);
if (hints.has("jpeg32_bitorder")) {
if (hints.contains("jpeg32_bitorder")) {
UncompressedDecompressor u(input, mRaw, iRectangle2D(pos, mRaw->dim),
width * bps / 8, bps, BitOrder::MSB32);
mRaw->createData();
Expand Down Expand Up @@ -206,7 +206,7 @@ void RafDecoder::applyCorrections(const Camera* cam) {
if (applyCrop) {
new_size = cam->cropSize;
crop_offset = cam->cropPos;
bool double_width = hints.has("double_width_unpacked");
bool double_width = hints.contains("double_width_unpacked");
// If crop size is negative, use relative cropping
if (new_size.x <= 0) {
new_size.x =
Expand All @@ -217,7 +217,7 @@ void RafDecoder::applyCorrections(const Camera* cam) {
new_size.y = mRaw->dim.y - cam->cropPos.y + new_size.y;
}

bool rotate = hints.has("fuji_rotate");
bool rotate = hints.contains("fuji_rotate");
rotate = rotate && fujiRotate;

// Rotate 45 degrees - could be multithreaded.
Expand Down
8 changes: 4 additions & 4 deletions src/librawspeed/decoders/Rw2Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ RawImage Rw2Decoder::decodeRawInternal() {
PanasonicV4Decompressor p(
mRaw,
ByteStream(DataBuffer(mFile.getSubView(offset), Endianness::little)),
hints.has("zero_is_not_bad"), section_split_offset);
hints.contains("zero_is_not_bad"), section_split_offset);
mRaw->createData();
p.decompress();
}
Expand All @@ -136,7 +136,7 @@ RawImage Rw2Decoder::decodeRawInternal() {
raw->getEntry(TiffTag::PANASONIC_RAWFORMAT)->getU16()) {
case 4: {
uint32_t section_split_offset = 0x1FF8;
PanasonicV4Decompressor p(mRaw, bs, hints.has("zero_is_not_bad"),
PanasonicV4Decompressor p(mRaw, bs, hints.contains("zero_is_not_bad"),
section_split_offset);
mRaw->createData();
p.decompress();
Expand Down Expand Up @@ -343,8 +343,8 @@ std::string Rw2Decoder::guessMode() const {
}

rawspeed::iRectangle2D Rw2Decoder::getDefaultCrop() {
const TiffIFD* raw = getRaw();
if (raw->hasEntry(TiffTag::PANASONIC_SENSORLEFTBORDER) &&
if (const TiffIFD* raw = getRaw();
raw->hasEntry(TiffTag::PANASONIC_SENSORLEFTBORDER) &&
raw->hasEntry(TiffTag::PANASONIC_SENSORTOPBORDER) &&
raw->hasEntry(TiffTag::PANASONIC_SENSORRIGHTBORDER) &&
raw->hasEntry(TiffTag::PANASONIC_SENSORBOTTOMBORDER)) {
Expand Down
12 changes: 9 additions & 3 deletions src/librawspeed/decompressors/AbstractDngDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include "common/Common.h"
#include "common/RawImage.h"
#include "decoders/RawDecoderException.h"
#include "decompressors/DeflateDecompressor.h"
#include "decompressors/JpegDecompressor.h"
#include "decompressors/LJpegDecoder.h"
#include "decompressors/UncompressedDecompressor.h"
#include "decompressors/VC5Decompressor.h"
Expand All @@ -36,10 +34,18 @@
#include "io/IOException.h"
#include <cstdint>
#include <limits>
#include <memory>
#include <string>
#include <vector>

#ifdef HAVE_ZLIB
#include "decompressors/DeflateDecompressor.h"
#include <memory>
#endif

#ifdef HAVE_JPEG
#include "decompressors/JpegDecompressor.h"
#endif

namespace rawspeed {

template <> void AbstractDngDecompressor::decompressThread<1>() const noexcept {
Expand Down
4 changes: 0 additions & 4 deletions src/librawspeed/decompressors/Cr2Decompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ struct Cr2SliceWidthIterator final {
invariant(&a.slicing == &b.slicing && "Comparing unrelated iterators.");
return a.sliceId == b.sliceId;
}
friend bool operator!=(const Cr2SliceWidthIterator& a,
const Cr2SliceWidthIterator& b) {
return !(a == b);
}
};

inline Cr2SliceWidthIterator Cr2SliceWidths::begin() const {
Expand Down
11 changes: 0 additions & 11 deletions src/librawspeed/decompressors/Cr2DecompressorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ struct Cr2SliceIterator final {
invariant(a.frameHeight == b.frameHeight && "Unrelated iterators.");
return a.widthIter == b.widthIter;
}
friend bool operator!=(const Cr2SliceIterator& a, const Cr2SliceIterator& b) {
return !(a == b);
}
};

struct Cr2OutputTileIterator final {
Expand Down Expand Up @@ -145,10 +142,6 @@ struct Cr2OutputTileIterator final {
// NOTE: outPos is correctly omitted here.
return a.sliceIter == b.sliceIter && a.sliceRow == b.sliceRow;
}
friend bool RAWSPEED_READONLY operator!=(const Cr2OutputTileIterator& a,
const Cr2OutputTileIterator& b) {
return !(a == b);
}
};

class Cr2VerticalOutputStripIterator final {
Expand Down Expand Up @@ -199,10 +192,6 @@ class Cr2VerticalOutputStripIterator final {
"Comparing unrelated iterators.");
return a.outputTileIterator == b.outputTileIterator;
}
friend bool operator!=(const Cr2VerticalOutputStripIterator& a,
const Cr2VerticalOutputStripIterator& b) {
return !(a == b);
}
};

template <typename PrefixCodeDecoder>
Expand Down
18 changes: 9 additions & 9 deletions src/librawspeed/decompressors/DeflateDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "rawspeedconfig.h"
#include "adt/CroppedArray1DRef.h"
#include "adt/CroppedArray2DRef.h"
#include "adt/Invariant.h"
#include "common/Common.h"
#include "common/RawImage.h"
#include "io/Buffer.h"
#include <array>
#include <climits>
#include "rawspeedconfig.h" // IWYU pragma: keep

#ifdef HAVE_ZLIB

#include "adt/CroppedArray1DRef.h"
#include "adt/CroppedArray2DRef.h"
#include "adt/Invariant.h"
#include "adt/Point.h"
#include "common/Common.h"
#include "common/FloatingPoint.h"
#include "common/RawImage.h"
#include "decoders/RawDecoderException.h"
#include "decompressors/DeflateDecompressor.h"
#include "io/Buffer.h"
#include "io/Endianness.h"
#include <array>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <utility>
Expand Down
6 changes: 3 additions & 3 deletions src/librawspeed/decompressors/JpegDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "rawspeedconfig.h"
#include "adt/AlignedAllocator.h"
#include <cstdint>
#include "rawspeedconfig.h" // IWYU pragma: keep

#ifdef HAVE_JPEG

#include "adt/AlignedAllocator.h"
#include "adt/Array2DRef.h"
#include "adt/Point.h"
#include "decoders/RawDecoderException.h"
#include "decompressors/JpegDecompressor.h"
#include <algorithm>
#include <array>
#include <cstdint>
#include <jpeglib.h>
#include <memory>
#include <vector>
Expand Down
Loading

0 comments on commit d93e9e3

Please sign in to comment.