Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TileOffsets for DNGs containing one tile #6576

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions rtengine/dcraw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1131,9 +1131,13 @@ void CLASS lossless_dng_load_raw()
struct jhead jh;
ushort *rp;

size_t tilesWide = (raw_width + tile_width - 1) / tile_width;
size_t tilesHigh = (raw_height + tile_length - 1) / tile_length;
size_t tileCount = tilesWide * tilesHigh;

while (trow < raw_height) {
save = ftell(ifp);
if (tile_length < INT_MAX)
if (tileCount > 1)
fseek (ifp, get4(), SEEK_SET);
if (!ljpeg_start (&jh, 0)) break;
jwide = jh.wide;
Expand Down Expand Up @@ -6550,8 +6554,6 @@ int CLASS parse_tiff_ifd (int base)
break;
case 324: /* TileOffsets */
tiff_ifd[ifd].offset = len > 1 ? ftell(ifp) : get4();
if (len == 1)
tiff_ifd[ifd].tile_width = tiff_ifd[ifd].tile_length = 0;
Comment on lines -6553 to -6554
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this will affect the logic here:

RawTherapee/rtengine/dcraw.cc

Lines 7065 to 7066 in 2ce5b82

if (!tile_width ) tile_width = INT_MAX;
if (!tile_length) tile_length = INT_MAX;

...but I'm not sure why you would like to set tile_width/tile_length to 0 or INT_MAX...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this breaks lossless JPEG decoding for some reason...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing

RawTherapee/rtengine/dcraw.cc

Lines 1136 to 1137 in 2ce5b82

if (tile_length < INT_MAX)
fseek (ifp, get4(), SEEK_SET);

seems to solve the problem for lossless JPEG encoded single tiled DNGs, but will at the same break things for some multi-tiled images...

It might also be worth looking into the logic deciding between the two functions lossless_jpeg_load_raw and lossless_dng_load_raw.

if (len == 4) {
load_raw = &CLASS sinar_4shot_load_raw;
is_raw = 5;
Expand Down Expand Up @@ -10909,8 +10911,12 @@ void CLASS deflate_dng_load_raw() {
size_t tileCount = tilesWide * tilesHigh;
//fprintf(stderr, "%dx%d tiles, %d total\n", tilesWide, tilesHigh, tileCount);
size_t tileOffsets[tileCount];
for (size_t t = 0; t < tileCount; ++t) {
tileOffsets[t] = get4();
if (tileCount == 1) {
tileOffsets[0] = ifd->offset;
} else {
for (size_t t = 0; t < tileCount; ++t) {
tileOffsets[t] = get4();
}
}
size_t tileBytes[tileCount];
uLongf maxCompressed = 0;
Expand Down