GuiLite/workspace/core_include/bitmap.h

94 lines
3.1 KiB
C
Raw Normal View History

#pragma once
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/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)
{
2020-06-21 22:48:26 +08:00
ASSERT(pBitmap);
unsigned short* lower_fb_16 = 0;
unsigned int* lower_fb_32 = 0;
2020-06-21 22:48:26 +08:00
int lower_fb_width = 0;
c_rect lower_fb_rect;
2020-01-22 11:03:29 +08:00
if (z_order >= Z_ORDER_LEVEL_1)
{
2020-06-26 17:25:00 +08:00
lower_fb_16 = (unsigned short*)surface->m_layers[z_order - 1].fb;
lower_fb_32 = (unsigned int*)surface->m_layers[z_order - 1].fb;
lower_fb_rect = surface->m_layers[z_order - 1].rect;
2020-07-02 13:39:26 +08:00
lower_fb_width = lower_fb_rect.width();
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;
int color_bytes = surface->m_color_bytes;
2020-06-21 22:48:26 +08:00
for (int y_ = y; y_ < y + ysize; y_++)
2020-01-22 11:03:29 +08:00
{
2020-06-21 22:48:26 +08:00
for (int x_ = x; x_ < x + xsize; x_++)
2020-01-22 11:03:29 +08:00
{
unsigned int rgb = *pData++;
if (mask_rgb_16 == rgb)
{
2020-07-02 13:39:26 +08:00
if (lower_fb_rect.pt_in_rect(x_, y_))
2020-06-21 22:48:26 +08:00
{//show lower layer
surface->draw_pixel(x_, y_, (color_bytes == 4) ? lower_fb_32[(y_ - lower_fb_rect.m_top) * lower_fb_width + (x_ - lower_fb_rect.m_left)] : GL_RGB_16_to_32(lower_fb_16[(y_ - lower_fb_rect.m_top) * lower_fb_width + (x_ - lower_fb_rect.m_left)]), z_order);
2020-01-22 11:03:29 +08:00
}
}
else
{
2020-06-21 22:48:26 +08:00
surface->draw_pixel(x_, y_, GL_RGB_16_to_32(rgb), z_order);
2020-01-22 11:03:29 +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;
}
unsigned short* lower_fb_16 = 0;
unsigned int* lower_fb_32 = 0;
2020-06-21 22:48:26 +08:00
int lower_fb_width = 0;
c_rect lower_fb_rect;
2020-01-22 11:03:29 +08:00
if (z_order >= Z_ORDER_LEVEL_1)
{
2020-06-26 17:25:00 +08:00
lower_fb_16 = (unsigned short*)surface->m_layers[z_order - 1].fb;
lower_fb_32 = (unsigned int*)surface->m_layers[z_order - 1].fb;
lower_fb_rect = surface->m_layers[z_order - 1].rect;
2020-07-02 13:39:26 +08:00
lower_fb_width = lower_fb_rect.width();
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;
int color_bytes = surface->m_color_bytes;
2020-06-21 22:48:26 +08:00
for (int y_ = 0; y_ < height; y_++)
2020-01-22 11:03:29 +08:00
{
2020-06-21 22:48:26 +08:00
const unsigned short* p = &pData[src_x + (src_y + y_) * pBitmap->width];
for (int x_ = 0; x_ < width; x_++)
2020-01-22 11:03:29 +08:00
{
unsigned int rgb = *p++;
if (mask_rgb_16 == rgb)
{
2020-07-02 13:39:26 +08:00
if (lower_fb_rect.pt_in_rect(x + x_, y + y_))
2020-06-21 22:48:26 +08:00
{//show lower layer
surface->draw_pixel(x + x_, y + y_, (color_bytes == 4) ? lower_fb_32[(y + y_ - lower_fb_rect.m_top) * lower_fb_width + x + x_ - lower_fb_rect.m_left] : GL_RGB_16_to_32(lower_fb_16[(y + y_ - lower_fb_rect.m_top) * lower_fb_width + x + x_ - lower_fb_rect.m_left]), z_order);
2020-01-22 11:03:29 +08:00
}
}
else
{
2020-06-21 22:48:26 +08:00
surface->draw_pixel(x + x_, y + y_, GL_RGB_16_to_32(rgb), z_order);
2020-01-22 11:03:29 +08:00
}
}
}
}
2017-12-06 21:43:47 +08:00
};