📄 bmploader.cpp
字号:
#include "stdafx.h"
#include "mmi.h"
#define IMAGE_STATIC_ROW_DATA_SIZE 1024
#define IMAGE_STATIC_PALETTE_SIZE 768
#define IMAGE_STATIC_BUFFER_SIZE 409600
typedef struct _bitmap_file_header
{
U16 file_type;
U32 file_size;
U16 reserved1;
U16 reserved2;
U32 bitmap_offset;
} bitmap_file_header;
typedef struct _bitmap_info_header
{
U32 header_size;
U32 width;
U32 height;
U16 number_of_planes;
U16 bits_per_pixel;
U32 compression;
U32 bitmap_size;
U32 device_width;
U32 device_height;
U32 number_of_colors;
U32 number_of_important_colors;
} bitmap_info_header;
U32 image_static_row_data[(IMAGE_STATIC_ROW_DATA_SIZE + 3) / 4];
U32 image_static_palette[(IMAGE_STATIC_PALETTE_SIZE + 3) / 4];
U32 image_static_buffer[(IMAGE_STATIC_BUFFER_SIZE + 3) / 4];
static S32 BMP_write_color(
U8 *start,
U8 A,
U8 R,
U8 G,
U8 B,
S8 dest_color_depth,
U8 transparent)
{
switch (dest_color_depth)
{
case 32:
{
U32 *color = (U32 *)start;
if (transparent)
{
*color = (U32)RGB_TRANSPARENT_COLOR_32;
}
else
{
*color = (U32)MMI_RGB_TO_HW_FORMAT_32(A,R,G,B);
}
return 4;
break;
}
case 24:
{
if (transparent)
{
*start = (U8)0x56;
*(start+1) = (U8)0x34;
*(start+2) = (U8)0x12;
}
else
{
*start = B;
*(start+1) = G;
*(start+2) = R;
}
return 3;
break;
}
case 16:
default:
{
U16 *color = (U16 *)start;
if (transparent)
{
*color = (U16)RGB_TRANSPARENT_COLOR_16;
}
else
{
*color = (U16)MMI_RGB_TO_HW_FORMAT_16(A,R,G,B);
}
return 2;
break;
}
}
}
/*****************************************************************************
* FUNCTION
* BMP_write_line
* DESCRIPTION
*
* PARAMETERS
* b [?]
* buffer [?]
* row_bytes [IN]
* color_depth [IN]
* dest_color_depth[IN]
* width [IN]
* y [IN]
* palette [?]
* RETURNS
* void
*****************************************************************************/
static void BMP_write_line(
bitmap *b,
U8 *buffer,
long int row_bytes,
S8 color_depth,
S8 dest_color_depth,
long int width,
long int y,
U8 palette[][3])
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
U32 offset;
U32 boffset = 0;
U8 color_index;
U8 data;
S32 w;
U8 A, R, G, B;
U8 transparent = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
UI_UNUSED_PARAMETER(row_bytes);
{
S32 i, j;
U8 *bitmap_data = b->data;
S32 ret;
offset = y * b->row_bytes;
switch (color_depth)
{
case 32:
for (i = 0; i < width; i++)
{
transparent = 0;
B = buffer[boffset++];
G = buffer[boffset++];
R = buffer[boffset++];
A = buffer[boffset++];
if ((A == 0xFF) && (R == 0x0A) && (G == 0x0B) && (B == 0x0C))
{
transparent = 1;
}
ret = BMP_write_color(bitmap_data+offset, A, R, G, B, dest_color_depth, transparent);
offset += ret;
}
break;
case 24:
for (i = 0; i < width; i++)
{
transparent = 0;
B = buffer[boffset++];
G = buffer[boffset++];
R = buffer[boffset++];
A = 255;
if ((R == 0x0A) && (G == 0x0B) && (B == 0x0C))
{
transparent = 1;
}
ret = BMP_write_color(bitmap_data+offset, A, R, G, B, dest_color_depth, transparent);
offset += ret;
}
break;
case 16: /* RGB-555 */
for (i = 0; i < width; i++)
{
U16 data = 0;
data = ((U16*)buffer)[boffset++];
transparent = 0;
R = ((data >> 10) & 0x1F) << 3;
G = ((data >> 5) & 0x1F) << 3;
B = (data & 0x1F) << 3;
A = 255;
if ((R == 0x0A) && (G == 0x0B) && (B == 0x0C))
{
transparent = 1;
}
ret = BMP_write_color(bitmap_data+offset, A, R, G, B, dest_color_depth, transparent);
offset += ret;
}
break;
case 8:
for (i = 0; i < width; i++)
{
transparent = 0;
color_index = buffer[boffset++];
B = palette[color_index][2];
G = palette[color_index][1];
R = palette[color_index][0];
A = 255;
if (color_index == 0x00)
{
transparent = 1;
}
ret = BMP_write_color(bitmap_data+offset, A, R, G, B, dest_color_depth, transparent);
offset += ret;
}
break;
case 4:
w = (width >> 1);
if (width & 1)
{
w++;
}
for (i = 0; i < w; i++)
{
data = buffer[boffset++];
for (j = 0; j < 2; j++)
{
if (((i << 1) + j) >= width)
{
break;
}
transparent = 0;
color_index = (U8) ((data >> ((1 - j) << 2)) & 0xf);
B = palette[color_index][2];
G = palette[color_index][1];
R = palette[color_index][0];
A = 255;
if (color_index == 0x00)
{
transparent = 1;
}
ret = BMP_write_color(bitmap_data+offset, A, R, G, B, dest_color_depth, transparent);
offset += ret;
}
}
break;
case 1:
w = (width >> 3);
if (width & 7)
{
w++;
}
for (i = 0; i < w; i++)
{
data = buffer[boffset++];
for (j = 0; j < 8; j++)
{
if (((i << 3) + j) >= width)
{
break;
}
if (data & (1 << (7 - j)))
{
transparent = 0;
B = 255;
G = 255;
R = 255;
A = 255;
ret = BMP_write_color(bitmap_data+offset, A, R, G, B, dest_color_depth, transparent);
offset += ret;
}
else
{
transparent = 0;
B = 0;
G = 0;
R = 0;
A = 0;
ret = BMP_write_color(bitmap_data+offset, A, R, G, B, dest_color_depth, transparent);
offset += ret;
}
}
}
break;
}
}
}
/*****************************************************************************
* FUNCTION
* BMP_load_file_header
* DESCRIPTION
*
* PARAMETERS
* h [?]
* file [?]
* RETURNS
* void
*****************************************************************************/
void BMP_load_file_header(bitmap_file_header *h, bytestream *file)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
h->file_type = bytestream_fgetword(file);
h->file_size = bytestream_fgetdword(file);
h->reserved1 = bytestream_fgetword(file);
h->reserved2 = bytestream_fgetword(file);
h->bitmap_offset = bytestream_fgetdword(file);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -