Skip to content

Commit

Permalink
ArwDecoder: LJpeg decompressor supports {2,2} MCU's, drop workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
LebedevRI committed Mar 26, 2024
1 parent e2ff718 commit 7d97477
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
43 changes: 1 addition & 42 deletions src/librawspeed/decoders/ArwDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#include "decoders/ArwDecoder.h"
#include "MemorySanitizer.h"
#include "adt/Array1DRef.h"
#include "adt/Array2DRef.h"
#include "adt/Casts.h"
Expand Down Expand Up @@ -318,17 +317,14 @@ void ArwDecoder::DecodeLJpeg(const TiffIFD* raw) {
width > 9728 || height > 6656)
ThrowRDE("Unexpected image dimensions found: (%u; %u)", width, height);

mRaw->dim = iPoint2D(2 * width, height / 2);
mRaw->dim = iPoint2D(width, height);

auto tilew = uint64_t(raw->getEntry(TiffTag::TILEWIDTH)->getU32());
uint32_t tileh = raw->getEntry(TiffTag::TILELENGTH)->getU32();

if (tilew <= 0 || tileh <= 0 || tileh % 2 != 0)
ThrowRDE("Invalid tile size: (%" PRIu64 ", %u)", tilew, tileh);

tileh /= 2;
tilew *= 2;

assert(tilew > 0);
const auto tilesX =
implicit_cast<uint32_t>(roundUpDivision(mRaw->dim.x, tilew));
Expand Down Expand Up @@ -409,48 +405,11 @@ void ArwDecoder::DecodeLJpeg(const TiffIFD* raw) {
firstErr.c_str());
}

PostProcessLJpeg();

const TiffEntry* size_entry = raw->getEntry(TiffTag::SONYRAWIMAGESIZE);
iRectangle2D crop(0, 0, size_entry->getU32(0), size_entry->getU32(1));
mRaw->subFrame(crop);
}

void ArwDecoder::PostProcessLJpeg() {
MSan::CheckMemIsInitialized(mRaw->getByteDataAsUncroppedArray2DRef());
RawImage nonInterleavedRaw = mRaw;

invariant(nonInterleavedRaw->dim.x % 4 == 0);
iPoint2D interleavedDims = {nonInterleavedRaw->dim.x / 2,
2 * nonInterleavedRaw->dim.y};
mRaw = RawImage::create(interleavedDims, RawImageType::UINT16, 1);

const Array2DRef<const uint16_t> in =
nonInterleavedRaw->getU16DataAsUncroppedArray2DRef();
const Array2DRef<uint16_t> out = mRaw->getU16DataAsUncroppedArray2DRef();

#ifdef HAVE_OPENMP
#pragma omp parallel for schedule(static) default(none) firstprivate(in, out)
#endif
for (int inRow = 0; inRow < in.height(); ++inRow) {
static constexpr iPoint2D inMCUSize = {4, 1};
static constexpr iPoint2D outMCUSize = {2, 2};

invariant(in.width() % inMCUSize.x == 0);
for (int MCUIdx = 0, numMCUsPerRow = in.width() / inMCUSize.x;
MCUIdx < numMCUsPerRow; ++MCUIdx) {
for (int outMCURow = 0; outMCURow != outMCUSize.y; ++outMCURow) {
for (int outMCUСol = 0; outMCUСol != outMCUSize.x; ++outMCUСol) {
out(outMCUSize.y * inRow + outMCURow,
outMCUSize.x * MCUIdx + outMCUСol) =
in(inRow,
MCUIdx * inMCUSize.x + outMCUSize.x * outMCURow + outMCUСol);
}
}
}
}
}

void ArwDecoder::DecodeARW2(ByteStream input, uint32_t w, uint32_t h,
uint32_t bpp) {

Expand Down
1 change: 0 additions & 1 deletion src/librawspeed/decoders/ArwDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ArwDecoder final : public AbstractTiffDecoder {
RawImage decodeSRF();
void DecodeARW2(ByteStream input, uint32_t w, uint32_t h, uint32_t bpp);
void DecodeLJpeg(const TiffIFD* raw);
void PostProcessLJpeg();
void DecodeUncompressed(const TiffIFD* raw) const;
static void SonyDecrypt(Array1DRef<const uint8_t> ibuf,
Array1DRef<uint8_t> obuf, int len, uint32_t key);
Expand Down

0 comments on commit 7d97477

Please sign in to comment.