Skip to content

Commit a662a66

Browse files
committed
MultiPage: using new Plugin2 API for opening memory only once for all pages
1 parent 8a52bb1 commit a662a66

7 files changed

Lines changed: 263 additions & 94 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 4.2)
33
project(FreeImageRe)
44

55
set(FREEIMAGERE_MAJOR_VERSION "4")
6-
set(FREEIMAGERE_MINOR_VERSION "1")
7-
set(FREEIMAGERE_PATCH_VERSION "2")
6+
set(FREEIMAGERE_MINOR_VERSION "2")
7+
set(FREEIMAGERE_PATCH_VERSION "0")
88

99
if (PROJECT_IS_TOP_LEVEL)
1010
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ fi.save(fi.FIF_EXR, zero, "zero.exr") # Accepts 2D or 3D numpy arrays
4646
Changes made to FreeImage v3.18:
4747

4848

49+
Version 4.2.0:
50+
- Extended Plugin2 API to support opening multibitmap memory only once for all pages
51+
52+
4953
Version 4.1.1:
5054
- Updated zlib till v1.3.2
5155
- Updated LibPNG till v1.6.55

Source/FreeImage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ typedef const char* (DLL_CALLCONV* FI_ExtensionListProc2)(void* ctx);
678678
typedef const char* (DLL_CALLCONV* FI_RegExprProc2)(void* ctx);
679679
typedef void* (DLL_CALLCONV* FI_OpenProc2)(void* ctx, FreeImageIO* io, fi_handle handle, FIBOOL read);
680680
typedef void (DLL_CALLCONV* FI_CloseProc2)(void* ctx, FreeImageIO* io, fi_handle handle, void* data);
681+
typedef void* (DLL_CALLCONV* FI_OpenPersistentProc2)(void* ctx, FreeImageIO* io, fi_handle handle, FIBOOL read);
682+
typedef void (DLL_CALLCONV* FI_ClosePersistentProc2)(void* ctx, FreeImageIO* io, fi_handle handle, void* data);
681683
typedef uint32_t(DLL_CALLCONV* FI_PageCountProc2)(void* ctx, FreeImageIO* io, fi_handle handle, void* data);
682684
typedef uint32_t(DLL_CALLCONV* FI_PageCapabilityProc2)(void* ctx, FreeImageIO* io, fi_handle handle, void* data);
683685
typedef FIBITMAP* (DLL_CALLCONV* FI_LoadProc2)(void* ctx, FreeImageIO* io, fi_handle handle, uint32_t page, uint32_t flags, void* data);
@@ -708,6 +710,8 @@ FI_STRUCT(Plugin2) {
708710
FI_SupportsICCProfilesProc2 supports_icc_profiles_proc FI_DEFAULT(NULL);
709711
FI_SupportsNoPixelsProc2 supports_no_pixels_proc FI_DEFAULT(NULL);
710712
FI_ReleaseProc2 release_proc FI_DEFAULT(NULL);
713+
FI_OpenPersistentProc2 open_persistent_proc FI_DEFAULT(NULL);
714+
FI_ClosePersistentProc2 close_persistent_proc FI_DEFAULT(NULL);
711715
};
712716

713717
// Plugin behaviour hould be invariant to FIF_SOMETHING enum value

Source/FreeImage.hpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,18 +1543,56 @@ namespace fi
15431543
class Plugin2
15441544
{
15451545
public:
1546+
enum class FeatureFlag : uint32_t
1547+
{
1548+
eNone = 0,
1549+
eSupportsLoad = 0x1,
1550+
eSupportsSave = 0x1 << 1,
1551+
eSupportsPersistentOpen = 0x1 << 2
1552+
};
1553+
1554+
friend constexpr
1555+
FeatureFlag operator&(FeatureFlag lhs, FeatureFlag rhs) {
1556+
return static_cast<FeatureFlag>(static_cast<std::underlying_type_t<FeatureFlag>>(lhs) & static_cast<std::underlying_type_t<FeatureFlag>>(rhs));
1557+
}
1558+
1559+
friend constexpr
1560+
FeatureFlag operator|(FeatureFlag lhs, FeatureFlag rhs) {
1561+
return static_cast<FeatureFlag>(static_cast<std::underlying_type_t<FeatureFlag>>(lhs) | static_cast<std::underlying_type_t<FeatureFlag>>(rhs));
1562+
}
1563+
1564+
15461565
static ImageFormat RegisterLocal(std::shared_ptr<Plugin2> plugin);
15471566
static bool ResetLocalPlugin(ImageFormat fif, std::shared_ptr<Plugin2> plugin, bool force = false);
15481567

1568+
1569+
Plugin2(FeatureFlag flags = FeatureFlag::eSupportsLoad | FeatureFlag::eSupportsSave)
1570+
: mFeatureFlags(flags)
1571+
{ }
1572+
1573+
Plugin2(const Plugin2&) = default;
1574+
Plugin2(Plugin2&&) noexcept = default;
1575+
15491576
virtual ~Plugin2() = default;
15501577

1578+
Plugin2& operator=(const Plugin2&) = default;
1579+
Plugin2& operator=(Plugin2&&) noexcept = default;
1580+
1581+
1582+
const FeatureFlag& GetFeatureFlags() const {
1583+
return mFeatureFlags;
1584+
}
1585+
1586+
15511587
// Plugin2 API
15521588
virtual const char* FormatProc() { return nullptr; };
15531589
virtual const char* DescriptionProc() { return nullptr; };
15541590
virtual const char* ExtensionListProc() { return nullptr; };
15551591
virtual const char* RegExprProc() { return nullptr; };
15561592
virtual void* OpenProc(FreeImageIO* /*io*/, fi_handle /*handle*/, bool /*read*/) { return nullptr; };
15571593
virtual void CloseProc(FreeImageIO* /*io*/, fi_handle /*handle*/, void* /*data*/) {};
1594+
virtual void* OpenPersistentProc(FreeImageIO* /*io*/, fi_handle /*handle*/, bool /*read*/) { return nullptr; };
1595+
virtual void ClosePersistentProc(FreeImageIO* /*io*/, fi_handle /*handle*/, void* /*data*/) {};
15581596
virtual uint32_t PageCountProc(FreeImageIO* /*io*/, fi_handle /*handle*/, void* /*data*/) { return 1U; };
15591597
virtual uint32_t PageCapabilityProc(FreeImageIO* /*io*/, fi_handle /*handle*/, void* /*data*/) { return 1U; };
15601598
virtual FIBITMAP* LoadProc(FreeImageIO* /*io*/, fi_handle /*handle*/, uint32_t /*page*/, uint32_t /*flags*/, void* /*data*/) { return nullptr; };
@@ -1565,9 +1603,14 @@ namespace fi
15651603
virtual bool SupportsExportTypeProc(FREE_IMAGE_TYPE /*type*/) { return false; };
15661604
virtual bool SupportsICCProfilesProc() { return false; };
15671605
virtual bool SupportsNoPixelsProc() { return false; };
1606+
1607+
private:
1608+
FeatureFlag mFeatureFlags;
15681609
};
15691610

15701611

1612+
1613+
15711614
namespace details {
15721615

15731616
class Plugin2Wrapper
@@ -1580,6 +1623,8 @@ namespace fi
15801623
static const char* DLL_CALLCONV RegExprProc(void* ctx) try { return unwrap(ctx).RegExprProc(); } catch (...) { return nullptr; };
15811624
static void* DLL_CALLCONV OpenProc(void* ctx, FreeImageIO* io, fi_handle handle, FIBOOL read) try { return unwrap(ctx).OpenProc(io, handle, read); } catch (...) { return nullptr; };
15821625
static void DLL_CALLCONV CloseProc(void* ctx, FreeImageIO* io, fi_handle handle, void* data) try { unwrap(ctx).CloseProc(io, handle, data); } catch (...) { };
1626+
static void* DLL_CALLCONV OpenPersistentProc(void* ctx, FreeImageIO* io, fi_handle handle, FIBOOL read) try { return unwrap(ctx).OpenPersistentProc(io, handle, read); } catch (...) { return nullptr; };
1627+
static void DLL_CALLCONV ClosePersistentProc(void* ctx, FreeImageIO* io, fi_handle handle, void* data) try { unwrap(ctx).ClosePersistentProc(io, handle, data); } catch (...) { };
15831628
static uint32_t DLL_CALLCONV PageCountProc(void* ctx, FreeImageIO* io, fi_handle handle, void* data) try { return unwrap(ctx).PageCountProc(io, handle, data); } catch (...) { return 1U; };
15841629
static uint32_t DLL_CALLCONV PageCapabilityProc(void* ctx, FreeImageIO* io, fi_handle handle, void* data) try { return unwrap(ctx).PageCapabilityProc(io, handle, data); } catch (...) { return 1U; };
15851630
static FIBITMAP* DLL_CALLCONV LoadProc(void* ctx, FreeImageIO* io, fi_handle handle, uint32_t page, uint32_t flags, void* data) try { return unwrap(ctx).LoadProc(io, handle, page, flags, data); } catch (...) { return nullptr; };
@@ -1596,10 +1641,13 @@ namespace fi
15961641
}
15971642

15981643
static FIBOOL DLL_CALLCONV InitProc(::Plugin2* plugin, void* ctx) {
1644+
using FeatureFlag = Plugin2::FeatureFlag;
15991645
if (!plugin) {
16001646
return FALSE;
16011647
}
16021648

1649+
const auto flags = unwrap(ctx).GetFeatureFlags();
1650+
16031651
using This = fi::details::Plugin2Wrapper;
16041652
plugin->format_proc = &This::FormatProc;
16051653
plugin->description_proc = &This::DescriptionProc;
@@ -1609,15 +1657,17 @@ namespace fi
16091657
plugin->close_proc = &This::CloseProc;
16101658
plugin->pagecount_proc = &This::PageCountProc;
16111659
plugin->pagecapability_proc = &This::PageCapabilityProc;
1612-
plugin->load_proc = &This::LoadProc;
1613-
plugin->save_proc = &This::SaveProc;
1660+
plugin->load_proc = ((flags & FeatureFlag::eSupportsLoad) != FeatureFlag::eNone) ? &This::LoadProc : nullptr;
1661+
plugin->save_proc = ((flags & FeatureFlag::eSupportsSave) != FeatureFlag::eNone) ? &This::SaveProc : nullptr;
16141662
plugin->validate_proc = &This::ValidateProc;
16151663
plugin->mime_proc = &This::MimeProc;
16161664
plugin->supports_export_bpp_proc = &This::SupportsExportBPPProc;
16171665
plugin->supports_export_type_proc = &This::SupportsExportTypeProc;
16181666
plugin->supports_icc_profiles_proc = &This::SupportsICCProfilesProc;
16191667
plugin->supports_no_pixels_proc = &This::SupportsNoPixelsProc;
16201668
plugin->release_proc = &This::ReleaseProc;
1669+
plugin->open_persistent_proc = ((flags & FeatureFlag::eSupportsPersistentOpen) != FeatureFlag::eNone) ? &This::OpenPersistentProc : nullptr;
1670+
plugin->close_persistent_proc = ((flags & FeatureFlag::eSupportsPersistentOpen) != FeatureFlag::eNone) ? &This::ClosePersistentProc : nullptr;
16211671

16221672
return TRUE;
16231673
}

0 commit comments

Comments
 (0)