Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
107e5c47
Commit
107e5c47
authored
May 08, 2021
by
Rahix
Browse files
chore(display): Reimplement epic_disp_blit()
Reimplement `epic_disp_blit()` without relying on the gfx library.
parent
4d6d634e
Changes
1
Hide whitespace changes
Inline
Side-by-side
epicardium/drivers/display/api.c
View file @
107e5c47
...
...
@@ -2,17 +2,15 @@
#include "drivers/display/lcd.h"
#include "drivers/display/epic_ctx.h"
#include "display.h"
#include "Fonts/fonts.h"
#include "FreeRTOS.h"
#include "LCD_Driver.h"
#include "gfx.h"
#include "gpio.h"
#include "task.h"
#include "tmr.h"
#include "tmr_utils.h"
#include <machine/endian.h>
#include <string.h>
static
TaskHandle_t
lock
=
NULL
;
...
...
@@ -126,6 +124,39 @@ int epic_disp_pixel(int16_t x, int16_t y, uint16_t color)
return
0
;
}
static
uint16_t
rgb565_pixel_from_buf
(
uint8_t
*
img
,
enum
epic_rgb_format
format
,
int16_t
width
,
int16_t
x
,
int16_t
y
,
uint8_t
*
alpha
)
{
uint16_t
tmp16
;
uint8_t
rgba
[
4
];
switch
(
format
)
{
case
EPIC_RGB565
:
*
alpha
=
255
;
memcpy
(
&
tmp16
,
&
img
[
y
*
width
*
2
+
x
*
2
],
2
);
return
tmp16
;
case
EPIC_RGBA5551
:
memcpy
(
&
tmp16
,
&
img
[
y
*
width
*
2
+
x
*
2
],
2
);
*
alpha
=
(
tmp16
&
0x01
)
?
255
:
0
;
return
(
tmp16
&
0xFFC0
)
|
((
tmp16
&
0x3E
)
>>
1
);
case
EPIC_RGB8
:
*
alpha
=
255
;
memcpy
(
rgba
,
&
img
[
y
*
width
*
3
+
x
*
3
],
3
);
return
rgb888_to_rgb565
(
rgba
);
case
EPIC_RGBA8
:
memcpy
(
rgba
,
&
img
[
y
*
width
*
4
+
x
*
4
],
4
);
*
alpha
=
rgba
[
3
];
return
rgb888_to_rgb565
(
rgba
);
default:
return
0xFFFF
;
}
}
int
epic_disp_blit
(
int16_t
pos_x
,
int16_t
pos_y
,
...
...
@@ -139,69 +170,27 @@ int epic_disp_blit(
return
cl
;
}
int16_t
offset_x
=
(
pos_x
<
0
)
?
-
pos_x
:
0
;
int16_t
count_x
=
width
-
offset_x
;
int16_t
offset_y
=
(
pos_
y
<
0
)
?
-
pos_y
:
0
;
int16_t
count_y
=
height
-
offset_y
;
if
(
pos_x
+
width
>=
160
)
{
count_x
-=
(
pos_x
+
width
)
%
160
;
}
if
(
pos_y
+
height
>=
80
)
{
count_y
-=
(
pos_y
+
height
)
%
80
;
}
size_t
bpp
;
enum
gfx_encoding
encoding
;
for
(
int16_t
xsrc
=
0
;
xsrc
<
width
;
xsrc
+=
1
)
{
for
(
int16_t
ysrc
=
0
;
ysrc
<
height
;
ysrc
+=
1
)
{
int16_t
xscreen
=
pos_
x
+
xsrc
;
int16_t
yscreen
=
pos_y
+
ysrc
;
size_t
offset
=
yscreen
*
160
*
2
+
xscreen
*
2
;
if
(
xscreen
<
0
||
xscreen
>=
160
||
yscreen
<
0
||
yscreen
>=
80
)
{
continue
;
}
uint8_t
alpha
=
255
;
uint16_t
pixel
=
rgb565_pixel_from_buf
(
img
,
format
,
width
,
xsrc
,
ysrc
,
&
alpha
)
;
switch
(
format
)
{
case
EPIC_RGB565
:
bpp
=
2
;
encoding
=
GFX_RGB565
;
break
;
case
EPIC_RGBA5551
:
bpp
=
2
;
encoding
=
GFX_RGBA5551
;
break
;
case
EPIC_RGB8
:
bpp
=
3
;
encoding
=
GFX_RGB8
;
break
;
case
EPIC_RGBA8
:
bpp
=
4
;
encoding
=
GFX_RGBA8
;
break
;
default:
return
-
1
;
break
;
}
if
(
alpha
==
0
)
{
continue
;
}
if
(
offset_x
==
0
&&
offset_y
==
0
&&
count_x
==
width
&&
count_y
==
height
)
{
/* Copy full image. No cropping.*/
gfx_copy_region
(
&
display_screen
,
pos_x
,
pos_y
,
width
,
height
,
encoding
,
img
);
}
else
{
/* Copy cropped image line by line. */
int16_t
curr_y
;
for
(
curr_y
=
offset_y
;
curr_y
<
offset_y
+
count_y
;
curr_y
++
)
{
uint8_t
*
line
=
img
+
(
curr_y
*
width
+
offset_x
)
*
bpp
;
gfx_copy_region
(
&
display_screen
,
pos_x
+
offset_x
,
pos_y
+
curr_y
,
count_x
,
1
,
encoding
,
line
);
epicardium_ctx_fb
[
offset
]
=
(
pixel
&
0xFF00
)
>>
8
;
epicardium_ctx_fb
[
offset
+
1
]
=
pixel
&
0xFF
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment