CVB++ 15.0
detail_wrapped_image.hpp
1#pragma once
2
3#pragma once
4
5#include "../_decl/decl_wrapped_image.hpp"
6#include "../_decl/decl_image_plane.hpp"
7#include "../plane.hpp"
8#include "../_decl/decl_vpat.hpp"
9
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
15 inline std::unique_ptr<WrappedImage> WrappedImage::FromArray(const IArray &array)
16 {
17 if (typeid(array) == typeid(Cvb::Plane))
18 {
19 const auto &plane = dynamic_cast<const Cvb::Plane &>(array);
20 if (plane.Rank() != 2)
21 throw std::runtime_error("currently only two dimensional planes can be wrapped by an image");
22
23 auto basePtr = plane.BasePtr();
24 auto xInc = plane.Increment(0);
25 auto yInc = plane.Increment(1);
26 auto dataType = plane.DataType();
27 auto width = plane.Length(0);
28 auto height = plane.Length(1);
29 auto bufferSize = width * height * dataType.BytesPerPixel();
30
31 return FromGreyPixels(reinterpret_cast<void *>(basePtr), bufferSize, width, height, dataType,
32 static_cast<int>(xInc), static_cast<int>(yInc));
33 }
34 else // Image plane
35 {
36 const auto &imagePlane = dynamic_cast<const ImagePlane &>(array);
37 const auto &image = imagePlane.Parent();
38 auto linearAccess = imagePlane.LinearAccess();
39 auto dataType = imagePlane.DataType();
40 auto width = image.Width();
41 auto height = image.Width();
42 auto bufferSize = width * height * dataType.BytesPerPixel();
43
44 return FromGreyPixels(reinterpret_cast<void *>(linearAccess.BasePtr()), bufferSize, width, height, dataType,
45 static_cast<int>(linearAccess.XInc()), static_cast<int>(linearAccess.YInc()));
46 }
47 }
48
49 CVB_END_INLINE_NS
50
51} // namespace Cvb
Array interface.
Definition iarray.hpp:16
static std::unique_ptr< WrappedImage > FromGreyPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride)
Wraps, without copying, the given monochrome pixel buffer in an image.
Definition decl_wrapped_image.hpp:46
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17