You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/embed/lib/gl_bitblt_rgb565.c

137 lines
4.1 KiB

/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gl_bitblt.h"
#if USE_DMA2D
#include "dma2d_bitblt.h"
#endif
void gl_rgb565_fill(const gl_bitblt_t* bb) {
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
if (!dma2d_rgb565_fill(bb))
#endif
{
uint16_t* dst_ptr = (uint16_t*)bb->dst_row + bb->dst_x;
uint16_t height = bb->height;
if (bb->src_alpha == 255) {
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
dst_ptr[x] = bb->src_fg;
}
dst_ptr += bb->dst_stride / sizeof(*dst_ptr);
}
} else {
uint8_t alpha = bb->src_alpha;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
dst_ptr[x] = gl_color16_blend_a8(bb->src_fg, dst_ptr[x], alpha);
}
dst_ptr += bb->dst_stride / sizeof(*dst_ptr);
}
}
}
}
void gl_rgb565_copy_mono1p(const gl_bitblt_t* bb) {
uint16_t* dst_ptr = (uint16_t*)bb->dst_row + bb->dst_x;
uint8_t* src = (uint8_t*)bb->src_row;
uint16_t src_ofs = bb->src_stride * bb->src_y + bb->src_x;
uint16_t height = bb->height;
uint16_t fg = gl_color_to_color16(bb->src_fg);
uint16_t bg = gl_color_to_color16(bb->src_bg);
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
uint8_t mask = 1 << (7 - ((src_ofs + x) & 7));
uint8_t data = src[(src_ofs + x) / 8];
dst_ptr[x] = (data & mask) ? fg : bg;
}
dst_ptr += bb->dst_stride / sizeof(*dst_ptr);
src_ofs += bb->src_stride;
}
}
void gl_rgb565_copy_mono4(const gl_bitblt_t* bb) {
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
if (!dma2d_rgb565_copy_mono4(bb))
#endif
{
const gl_color16_t* gradient =
gl_color16_gradient_a4(bb->src_fg, bb->src_bg);
uint16_t* dst_ptr = (uint16_t*)bb->dst_row + bb->dst_x;
uint8_t* src_row = (uint8_t*)bb->src_row;
uint16_t height = bb->height;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
uint8_t fg_data = src_row[(x + bb->src_x) / 2];
uint8_t fg_lum = (x + bb->src_x) & 1 ? fg_data >> 4 : fg_data & 0xF;
dst_ptr[x] = gradient[fg_lum];
}
dst_ptr += bb->dst_stride / sizeof(*dst_ptr);
src_row += bb->src_stride / sizeof(*src_row);
}
}
}
void gl_rgb565_copy_rgb565(const gl_bitblt_t* bb) {
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
if (!dma2d_rgb565_copy_rgb565(bb))
#endif
{
uint16_t* dst_ptr = (uint16_t*)bb->dst_row + bb->dst_x;
uint16_t* src_ptr = (uint16_t*)bb->src_row + bb->src_x;
uint16_t height = bb->height;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
dst_ptr[x] = src_ptr[x];
}
dst_ptr += bb->dst_stride / sizeof(*dst_ptr);
src_ptr += bb->src_stride / sizeof(*src_ptr);
}
}
}
void gl_rgb565_blend_mono4(const gl_bitblt_t* bb) {
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
if (!dma2d_rgb565_blend_mono4(bb))
#endif
{
uint16_t* dst_ptr = (uint16_t*)bb->dst_row + bb->dst_x;
uint8_t* src_row = (uint8_t*)bb->src_row;
uint16_t height = bb->height;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
uint8_t fg_data = src_row[(x + bb->src_x) / 2];
uint8_t fg_alpha = (x + bb->src_x) & 1 ? fg_data >> 4 : fg_data & 0x0F;
dst_ptr[x] = gl_color16_blend_a4(
bb->src_fg, gl_color16_to_color(dst_ptr[x]), fg_alpha);
}
dst_ptr += bb->dst_stride / sizeof(*dst_ptr);
src_row += bb->src_stride / sizeof(*src_row);
}
}
}