This repository was archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImage_ImageData.cpp
More file actions
78 lines (72 loc) · 3.93 KB
/
Image_ImageData.cpp
File metadata and controls
78 lines (72 loc) · 3.93 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
*******************************************************************************
* Copyright (c) 2009-2023 ectotropic (ectotropic@gmail.com, *
* https://github.com/ectotropic) *
* *
* This program is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation, either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************
******************************************************************************/
//--------------------------------------
//
#include "CommonHeaders.h"
#include "Image_ImageData.h"
//--------------------------------------
namespace Image {
//**************************************************************************
// ImageData::Compact
//**************************************************************************
ImageData::Compact::Compact(const sparse_type& sparse) :
m_iWidth { sparse.iWidth },
m_iHeight{ sparse.iHeight } {
const auto pixelStorageBits { sparse.cBytesPerPixel * 8 };
const auto pixelStrideBits { sparse.cPixelStride * 8 };
const auto scanByteSize { sparse.iWidth * sparse.cBytesPerPixel };
const auto dataByteSize { scanByteSize * sparse.iHeight };
const auto compactPixels{
(pixelStrideBits == pixelStorageBits) &&
(pixelStorageBits == sparse.cBitsPerPixel)
};
const auto compactRows{ scanByteSize == sparse.cScanStride };
m_Pixels.resize(dataByteSize);
if (compactRows && compactPixels) {
std::memcpy(m_Pixels.data(), sparse.pPixels, dataByteSize);
} else if (compactPixels) {
auto* byteDst{ m_Pixels.data() };
const auto* byteSrc{ static_cast<const byte_type*>(sparse.pPixels) };
for (auto line = 0; line < sparse.iHeight; ++line) {
std::memcpy(byteDst, byteSrc, scanByteSize);
byteSrc += sparse.cScanStride;
byteDst += scanByteSize;
}
} else {
auto* byteDst{ m_Pixels.data() };
const auto* byteSrc{ static_cast<const byte_type*>(sparse.pPixels) };
if (pixelStorageBits > (sparse.cBitsPerPixel / 8)) {
std::memset(byteDst, 0, dataByteSize);
}
for (auto line = 0; line < sparse.iHeight; ++line) {
auto* dstPixel = byteDst;
const auto* srcPixel = byteSrc;
for (auto pixel = 0; pixel < sparse.iWidth; ++pixel) {
std::memcpy(dstPixel, srcPixel, sparse.cBytesPerPixel);
srcPixel += sparse.cPixelStride;
dstPixel += sparse.cBytesPerPixel;
}
byteSrc += sparse.cScanStride;
byteDst += scanByteSize;
}
}
}
} // namespace Image