Skip to content

Commit 2000a2b

Browse files
committed
Array1DRef: add getBlock() QOL helper
1 parent a48434e commit 2000a2b

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

src/librawspeed/adt/Array1DRef.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ template <class T> class Array1DRef final {
7979
numElts(sizeof(T2) * RHS.numElts) {}
8080

8181
[[nodiscard]] CroppedArray1DRef<T> getCrop(int offset, int numElts) const;
82+
[[nodiscard]] CroppedArray1DRef<T> getBlock(int numElts, int index) const;
8283

8384
[[nodiscard]] int RAWSPEED_READONLY size() const;
8485

@@ -116,6 +117,17 @@ template <class T>
116117
return {*this, offset, size};
117118
}
118119

120+
template <class T>
121+
[[nodiscard]] CroppedArray1DRef<T> Array1DRef<T>::getBlock(int size,
122+
int index) const {
123+
establishClassInvariants();
124+
invariant(index >= 0);
125+
invariant(size >= 0);
126+
invariant(index <= numElts);
127+
invariant(size <= numElts);
128+
return getCrop(size * index, size);
129+
}
130+
119131
template <class T> inline T* Array1DRef<T>::addressOf(const int eltIdx) const {
120132
establishClassInvariants();
121133
invariant(eltIdx >= 0);

src/librawspeed/common/RawImage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void RawImageData::fixBadPixelsThread(int start_y, int end_y) {
299299

300300
for (int y = start_y; y < end_y; y++) {
301301
for (int x = 0; x < gw; x++) {
302-
const auto block = bad[y].getCrop((32 * x) / 8, 4);
302+
const auto block = bad[y].getBlock(32 / 8, x);
303303

304304
// Test if there is a bad pixel within these 32 pixels
305305
if (std::all_of(block.begin(), block.end(),

src/librawspeed/decoders/ArwDecoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ void ArwDecoder::SonyDecrypt(Array1DRef<const uint8_t> ibuf,
565565
uint32_t pv = pad[p & 127];
566566

567567
uint32_t bv;
568-
memcpy(&bv, ibuf.getCrop(4 * i, 4).begin(), sizeof(uint32_t));
568+
memcpy(&bv, ibuf.getBlock(4, i).begin(), sizeof(uint32_t));
569569

570570
bv ^= pv;
571571

572-
memcpy(obuf.getCrop(4 * i, 4).begin(), &bv, sizeof(uint32_t));
572+
memcpy(obuf.getBlock(4, i).begin(), &bv, sizeof(uint32_t));
573573

574574
p++;
575575
}

src/librawspeed/decompressors/Cr2DecompressorImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ void Cr2Decompressor<PrefixCodeDecoder>::decompressN_X_Y() const {
434434
for (int c = 0; c < N_COMP; ++c)
435435
pred[c] = predNext(c == 0 ? c : dsc.groupSize - (N_COMP - c));
436436
predNext = out[row]
437-
.getCrop(/*offset=*/dsc.groupSize * col,
438-
/*size=*/dsc.groupSize)
437+
.getBlock(/*size=*/dsc.groupSize,
438+
/*index=*/col)
439439
.getAsArray1DRef();
440440
++globalFrameRow;
441441
globalFrameCol = 0;

src/librawspeed/decompressors/PanasonicV7Decompressor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ void PanasonicV7Decompressor::decompressRow(int row) const noexcept {
8686
ByteStream rowInput = input.getSubStream(bytesPerRow * row, bytesPerRow);
8787
for (int rblock = 0; rblock < blocksperrow; rblock++) {
8888
ByteStream block = rowInput.getStream(BytesPerBlock);
89-
decompressBlock(block,
90-
outRow.getCrop(PixelsPerBlock * rblock, PixelsPerBlock));
89+
decompressBlock(block, outRow.getBlock(PixelsPerBlock, rblock));
9190
}
9291
}
9392

0 commit comments

Comments
 (0)