Combine ft_chars, ft_allocdata into one allocation
This commit is contained in:
parent
4aea3b8fdc
commit
e07c9a5f87
|
@ -43,7 +43,7 @@ namespace dcx {
|
|||
// Allocated a bitmap and makes its data be raw_data that is already somewhere.
|
||||
static grs_bitmap_ptr gr_create_bitmap_raw(uint16_t w, uint16_t h, unsigned char * raw_data);
|
||||
|
||||
void gr_set_bitmap_data (grs_bitmap &bm, unsigned char *data)
|
||||
void gr_set_bitmap_data(grs_bitmap &bm, const uint8_t *data)
|
||||
{
|
||||
#ifdef OGL
|
||||
ogl_freebmtexture(bm);
|
||||
|
@ -65,7 +65,7 @@ grs_bitmap_ptr gr_create_bitmap_raw(uint16_t w, uint16_t h, unsigned char * raw_
|
|||
return n;
|
||||
}
|
||||
|
||||
void gr_init_bitmap(grs_bitmap &bm, uint8_t mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline, unsigned char * data ) // TODO: virtualize
|
||||
void gr_init_bitmap(grs_bitmap &bm, uint8_t mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline, const uint8_t *data) // TODO: virtualize
|
||||
{
|
||||
bm.bm_x = x;
|
||||
bm.bm_y = y;
|
||||
|
|
|
@ -139,7 +139,7 @@ void gr_clear_canvas(color_t color);
|
|||
// Bitmap functions:
|
||||
|
||||
// these are the two workhorses, the others just use these
|
||||
void gr_init_bitmap(grs_bitmap &bm, uint8_t mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline, unsigned char * data);
|
||||
void gr_init_bitmap(grs_bitmap &bm, uint8_t mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline, const uint8_t* data);
|
||||
void gr_init_sub_bitmap (grs_bitmap &bm, grs_bitmap &bmParent, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
|
||||
void gr_init_bitmap_alloc(grs_bitmap &bm, uint8_t mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline);
|
||||
|
@ -164,7 +164,7 @@ void gr_bm_ubitblt(unsigned w, unsigned h, int dx, int dy, int sx, int sy, const
|
|||
void gr_bm_ubitbltm(unsigned w, unsigned h, unsigned dx, unsigned dy, unsigned sx, unsigned sy, const grs_bitmap &src, grs_bitmap &dest);
|
||||
#define gr_settransblend(A,B) gr_settransblend(A)
|
||||
#endif
|
||||
void gr_set_bitmap_data(grs_bitmap &bm, unsigned char *data);
|
||||
void gr_set_bitmap_data(grs_bitmap &bm, const uint8_t *data);
|
||||
}
|
||||
|
||||
#ifdef dsx
|
||||
|
|
|
@ -85,9 +85,9 @@ struct grs_font : public prohibit_void_ptr<grs_font>
|
|||
ubyte ft_minchar; // First char defined by this font
|
||||
ubyte ft_maxchar; // Last char defined by this font
|
||||
array<char, 13> ft_filename;
|
||||
ubyte * ft_data; // Ptr to raw data.
|
||||
std::unique_ptr<ubyte *[]> ft_chars; // Ptrs to data for each char (required for prop font)
|
||||
short * ft_widths; // Array of widths (required for prop font)
|
||||
const uint8_t *ft_data; // Ptr to raw data.
|
||||
const uint8_t *const *ft_chars; // Ptrs to data for each char (required for prop font)
|
||||
const int16_t *ft_widths; // Array of widths (required for prop font)
|
||||
const uint8_t *ft_kerndata; // Array of kerning triplet data
|
||||
std::unique_ptr<uint8_t[]> ft_allocdata;
|
||||
#ifdef OGL
|
||||
|
|
|
@ -345,7 +345,6 @@ static int gr_internal_color_string(int x, int y, const char *s )
|
|||
grs_bitmap char_bm = {};
|
||||
char_bm.set_type(BM_LINEAR);
|
||||
char_bm.bm_flags = BM_FLAG_TRANSPARENT;
|
||||
unsigned char * fp;
|
||||
const char *text_ptr, *next_row, *text_ptr1;
|
||||
int letter;
|
||||
int xx,yy;
|
||||
|
@ -391,10 +390,9 @@ static int gr_internal_color_string(int x, int y, const char *s )
|
|||
continue;
|
||||
}
|
||||
|
||||
if (cv_font.ft_flags & FT_PROPORTIONAL)
|
||||
fp = cv_font.ft_chars[letter];
|
||||
else
|
||||
fp = &cv_font.ft_data[letter * BITS_TO_BYTES(width) * cv_font.ft_h];
|
||||
const auto fp = (cv_font.ft_flags & FT_PROPORTIONAL)
|
||||
? cv_font.ft_chars[letter]
|
||||
: &cv_font.ft_data[letter * BITS_TO_BYTES(width) * cv_font.ft_h];
|
||||
|
||||
gr_init_bitmap(char_bm, BM_LINEAR, 0, 0, width, cv_font.ft_h, width, fp);
|
||||
gr_bitmapm(xx,yy,char_bm);
|
||||
|
@ -499,7 +497,6 @@ static void ogl_init_font(grs_font * font)
|
|||
int oglflags = OGL_FLAG_ALPHA;
|
||||
int nchars = font->ft_maxchar-font->ft_minchar+1;
|
||||
int w,h,tw,th,curx=0,cury=0;
|
||||
unsigned char *fp;
|
||||
ubyte *data;
|
||||
int gap=1; // x/y offset between the chars so we can filter
|
||||
|
||||
|
@ -539,10 +536,9 @@ static void ogl_init_font(grs_font * font)
|
|||
|
||||
if (font->ft_flags & FT_COLOR)
|
||||
{
|
||||
if (font->ft_flags & FT_PROPORTIONAL)
|
||||
fp = font->ft_chars[i];
|
||||
else
|
||||
fp = font->ft_data + i * w*h;
|
||||
const auto fp = (font->ft_flags & FT_PROPORTIONAL)
|
||||
? font->ft_chars[i]
|
||||
: font->ft_data + i * w*h;
|
||||
for (int y=0;y<h;y++)
|
||||
{
|
||||
for (int x=0;x<w;x++)
|
||||
|
@ -574,10 +570,9 @@ static void ogl_init_font(grs_font * font)
|
|||
else
|
||||
{
|
||||
int BitMask,bits=0,white=gr_find_closest_color(63,63,63);
|
||||
if (font->ft_flags & FT_PROPORTIONAL)
|
||||
fp = font->ft_chars[i];
|
||||
else
|
||||
fp = font->ft_data + i * BITS_TO_BYTES(w)*h;
|
||||
auto fp = (font->ft_flags & FT_PROPORTIONAL)
|
||||
? font->ft_chars[i]
|
||||
: font->ft_data + i * BITS_TO_BYTES(w)*h;
|
||||
for (int y=0;y<h;y++){
|
||||
BitMask=0;
|
||||
for (int x=0; x< w; x++ )
|
||||
|
@ -895,7 +890,8 @@ static void grs_font_read(grs_font *gf, PHYSFS_File *fp)
|
|||
|
||||
static std::unique_ptr<grs_font> gr_internal_init_font(const char *fontname)
|
||||
{
|
||||
unsigned char * ptr;
|
||||
const uint8_t *ptr;
|
||||
uint8_t *ft_data;
|
||||
struct {
|
||||
array<char, 4> magic;
|
||||
unsigned datasize; //size up to (but not including) palette
|
||||
|
@ -923,15 +919,19 @@ static std::unique_ptr<grs_font> gr_internal_init_font(const char *fontname)
|
|||
auto font = make_unique<grs_font>();
|
||||
grs_font_read(font.get(), fontfile);
|
||||
|
||||
auto font_data = make_unique<uint8_t[]>(datasize);
|
||||
const unsigned nchars = font->ft_maxchar - font->ft_minchar + 1;
|
||||
std::size_t ft_chars_storage = (font->ft_flags & FT_PROPORTIONAL)
|
||||
? sizeof(uint8_t *) * nchars
|
||||
: 0;
|
||||
|
||||
auto ft_allocdata = make_unique<uint8_t[]>(datasize + ft_chars_storage);
|
||||
const auto font_data = &ft_allocdata[ft_chars_storage];
|
||||
if (PHYSFS_read(fontfile, font_data, 1, datasize) != datasize)
|
||||
{
|
||||
con_printf(CON_URGENT, "Insufficient data in font file %s", fontname);
|
||||
return {};
|
||||
}
|
||||
|
||||
const unsigned nchars = font->ft_maxchar - font->ft_minchar + 1;
|
||||
|
||||
if (font->ft_flags & FT_PROPORTIONAL) {
|
||||
const auto offset_widths = reinterpret_cast<uintptr_t>(font->ft_widths);
|
||||
auto w = reinterpret_cast<short *>(&font_data[offset_widths]);
|
||||
|
@ -947,14 +947,13 @@ static std::unique_ptr<grs_font> gr_internal_init_font(const char *fontname)
|
|||
con_printf(CON_URGENT, "Missing data in font file %s", fontname);
|
||||
return {};
|
||||
}
|
||||
font->ft_data = reinterpret_cast<unsigned char *>(&font_data[offset_data]);
|
||||
font->ft_chars = make_unique<uint8_t *[]>(nchars);
|
||||
|
||||
ptr = font->ft_data;
|
||||
font->ft_data = ptr = ft_data = reinterpret_cast<unsigned char *>(&font_data[offset_data]);
|
||||
const auto ft_chars = reinterpret_cast<const uint8_t **>(ft_allocdata.get());
|
||||
font->ft_chars = reinterpret_cast<const uint8_t *const *>(ft_chars);
|
||||
|
||||
const unsigned is_color = font->ft_flags & FT_COLOR;
|
||||
const unsigned ft_h = font->ft_h;
|
||||
std::generate_n(font->ft_chars.get(), nchars, [is_color, ft_h, &w, &ptr]{
|
||||
std::generate_n(ft_chars, nchars, [is_color, ft_h, &w, &ptr]{
|
||||
const unsigned s = INTEL_SHORT(*w);
|
||||
if (words_bigendian)
|
||||
*w = static_cast<uint16_t>(s);
|
||||
|
@ -965,7 +964,7 @@ static std::unique_ptr<grs_font> gr_internal_init_font(const char *fontname)
|
|||
});
|
||||
} else {
|
||||
|
||||
font->ft_data = font_data.get();
|
||||
font->ft_data = ft_data = font_data;
|
||||
font->ft_widths = NULL;
|
||||
|
||||
ptr = font->ft_data + (nchars * font->ft_w * font->ft_h);
|
||||
|
@ -1007,13 +1006,13 @@ static std::unique_ptr<grs_font> gr_internal_init_font(const char *fontname)
|
|||
|
||||
colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR; // changed from colormap[255] = 255 to this for macintosh
|
||||
|
||||
decode_data(font->ft_data, ptr - font->ft_data, colormap, freq );
|
||||
decode_data(ft_data, ptr - font->ft_data, colormap, freq );
|
||||
}
|
||||
fontfile.reset();
|
||||
//set curcanv vars
|
||||
|
||||
auto &ft_filename = font->ft_filename;
|
||||
font->ft_allocdata = move(font_data);
|
||||
font->ft_allocdata = move(ft_allocdata);
|
||||
strncpy(&ft_filename[0], fontname, ft_filename.size());
|
||||
return font;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue