Skip to content

Commit

Permalink
Fixes to RAW reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Sep 27, 2023
1 parent 6aa27b9 commit 619aaba
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 14 deletions.
2 changes: 1 addition & 1 deletion etc/SuperBuild/cmake/Modules/BuildLibRaw.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set(LibRaw_ARGS
-DBUILD_SHARED_LIBS=ON
-DBUILD_STATIC_LIBS=OFF
-DENABLE_OPENMP=ON
-DENABLE_JASPER=OFF
-DENABLE_JASPER=ON
-DENABLE_LCMS=ON
-DENABLE_EXAMPLES=OFF
-DBUILD_TESTING=OFF
Expand Down
84 changes: 71 additions & 13 deletions lib/tlIO/RAWRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,15 @@ namespace tl
LIBRAW_ERROR(unpack, ret);
}

#if 0
ret = _processor->adjust_sizes_info_only();
LIBRAW_ERROR(adjust_sizes_info_only, ret);
#endif

const math::Size2i size(sizes.iwidth, sizes.iheight);
if (size.w > info.size.w || size.h > info.size.h)
throw std::runtime_error(
"Decoded image size bigger than original size. "
" Cannot display.");

ret = _processor->raw2image_ex(/*substract_black=*/true);
LIBRAW_ERROR(raw2image_ex, ret);

Expand Down Expand Up @@ -235,23 +240,76 @@ namespace tl
"Not supported color depth");
}

if (_image->colors == 3)
if (size.w < info.size.w || size.h < info.size.h)
{
memcpy(out.image->getData(), _image->data,
_image->data_size);
out.image->zero();
uint16_t* data = reinterpret_cast<uint16_t*>(
out.image->getData());
size_t step = 3 * sizeof(uint16_t);
size_t xoffset = (info.size.w - size.w) / 2;
size_t yoffset = (info.size.h - size.h) / 2;

if (_image->colors == 3)
{
for (size_t y = 0; y < size.h; ++y)
{
memcpy(
data + (y + yoffset) * info.size.w * 3 +
xoffset * 3,
_image->data + y * size.w * step,
size.w * step);
}
}
else if (_image->colors == 1)
{
for (size_t y = 0; y < size.h; ++y)
{
uint16_t* dst =
data + (y + yoffset) * info.size.w * 3 +
xoffset * 3;
uint16_t* src = reinterpret_cast<uint16_t*>(
_image->data) +
y * size.w;
for (size_t x = 0; x < size.w; ++x)
{
const size_t j = y * size.w * 3 + x;
dst[j] = src[j];
dst[j+1] = src[j+1];
dst[j+2] = src[j+2];
}
}
}
else
{
throw std::runtime_error(
"Unsupport color depth");
}
}
else // image->colors == 1
else
{
uint16_t* data = reinterpret_cast<uint16_t*>(out.image->getData());
for (size_t i = 0; i < _image->data_size; ++i)
if (_image->colors == 3)
{
memcpy(out.image->getData(), _image->data,
_image->data_size);
}
else if (_image->colors == 1)
{
const size_t j = i * 3;
data[j] = _image->data[i];
data[j + 1] = _image->data[i];
data[j + 2] = _image->data[i];
uint16_t* data = reinterpret_cast<uint16_t*>(
out.image->getData());
for (size_t i = 0; i < _image->data_size; ++i)
{
const size_t j = i * 3;
data[j] = _image->data[i];
data[j + 1] = _image->data[i];
data[j + 2] = _image->data[i];
}
}
else
{
throw std::runtime_error(
"Unsupport color depth");
}
}

_processor->dcraw_clear_mem(_image);
_processor->recycle();

Expand Down

0 comments on commit 619aaba

Please sign in to comment.