2019-08-19 16:03:27 +08:00
|
|
|
#ifndef GUILITE_CORE_INCLUDE_BITMAP_H
|
|
|
|
#define GUILITE_CORE_INCLUDE_BITMAP_H
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2020-01-22 11:03:29 +08:00
|
|
|
#include "../core_include/api.h"
|
|
|
|
#include "../core_include/resource.h"
|
|
|
|
#include "../core_include/rect.h"
|
|
|
|
#include "../core_include/display.h"
|
|
|
|
|
2019-02-20 12:55:27 +08:00
|
|
|
#define DEFAULT_MASK_COLOR 0xFF080408
|
2017-12-06 21:43:47 +08:00
|
|
|
class c_surface;
|
|
|
|
class c_bitmap
|
|
|
|
{
|
|
|
|
public:
|
2020-01-22 11:03:29 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (0 == pBitmap)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-03-17 13:16:47 +08:00
|
|
|
unsigned short* lower_fb_16 = 0;
|
|
|
|
unsigned int* lower_fb_32 = 0;
|
2020-01-22 11:03:29 +08:00
|
|
|
int lower_fb_width = surface->m_width;
|
|
|
|
if (z_order >= Z_ORDER_LEVEL_1)
|
|
|
|
{
|
2020-03-17 13:16:47 +08:00
|
|
|
lower_fb_16 = (unsigned short*)surface->m_frame_layers[z_order - 1].fb;
|
|
|
|
lower_fb_32 = (unsigned int*)surface->m_frame_layers[z_order - 1].fb;
|
2020-01-22 11:03:29 +08:00
|
|
|
}
|
|
|
|
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
|
|
|
|
int xsize = pBitmap->width;
|
|
|
|
int ysize = pBitmap->height;
|
|
|
|
const unsigned short* pData = (const unsigned short*)pBitmap->pixel_color_array;
|
2020-03-17 13:16:47 +08:00
|
|
|
int color_bytes = surface->m_color_bytes;
|
2020-01-22 11:03:29 +08:00
|
|
|
for (int j = 0; j < ysize; j++)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < xsize; i++)
|
|
|
|
{
|
|
|
|
unsigned int rgb = *pData++;
|
|
|
|
if (mask_rgb_16 == rgb)
|
|
|
|
{
|
2020-03-17 13:16:47 +08:00
|
|
|
if (lower_fb_16)
|
2020-01-22 11:03:29 +08:00
|
|
|
{//restore lower layer
|
2020-03-17 13:16:47 +08:00
|
|
|
surface->draw_pixel(x + i, y + j, (color_bytes == 4) ? lower_fb_32[(y + j) * lower_fb_width + x + i] : GL_RGB_16_to_32(lower_fb_16[(y + j) * lower_fb_width + x + i]), z_order);
|
2020-01-22 11:03:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 13:16:47 +08:00
|
|
|
|
2020-01-22 11:03:29 +08:00
|
|
|
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO* pBitmap, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
|
|
|
|
{
|
|
|
|
if (0 == pBitmap || (src_x + width > pBitmap->width) || (src_y + height > pBitmap->height))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 13:16:47 +08:00
|
|
|
unsigned short* lower_fb_16 = 0;
|
|
|
|
unsigned int* lower_fb_32 = 0;
|
2020-01-22 11:03:29 +08:00
|
|
|
int lower_fb_width = surface->m_width;
|
|
|
|
if (z_order >= Z_ORDER_LEVEL_1)
|
|
|
|
{
|
2020-03-17 13:16:47 +08:00
|
|
|
lower_fb_16 = (unsigned short*)surface->m_frame_layers[z_order - 1].fb;
|
|
|
|
lower_fb_32 = (unsigned int*)surface->m_frame_layers[z_order - 1].fb;
|
2020-01-22 11:03:29 +08:00
|
|
|
}
|
|
|
|
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
|
|
|
|
const unsigned short* pData = (const unsigned short*)pBitmap->pixel_color_array;
|
2020-03-17 13:16:47 +08:00
|
|
|
int color_bytes = surface->m_color_bytes;
|
2020-01-22 11:03:29 +08:00
|
|
|
for (int j = 0; j < height; j++)
|
|
|
|
{
|
|
|
|
const unsigned short* p = &pData[src_x + (src_y + j) * pBitmap->width];
|
|
|
|
for (int i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
unsigned int rgb = *p++;
|
|
|
|
if (mask_rgb_16 == rgb)
|
|
|
|
{
|
2020-03-17 13:16:47 +08:00
|
|
|
if (lower_fb_16)
|
2020-01-22 11:03:29 +08:00
|
|
|
{//restore lower layer
|
2020-03-17 13:16:47 +08:00
|
|
|
surface->draw_pixel(x + i, y + j, (color_bytes == 4) ? lower_fb_32[(y + j) * lower_fb_width + x + i] : GL_RGB_16_to_32(lower_fb_16[(y + j) * lower_fb_width + x + i]), z_order);
|
2020-01-22 11:03:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:43:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|