Improved check for lj92 compressed dng files, #4285

This commit is contained in:
heckflosse
2018-11-09 17:36:13 +01:00
parent 58e26add76
commit f7109eec21

View File

@@ -1134,6 +1134,7 @@ void CLASS lossless_dnglj92_load_raw()
tiff_bps = 16;
int save = ifp->pos;
uint16_t *lincurve = !strncmp(make,"Blackmagic",10) ? curve : nullptr;
tile_width = tile_length < INT_MAX ? tile_width : raw_width;
size_t tileCount = raw_width / tile_width;
@@ -1149,20 +1150,30 @@ void CLASS lossless_dnglj92_load_raw()
uint8_t *data = (uint8_t*)malloc(ifp->size);
fseek(ifp, 0, SEEK_SET);
// read whole file
fread(data, 1, ifp->size, ifp);
int data_length = ifp->size;
fread(data, 1, data_length, ifp);
lj92 lj;
int newwidth, newheight, newbps;
lj92_open(&lj, &data[dataOffset[0]], data_length, &newwidth, &newheight, &newbps);
lj92_close(lj);
if (newwidth * newheight * tileCount != raw_width * raw_height) {
// not a lj92 file
fseek(ifp, save, SEEK_SET);
free(data);
lossless_dng_load_raw();
return;
}
#ifdef _OPENMP
#pragma omp parallel for num_threads(std::min<int>(tileCount, omp_get_max_threads()))
#endif
for (size_t t = 0; t < tileCount; ++t) {
size_t tcol = t * tile_width;
int data_length = ifp->size;
lj92 lj;
int newwidth, newheight, newbps;
lj92_open(&lj, &data[dataOffset[t]], data_length, &newwidth, &newheight, &newbps);
uint16_t *target = (uint16_t*)malloc(newwidth * newheight * 2 * sizeof *target);
uint16_t *target = (uint16_t*)malloc(newwidth * newheight * sizeof *target);
lj92_decode(lj, target, tile_width, 0, lincurve, 0x1000);
for (int y = 0; y < height; ++y) {
for(int x = 0; x < tile_width; ++x) {
@@ -9331,7 +9342,7 @@ void CLASS identify()
switch (tiff_compress) {
case 0:
case 1: load_raw = &CLASS packed_dng_load_raw; break;
case 7: load_raw = (!RT_from_adobe_dng_converter && ((!strncmp(make,"Blackmagic",10) && strncmp(model, "Pocket Cinema Camera 4K", 23)) || !strncmp(make,"Canon",5))) ? &CLASS lossless_dnglj92_load_raw : &CLASS lossless_dng_load_raw; break;
case 7: load_raw = (!strncmp(make,"Blackmagic",10) || !strncmp(make,"Canon",5)) ? &CLASS lossless_dnglj92_load_raw : &CLASS lossless_dng_load_raw; break;
case 8: load_raw = &CLASS deflate_dng_load_raw; break;
case 34892: load_raw = &CLASS lossy_dng_load_raw; break;
default: load_raw = 0;