Skip to content

Commit 7cafec2

Browse files
committed
bflibrary: Work on creation of sprites for tests
The sprites have now palette mapped to the palette used in test. Now they have to be encoded into DAT/TAB sprite list.
1 parent d1149a7 commit 7cafec2

5 files changed

Lines changed: 103 additions & 16 deletions

File tree

bflibrary/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ bflib_test_sprdrw_SOURCES = \
259259
tests/mock_palette.c \
260260
tests/mock_screen.c \
261261
tests/mock_windows.c \
262-
tests/helpers_screen.c \
262+
tests/helpers_sprite.c \
263263
tests/bflib_test_sprdrw.c
264264

265265
bflib_test_sprdrw_CPPFLAGS = \

bflibrary/tests/bflib_test_sprdrw.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ TbBool test_spritedraw(void)
5151
ubyte ref_pal[PALETTE_8b_SIZE];
5252
TbPixel unaffected_colours[] = {0,};
5353
TbScreenModeInfo *mdinfo;
54-
TbScreenMode mode = Lb_SCREEN_MODE_640_480_8;
54+
TbScreenMode mode;
5555
ubyte *texmap;
5656
TbPixel *ref_buffer;
5757
ulong picno;
58+
int sprfile_no = 1;
59+
int len;
5860

5961
if (LbErrorLogSetup(NULL, "tst_sprdrw.log", Lb_ERROR_LOG_NEW) != Lb_SUCCESS) {
6062
LOGERR("execution log setup failed");
@@ -67,13 +69,46 @@ TbBool test_spritedraw(void)
6769
}
6870
LbMemorySetup();
6971

70-
mdinfo = LbScreenGetModeInfo(mode);
71-
7272
// Prepare a palette, and colour tables for it
7373
make_general_palette(pal);
7474
LbFileSaveAt("tst_gp.pal", &pal, sizeof(pal));
7575
LbColourTablesGenerate(pal, unaffected_colours, "tst_gptbl.dat");
7676

77+
mode = get_example_sprites_screen_mode(sprfile_no);
78+
mdinfo = LbScreenGetModeInfo(mode);
79+
if (MockScreenSetupAnyMode(mode, mdinfo->Width, mdinfo->Height, pal) != Lb_SUCCESS) {
80+
LOGERR("mock screen initialization failed");
81+
return false;
82+
}
83+
84+
MockScreenLock();
85+
86+
{ // Read image file containing sprites
87+
char loc_fname[64];
88+
ubyte colour_remap[PALETTE_8b_COLORS];
89+
ulong ref_width, ref_height;
90+
91+
ref_buffer = malloc(mdinfo->Width * (mdinfo->Height + 1) * 1);
92+
get_example_sprites_file_name(sprfile_no, loc_fname);
93+
memset(ref_pal, 0, PALETTE_8b_SIZE);
94+
LbPngLoad(loc_fname, ref_buffer, &ref_width, &ref_height, ref_pal);
95+
if ((ref_width != mdinfo->Width) || (ref_height != mdinfo->Height)) {
96+
LOGERR("%s: unexpected sprites image size", loc_fname);
97+
return false;
98+
}
99+
palette_remap_to_screen(colour_remap, ref_pal);
100+
LbScreenCopyRemap(ref_buffer, lbDisplay.WScreen, lbDisplay.GraphicsWindowHeight,
101+
colour_remap);
102+
free(ref_buffer);
103+
}
104+
105+
//len = generate_example_sprites_from_screen(sprfile_no, pal, ubyte *p_dat, TbSprite *p_tab);
106+
107+
MockScreenUnlock();
108+
MockScreenReset();
109+
110+
mode = Lb_SCREEN_MODE_640_480_8;
111+
mdinfo = LbScreenGetModeInfo(mode);
77112
if (MockScreenSetupAnyMode(mode, mdinfo->Width, mdinfo->Height, pal) != Lb_SUCCESS) {
78113
LOGERR("mock screen initialization failed");
79114
return false;
@@ -84,9 +119,6 @@ TbBool test_spritedraw(void)
84119
texmap = LbMemoryAlloc(256*256*1);
85120
LbMemorySet(texmap, 0, 256*256*1);
86121

87-
setup_vecs(lbDisplay.WScreen, texmap, lbDisplay.PhysicalScreenWidth,
88-
lbDisplay.PhysicalScreenWidth, lbDisplay.PhysicalScreenHeight);
89-
90122
ref_buffer = malloc(mdinfo->Width * mdinfo->Height * (lbEngineBPP+7) / 8);
91123
if (ref_buffer == NULL) {
92124
LOGERR("reference screen buffer alloc failed");

bflibrary/tests/helpers_sprite.c

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/******************************************************************************/
2020
#include <string.h>
2121
#include "helpers_sprite.h"
22+
#include "bfanywnd.h"
2223
#include "bfpalette.h"
2324
#include "bfutility.h"
2425
#include "bftstlog.h"
@@ -27,29 +28,66 @@ static struct TbAnyWindow sprites1_list[] = {
2728
{0, 0, 0, 0, NULL,},
2829
};
2930

30-
void generate_example_sprites_from_png(int sprfile_no, const ubyte *pal,
31+
void get_example_sprites_file_name(int sprfile_no, char *fname)
32+
{
33+
switch (sprfile_no)
34+
{
35+
case 1:
36+
strcpy(fname, "referenc/spr_devpac-mans16.png");
37+
break;
38+
default:
39+
fname[0] = '\0';
40+
break;
41+
}
42+
}
43+
44+
TbScreenMode get_example_sprites_screen_mode(int sprfile_no)
45+
{
46+
char locstr[64];
47+
ulong img_width, img_height, img_bpp;
48+
ulong flags;
49+
50+
switch (sprfile_no)
51+
{
52+
case 1:
53+
img_width = 320;
54+
img_height = 1024;
55+
img_bpp = 8;
56+
break;
57+
default:
58+
img_width = 4;
59+
img_height = 4;
60+
img_bpp = 8;
61+
break;
62+
}
63+
64+
sprintf(locstr, "%lux%lux%lu", img_width, img_height, img_bpp);
65+
if (img_bpp <= 8)
66+
flags = Lb_VF_PALETTE;
67+
else
68+
flags = Lb_VF_RGBCOLOUR;
69+
return LbRegisterVideoMode(locstr, img_width, img_height, img_bpp, flags);
70+
}
71+
72+
void generate_example_sprites_from_screen(int sprfile_no, const ubyte *pal,
3173
ubyte *p_dat, TbSprite *p_tab)
3274
{
33-
const char *img_fname;
3475
TbSprite *p_spr;
3576
struct TbAnyWindow *p_wnd;
3677
int tot_sprites, i;
3778

3879
switch (sprfile_no)
3980
{
4081
case 1:
41-
img_fname = "referenc/spr_devpac-mans16.png";
4282
tot_sprites = sizeof(sprites1_list)/sizeof(sprites1_list[0]);
43-
p_wnd = &sprites1_list[i];
83+
p_wnd = &sprites1_list[0];
4484
break;
4585
default:
46-
img_fname = NULL;
4786
tot_sprites = 0;
4887
p_wnd = NULL;
4988
break;
5089
}
51-
// Load the sprite image
52-
90+
5391
// Convert each area into a sprite
5492
p_spr = p_tab;
5593
for (i = 0; i < tot_sprites; i++)
@@ -65,4 +103,17 @@ void generate_example_sprites_from_png(int sprfile_no, const ubyte *pal,
65103

66104
}
67105

106+
void palette_remap_to_screen(TbPixel *p_remap, const TbPixel *p_altpal)
107+
{
108+
int i;
109+
for (i = 0; i < PALETTE_8b_COLORS; i++)
110+
{
111+
ubyte r, g, b;
112+
r = p_altpal[3*i + 0];
113+
g = p_altpal[3*i + 1];
114+
b = p_altpal[3*i + 2];
115+
p_remap[i] = LbPaletteFindColour(lbDisplay.Palette, r, g, b);
116+
}
117+
}
118+
68119
/******************************************************************************/

bflibrary/tests/helpers_sprite.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222

2323
#include "bftypes.h"
2424
#include "bfsprite.h"
25+
#include "bfscreen.h"
2526

2627
#ifdef __cplusplus
2728
extern "C" {
2829
#endif
2930

30-
void generate_example_sprites_from_png(int sprfile_no, const ubyte *pal,
31+
void get_example_sprites_file_name(int sprfile_no, char *fname);
32+
TbScreenMode get_example_sprites_screen_mode(int sprfile_no);
33+
void palette_remap_to_screen(TbPixel *p_remap, const TbPixel *p_altpal);
34+
35+
void generate_example_sprites_from_screen(int sprfile_no, const ubyte *pal,
3136
ubyte *p_dat, TbSprite *p_tab);
32-
void raw_to_sprite(short X, short Y, ushort Width, ushort Height, ubyte *Raw);
3337

3438
#ifdef __cplusplus
3539
};
33.7 KB
Loading

0 commit comments

Comments
 (0)