2011-03-08 17:11:56 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Dave Chapman
|
|
|
|
*
|
|
|
|
* Rockbox driver for 16-bit colour LCDs
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/* to be #included by lcd-16bit*.c */
|
|
|
|
|
|
|
|
#if !defined(ROW_INC) || !defined(COL_INC)
|
|
|
|
#error ROW_INC or COL_INC not defined
|
|
|
|
#endif
|
|
|
|
|
2012-03-20 21:39:48 +00:00
|
|
|
/* Clear the current viewport */
|
|
|
|
void lcd_clear_viewport(void)
|
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
struct viewport *vp = lcd_current_viewport;
|
2012-03-20 21:39:48 +00:00
|
|
|
fb_data *dst, *dst_end;
|
|
|
|
int x, y, width, height;
|
|
|
|
int len, step;
|
|
|
|
|
2022-10-01 23:54:11 +00:00
|
|
|
x = vp->x;
|
|
|
|
y = vp->y;
|
|
|
|
width = vp->width;
|
|
|
|
height = vp->height;
|
2012-03-20 21:39:48 +00:00
|
|
|
|
|
|
|
len = STRIDE_MAIN(width, height);
|
|
|
|
step = STRIDE_MAIN(ROW_INC, COL_INC);
|
|
|
|
|
|
|
|
dst = FBADDR(x, y);
|
|
|
|
dst_end = FBADDR(x + width - 1 , y + height - 1);
|
|
|
|
|
2022-10-01 23:54:11 +00:00
|
|
|
if (vp->drawmode & DRMODE_INVERSEVID)
|
2012-03-20 21:39:48 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
memset16(dst, vp->fg_pattern, len);
|
2012-03-20 21:39:48 +00:00
|
|
|
dst += step;
|
|
|
|
}
|
2012-05-19 10:02:24 +00:00
|
|
|
while (dst <= dst_end);
|
2012-03-20 21:39:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
if (lcd_backdrop && vp->buffer == &lcd_framebuffer_default)
|
2012-03-20 21:39:48 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2020-10-31 04:18:57 +00:00
|
|
|
memcpy(dst, PTR_ADD(dst, lcd_backdrop_offset),
|
|
|
|
len * sizeof(fb_data));
|
2012-03-20 21:39:48 +00:00
|
|
|
dst += step;
|
|
|
|
}
|
2012-05-19 10:02:24 +00:00
|
|
|
while (dst <= dst_end);
|
2012-03-20 21:39:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
memset16(dst, vp->bg_pattern, len);
|
2012-03-20 21:39:48 +00:00
|
|
|
dst += step;
|
|
|
|
}
|
2012-05-19 10:02:24 +00:00
|
|
|
while (dst <= dst_end);
|
2012-03-20 21:39:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-01 23:54:11 +00:00
|
|
|
if (vp == &default_vp)
|
2013-04-03 14:33:23 +00:00
|
|
|
lcd_scroll_stop();
|
2012-03-20 21:39:48 +00:00
|
|
|
else
|
2022-10-01 23:54:11 +00:00
|
|
|
lcd_scroll_stop_viewport(vp);
|
2020-10-07 06:01:35 +00:00
|
|
|
|
2022-10-01 23:54:11 +00:00
|
|
|
vp->flags &= ~(VP_FLAG_VP_SET_CLEAN);
|
2012-03-20 21:39:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 22:19:17 +00:00
|
|
|
/*** low-level drawing functions ***/
|
|
|
|
|
|
|
|
static void ICODE_ATTR setpixel(fb_data *address)
|
|
|
|
{
|
2020-10-07 06:01:35 +00:00
|
|
|
*address = lcd_current_viewport->fg_pattern;
|
2011-12-03 22:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ICODE_ATTR clearpixel(fb_data *address)
|
|
|
|
{
|
2020-10-07 06:01:35 +00:00
|
|
|
*address = lcd_current_viewport->bg_pattern;
|
2011-12-03 22:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ICODE_ATTR clearimgpixel(fb_data *address)
|
|
|
|
{
|
2017-01-15 23:10:38 +00:00
|
|
|
*address = *PTR_ADD(address, lcd_backdrop_offset);
|
2011-12-03 22:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ICODE_ATTR flippixel(fb_data *address)
|
|
|
|
{
|
|
|
|
*address = ~(*address);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ICODE_ATTR nopixel(fb_data *address)
|
|
|
|
{
|
|
|
|
(void)address;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd_fastpixelfunc_type* const lcd_fastpixelfuncs_bgcolor[8] = {
|
|
|
|
flippixel, nopixel, setpixel, setpixel,
|
|
|
|
nopixel, clearpixel, nopixel, clearpixel
|
|
|
|
};
|
|
|
|
|
|
|
|
lcd_fastpixelfunc_type* const lcd_fastpixelfuncs_backdrop[8] = {
|
|
|
|
flippixel, nopixel, setpixel, setpixel,
|
|
|
|
nopixel, clearimgpixel, nopixel, clearimgpixel
|
|
|
|
};
|
|
|
|
|
|
|
|
lcd_fastpixelfunc_type* const * lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
|
|
|
|
|
2012-03-20 22:04:05 +00:00
|
|
|
/* Fill a rectangular area */
|
|
|
|
void lcd_fillrect(int x, int y, int width, int height)
|
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
struct viewport *vp = lcd_current_viewport;
|
2012-03-20 22:04:05 +00:00
|
|
|
unsigned bits = 0;
|
|
|
|
enum fill_opt fillopt = OPT_NONE;
|
|
|
|
fb_data *dst, *dst_end;
|
|
|
|
int len, step;
|
|
|
|
|
2022-10-01 23:54:31 +00:00
|
|
|
if (!clip_viewport_rect(vp, &x, &y, &width, &height, NULL, NULL))
|
2012-03-20 22:04:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* drawmode and optimisation */
|
2022-10-01 23:54:11 +00:00
|
|
|
if (vp->drawmode & DRMODE_INVERSEVID)
|
2012-03-20 22:04:05 +00:00
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
if (vp->drawmode & DRMODE_BG)
|
2012-03-20 22:04:05 +00:00
|
|
|
{
|
|
|
|
if (!lcd_backdrop)
|
|
|
|
{
|
|
|
|
fillopt = OPT_SET;
|
2022-10-01 23:54:11 +00:00
|
|
|
bits = vp->bg_pattern;
|
2012-03-20 22:04:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
fillopt = OPT_COPY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
if (vp->drawmode & DRMODE_FG)
|
2012-03-20 22:04:05 +00:00
|
|
|
{
|
|
|
|
fillopt = OPT_SET;
|
2022-10-01 23:54:11 +00:00
|
|
|
bits = vp->fg_pattern;
|
2012-03-20 22:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-01 23:54:11 +00:00
|
|
|
if (fillopt == OPT_NONE && vp->drawmode != DRMODE_COMPLEMENT)
|
2012-03-20 22:04:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
dst = FBADDR(x, y);
|
|
|
|
dst_end = FBADDR(x + width - 1, y + height - 1);
|
|
|
|
|
|
|
|
len = STRIDE_MAIN(width, height);
|
|
|
|
step = STRIDE_MAIN(ROW_INC, COL_INC);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
switch (fillopt)
|
|
|
|
{
|
|
|
|
case OPT_SET:
|
|
|
|
memset16(dst, bits, len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_COPY:
|
2017-01-15 23:10:38 +00:00
|
|
|
memcpy(dst, PTR_ADD(dst, lcd_backdrop_offset),
|
2012-03-20 22:04:05 +00:00
|
|
|
len * sizeof(fb_data));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_NONE: /* DRMODE_COMPLEMENT */
|
|
|
|
{
|
|
|
|
fb_data *start = dst;
|
|
|
|
fb_data *end = start + len;
|
|
|
|
do
|
|
|
|
*start = ~(*start);
|
|
|
|
while (++start < end);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += step;
|
|
|
|
}
|
2012-05-19 10:02:24 +00:00
|
|
|
while (dst <= dst_end);
|
2012-03-20 22:04:05 +00:00
|
|
|
}
|
2011-12-03 22:19:17 +00:00
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
/* About Rockbox' internal monochrome bitmap format:
|
|
|
|
*
|
|
|
|
* A bitmap contains one bit for every pixel that defines if that pixel is
|
|
|
|
* black (1) or white (0). Bits within a byte are arranged vertically, LSB
|
|
|
|
* at top.
|
|
|
|
* The bytes are stored in row-major order, with byte 0 being top left,
|
|
|
|
* byte 1 2nd from left etc. The first row of bytes defines pixel rows
|
|
|
|
* 0..7, the second row defines pixel row 8..15 etc.
|
|
|
|
*
|
|
|
|
* This is the mono bitmap format used on all other targets so far; the
|
|
|
|
* pixel packing doesn't really matter on a 8bit+ target. */
|
|
|
|
|
|
|
|
/* Draw a partial monochrome bitmap */
|
|
|
|
|
|
|
|
void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|
|
|
int src_y, int stride, int x, int y,
|
|
|
|
int width, int height)
|
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
struct viewport *vp = lcd_current_viewport;
|
2022-10-01 23:54:31 +00:00
|
|
|
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
2011-03-08 17:11:56 +00:00
|
|
|
return;
|
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
/* move starting point */
|
|
|
|
src += stride * (src_y >> 3) + src_x;
|
|
|
|
src_y &= 7;
|
|
|
|
|
|
|
|
unsigned dmask = 0;
|
2022-10-01 23:54:11 +00:00
|
|
|
int drmode = vp->drawmode;
|
2011-12-03 22:19:17 +00:00
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
if (drmode & DRMODE_INVERSEVID)
|
|
|
|
{
|
2021-11-21 18:07:13 +00:00
|
|
|
dmask = 0xff;
|
2011-03-08 17:11:56 +00:00
|
|
|
drmode &= DRMODE_SOLID; /* mask out inversevid */
|
|
|
|
}
|
|
|
|
|
2013-02-08 22:33:54 +00:00
|
|
|
/* Use extra bit to avoid if () in the switch-cases below */
|
|
|
|
if ((drmode & DRMODE_BG) && lcd_backdrop)
|
2013-12-28 13:27:18 +00:00
|
|
|
drmode |= DRMODE_INT_BD;
|
2013-02-08 22:33:54 +00:00
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
fb_data* dst = FBADDR(x, y);
|
|
|
|
while(height > 0)
|
2011-03-08 17:11:56 +00:00
|
|
|
{
|
2021-11-21 18:07:13 +00:00
|
|
|
const unsigned char* src_col = src;
|
|
|
|
const unsigned char* src_end = src + width;
|
|
|
|
fb_data* dst_col = dst;
|
|
|
|
|
|
|
|
unsigned data;
|
2011-03-08 17:11:56 +00:00
|
|
|
int fg, bg;
|
2013-02-08 22:33:54 +00:00
|
|
|
uintptr_t bo;
|
2011-03-08 17:11:56 +00:00
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
switch (drmode) {
|
|
|
|
case DRMODE_COMPLEMENT:
|
|
|
|
do {
|
|
|
|
data = (*src_col++ ^ dmask) >> src_y;
|
|
|
|
if(data & 0x01)
|
|
|
|
*dst_col = ~(*dst_col);
|
2011-03-08 17:11:56 +00:00
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
dst_col += COL_INC;
|
|
|
|
} while(src_col != src_end);
|
2011-03-08 17:11:56 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
case DRMODE_BG|DRMODE_INT_BD:
|
2013-02-08 22:33:54 +00:00
|
|
|
bo = lcd_backdrop_offset;
|
2021-11-21 18:07:13 +00:00
|
|
|
do {
|
|
|
|
data = (*src_col++ ^ dmask) >> src_y;
|
|
|
|
if(!(data & 0x01))
|
|
|
|
*dst_col = *PTR_ADD(dst_col, bo);
|
2011-03-08 17:11:56 +00:00
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
dst_col += COL_INC;
|
|
|
|
} while(src_col != src_end);
|
2013-02-08 22:33:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRMODE_BG:
|
2022-10-01 23:54:11 +00:00
|
|
|
bg = vp->bg_pattern;
|
2021-11-21 18:07:13 +00:00
|
|
|
do {
|
|
|
|
data = (*src_col++ ^ dmask) >> src_y;
|
|
|
|
if(!(data & 0x01))
|
|
|
|
*dst_col = bg;
|
2011-03-08 17:11:56 +00:00
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
dst_col += COL_INC;
|
|
|
|
} while(src_col != src_end);
|
2011-03-08 17:11:56 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
case DRMODE_FG:
|
2022-10-01 23:54:11 +00:00
|
|
|
fg = vp->fg_pattern;
|
2021-11-21 18:07:13 +00:00
|
|
|
do {
|
|
|
|
data = (*src_col++ ^ dmask) >> src_y;
|
|
|
|
if(data & 0x01)
|
|
|
|
*dst_col = fg;
|
2011-03-08 17:11:56 +00:00
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
dst_col += COL_INC;
|
|
|
|
} while(src_col != src_end);
|
2011-03-08 17:11:56 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
case DRMODE_SOLID|DRMODE_INT_BD:
|
2022-10-01 23:54:11 +00:00
|
|
|
fg = vp->fg_pattern;
|
2013-02-08 22:33:54 +00:00
|
|
|
bo = lcd_backdrop_offset;
|
2021-11-21 18:07:13 +00:00
|
|
|
do {
|
|
|
|
data = (*src_col++ ^ dmask) >> src_y;
|
|
|
|
if(data & 0x01)
|
|
|
|
*dst_col = fg;
|
|
|
|
else
|
|
|
|
*dst_col = *PTR_ADD(dst_col, bo);
|
|
|
|
|
|
|
|
dst_col += COL_INC;
|
|
|
|
} while(src_col != src_end);
|
2013-02-08 22:33:54 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-21 18:07:13 +00:00
|
|
|
case DRMODE_SOLID:
|
2022-10-01 23:54:11 +00:00
|
|
|
fg = vp->fg_pattern;
|
|
|
|
bg = vp->bg_pattern;
|
2021-11-21 18:07:13 +00:00
|
|
|
do {
|
|
|
|
data = (*src_col++ ^ dmask) >> src_y;
|
|
|
|
if(data & 0x01)
|
|
|
|
*dst_col = fg;
|
|
|
|
else
|
|
|
|
*dst_col = bg;
|
|
|
|
|
|
|
|
dst_col += COL_INC;
|
|
|
|
} while(src_col != src_end);
|
2011-03-08 17:11:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-11-21 18:07:13 +00:00
|
|
|
|
|
|
|
src_y = (src_y + 1) & 7;
|
|
|
|
if(src_y == 0)
|
|
|
|
src += stride;
|
|
|
|
|
|
|
|
dst += ROW_INC;
|
|
|
|
height--;
|
2011-03-08 17:11:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-21 18:07:13 +00:00
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
/* Draw a full monochrome bitmap */
|
|
|
|
void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width, int height)
|
|
|
|
{
|
2021-08-26 02:18:14 +00:00
|
|
|
lcd_mono_bitmap_part(src, 0, 0, width, x, y, width, height);
|
2011-03-08 17:11:56 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 19:05:11 +00:00
|
|
|
|
2023-01-03 21:51:52 +00:00
|
|
|
/* About Rockbox' internal alpha channel format (for ALPHA_BPP == 4)
|
2011-11-11 19:05:11 +00:00
|
|
|
*
|
2013-02-12 09:26:44 +00:00
|
|
|
* For each pixel, 4bit of alpha information is stored in a byte-stream,
|
2011-11-11 19:05:11 +00:00
|
|
|
* so two pixels are packed into one byte.
|
|
|
|
* The lower nibble is the first pixel, the upper one the second. The stride is
|
|
|
|
* horizontal. E.g row0: pixel0: byte0[0:3], pixel1: byte0[4:7], pixel2: byte1[0:3],...
|
2012-01-22 21:45:10 +00:00
|
|
|
* The format is independant of the internal display orientation and color
|
|
|
|
* representation, as to support the same font files on all displays.
|
2013-02-12 09:26:44 +00:00
|
|
|
* The values go linear from 0 (fully opaque) to 15 (fully transparent)
|
|
|
|
* (note how this is the opposite of the alpha channel in the ARGB format).
|
2011-11-11 19:05:11 +00:00
|
|
|
*
|
|
|
|
* This might suggest that rows need to have an even number of pixels.
|
|
|
|
* However this is generally not the case. lcd_alpha_bitmap_part_mix() can deal
|
|
|
|
* with uneven colums (i.e. two rows can share one byte). And font files do
|
|
|
|
* exploit this.
|
|
|
|
* However, this is difficult to do for image files, especially bottom-up bitmaps,
|
|
|
|
* so lcd_bmp() do expect even rows.
|
|
|
|
*/
|
|
|
|
|
2023-01-03 21:51:52 +00:00
|
|
|
#define ALPHA_BPP 4
|
|
|
|
#define ALPHA_MASK ((1 << ALPHA_BPP) - 1)
|
|
|
|
#define ALPHA_PIXELS_PER_BYTE (CHAR_BIT / ALPHA_BPP)
|
|
|
|
|
|
|
|
#define ALPHA_WORD_T uint32_t
|
|
|
|
#define ALPHA_WORD_LOAD load_le32
|
|
|
|
#define ALPHA_WORDSIZE sizeof(ALPHA_WORD_T)
|
|
|
|
#define ALPHA_PIXELS_PER_WORD (ALPHA_WORDSIZE * CHAR_BIT / ALPHA_BPP)
|
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
#ifdef CPU_ARM
|
|
|
|
#define BLEND_INIT do {} while (0)
|
2012-01-05 23:00:14 +00:00
|
|
|
#define BLEND_FINISH do {} while(0)
|
2011-03-08 17:11:56 +00:00
|
|
|
#define BLEND_START(acc, color, alpha) \
|
|
|
|
asm volatile("mul %0, %1, %2" : "=&r" (acc) : "r" (color), "r" (alpha))
|
|
|
|
#define BLEND_CONT(acc, color, alpha) \
|
|
|
|
asm volatile("mla %0, %1, %2, %0" : "+&r" (acc) : "r" (color), "r" (alpha))
|
|
|
|
#define BLEND_OUT(acc) do {} while (0)
|
2023-01-03 21:51:52 +00:00
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
#elif defined(CPU_COLDFIRE)
|
|
|
|
#define ALPHA_BITMAP_READ_WORDS
|
2012-01-05 23:00:14 +00:00
|
|
|
#define BLEND_INIT \
|
|
|
|
unsigned long _macsr = coldfire_get_macsr(); \
|
|
|
|
coldfire_set_macsr(EMAC_UNSIGNED)
|
|
|
|
#define BLEND_FINISH \
|
|
|
|
coldfire_set_macsr(_macsr)
|
2011-03-08 17:11:56 +00:00
|
|
|
#define BLEND_START(acc, color, alpha) \
|
|
|
|
asm volatile("mac.l %0, %1, %%acc0" :: "%d" (color), "d" (alpha))
|
|
|
|
#define BLEND_CONT BLEND_START
|
|
|
|
#define BLEND_OUT(acc) asm volatile("movclr.l %%acc0, %0" : "=d" (acc))
|
2023-01-03 21:51:52 +00:00
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
#else
|
|
|
|
#define BLEND_INIT do {} while (0)
|
2012-01-05 23:00:14 +00:00
|
|
|
#define BLEND_FINISH do {} while(0)
|
2011-03-08 17:11:56 +00:00
|
|
|
#define BLEND_START(acc, color, alpha) ((acc) = (color) * (alpha))
|
|
|
|
#define BLEND_CONT(acc, color, alpha) ((acc) += (color) * (alpha))
|
|
|
|
#define BLEND_OUT(acc) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Blend the given two colors */
|
|
|
|
static inline unsigned blend_two_colors(unsigned c1, unsigned c2, unsigned a)
|
|
|
|
{
|
2023-01-03 21:51:52 +00:00
|
|
|
a += a >> (ALPHA_BPP - 1);
|
2011-03-08 17:11:56 +00:00
|
|
|
#if (LCD_PIXELFORMAT == RGB565SWAPPED)
|
|
|
|
c1 = swap16(c1);
|
|
|
|
c2 = swap16(c2);
|
|
|
|
#endif
|
|
|
|
unsigned c1l = (c1 | (c1 << 16)) & 0x07e0f81f;
|
|
|
|
unsigned c2l = (c2 | (c2 << 16)) & 0x07e0f81f;
|
|
|
|
unsigned p;
|
|
|
|
BLEND_START(p, c1l, a);
|
2023-01-03 21:51:52 +00:00
|
|
|
BLEND_CONT(p, c2l, ALPHA_MASK + 1 - a);
|
2011-03-08 17:11:56 +00:00
|
|
|
BLEND_OUT(p);
|
2023-01-03 21:51:52 +00:00
|
|
|
p = (p >> ALPHA_BPP) & 0x07e0f81f;
|
2011-03-08 17:11:56 +00:00
|
|
|
p |= (p >> 16);
|
|
|
|
#if (LCD_PIXELFORMAT == RGB565SWAPPED)
|
|
|
|
return swap16(p);
|
|
|
|
#else
|
|
|
|
return p;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-01-03 21:51:52 +00:00
|
|
|
static void ICODE_ATTR lcd_alpha_bitmap_part_mix(
|
|
|
|
const fb_data* image, const unsigned char *alpha,
|
|
|
|
int src_x, int src_y,
|
|
|
|
int x, int y, int width, int height,
|
|
|
|
int stride_image, int stride_alpha)
|
2011-03-08 17:11:56 +00:00
|
|
|
{
|
2022-10-01 23:54:11 +00:00
|
|
|
struct viewport *vp = lcd_current_viewport;
|
2023-01-03 21:51:52 +00:00
|
|
|
unsigned int dmask = 0;
|
2022-10-01 23:54:11 +00:00
|
|
|
int drmode = vp->drawmode;
|
2023-01-03 21:51:52 +00:00
|
|
|
fb_data *dst;
|
|
|
|
#ifdef ALPHA_BITMAP_READ_WORDS
|
|
|
|
ALPHA_WORD_T alpha_data, *alpha_word;
|
|
|
|
size_t alpha_offset = 0, alpha_pixels;
|
|
|
|
#else
|
|
|
|
unsigned char alpha_data;
|
|
|
|
size_t alpha_pixels;
|
|
|
|
#endif
|
2022-09-26 07:37:00 +00:00
|
|
|
|
2022-10-01 23:54:31 +00:00
|
|
|
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
2011-03-08 17:11:56 +00:00
|
|
|
return;
|
2022-09-26 07:37:00 +00:00
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
if (drmode & DRMODE_INVERSEVID)
|
|
|
|
{
|
2023-01-03 21:51:52 +00:00
|
|
|
dmask = 0xFFFFFFFFu;
|
|
|
|
drmode &= ~DRMODE_INVERSEVID;
|
2011-03-08 17:11:56 +00:00
|
|
|
}
|
2013-12-28 13:27:18 +00:00
|
|
|
|
2013-02-12 09:26:44 +00:00
|
|
|
if (image != NULL)
|
2013-12-28 13:27:18 +00:00
|
|
|
drmode |= DRMODE_INT_IMG;
|
|
|
|
|
2013-02-08 22:33:54 +00:00
|
|
|
if ((drmode & DRMODE_BG) && lcd_backdrop)
|
2013-12-28 13:27:18 +00:00
|
|
|
drmode |= DRMODE_INT_BD;
|
2011-03-08 17:11:56 +00:00
|
|
|
|
|
|
|
#ifdef ALPHA_BITMAP_READ_WORDS
|
2023-01-03 21:51:52 +00:00
|
|
|
#define INIT_ALPHA() \
|
|
|
|
do { \
|
|
|
|
alpha_offset = src_y * stride_alpha + src_x; \
|
|
|
|
} while(0)
|
|
|
|
#define START_ALPHA() \
|
|
|
|
do { \
|
|
|
|
size_t __byteskip = (uintptr_t)alpha % ALPHA_WORDSIZE; \
|
|
|
|
size_t __byteoff = alpha_offset / ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_word = (ALPHA_WORD_T *)ALIGN_DOWN(alpha + __byteoff, ALPHA_WORDSIZE); \
|
|
|
|
alpha_data = ALPHA_WORD_LOAD(alpha_word++) ^ dmask; \
|
|
|
|
alpha_pixels = ((__byteoff + __byteskip) % ALPHA_WORDSIZE) * ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_pixels += alpha_offset % ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_data >>= alpha_pixels * ALPHA_BPP; \
|
|
|
|
alpha_pixels = ALPHA_PIXELS_PER_WORD - alpha_pixels; \
|
|
|
|
} while(0)
|
|
|
|
#define END_ALPHA() \
|
|
|
|
do { \
|
|
|
|
alpha_offset += stride_alpha; \
|
|
|
|
} while(0)
|
|
|
|
#define READ_ALPHA() \
|
|
|
|
({ \
|
|
|
|
if (alpha_pixels == 0) { \
|
|
|
|
alpha_data = ALPHA_WORD_LOAD(alpha_word++) ^ dmask; \
|
|
|
|
alpha_pixels = ALPHA_PIXELS_PER_WORD; \
|
|
|
|
} \
|
|
|
|
ALPHA_WORD_T __ret = alpha_data & ALPHA_MASK; \
|
|
|
|
alpha_data >>= ALPHA_BPP; \
|
|
|
|
alpha_pixels--; \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
#elif ALPHA_BPP == 4
|
|
|
|
#define INIT_ALPHA() \
|
|
|
|
do { \
|
|
|
|
alpha_pixels = src_y * stride_alpha + src_x; \
|
|
|
|
stride_alpha = stride_alpha - width; \
|
|
|
|
alpha += alpha_pixels / ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_pixels &= 1; \
|
|
|
|
if (alpha_pixels) { \
|
|
|
|
alpha_data = *alpha++ ^ dmask; \
|
|
|
|
alpha_data >>= ALPHA_BPP; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
#define START_ALPHA() do { } while(0)
|
|
|
|
#define END_ALPHA() \
|
|
|
|
do { \
|
|
|
|
if (stride_alpha) { \
|
|
|
|
alpha_pixels = stride_alpha - alpha_pixels; \
|
|
|
|
alpha += alpha_pixels / ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_pixels &= 1; \
|
2023-01-08 10:44:47 +00:00
|
|
|
if (alpha_pixels) { \
|
|
|
|
alpha_data = *alpha++ ^ dmask; \
|
2023-01-03 21:51:52 +00:00
|
|
|
alpha_data >>= ALPHA_BPP; \
|
2023-01-08 10:44:47 +00:00
|
|
|
} \
|
2023-01-03 21:51:52 +00:00
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
#define READ_ALPHA() \
|
|
|
|
({ \
|
|
|
|
if (alpha_pixels == 0) \
|
|
|
|
alpha_data = *alpha++ ^ dmask; \
|
|
|
|
unsigned char __ret = alpha_data & ALPHA_MASK; \
|
|
|
|
alpha_data >>= ALPHA_BPP; \
|
|
|
|
alpha_pixels ^= 1; \
|
|
|
|
__ret; \
|
|
|
|
})
|
2011-03-08 17:11:56 +00:00
|
|
|
#else
|
2023-01-03 21:51:52 +00:00
|
|
|
#define INIT_ALPHA() \
|
|
|
|
do { \
|
|
|
|
alpha_pixels = src_y * stride_alpha + src_x; \
|
|
|
|
stride_alpha = stride_alpha - width; \
|
|
|
|
alpha += alpha_pixels / ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_data = *alpha++ ^ dmask; \
|
|
|
|
alpha_pixels %= ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_data >>= ALPHA_BPP * alpha_pixels; \
|
|
|
|
alpha_pixels = ALPHA_PIXELS_PER_BYTE - alpha_pixels; \
|
|
|
|
} while(0)
|
|
|
|
#define START_ALPHA() do { } while(0)
|
|
|
|
#define END_ALPHA() \
|
|
|
|
do { \
|
|
|
|
if ((size_t)stride_alpha <= alpha_pixels) \
|
|
|
|
alpha_pixels -= stride_alpha; \
|
|
|
|
else { \
|
|
|
|
alpha_pixels = stride_alpha - alpha_pixels; \
|
|
|
|
alpha += alpha_pixels / ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_data = *alpha++ ^ dmask; \
|
|
|
|
alpha_pixels %= ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
alpha_data >>= ALPHA_BPP * alpha_pixels; \
|
|
|
|
alpha_pixels = ALPHA_PIXELS_PER_BYTE - alpha_pixels; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
#define READ_ALPHA() \
|
|
|
|
({ \
|
|
|
|
if (alpha_pixels == 0) { \
|
|
|
|
alpha_data = *alpha++ ^ dmask; \
|
|
|
|
alpha_pixels = ALPHA_PIXELS_PER_BYTE; \
|
|
|
|
} \
|
|
|
|
unsigned char __ret = alpha_data & ALPHA_MASK; \
|
|
|
|
alpha_data >>= ALPHA_BPP; \
|
|
|
|
alpha_pixels--; \
|
|
|
|
__ret; \
|
|
|
|
})
|
2011-03-08 17:11:56 +00:00
|
|
|
#endif
|
|
|
|
|
2023-01-03 21:51:52 +00:00
|
|
|
dst = FBADDR(x, y);
|
|
|
|
image += STRIDE_MAIN(src_y * stride_image + src_x,
|
|
|
|
src_x * stride_image + src_y);
|
|
|
|
|
|
|
|
INIT_ALPHA();
|
|
|
|
BLEND_INIT;
|
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
do
|
|
|
|
{
|
2023-01-03 21:51:52 +00:00
|
|
|
intptr_t bo, io;
|
|
|
|
unsigned int fg, bg;
|
|
|
|
int col = width;
|
|
|
|
fb_data *dst_row = dst;
|
|
|
|
|
|
|
|
START_ALPHA();
|
2013-12-28 13:27:18 +00:00
|
|
|
|
2011-03-08 17:11:56 +00:00
|
|
|
switch (drmode)
|
|
|
|
{
|
2023-01-03 21:51:52 +00:00
|
|
|
case DRMODE_COMPLEMENT:
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(*dst, ~(*dst), READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_BG|DRMODE_INT_BD:
|
|
|
|
bo = lcd_backdrop_offset;
|
|
|
|
do
|
2011-03-08 17:11:56 +00:00
|
|
|
{
|
2023-01-03 21:51:52 +00:00
|
|
|
*dst = blend_two_colors(*PTR_ADD(dst, bo), *dst, READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_BG:
|
|
|
|
bg = vp->bg_pattern;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(bg, *dst, READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_FG|DRMODE_INT_IMG:
|
|
|
|
io = image - dst;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(*dst, *(dst + io), READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_FG:
|
|
|
|
fg = vp->fg_pattern;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(*dst, fg, READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_SOLID|DRMODE_INT_BD:
|
|
|
|
fg = vp->fg_pattern;
|
|
|
|
bo = lcd_backdrop_offset;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(*PTR_ADD(dst, bo), fg, READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_SOLID|DRMODE_INT_IMG:
|
|
|
|
bg = vp->bg_pattern;
|
|
|
|
io = image - dst;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(bg, *(dst + io), READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_SOLID|DRMODE_INT_BD|DRMODE_INT_IMG:
|
|
|
|
bo = lcd_backdrop_offset;
|
|
|
|
io = image - dst;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(*PTR_ADD(dst, bo), *(dst + io), READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
|
|
|
case DRMODE_SOLID:
|
|
|
|
fg = vp->fg_pattern;
|
|
|
|
bg = vp->bg_pattern;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dst = blend_two_colors(bg, fg, READ_ALPHA());
|
|
|
|
dst += COL_INC;
|
|
|
|
} while (--col);
|
|
|
|
break;
|
2011-03-08 17:11:56 +00:00
|
|
|
}
|
2013-12-28 13:27:18 +00:00
|
|
|
|
2023-01-03 21:51:52 +00:00
|
|
|
END_ALPHA();
|
|
|
|
image += STRIDE_MAIN(stride_image, 1);
|
|
|
|
dst = dst_row + ROW_INC;
|
|
|
|
} while (--height);
|
2012-01-05 23:00:14 +00:00
|
|
|
|
|
|
|
BLEND_FINISH;
|
2011-03-08 17:11:56 +00:00
|
|
|
}
|