mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-01 06:50:59 +00:00
[image] Add function to get image memory size
This commit is contained in:
parent
785be9d340
commit
40aa629ef8
2 changed files with 30 additions and 0 deletions
|
@ -53,6 +53,8 @@ typedef struct tex_s {
|
||||||
|
|
||||||
tex_t *LoadImage (const char *imageFile, int load);
|
tex_t *LoadImage (const char *imageFile, int load);
|
||||||
|
|
||||||
|
size_t ImageSize (const tex_t *tex, int incl_struct) __attribute__((pure));
|
||||||
|
|
||||||
typedef struct colcache_s colcache_t;
|
typedef struct colcache_s colcache_t;
|
||||||
|
|
||||||
colcache_t *ColorCache_New (void);
|
colcache_t *ColorCache_New (void);
|
||||||
|
|
|
@ -106,3 +106,31 @@ LoadImage (const char *imageFile, int load)
|
||||||
dstring_delete (tmpFile);
|
dstring_delete (tmpFile);
|
||||||
return (tex);
|
return (tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
ImageSize (const tex_t *tex, int incl_struct)
|
||||||
|
{
|
||||||
|
size_t w =tex->width;
|
||||||
|
size_t h =tex->height;
|
||||||
|
size_t bpp = 1;
|
||||||
|
switch (tex->format) {
|
||||||
|
case tex_palette:
|
||||||
|
case tex_rgb:
|
||||||
|
bpp = 3;
|
||||||
|
break;
|
||||||
|
case tex_l:
|
||||||
|
case tex_a:
|
||||||
|
bpp = 1;
|
||||||
|
break;
|
||||||
|
case tex_la:
|
||||||
|
bpp = 2;
|
||||||
|
break;
|
||||||
|
case tex_rgba:
|
||||||
|
bpp = 4;
|
||||||
|
break;
|
||||||
|
case tex_frgba:
|
||||||
|
bpp = 16;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return bpp * w * h + (incl_struct ? sizeof (tex_t) : 0);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue