diff --git a/src/Psd/PsdColorModeDataSection.h b/src/Psd/PsdColorModeDataSection.h index 9f6a067..f853c2f 100644 --- a/src/Psd/PsdColorModeDataSection.h +++ b/src/Psd/PsdColorModeDataSection.h @@ -11,6 +11,8 @@ PSD_NAMESPACE_BEGIN /// \brief A struct representing the information extracted from the Color Mode Data section. struct ColorModeDataSection { + uint8_t* colorData; + uint32_t sizeOfColorData; }; PSD_NAMESPACE_END diff --git a/src/Psd/PsdParseColorModeDataSection.cpp b/src/Psd/PsdParseColorModeDataSection.cpp index ae413a4..8d75f9d 100644 --- a/src/Psd/PsdParseColorModeDataSection.cpp +++ b/src/Psd/PsdParseColorModeDataSection.cpp @@ -4,20 +4,42 @@ #include "PsdPch.h" #include "PsdParseColorModeDataSection.h" -#include "PsdColorModeDataSection.h" #include "PsdAllocator.h" +#include "PsdAssert.h" +#include "PsdColorModeDataSection.h" +#include "PsdDocument.h" #include "PsdMemoryUtil.h" +#include "PsdSyncFileReader.h" +#include "PsdSyncFileUtil.h" PSD_NAMESPACE_BEGIN // --------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------- -ColorModeDataSection* ParseColorModeDataSection(const Document&, File*, Allocator*) +ColorModeDataSection* ParseColorModeDataSection(const Document* document, File* file, Allocator* allocator) { - // not implemented yet. - // only indexed color and Duotone have color mode data, but both are not supported by this library at the moment. - return nullptr; + PSD_ASSERT_NOT_NULL(document); + PSD_ASSERT_NOT_NULL(file); + PSD_ASSERT_NOT_NULL(allocator); + + const Section& section = document->colorModeDataSection; + if (section.length == 0u) + { + return nullptr; + } + + ColorModeDataSection* colorModeData = memoryUtil::Allocate(allocator); + *colorModeData = ColorModeDataSection(); + + SyncFileReader reader(file); + reader.SetPosition(document->colorModeDataSection.offset); + + colorModeData->colorData = memoryUtil::AllocateArray(allocator, section.length); + colorModeData->sizeOfColorData = section.length; + reader.Read(colorModeData->colorData, section.length); + + return colorModeData; } @@ -28,6 +50,10 @@ void DestroyColorModeDataSection(ColorModeDataSection*& section, Allocator* allo PSD_ASSERT_NOT_NULL(section); PSD_ASSERT_NOT_NULL(allocator); + if (section->colorData) + { + memoryUtil::FreeArray(allocator, section->colorData); + } memoryUtil::Free(allocator, section); } diff --git a/src/Psd/PsdParseColorModeDataSection.h b/src/Psd/PsdParseColorModeDataSection.h index 7c0e3a7..6b386bf 100644 --- a/src/Psd/PsdParseColorModeDataSection.h +++ b/src/Psd/PsdParseColorModeDataSection.h @@ -16,7 +16,7 @@ struct ColorModeDataSection; /// Parses the color mode data section in the document, and returns a newly created instance that needs to be freed /// by a call to \ref DestroyColorModeDataSection. /// \remark This function does not yet parse meaningful data. -ColorModeDataSection* ParseColorModeDataSection(const Document& document, File* file, Allocator* allocator); +ColorModeDataSection* ParseColorModeDataSection(const Document* document, File* file, Allocator* allocator); /// \ingroup Parser /// Destroys and nullifies the given \a section previously created by a call to \ref ParseColorModeDataSection.