-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrameBuffer.cpp
More file actions
128 lines (106 loc) · 3.21 KB
/
FrameBuffer.cpp
File metadata and controls
128 lines (106 loc) · 3.21 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// AUTHOR: Nenad Amodaj, nenad@amodaj.com
//
// COPYRIGHT: 2005 Nenad Amodaj
// 2005-2015 Regents of the University of California
// 2017 Open Imaging, Inc.
//
// LICENSE: This file is free for use, modification and distribution and
// is distributed under terms specified in the BSD license
// This file 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.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
// NOTE: Imported from ADVI for use in Micro-Manager
#include "FrameBuffer.h"
#include <cmath>
#include <cstring>
namespace mmcore {
namespace internal {
ImgBuffer::ImgBuffer(unsigned xSize, unsigned ySize, unsigned pixDepth) :
pixels_(new unsigned char[xSize * ySize * pixDepth]()),
width_(xSize), height_(ySize), pixDepth_(pixDepth)
{
}
ImgBuffer::~ImgBuffer() = default;
const unsigned char* ImgBuffer::GetPixels() const
{
return pixels_.get();
}
void ImgBuffer::SetPixels(const void* pix)
{
memcpy((void*)pixels_.get(), pix, width_ * height_ * pixDepth_);
}
void ImgBuffer::Resize(unsigned xSize, unsigned ySize, unsigned pixDepth)
{
// re-allocate internal buffer if it is not big enough
if (width_ * height_ * pixDepth_ < xSize * ySize * pixDepth)
{
pixels_.reset(new unsigned char[xSize * ySize * pixDepth]);
}
width_ = xSize;
height_ = ySize;
pixDepth_ = pixDepth;
}
void ImgBuffer::Resize(unsigned xSize, unsigned ySize)
{
// re-allocate internal buffer if it is not big enough
if (width_ * height_ < xSize * ySize)
{
pixels_.reset(new unsigned char[xSize * ySize * pixDepth_]);
}
width_ = xSize;
height_ = ySize;
memset(pixels_.get(), 0, width_ * height_ * pixDepth_);
}
void ImgBuffer::SetMetadata(const Metadata& md)
{
//metadata_ = md;
// Serialize/Restore instead of =operator used to avoid object new/delete
// issues across the DLL boundary (on Windows)
// TODO: this is inefficient and should be revised
metadata_.Restore(md.Serialize().c_str());
}
///////////////////////////////////////////////////////////////////////////////
// FrameBuffer class
///////////////////////////////////////////////////////////////////////////////
FrameBuffer::FrameBuffer(unsigned xSize, unsigned ySize, unsigned byteDepth)
{
width_ = xSize;
height_ = ySize;
depth_ = byteDepth;
}
FrameBuffer::FrameBuffer()
{
width_ = 0;
height_ = 0;
depth_ = 0;
}
void FrameBuffer::Clear()
{
buffer_.reset();
}
void FrameBuffer::Preallocate()
{
if (!buffer_) {
buffer_ = std::make_unique<ImgBuffer>(width_, height_, depth_);
}
}
void FrameBuffer::Resize(unsigned xSize, unsigned ySize, unsigned byteDepth)
{
Clear();
width_ = xSize;
height_ = ySize;
depth_ = byteDepth;
}
ImgBuffer* FrameBuffer::FindImage(unsigned channel) const
{
if (channel > 0)
return nullptr;
return buffer_.get();
}
} // namespace internal
} // namespace mmcore