@@ -322,7 +322,10 @@ ImagePyramidAccess::pointer ImagePyramid::getAccess(accessType type) {
322322 std::unique_lock<std::mutex> lock (mDataIsBeingAccessedMutex );
323323 mDataIsBeingAccessed = true ;
324324 }
325- return std::make_unique<ImagePyramidAccess>(m_levels, m_fileHandle, m_tiffHandle, std::static_pointer_cast<ImagePyramid>(mPtr .lock ()), type == ACCESS_READ_WRITE, m_initializedPatchList, m_readMutex, m_compressionFormat);
325+ auto access = std::make_unique<ImagePyramidAccess>(m_levels, m_fileHandle, m_tiffHandle, std::static_pointer_cast<ImagePyramid>(mPtr .lock ()), type == ACCESS_READ_WRITE, m_initializedPatchList, m_readMutex, m_compressionFormat);
326+ if (m_JPEGTablesCount > 0 )
327+ access->setJPEGTables (m_JPEGTablesCount, m_JPEGTablesData);
328+ return access;
326329}
327330
328331void ImagePyramid::setDirtyPatch (int level, int patchIdX, int patchIdY) {
@@ -437,6 +440,20 @@ ImagePyramid::ImagePyramid(TIFF *fileHandle, std::vector<ImagePyramidLevel> leve
437440 throw Exception (" Unable to get JPEG quality from TIFF" );
438441 m_compressionQuality = quality;
439442 }
443+ {
444+ // Check if there is JPEG table data stored in the TIFF
445+ // If so we use this table for all tiles
446+ uint32_t tablesCount = 0 ;
447+ void *tableData;
448+ int res = TIFFGetField (m_tiffHandle, TIFFTAG_JPEGTABLES, &tablesCount, &tableData);
449+ if (res == 1 ) {
450+ reportInfo () << " Got JPEG tables data from the TIFF file with size: " << tablesCount << reportEnd ();
451+ m_JPEGTablesCount = tablesCount;
452+ // Have to copy the table
453+ m_JPEGTablesData = new uchar[tablesCount];
454+ std::memcpy (m_JPEGTablesData, tableData, sizeof (uchar)*tablesCount);
455+ }
456+ }
440457 break ;
441458 case COMPRESSION_JXL:
442459 compression = ImageCompression::JPEGXL;
0 commit comments