1 #include <map>
3 #include "mappedbuffer.h"
5 using namespace std;
7 namespace kms {
9 struct FormatPlaneInfo
10 {
11 uint8_t bitspp; /* bits per (macro) pixel */
12 uint8_t xsub;
13 uint8_t ysub;
14 };
16 struct FormatInfo
17 {
18 uint8_t num_planes;
19 struct FormatPlaneInfo planes[4];
20 };
22 static const map<PixelFormat, FormatInfo> format_info_array = {
23 /* YUV packed */
24 { PixelFormat::UYVY, { 1, { { 32, 2, 1 } }, } },
25 { PixelFormat::YUYV, { 1, { { 32, 2, 1 } }, } },
26 { PixelFormat::YVYU, { 1, { { 32, 2, 1 } }, } },
27 { PixelFormat::VYUY, { 1, { { 32, 2, 1 } }, } },
28 /* YUV semi-planar */
29 { PixelFormat::NV12, { 2, { { 8, 1, 1, }, { 16, 2, 2 } }, } },
30 { PixelFormat::NV21, { 2, { { 8, 1, 1, }, { 16, 2, 2 } }, } },
31 /* RGB16 */
32 { PixelFormat::RGB565, { 1, { { 16, 1, 1 } }, } },
33 /* RGB32 */
34 { PixelFormat::XRGB8888, { 1, { { 32, 1, 1 } }, } },
35 { PixelFormat::XBGR8888, { 1, { { 32, 1, 1 } }, } },
36 { PixelFormat::ARGB8888, { 1, { { 32, 1, 1 } }, } },
37 { PixelFormat::ABGR8888, { 1, { { 32, 1, 1 } }, } },
38 };
40 MappedCPUBuffer::MappedCPUBuffer(uint32_t width, uint32_t height, PixelFormat format)
41 : m_width(width), m_height(height), m_format(format)
42 {
43 const FormatInfo& format_info = format_info_array.at(m_format);
45 m_num_planes = format_info.num_planes;
47 for (unsigned i = 0; i < format_info.num_planes; ++i) {
48 const FormatPlaneInfo& pi = format_info.planes[i];
49 FramebufferPlane& plane = m_planes[i];
51 plane.stride = width * pi.bitspp / 8 / pi.xsub;
52 plane.size = plane.stride * height/ pi.ysub;
53 plane.offset = 0;
54 plane.map = new uint8_t[plane.size];
55 }
56 }
58 MappedCPUBuffer::~MappedCPUBuffer()
59 {
60 for (unsigned i = 0; i < m_num_planes; ++i) {
61 FramebufferPlane& plane = m_planes[i];
63 delete plane.map;
64 }
65 }
67 }