Skip to content

Commit 22b42f6

Browse files
committed
Replace soon to be deprecated emg::Buffer<> with std::vector<>
1 parent ee04ebe commit 22b42f6

File tree

23 files changed

+138
-109
lines changed

23 files changed

+138
-109
lines changed

include/iconograph/canvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Canvas : public QLabel
1717
Select
1818
};
1919

20-
Canvas(QWidget *parent = 0, Qt::WindowFlags f = 0);
20+
Canvas(QWidget *parent = 0, Qt::WindowFlags f = {});
2121
// ~Canvas() {}
2222

2323

include/iconograph/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class MainWindow : public QMainWindow
123123

124124
psinc::ImageHandler<uint16_t> hdrHandler;
125125
emg::Image<uint16_t, emg::rgb> hdrImage;
126-
emg::Buffer<int> histogram;
126+
std::array<int, 4096> histogram;
127127

128128

129129
// bool lensCorrect = false;

include/psinc/Camera.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ namespace psinc
136136

137137
/// Byte buffer containing the packet to be transmitted to the actual device
138138
/// this class represents.
139-
emg::Buffer<byte> send;
139+
std::vector<byte> send;
140140

141141
/// Byte buffer used to receive data from the device during a capture.
142-
emg::Buffer<byte> receive;
142+
std::vector<byte> receive;
143143

144144

145145
/// Image capture complete callback

include/psinc/Transport.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <emergent/Emergent.hpp>
4-
#include <emergent/struct/Buffer.hpp>
54
// #include <psinc/TransportBuffer.hpp>
65
#include <libusb-1.0/libusb.h>
76
#include <atomic>
@@ -46,7 +45,7 @@ namespace psinc
4645

4746

4847
/// Transfer packets to and from the actual device
49-
bool Transfer(emg::Buffer<byte> *send, emg::Buffer<byte> *receive, std::atomic<bool> &waiting, bool check = true, bool truncate = false);
48+
bool Transfer(std::vector<byte> *send, std::vector<byte> *receive, std::atomic<bool> &waiting, bool check = true, bool truncate = false);
5049

5150

5251
/// Reset the connection to the actual device.
@@ -93,7 +92,7 @@ namespace psinc
9392

9493

9594
/// Tranfer the given data to the device (write) or from the device (!write)
96-
bool Transfer(emg::Buffer<byte> *buffer, bool write, bool check, bool truncate);
95+
bool Transfer(std::vector<byte> *buffer, bool write, bool check, bool truncate);
9796

9897

9998
/// Releases the device.

include/psinc/driver/Device.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace psinc
5858

5959

6060
/// Write the binary data to the device
61-
bool Write(const emg::Buffer<byte> &buffer);
61+
bool Write(const std::vector<byte> &buffer);
6262

6363

6464
/// Write the binary data to the device
@@ -70,12 +70,12 @@ namespace psinc
7070

7171

7272
/// Read binary data from the device
73-
emg::Buffer<byte> Read();
73+
std::vector<byte> Read();
7474

7575

7676
/// Read binary data from the device into the supplied buffer. The buffer size
7777
/// is used to determine how much data can be received from the device
78-
bool Read(emg::Buffer<byte> &buffer);
78+
bool Read(std::vector<byte> &buffer);
7979

8080

8181
/// Set the channel for this device. Will return the channel information including

include/psinc/driver/Register.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace psinc
3939
/// When performing a full refresh of all registers, the values are returned
4040
/// in page blocks and this is used to update a particular register from that
4141
/// data block.
42-
void Refresh(emg::Buffer<byte> &data);
42+
void Refresh(std::vector<byte> &data);
4343

4444

4545
/// Returns the address of this particular register

include/psinc/handlers/DataHandler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace psinc
1616
virtual ~DataHandler() {}
1717

1818
/// Process the data in the supplied buffer using the known width and height of the image
19-
virtual bool Process(bool monochrome, bool hdr, emg::Buffer<emg::byte> &data, int width, int height, emg::byte bayerMode) = 0;
19+
virtual bool Process(bool monochrome, const bool hdr, const std::vector<emg::byte> &data, const int width, const int height, const emg::byte bayerMode) = 0;
2020

2121
// This should only be written to by the acquisition system, but can be read
2222
// from outside to know when the USB transport has prepped the camera for

include/psinc/handlers/ImageHandler.hpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <emergent/image/Image.hpp>
88

99

10-
1110
namespace psinc
1211
{
1312
enum class DecodeMode
@@ -28,8 +27,6 @@ namespace psinc
2827
struct Configuration
2928
{
3029
DecodeMode mode = DecodeMode::Automatic;
31-
// bool forceBayer = false;
32-
// Filter::Configuration filter;
3330
};
3431

3532
ImageHandler() {}
@@ -62,7 +59,7 @@ namespace psinc
6259
}
6360

6461

65-
bool Process(bool monochrome, bool hdr, emg::Buffer<byte> &data, int width, int height, byte bayerMode) override
62+
bool Process(bool monochrome, const bool hdr, const std::vector<byte> &data, const int width, const int height, const byte bayerMode) override
6663
{
6764
// Allow the monochrome flag to be overridden - could have unexpected effects.
6865
switch (configuration.mode)
@@ -73,25 +70,25 @@ namespace psinc
7370
default: break;
7471
}
7572

76-
int w = monochrome ? width : width - 4;
77-
int h = monochrome ? height : height - 4;
73+
const int w = monochrome ? width : width - 4;
74+
const int h = monochrome ? height : height - 4;
7875

79-
if (w > 0 && h > 0 && data.Size() == width * height * (hdr ? 2 : 1))
76+
if (w > 0 && h > 0 && data.size() == width * height * (hdr ? 2 : 1))
8077
{
81-
int depth = this->image->Depth();
78+
const byte depth = this->image->Depth();
8279
this->image->Resize(w, h);
8380

8481
if (hdr)
8582
{
86-
if (monochrome) Monochrome::Decode((uint16_t *)data.Data(), this->image->Data(), width, height, depth, this->shiftBits);
87-
else if (depth == 3) Bayer::Colour((uint16_t *)data.Data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
88-
else Bayer::Grey((uint16_t *)data.Data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
83+
if (monochrome) Monochrome::Decode((uint16_t *)data.data(), this->image->Data(), width, height, depth, this->shiftBits);
84+
else if (depth == 3) Bayer::Colour((uint16_t *)data.data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
85+
else Bayer::Grey((uint16_t *)data.data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
8986
}
9087
else
9188
{
92-
if (monochrome) Monochrome::Decode(data.Data(), this->image->Data(), width, height, depth, this->shiftBits);
93-
else if (depth == 3) Bayer::Colour(data.Data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
94-
else Bayer::Grey(data.Data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
89+
if (monochrome) Monochrome::Decode(data.data(), this->image->Data(), width, height, depth, this->shiftBits);
90+
else if (depth == 3) Bayer::Colour(data.data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
91+
else Bayer::Grey(data.data(), this->image->Data(), width, height, bayerMode, this->shiftBits);
9592
}
9693

9794
// Filter::Process(this->configuration.filter, *this->image);

include/psinc/handlers/NoopHandler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace psinc
1212
public:
1313

1414
// Refer to parent documentation
15-
bool Process(bool monochrome, bool hdr, emg::Buffer<emg::byte> &data, int width, int height, emg::byte bayerMode) override
15+
bool Process(bool monochrome, const bool hdr, const std::vector<emg::byte> &data, const int width, const int height, const emg::byte bayerMode) override
1616
{
1717
return true;
1818
}

include/psinc/handlers/helpers/Bayer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ namespace psinc
5757
}
5858

5959

60-
static inline void Clamp(int value, uint16_t*, uint16_t *dst, const uint16_t) { *dst = value > 65535 ? 65535 : value < 0 ? 0 : value; }
61-
static inline void Clamp(int value, uint16_t*, byte *dst, const uint16_t shift) { value = value >> shift; *dst = value > 255 ? 255 : value < 0 ? 0 : value; }
62-
static inline void Clamp(int value, byte*, uint16_t *dst, const uint16_t) { *dst = value < 0 ? 0 : value; }
63-
static inline void Clamp(int value, byte*, byte *dst, const uint16_t) { *dst = value > 255 ? 255 : value < 0 ? 0 : value; }
60+
static inline void Clamp(int value, const uint16_t*, uint16_t *dst, const uint16_t) { *dst = value > 65535 ? 65535 : value < 0 ? 0 : value; }
61+
static inline void Clamp(int value, const uint16_t*, byte *dst, const uint16_t shift) { value = value >> shift; *dst = value > 255 ? 255 : value < 0 ? 0 : value; }
62+
static inline void Clamp(int value, const byte*, uint16_t *dst, const uint16_t) { *dst = value < 0 ? 0 : value; }
63+
static inline void Clamp(int value, const byte*, byte *dst, const uint16_t) { *dst = value > 255 ? 255 : value < 0 ? 0 : value; }
6464

6565

6666
// Even row

packages/debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
libpsinc0 (0.1.42) unstable; urgency=medium
2+
3+
* Replace soon to be deprecated emg::Buffer<> with std::vector<>
4+
5+
-- Dan Parnham <dan@emergent-design.co.uk> Wed, 21 Dec 2022 11:51:14 +0000
6+
17
libpsinc0 (0.1.41) unstable; urgency=medium
28

39
* Patch the patch so that it compiles.

packages/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.41
1+
0.1.42

src/examples/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
for var in "$@"; do
44
if [ "$var" = "control-flash.cpp" ]; then
5-
clang++ -O3 -o ${var%.*} -std=c++14 $var -lserialport -lpthread
5+
clang++ -g -O3 -o ${var%.*} -std=c++17 $var -lserialport -lpthread
66
else
7-
clang++ -O3 -o ${var%.*} -std=c++14 $var -lpsinc -lfreeimage -lpthread
7+
clang++ -g -O3 -o ${var%.*} -std=c++17 $var -lpsinc -lfreeimage -lpthread
88
fi
99
done
1010

src/examples/capture-images.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
#include <psinc/Camera.h>
33
#include <psinc/handlers/ImageHandler.hpp>
44

5-
using namespace std;
6-
using namespace emg;
7-
using namespace psinc;
5+
// using namespace std;
6+
// using namespace emg;
7+
// using namespace psinc;
8+
using namespace std::chrono_literals;
9+
10+
using psinc::Camera;
11+
using psinc::ImageHandler;
12+
using emg::Image;
13+
using emg::byte;
14+
815

916
void CaptureMonoImage(Camera &camera, ImageHandler<byte> &handler)
1017
{
@@ -31,7 +38,10 @@ void CaptureMonoImage(Camera &camera, ImageHandler<byte> &handler)
3138
// Need to make sure we've finished grabbing before re-using the camera
3239
// or exiting the program (as the grab call is asynchronous and we're
3340
// calling it from a trivial single-thread application)
34-
while (camera.Grabbing()) this_thread::sleep_for(1ms);
41+
while (camera.Grabbing())
42+
{
43+
std::this_thread::sleep_for(1ms);
44+
}
3545

3646
}
3747

@@ -61,7 +71,10 @@ void CaptureColourImage(Camera &camera, ImageHandler<byte> &handler)
6171
// Need to make sure we've finished grabbing before re-using the camera
6272
// or exiting the program (as the grab call is asynchronous and we're
6373
// calling it from a trivial single-thread application)
64-
while (camera.Grabbing()) this_thread::sleep_for(1ms);
74+
while (camera.Grabbing())
75+
{
76+
std::this_thread::sleep_for(1ms);
77+
}
6578
}
6679

6780

@@ -90,7 +103,11 @@ void CaptureHdrMonoImage(Camera &camera, ImageHandler<uint16_t> &handler)
90103
// Need to make sure we've finished grabbing before re-using the camera
91104
// or exiting the program (as the grab call is asynchronous and we're
92105
// calling it from a trivial single-thread application)
93-
while (camera.Grabbing()) this_thread::sleep_for(1ms);
106+
while (camera.Grabbing())
107+
{
108+
std::this_thread::sleep_for(1ms);
109+
}
110+
94111
}
95112

96113

@@ -119,14 +136,17 @@ void CaptureHdrColourImage(Camera &camera, ImageHandler<uint16_t> &handler)
119136
// Need to make sure we've finished grabbing before re-using the camera
120137
// or exiting the program (as the grab call is asynchronous and we're
121138
// calling it from a trivial single-thread application)
122-
while (camera.Grabbing()) this_thread::sleep_for(1ms);
139+
while (camera.Grabbing())
140+
{
141+
std::this_thread::sleep_for(1ms);
142+
}
123143
}
124144

125145

126146
int main(int argc, char *argv[])
127147
{
128-
cout << "This test application connects to the first camera it finds" << endl;
129-
cout << "and captures various types of image" << endl;
148+
std::cout << "This test application connects to the first camera it finds\n";
149+
std::cout << "and captures various types of image\n";
130150

131151
Camera camera;
132152

@@ -144,7 +164,10 @@ int main(int argc, char *argv[])
144164
// thread like this - using the callback function as shown
145165
// in https://github.com/emergent-design/libpsinc/wiki#camera
146166
// is a better idea.
147-
while (!camera.Connected()) this_thread::sleep_for(1ms);
167+
while (!camera.Connected())
168+
{
169+
std::this_thread::sleep_for(1ms);
170+
}
148171

149172
//Use the camera and normal image handler for byte images
150173
CaptureMonoImage(camera, handler);

src/iconograph/canvas.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,18 @@ void Canvas::wheelEvent(QWheelEvent *event)
161161
this->offset = this->rect.topLeft();
162162
}
163163

164+
const auto position = event->position();
165+
164166
// Origin of zoom in image space
165-
double x = (event->x() - this->offset.x()) / this->zoom;
166-
double y = (event->y() - this->offset.y()) / this->zoom;
167+
const double x = (position.x() - this->offset.x()) / this->zoom;
168+
const double y = (position.y() - this->offset.y()) / this->zoom;
167169

168-
double step = event->delta() < 0 ? -0.05 : 0.05;
170+
// double step = event->delta() < 0 ? -0.05 : 0.05;
171+
double step = event->angleDelta().y() < 0 ? -0.05 : 0.05;
169172
this->zoom = std::max(this->minScale, std::min(1.0, this->zoom + step));
170173
this->offset = {
171-
(int)lrint(event->x() - this->zoom * x),
172-
(int)lrint(event->y() - this->zoom * y)
174+
(int)lrint(position.x() - this->zoom * x),
175+
(int)lrint(position.y() - this->zoom * y)
173176
};
174177
}
175178
}

src/iconograph/mainwindow.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ QImage *MainWindow::ConvertWindow()
138138
int jump = (width - rw) * 3;
139139
uint16_t *src = this->hdrImage + roi.top() * width * 3 + roi.left() * 3;
140140

141-
this->histogram.Resize(4096);
142-
this->histogram.Clear();
141+
this->histogram.fill(0);
143142

144143
for (y=0; y<rh; y++, src+=jump)
145144
{
@@ -323,7 +322,7 @@ template <typename T> std::array<int64_t, 7> GetRegionMeans(const emg::Image<T,
323322
auto sum = std::array<int64_t, 3>{ 0, 0, 0 };
324323
auto bayer = std::array<int64_t, 4> { 0, 0, 0, 0 };
325324
auto tally = std::array<int, 4> { 0, 0, 0, 0 };
326-
T *src = image + sy * width * 3 + sx * 3;
325+
auto *src = image + sy * width * 3 + sx * 3;
327326

328327
for (int y=0; y<roi.height(); y++, src+=jump)
329328
{

src/psinc-c/device.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ extern "C"
5252

5353
// Perhaps we need some sort of buffer view to handle this case without
5454
// unnecessary memory allocation and copying.
55-
Buffer<emg::byte> data(size);
55+
std::vector<emg::byte> data(size);
5656

5757
if (c->devices.count(device))
5858
{
5959
if (c->devices[device].Read(data))
6060
{
61-
used = data.Size();
62-
memcpy(buffer, data.Data(), used);
61+
used = data.size();
62+
memcpy(buffer, data.data(), used);
6363
return PSINC_OK;
6464
}
6565
else return PSINC_CAMERA_IO_ERROR;

0 commit comments

Comments
 (0)