Stefan Schuermans commited on 2018-08-14 19:32:50
Showing 1 changed files, with 23 additions and 11 deletions.
... | ... |
@@ -125,7 +125,9 @@ void EtherPix::displayFrame(stBlinkenFrame *pFrame) |
125 | 125 |
#ifdef BLINKER_CFG_ETHERPIX |
126 | 126 |
char data[65536]; |
127 | 127 |
bool haveData = false; |
128 |
+ etp_pixfmt_t pixfmt; |
|
128 | 129 |
stBlinkenFrame *pClonedFrame; |
130 |
+ int frameWidth, frameHeight, frameChannels, frameMaxval, channels; |
|
129 | 131 |
|
130 | 132 |
// leave if no display |
131 | 133 |
if (!m_pDisplay) |
... | ... |
@@ -136,38 +138,48 @@ void EtherPix::displayFrame(stBlinkenFrame *pFrame) |
136 | 138 |
|
137 | 139 |
// frame available |
138 | 140 |
if (pFrame) { |
139 |
- // format matches (size matches and 24bit RGB as required by EtherPix) |
|
140 |
- if (BlinkenFrameGetWidth(pFrame) == (int)m_size.m_width && |
|
141 |
- BlinkenFrameGetHeight(pFrame) == (int)m_size.m_height && |
|
142 |
- BlinkenFrameGetChannels(pFrame) == 3 && |
|
143 |
- BlinkenFrameGetMaxval(pFrame) == 255) { |
|
141 |
+ frameWidth = BlinkenFrameGetWidth(pFrame); |
|
142 |
+ frameHeight = BlinkenFrameGetHeight(pFrame); |
|
143 |
+ frameChannels = BlinkenFrameGetChannels(pFrame); |
|
144 |
+ frameMaxval = BlinkenFrameGetMaxval(pFrame); |
|
145 |
+ // format matches |
|
146 |
+ // (size matches and 24bit RGB or monochrome as required by EtherPix) |
|
147 |
+ if (frameWidth == (int)m_size.m_width && |
|
148 |
+ frameHeight == (int)m_size.m_height && |
|
149 |
+ (frameChannels == 1 || frameChannels == 3) && |
|
150 |
+ frameMaxval == 255) { |
|
144 | 151 |
// convert to MCUF packet |
145 | 152 |
haveData = BlinkenFrameToNetwork(pFrame, BlinkenProtoMcuf, |
146 | 153 |
data, sizeof(data)) >= 0; |
154 |
+ channels = frameChannels; |
|
147 | 155 |
} |
148 | 156 |
// format does not match |
149 | 157 |
else { |
150 | 158 |
// convert format: clone and resize |
151 | 159 |
pClonedFrame = BlinkenFrameClone(pFrame); |
152 | 160 |
if (pClonedFrame) { |
161 |
+ channels = frameChannels == 1 ? 1 : 3; |
|
153 | 162 |
BlinkenFrameResize(pClonedFrame, m_size.m_height, |
154 |
- m_size.m_width, 3, 255); |
|
163 |
+ m_size.m_width, channels, 255); |
|
155 | 164 |
// convert to MCUF packet |
156 | 165 |
haveData = BlinkenFrameToNetwork(pClonedFrame, BlinkenProtoMcuf, |
157 | 166 |
data, sizeof(data)) >= 0; |
158 |
- // free clones frame |
|
167 |
+ // free cloned frame |
|
159 | 168 |
BlinkenFrameFree(pClonedFrame); |
160 | 169 |
} |
161 | 170 |
} |
162 | 171 |
} |
163 | 172 |
|
164 | 173 |
// data available -> to EtherPix display |
165 |
- if (haveData) |
|
166 |
- etp_display_data(m_pDisplay, (etp_u8_t*)(data + 12), 3, m_size.m_width * 3, |
|
167 |
- 0, 0, m_size.m_width, m_size.m_height); |
|
174 |
+ if (haveData) { |
|
175 |
+ pixfmt = channels == 1 ? etp_pixfmt_mono8 : etp_pixfmt_rgb24; |
|
176 |
+ etp_display_data_fmt(m_pDisplay, (etp_u8_t*)(data + 12), |
|
177 |
+ channels, m_size.m_width * channels, |
|
178 |
+ 0, 0, m_size.m_width, m_size.m_height, pixfmt); |
|
168 | 179 |
// no data available -> clear EtherPix display |
169 |
- else |
|
180 |
+ } else { |
|
170 | 181 |
etp_display_data_clear(m_pDisplay); |
182 |
+ } |
|
171 | 183 |
|
172 | 184 |
// send configured frame |
173 | 185 |
sendFrame(); |
174 | 186 |