FabGL
ESP32 Display Controller and Graphics Library
cvbspalettedcontroller.h
Go to the documentation of this file.
1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2022 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27#pragma once
28
29
30
38#include <stdint.h>
39#include <stddef.h>
40#include <atomic>
41
42#include "freertos/FreeRTOS.h"
43#include "freertos/queue.h"
44
45#include "fabglconf.h"
46#include "fabutils.h"
47#include "displaycontroller.h"
49
50
51
52
53namespace fabgl {
54
55
56
57
58class CVBSPalettedController : public CVBSBaseController {
59
60public:
61
62 CVBSPalettedController(int columnsQuantum, NativePixelFormat nativePixelFormat, int viewPortRatioDiv, int viewPortRatioMul);
63 ~CVBSPalettedController();
64
65 // unwanted methods
66 CVBSPalettedController(CVBSPalettedController const&) = delete;
67 void operator=(CVBSPalettedController const&) = delete;
68
69 void end();
70
71 // abstract method of BitmappedDisplayController
72 void suspendBackgroundPrimitiveExecution();
73
74 // import "modeline" version of setResolution
75 using CVBSBaseController::setResolution;
76
77 void setResolution(CVBSParams const * params, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
78
79 int getPaletteSize();
80
81 virtual int colorsCount() { return getPaletteSize(); }
82
83 void setProcessPrimitivesOnBlank(bool value) { m_processPrimitivesOnBlank = value; }
84
85 // returns "static" version of m_viewPort
86 static uint8_t * sgetScanline(int y) { return (uint8_t*) s_viewPort[y]; }
87
88 // abstract method of BitmappedDisplayController
89 NativePixelFormat nativePixelFormat() { return m_nativePixelFormat; }
90
91
92protected:
93
94 void init();
95
96 virtual void setupDefaultPalette() = 0;
97
98 void updateRGB2PaletteLUT();
99 void calculateAvailableCyclesForDrawings();
100 static void primitiveExecTask(void * arg);
101
102 uint8_t RGB888toPaletteIndex(RGB888 const & rgb) {
103 return m_packedRGB222_to_PaletteIndex[RGB888toPackedRGB222(rgb)];
104 }
105
106 uint8_t RGB2222toPaletteIndex(uint8_t value) {
107 return m_packedRGB222_to_PaletteIndex[value & 0b00111111];
108 }
109
110 uint8_t RGB8888toPaletteIndex(RGBA8888 value) {
111 return RGB888toPaletteIndex(RGB888(value.R, value.G, value.B));
112 }
113
114 // abstract method of BitmappedDisplayController
115 void swapBuffers();
116
117
118 TaskHandle_t m_primitiveExecTask;
119
120 // optimization: clones of m_viewPort and m_viewPortVisible
121 static volatile uint8_t * * s_viewPort;
122 static volatile uint8_t * * s_viewPortVisible;
123
124 RGB222 * m_palette;
125
126
127protected:
128
129 void allocateViewPort();
130 void freeViewPort();
131 void checkViewPortSize();
132
133 // Maximum time (in CPU cycles) available for primitives drawing
134 volatile uint32_t m_primitiveExecTimeoutCycles;
135
136 volatile bool m_taskProcessingPrimitives;
137
138 // true = allowed time to process primitives is limited to the vertical blank. Slow, but avoid flickering
139 // false = allowed time is the half of an entire frame. Fast, but may flick
140 bool m_processPrimitivesOnBlank;
141
142 uint8_t m_packedRGB222_to_PaletteIndex[64];
143
144 // configuration
145 int m_columnsQuantum; // viewport width must be divisble by m_columnsQuantum
146 NativePixelFormat m_nativePixelFormat;
147 int m_viewPortRatioDiv;
148 int m_viewPortRatioMul;
149
150};
151
152
153
154} // end of namespace
155
156
157
158
159
160
161
162
This file contains fabgl::CVBSBaseController definition.
This file contains fabgl::BitmappedDisplayController definition.
This file contains FabGL library configuration settings, like number of supported colors,...
This file contains some utility classes and functions.
NativePixelFormat
This enum defines the display controller native pixel format.