Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions Codecs/CodecJPG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,3 @@ set(TargetName CodecJPG)
add_library (${TargetName} ${sourceFiles} )

target_link_libraries(${TargetName} PRIVATE libjpeg-turbo::libjpeg-turbo) # adjust to match built target name

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") AND NOT MINGW)
target_link_options(${TargetName} PUBLIC "/DELAYLOAD:turbojpeg.dll")
endif()
5 changes: 0 additions & 5 deletions Codecs/CodecPNG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,3 @@ target_include_directories(${TargetName} PRIVATE ${LibPNGFolder})
target_include_directories(${TargetName} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/libpng)
target_link_libraries(${TargetName} png_shared )
target_include_directories(png_shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/zlib)

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
target_link_options(${TargetName} PUBLIC "/DELAYLOAD:$<TARGET_FILE_BASE_NAME:png_shared>.dll")
target_link_options(${TargetName} PUBLIC "/DELAYLOAD:$<TARGET_FILE_BASE_NAME:zlib>.dll")
endif()
3 changes: 0 additions & 3 deletions Codecs/CodecTiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,3 @@ target_include_directories(${TargetName} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ext


target_link_libraries(${TargetName} tiff)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") AND NOT MINGW)
target_link_options(${TargetName} PUBLIC "/DELAYLOAD:$<TARGET_FILE_BASE_NAME:tiff>.dll")
endif()
125 changes: 90 additions & 35 deletions Codecs/CodecTiff/Source/CodecTiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <LLUtils/Exception.h>
#include <IImagePlugin.h>

#include <utility>

namespace IMCodec
{
class CodecTiff : public IImagePlugin
Expand Down Expand Up @@ -66,20 +68,15 @@ namespace IMCodec
case SAMPLEFORMAT_UINT:
switch (samplesPerPixel)
{
case 1:
switch (bitsPerSample)
{
case 8:
texelFormat = TexelFormat::I_A8;
break;
}
break;
case 3:
switch (bitsPerSample)
{
case 8:
texelFormat = TexelFormat::I_R8_G8_B8;
break;
case 16:
texelFormat = TexelFormat::I_R16_G16_B16;
break;
}
break;
case 4:
Expand All @@ -88,6 +85,9 @@ namespace IMCodec
case 8:
texelFormat = TexelFormat::I_R8_G8_B8_A8;
break;
case 16:
texelFormat = TexelFormat::I_R16_G16_B16_A16;
break;
}
break;
}
Expand All @@ -112,6 +112,9 @@ namespace IMCodec
case 32:
texelFormat = TexelFormat::F_X32;
break;
case 64:
texelFormat = TexelFormat::F_X64;
break;
default:
break;
}
Expand All @@ -127,37 +130,42 @@ namespace IMCodec
case 1:
texelFormat = TexelFormat::I_X1;
break;
case 4:
texelFormat = TexelFormat::I_X4;
break;
case 8:
texelFormat = TexelFormat::I_X8;
break;
case 16:
texelFormat = TexelFormat::I_X16;
break;
case SAMPLEFORMAT_INT:
switch (bitsPerSample)
{
case 8:
texelFormat = TexelFormat::S_X8;
break;
case 16:
texelFormat = TexelFormat::S_X16;
break;
default:
break;
}
}
break;
}
break;
case SAMPLEFORMAT_INT:
switch (samplesPerPixel)
{
case 1:
switch (bitsPerSample)
{
case 8:
texelFormat = TexelFormat::S_X8;
break;
case 16:
texelFormat = TexelFormat::S_X16;
break;
default:
break;
}
break;
}
break;
}
}


if (texelFormat == TexelFormat::UNKNOWN)
LL_ERROR(LLUtils::Exception::ErrorCode::NotImplemented, "CodecTiff: unsupported floating point format.");

return texelFormat;
}
return texelFormat;
}

std::vector<ImageItemSharedPtr> GetImage(TIFF* tiff)
{
Expand Down Expand Up @@ -201,6 +209,9 @@ namespace IMCodec
TIFFGetField(tiff, TIFFTAG_MAXSAMPLEVALUE, &maxSampleValue);*/
TIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extraSamples, &sampleTypes);

if (samplesPerPixel <= extraSamples)
return {};

const uint32_t bytesPerSample = bitsPerSample / CHAR_BIT;

uint32_t numberOfStripts = TIFFNumberOfStrips(tiff);
Expand Down Expand Up @@ -229,17 +240,38 @@ namespace IMCodec
//If there's an alpha channel and it's interleaved in the image data, return as single image with alpha channel
imageItem->descriptor.texelFormatDecompressed = imageItem->descriptor.texelFormatStorage = mainChannelTexelFormat;

if (planarConfig == PLANARCONFIG_CONTIG && extraSamples == 1 && sampleTypes[0] > 0)
auto extractExtraSampleImages = [&]()
{
imageItem->descriptor.texelFormatStorage = imageItem->descriptor.texelFormatDecompressed = GetTexelFormat(sampleFormat, bitsPerSample, samplesPerPixel, photoMetric);
return ExtactExtraSamples(width, height, rowPitch, samplesPerPixel, extraSamples, planarConfig
, bytesPerSample, imageItem->data, photoMetric, bitsPerSample, sampleFormat);
};

if (planarConfig == PLANARCONFIG_CONTIG && extraSamples > 0)
{
const auto interleavedTexelFormat = GetTexelFormat(sampleFormat, bitsPerSample, samplesPerPixel, photoMetric);

if (interleavedTexelFormat != TexelFormat::UNKNOWN)
{
imageItem->descriptor.texelFormatStorage = imageItem->descriptor.texelFormatDecompressed = interleavedTexelFormat;
}
else
{
auto extraChannelImages = extractExtraSampleImages();

if (extraChannelImages.empty() == false)
imageItems = extraChannelImages;
else
return {};
}
}
else
else if (extraSamples > 0)
{
auto extraChannelImages = ExtactExtraSamples(width, height, rowPitch, samplesPerPixel, extraSamples, planarConfig
, bytesPerSample, imageItem->data, photoMetric, bitsPerSample, sampleFormat);
auto extraChannelImages = extractExtraSampleImages();

if (extraChannelImages.empty() == false)
imageItems = extraChannelImages;
else
return {};
}
}
else
Expand Down Expand Up @@ -274,9 +306,13 @@ namespace IMCodec
{

const auto sampleSize = sampleCount * bytesPerSample;
const auto samplePhotometric = sampleOffset == 0 ? photometric : PHOTOMETRIC_MINISBLACK;

auto imageItem = std::make_shared<ImageItem>();
imageItem->descriptor.texelFormatStorage = GetTexelFormat(sampleFormat, bitsPerSample , sampleCount, photometric);
imageItem->descriptor.texelFormatStorage = GetTexelFormat(sampleFormat, bitsPerSample , sampleCount, samplePhotometric);
if (imageItem->descriptor.texelFormatStorage == TexelFormat::UNKNOWN)
return {};

imageItem->descriptor.texelFormatDecompressed = imageItem->descriptor.texelFormatStorage;
imageItem->descriptor.height = height;
imageItem->descriptor.width = width;
Expand All @@ -293,7 +329,7 @@ namespace IMCodec
{
for (size_t x = 0; x < width; x++)
{
const size_t sourceRowIndex = sampleOffset * sampleSize + x * samplesPerPixel * bytesPerSample;
const size_t sourceRowIndex = sampleOffset * bytesPerSample + x * samplesPerPixel * bytesPerSample;
const size_t destRowIndex = x * sampleSize;
memcpy(image.data() + destOffset + destRowIndex, sourceBuffer.data() + sourceOffset + sourceRowIndex, sampleSize);
}
Expand All @@ -318,12 +354,25 @@ namespace IMCodec

if (extraSmaples > 0)
{
if (bytesPerSample == 0 || bitsPerSample % CHAR_BIT != 0 || samplesPerPixel <= extraSmaples)
return {};

const auto mainImageSampleCount = samplesPerPixel - extraSmaples;

subChannels.push_back(extractSamples(0, mainImageSampleCount));
auto mainImage = extractSamples(0, mainImageSampleCount);
if (mainImage == nullptr)
return {};

subChannels.push_back(std::move(mainImage));

for (int i = 0; i < extraSmaples; i++)
subChannels.push_back(extractSamples(mainImageSampleCount + i, 1));
{
auto extraImage = extractSamples(mainImageSampleCount + i, 1);
if (extraImage == nullptr)
return {};

subChannels.push_back(std::move(extraImage));
}
}


Expand All @@ -344,6 +393,9 @@ namespace IMCodec
int currentSubImage = 0;

auto firstImageItemChannles = GetImage(tiff);
if (firstImageItemChannles.empty())
return ImageResult::FormatNotSupported;

firstImageItem = firstImageItemChannles.at(0);

if (firstImageItemChannles.size() > 1)
Expand All @@ -365,6 +417,9 @@ namespace IMCodec
}

auto nextImages = GetImage(tiff);
if (nextImages.empty())
return ImageResult::FormatNotSupported;

for (size_t i = 0; i < nextImages.size(); i++)
{
subImages.push_back(std::make_shared<Image>(nextImages.at(i), ImageItemType::Pages));
Expand Down
19 changes: 16 additions & 3 deletions ImageCodec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ if ( ${IMCODEC_BUILD_CODEC_FREEIMAGE})
endif()

target_link_libraries(${TargetName} PRIVATE TinyEXIFstatic)
target_link_libraries(${TargetName} PUBLIC delayimp)


if (${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND
(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") AND
NOT MINGW)
target_link_libraries(${TargetName} PUBLIC delayimp)
if ( ${IMCODEC_BUILD_CODEC_JPG})
target_link_options(${TargetName} PUBLIC "/DELAYLOAD:turbojpeg.dll")
endif()
if ( ${IMCODEC_BUILD_CODEC_PNG})
target_link_options(${TargetName} PUBLIC "/DELAYLOAD:$<TARGET_FILE_BASE_NAME:png_shared>.dll")
set_property(TARGET png_shared APPEND PROPERTY LINK_LIBRARIES delayimp)
set_property(TARGET png_shared APPEND PROPERTY LINK_OPTIONS "/DELAYLOAD:$<TARGET_FILE_BASE_NAME:zlib>.dll")
endif()
if ( ${IMCODEC_BUILD_CODEC_TIFF})
target_link_options(${TargetName} PUBLIC "/DELAYLOAD:$<TARGET_FILE_BASE_NAME:tiff>.dll")
endif()
endif()
Loading