|
@@ -58,29 +58,27 @@ static bool RegisterAllLoaders() |
|
|
* Our static image loader |
|
|
* Our static image loader |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
static class ImageLoader |
|
|
|
|
|
|
|
|
static class ImageBank |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
void Init(); |
|
|
void Init(); |
|
|
Image *Create(char const *path); |
|
|
Image *Create(char const *path); |
|
|
Image *Get(char const *path); |
|
|
|
|
|
Image *Load(char const *path); |
|
|
|
|
|
Image *Store(char const *path, Image *image); |
|
|
|
|
|
void Destroy(Image *img); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Unref(Image *img); |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
Map<String, Image *> m_images; |
|
|
Map<String, Image *> m_images; |
|
|
} |
|
|
} |
|
|
image_loader; |
|
|
|
|
|
|
|
|
g_image_bank; |
|
|
|
|
|
|
|
|
void ImageLoader::Init() |
|
|
|
|
|
|
|
|
void ImageBank::Init() |
|
|
{ |
|
|
{ |
|
|
/* Initialise loaders (see above) */ |
|
|
/* Initialise loaders (see above) */ |
|
|
static bool init = RegisterAllLoaders(); |
|
|
static bool init = RegisterAllLoaders(); |
|
|
UNUSED(init); |
|
|
UNUSED(init); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Image *ImageLoader::Create(char const *path) |
|
|
|
|
|
|
|
|
Image *ImageBank::Create(char const *path) |
|
|
{ |
|
|
{ |
|
|
Init(); |
|
|
Init(); |
|
|
|
|
|
|
|
@@ -93,7 +91,8 @@ Image *ImageLoader::Create(char const *path) |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
m_images[path] = Load(path); |
|
|
|
|
|
|
|
|
m_images[path] = new Image(); |
|
|
|
|
|
m_images[path]->m_data = ImageCodec::Load(path); |
|
|
img = m_images[path]; |
|
|
img = m_images[path]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -101,35 +100,7 @@ Image *ImageLoader::Create(char const *path) |
|
|
return img; |
|
|
return img; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Image *ImageLoader::Get(char const *path) |
|
|
|
|
|
{ |
|
|
|
|
|
/* Is our image already in the bank? If so, no need to create it. */ |
|
|
|
|
|
Image *img; |
|
|
|
|
|
if (m_images.HasKey(path)) |
|
|
|
|
|
{ |
|
|
|
|
|
img = m_images[path]; |
|
|
|
|
|
++img->m_data->m_refcount; |
|
|
|
|
|
return img; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Image *ImageLoader::Load(char const *path) |
|
|
|
|
|
{ |
|
|
|
|
|
Image* img = new Image(); |
|
|
|
|
|
img->m_data = ImageCodec::Load(path); |
|
|
|
|
|
return img; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Image *ImageLoader::Store(char const *path, Image *image) |
|
|
|
|
|
{ |
|
|
|
|
|
m_images[path] = image; |
|
|
|
|
|
++image->m_data->m_refcount; |
|
|
|
|
|
return image; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ImageLoader::Destroy(Image *img) |
|
|
|
|
|
|
|
|
void ImageBank::Unref(Image *img) |
|
|
{ |
|
|
{ |
|
|
ASSERT(img->m_data->m_refcount > 0); |
|
|
ASSERT(img->m_data->m_refcount > 0); |
|
|
if (--img->m_data->m_refcount == 0) |
|
|
if (--img->m_data->m_refcount == 0) |
|
@@ -151,22 +122,7 @@ void ImageLoader::Destroy(Image *img) |
|
|
|
|
|
|
|
|
Image *Image::Create(char const *path) |
|
|
Image *Image::Create(char const *path) |
|
|
{ |
|
|
{ |
|
|
return image_loader.Create(path); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Image *Image::Store(char const *path, Image *img) |
|
|
|
|
|
{ |
|
|
|
|
|
return image_loader.Store(path, img); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Image *Image::Load(char const *path) |
|
|
|
|
|
{ |
|
|
|
|
|
return image_loader.Load(path); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Image::Destroy(Image *img) |
|
|
|
|
|
{ |
|
|
|
|
|
return image_loader.Destroy(img); |
|
|
|
|
|
|
|
|
return g_image_bank.Create(path); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@@ -178,6 +134,11 @@ Image::Image() |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Image::Destroy() |
|
|
|
|
|
{ |
|
|
|
|
|
g_image_bank.Unref(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bool Image::Save(char const *path) |
|
|
bool Image::Save(char const *path) |
|
|
{ |
|
|
{ |
|
|
return m_data->Save(path); |
|
|
return m_data->Save(path); |
|
|