📄 nbmp.h
字号:
close(fp);
return 1;
#endif
}
else if (g_bmpbits == 8) /*打开的是8位256色位图*/
{
#ifndef NEO_8bit_bmp_unused
unsigned color256[256];
unsigned char *buffer, *b_tmp;
unsigned char pix24b[8];
wid_fix = (g_bmp_wid & 3) ? (4 - (g_bmp_wid & 3)) : 0;
if ((buffer = (unsigned char *)malloc(len2=(g_bmp_wid + wid_fix)))==NULL)
{
#ifndef NEO_sys_report_error_unused
Errinfo_t error = {"show_bmp", NO_MEMORY, 0};
close(fp);
throw_error(error);
#endif
}
for(i = 0; i < 256; ++i)
{
_READ(fp, &pix24b, 8);
color256[i] = ((((pix24b[2]>>3)<<g_green_mask)+(pix24b[1]>>g_green_bit))<<5)+(pix24b[0]>>3);
color256[++i] = ((((pix24b[6]>>3)<<g_green_mask)+(pix24b[5]>>g_green_bit))<<5)+(pix24b[4]>>3);
}
b_tmp = buffer - offset;
for(j = real_hig; j >= 0; j--)
{
if (((yy = y + (g_v_flip_?real_hig - j : j) )<g_rect_top) || (yy > g_rect_bottom))
{
cnt++;
continue; /*图象垂直溢出*/
}
else if (cnt)
{
lseek(fp, cnt * len2, SEEK_CUR);
cnt = 0;
}
read_scan_line(fp, buffer, len2);
page1 = (char)((addr1 = ((Uint32)yy + g_sl_offset) * g_screen_h + x) >> 15);
if (page1 == ((addr1 + length) >> 15))
{
int far *d_tmp = (int far *)(g_videoptr+ (unsigned)((addr1<<1) & 0xffff));
start = temp; k = g_rect_left - fix;
set_vbe_page(page1);
if (!g_mask_flag_)
{
for (; k < len; ++start ,++k)
{
#ifndef NEO_draw_mode_unused
switch(g_draw_mode)
{
case COPY_PUT : d_tmp[k] = color256[b_tmp[start]]; break;
case XOR_PUT : d_tmp[k] = d_tmp[k] ^ color256[b_tmp[start]]; break;
case NOT_PUT : d_tmp[k] = ~d_tmp[k]; break;
case OR_PUT : d_tmp[k] = d_tmp[k] | color256[b_tmp[start]];break;
case AND_PUT : d_tmp[k] = d_tmp[k] & color256[b_tmp[start]];break;
}
#else
d_tmp[k] = color256[b_tmp[start]];
#endif
}
}
else
{
for (; k < len; ++start ,++k)
{
if (b_tmp[start] != MASK_COLOR_8)
#ifndef NEO_draw_mode_unused
switch(g_draw_mode)
{
case COPY_PUT: d_tmp[k] = color256[b_tmp[start]]; break;
case XOR_PUT : d_tmp[k] = d_tmp[k] ^ color256[b_tmp[start]]; break;
case NOT_PUT : d_tmp[k] = ~d_tmp[k]; break;
case OR_PUT : d_tmp[k] = d_tmp[k] | color256[b_tmp[start]];break;
case AND_PUT : d_tmp[k] = d_tmp[k] & color256[b_tmp[start]];break;
}
#else
d_tmp[k] = color256[b_tmp[start]];
#endif
}
}
}
else
{
i = 0;
if (!g_mask_flag_)
{
for(; i < masklen; ++i)
{
dot(xx+i, yy, color256[buffer[i]]);
}
}
else
{
for (; i < masklen; ++i)
{
if (buffer[i] != MASK_COLOR_8)
dot(xx+i, yy, color256[buffer[i]]);
}
}
}
}
free(buffer);
close(fp);
return 1;
#endif
}
else
{
close(fp);
return -3;
}
#else
wid_fix += 0;
bmpfile += 0; x += 0; y+=0;
#endif
}
else
{
#ifndef NEO_sys_report_error_unused
Errinfo_t error = {"show_bmp", ERR_VIDEO_MODE, 0};
close(fp);
throw_error(error);
#endif
wid_fix += 0; masklen += 0; temp += 0; xx += 0; offset += 0;real_hig += 0; cnt += 0;
}
return -3;
}
char show_bmp_ex(PACKFILE *bmpfile, int x, int y, int param, long flags)
{
char retrn;
g_bmp_param = param;
g_bmp_flags = flags;
retrn = show_bmp(bmpfile, x, y);
g_bmp_flags = g_bmp_param = 0x0;
return retrn;
}
#endif /*NEO_showbmp_unused*/
#ifndef NEO_bmp_blit_unused
char bmp_blit(char *bmpname, int source_x, int source_y, int dest_x, int dest_y, int width, int height)
{
int xx = dest_x + width, yy = dest_y + height;
#ifndef NEO_rect_unused
rect_store();
#endif
if (dest_x > g_rect_right || xx < g_rect_left || dest_y > g_rect_bottom || yy < g_rect_top)
{
return FALSE;
}
if (dest_x > g_rect_left) g_rect_left = dest_x;
if (dest_y > g_rect_top) g_rect_top = dest_y;
if (xx < g_rect_right) g_rect_right = xx;
if (yy < g_rect_bottom) g_rect_bottom = yy;
#ifndef NEO_showbmp_unused
show_bmp(bmpname, dest_x - source_x, dest_y - source_y);
#endif
#ifndef NEO_rect_unused
rect_restore();
#endif
return TRUE;
}
#endif /*NEO_bmp_blit_unused*/
#ifndef NEO_bmp_masked_blit_unused
char bmp_masked_blit(char *bmpname, int source_x, int source_y, int dest_x, int dest_y, int width, int height)
{
int xx = dest_x + width, yy = dest_y + height;
#ifndef NEO_rect_unused
rect_store();
#endif
if (dest_x > g_rect_right || xx < g_rect_left || dest_y > g_rect_bottom || yy < g_rect_top)
{
return FALSE;
}
if (dest_x > g_rect_left) g_rect_left = dest_x;
if (dest_y > g_rect_top ) g_rect_top = dest_y;
if (xx < g_rect_right ) g_rect_right = xx;
if (yy < g_rect_bottom) g_rect_bottom = yy;
g_bmp_flags |= BMP_MASK_C; /*mask标志开*/
#ifndef NEO_showbmp_unused
show_bmp(bmpname, dest_x - source_x, dest_y - source_y);
#endif
g_bmp_flags &= !BMP_MASK_C; /*mask标志关*/
#ifndef NEO_rect_unused
rect_restore();
#endif
return TRUE;
}
#endif /*NEO_bmp_masked_blit_unused*/
#ifndef NEO_save_screen_unused
char rect_save_screen(char *bmp, int left, int top, int right, int bottom)
{
FILE *bmp_fp;
bitmap_file_head_t bmp_file_h;
bitmap_info_head_t bmp_header;
long addr;
int bmpwidth, len;
int bmpheight;
int *buf16;
int i, j;
char page;
char *buffer;
char div, off;
if (left >= right || top >= bottom)
return FALSE;
right = right >= SCREEN_W?SCREEN_W - 1 : right;
bottom = bottom>= SCREEN_H?SCREEN_H - 1 : bottom;
bmp_fp = fopen(bmp, "wb");
if (bmp_fp == NULL)
{
return FALSE;
}
bmpwidth = len = right - left + 1;
bmpheight = bottom - top + 1;
bmp_file_h.bf_type = BMP_MAGIC;
bmp_file_h.bf_offset = bmp_file_h.bf_size = 54;
bmp_header.clrImportant = bmp_header.compression = bmp_file_h.bf_reserved1 = bmp_file_h.bf_reserved2 = 0;
bmp_header.size = 40;
bmp_header.width= (long)bmpwidth;
bmp_header.height= (long)bmpheight;
bmp_header.planes= 1;
bmp_header.YpelsPerMeter = bmp_header.XpelsPerMeter = 3780/*2835*/;
if (g_color_depth == 8)
{
#ifndef NEO_color_depth_8_unused
#ifndef NEO_palette_unused
char pal_buf[256][3];
char pal[256][4];
len += (bmpwidth & 3) ? 4 - (bmpwidth & 3) : 0;
bmp_file_h.bf_size += 1024 + (long)len * (long)bmpheight;
bmp_file_h.bf_offset += 1024;
bmp_header.bitCount = 8;
bmp_header.clrUsed = 256;
bmp_header.sizeImage= (long)bmpwidth * (long)bmpheight;
_FWRITE(&bmp_file_h, 14, 1, bmp_fp);
_FWRITE(&bmp_header, 40, 1, bmp_fp);
get_palette(*pal_buf);
for (i = 0; i < 256; ++i)
{
pal[i][0] = pal_buf[i][2]<<g_dac_size_fix;
pal[i][1] = pal_buf[i][1]<<g_dac_size_fix;
pal[i][2] = pal_buf[i][0]<<g_dac_size_fix;
pal[i][3] = 0;
}
_FWRITE(pal, 4, 256, bmp_fp);
if ( (buffer = (char *)malloc(len)) == NULL) return FALSE;
div = 0;
off = 16;
#endif
#endif
}
else if (g_color_depth == 16 || g_color_depth == 15)
{
#ifndef NEO_color_depth_16_unused
bmp_file_h.bf_size += (long)len * (long)bmpheight << 1;
bmp_header.bitCount = 16;
bmp_header.clrUsed = 65536L;
bmp_header.sizeImage= (long)bmpwidth * (long)bmpheight << 1;
_FWRITE(&bmp_file_h, 14, 1, bmp_fp);
_FWRITE(&bmp_header, 40, 1, bmp_fp);
div = 1;
off = 15;
buffer = (char *)malloc(len = (len << 1) + (bmpwidth & 3));
if ( buffer == NULL) return FALSE;
buf16 = (int *)buffer;
#endif
}
else
{
fclose(bmp_fp);
return FALSE;
}
for (j = bottom; j >= top; --j)
{
page = (char)((addr = ((long)j + g_sl_offset) * g_screen_h + left) >> off);
if (page == ((addr + bmpwidth) >> off))
{
set_vbe_page(page);
movedata(0xa000, (unsigned)((addr << div) & 0xffff), FP_SEG(buffer), FP_OFF(buffer), len);
}
else
{
for (i = 0; i < bmpwidth; ++i)
{
if (g_color_depth == 8)
buffer[i] = get_dot(i + left, j);
else
{
#ifndef NEO_color_depth_16_unused
buf16[i] = get_dot(i + left, j);
#endif
}
}
}
_FWRITE(buffer, 1, len, bmp_fp);
}
free(buffer);
fclose(bmp_fp);
return TRUE;
}
BITMAP *get_image(int x0, int y0, int x1, int y1)
{
BITMAP *image;
char dir[16];
if ( (image = (BITMAP *)malloc(sizeof(BITMAP))) == NULL)
return FALSE;
if ( (image->fname = (char *)malloc(32)) == NULL)
{
free(image);
return FALSE;
}
#ifndef NEO_temp_dir_unused
strcpy(image->fname, "neotemp\\");
#endif
strcat(image->fname, tmpnam(dir));
image->flag = 0;
rect_save_screen(image->fname, x0, y0, x1, y1);
return image;
}
void put_image_ex(BITMAP *image, int x, int y, int param, long flags)
{
if (image != NULL)
{
if (image->flag == 0)
{
#ifndef NEO_showbmp_unused
show_bmp_ex(image->fname, x, y, param, flags);
#endif
}
}
}
#define put_image(image, x, y) put_image_ex(image, x, y, 0, 0)
/*加入扩展内存后该 #endif 往上挪位*/
#endif /*NEO_save_screen_unused*/
BITMAP *load_bmp(char *file, PALLETE pal)
{
BITMAP *image;
if ( (image = (BITMAP *)malloc(sizeof(BITMAP))) == NULL)
return FALSE;
if ( (image->fname = (char *)malloc(strlen(file) + 1)) == NULL)
{
free(image);
return FALSE;
}
image->flag = 0;
strcpy(image->fname, file);
#if !(defined NEO_color_depth_8_unused)
get_pal_from_bmp(file, pal);
#else
pal += 0;
#endif
return image;
}
void destroy_bitmap(BITMAP *bitmap)
{
if (bitmap != NULL)
{
if (bitmap->flag == 0)
{
free(bitmap->fname); /*释放保存文件名的内存*/
}
free(bitmap);
bitmap = NULL;
}
}
#endif /*NEO_bmp_support_unused*/
#endif /*__NBMP_H__*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -