Add mask color for c_bitmap

This commit is contained in:
idea4good
2019-02-20 12:55:27 +08:00
parent 3d58ef1c3f
commit 7ebae0b87e
6 changed files with 70 additions and 68 deletions

View File

@@ -1,16 +1,17 @@
#ifndef BITMAP_UNIT_H
#define BITMAP_UNIT_H
#define DEFAULT_MASK_COLOR 0xFF080408
class c_surface;
class c_bitmap
{
public:
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y);
static void draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type);
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR);
static void draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, unsigned int mask_rgb = DEFAULT_MASK_COLOR);
private:
static void draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel);
static void draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_color);
static void get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, int &x, int &y);
static void draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel);
static void draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_color);
c_bitmap(){}
c_bitmap(const c_bitmap&);

View File

@@ -25,7 +25,7 @@ struct EXTERNAL_GFX_OP
class c_display;
class c_surface {
friend class c_display;
friend class c_display; friend class c_bitmap;
public:
virtual void draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order);
virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order);

View File

@@ -4,28 +4,21 @@
#include "../core_include/bitmap.h"
#include "../core_include/surface.h"
void c_bitmap::draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y)
void c_bitmap::draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb)
{
if (0 == pBitmap)
{
return;
}
if (0 == pBitmap) { return; }
draw_bitmap_565(surface, z_order, x, y, pBitmap->XSize, pBitmap->YSize,
(unsigned char const *)pBitmap->pData);
(unsigned char const *)pBitmap->pData, mask_rgb);
}
void c_bitmap::draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type)
void c_bitmap::draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, unsigned int mask_rgb)
{
if (0 == pBitmap)
{
return;
}
if (0 == pBitmap) { return; }
int x, y;
get_bitmap_pos(pBitmap, rect, align_type, x, y);
draw_bitmap_565_in_rect(surface, z_order, rect.m_left + x, rect.m_top + y,
(rect.m_right - rect.m_left + 1), (rect.m_bottom - rect.m_top + 1),
pBitmap->XSize, pBitmap->YSize, (unsigned char const *)pBitmap->pData);
pBitmap->XSize, pBitmap->YSize, (unsigned char const *)pBitmap->pData, mask_rgb);
}
void c_bitmap::get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, int &x, int &y)
@@ -83,8 +76,15 @@ void c_bitmap::get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned
}
}
void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel)
void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_rgb)
{
unsigned short* lower_fb = NULL;
int lower_fb_width = surface->m_width;
if (z_order >= Z_ORDER_LEVEL_1)
{
lower_fb = surface->m_frame_layers[z_order - 1].fb;
}
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
const unsigned short* pData = (const unsigned short*)pPixel;
for (int j = 0; j < ysize; j++)
{
@@ -92,28 +92,51 @@ void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, in
for (int i = 0; i < xsize; i++)
{
unsigned int rgb = *p++;
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
if (mask_rgb_16 == rgb)
{
if (lower_fb)
{//restore lower layer
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(lower_fb[(y + j) * lower_fb_width + x + i]), z_order);
}
}
else
{
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
}
}
pData += xsize;
}
}
void c_bitmap::draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel)
void c_bitmap::draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_rgb)
{
unsigned short* lower_fb = NULL;
int lower_fb_width = surface->m_width;
if (z_order >= Z_ORDER_LEVEL_1)
{
lower_fb = surface->m_frame_layers[z_order - 1].fb;
}
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
const unsigned short* pData = (const unsigned short*)pPixel;
for (int j = 0; j < ysize; j++)
{
if(j >= height)break;
if (j >= height) { break; }
const unsigned short * p = pData;
for (int i = 0; i < xsize; i++)
{
if (i >= width)
{
break;
}
if (i >= width) { break; }
unsigned int rgb = *p++;
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
if (mask_rgb_16 == rgb)
{
if (lower_fb)
{//restore lower layer
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(lower_fb[(y + j) * lower_fb_width + x + i]), z_order);
}
}
else
{
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
}
}
pData += xsize;
}

View File

@@ -380,39 +380,20 @@ int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
}
m_top_zorder = (Z_ORDER_LEVEL)z_order;
c_rect current_rect = m_frame_layers[z_order].rect;
if (!current_rect.IsEmpty())
{
//Recover the lower layer
int src_zorder = (Z_ORDER_LEVEL)(z_order - 1);
int display_width = m_display->get_width();
int display_height = m_display->get_height();
c_rect old_rect = m_frame_layers[z_order].rect;
//Recover the lower layer
int src_zorder = (Z_ORDER_LEVEL)(z_order - 1);
int display_width = m_display->get_width();
int display_height = m_display->get_height();
for (int y = current_rect.m_top; y <= current_rect.m_bottom; y++)
for (int y = old_rect.m_top; y <= old_rect.m_bottom; y++)
{
for (int x = old_rect.m_left; x <= old_rect.m_right; x++)
{
for (int x = current_rect.m_left; x <= current_rect.m_right; x++)
if (!rect.PtInRect(x, y))
{
if (m_frame_layers[src_zorder].rect.PtInRect(x, y))
{
unsigned int rgb = ((unsigned short*)(m_frame_layers[src_zorder].fb))[x + y * m_width];
if (m_color_bytes == 4)
{
rgb = GL_RGB_16_to_32(rgb);
if (m_fb) { ((unsigned int*)m_fb)[y * m_width + x] = rgb; }
if (m_is_active && (x < display_width) && (y < display_height))
{
((unsigned int*)m_phy_fb)[y * display_width + x] = rgb;
}
}
else if(m_color_bytes == 2)
{
if (m_fb) { ((unsigned short*)m_fb)[y * m_width + x] = rgb; }
if (m_is_active && (x < display_width) && (y < display_height))
{
((unsigned short*)m_phy_fb)[y * display_width + x] = rgb;
}
}
}
unsigned int rgb = ((unsigned short*)(m_frame_layers[src_zorder].fb))[x + y * m_width];
draw_pixel_on_fb(x, y, GL_RGB_16_to_32(rgb));
}
}
}
@@ -422,7 +403,6 @@ int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
{
m_top_zorder = (Z_ORDER_LEVEL)(z_order - 1);
}
*m_phy_write_index = *m_phy_write_index + 1;
return 0;
}
@@ -524,10 +504,6 @@ void c_surface_no_fb::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned i
void c_surface_no_fb::draw_pixel_on_fb(int x, int y, unsigned int rgb)
{
if (x >= m_width || y >= m_height || x < 0 || y < 0)
{
return;
}
if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active)
{
m_gfx_op->draw_pixel(x, y, rgb);