forked from MolecularMatters/psd_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PsdParseColorModeDataSection.cpp
60 lines (46 loc) · 2.04 KB
/
PsdParseColorModeDataSection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2011-2020, Molecular Matters GmbH <[email protected]>
// See LICENSE.txt for licensing details (2-clause BSD License: https://opensource.org/licenses/BSD-2-Clause)
#include "PsdPch.h"
#include "PsdParseColorModeDataSection.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* document, File* file, Allocator* allocator)
{
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<ColorModeDataSection>(allocator);
*colorModeData = ColorModeDataSection();
SyncFileReader reader(file);
reader.SetPosition(document->colorModeDataSection.offset);
colorModeData->colorData = memoryUtil::AllocateArray<uint8_t>(allocator, section.length);
colorModeData->sizeOfColorData = section.length;
reader.Read(colorModeData->colorData, section.length);
return colorModeData;
}
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
void DestroyColorModeDataSection(ColorModeDataSection*& section, Allocator* allocator)
{
PSD_ASSERT_NOT_NULL(section);
PSD_ASSERT_NOT_NULL(allocator);
if (section->colorData)
{
memoryUtil::FreeArray(allocator, section->colorData);
}
memoryUtil::Free(allocator, section);
}
PSD_NAMESPACE_END