diff options
author | Paul Gilbert | 2018-11-18 20:29:14 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | bd86fd7bbf19324e06834ee8f2e08e7e0df02e14 (patch) | |
tree | 825c11b8f6f7c1f51c4e3cfd8954cda1502f57be /engines/glk/picture.cpp | |
parent | 0f0b8ae3b72d066259332a728eab1edc760de5df (diff) | |
download | scummvm-rg350-bd86fd7bbf19324e06834ee8f2e08e7e0df02e14.tar.gz scummvm-rg350-bd86fd7bbf19324e06834ee8f2e08e7e0df02e14.tar.bz2 scummvm-rg350-bd86fd7bbf19324e06834ee8f2e08e7e0df02e14.zip |
GLK: Implementing picture loading
Diffstat (limited to 'engines/glk/picture.cpp')
-rw-r--r-- | engines/glk/picture.cpp | 109 |
1 files changed, 99 insertions, 10 deletions
diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp index b87b1297eb..8461983c45 100644 --- a/engines/glk/picture.cpp +++ b/engines/glk/picture.cpp @@ -21,15 +21,109 @@ */ #include "glk/picture.h" +#include "common/file.h" +#include "image/jpeg.h" +#include "image/png.h" namespace Glk { -void PicList::increment() { - // TODO +void Pictures::clear() { + for (uint idx = 0; idx < _store.size(); ++idx) { + delete _store[idx]._picture; + delete _store[idx]._scaled; + } + + _store.clear(); +} + +void Pictures::increment() { + ++_refCount; +} + +void Pictures::decrement() { + if (_refCount > 0 && --_refCount == 0) + clear(); +} + +PictureEntry *Pictures::search(uint id) { + Picture *pic; + + for (uint idx = 0; idx < _store.size(); ++idx) { + pic = _store[idx]._picture; + + if (pic && pic->_id == id) + return &_store[idx]; + } + + return nullptr; +} + +void Pictures::storeOriginal(Picture *pic) { + PictureEntry newPic; + newPic._picture = pic; + + _store.push_back(newPic); +} + +void Pictures::storeScaled(Picture *pic) { + PictureEntry *entry = search(pic->_id); + if (!entry) + return; + + delete entry->_scaled; + entry->_scaled = pic; } -void PicList::decrement() { - // TODO +void Pictures::store(Picture *pic) { + if (!pic) + return; + + if (!pic->_scaled) + storeOriginal(pic); + else + storeScaled(pic); +} + +Picture *Pictures::retrieve(uint id, bool scaled) { + Picture *pic; + + for (uint idx = 0; idx < _store.size(); ++idx) { + pic = scaled ? _store[idx]._scaled : _store[idx]._picture; + + if (pic && pic->_id == id) + return pic; + } + + return nullptr; +} + +Picture *Pictures::load(uint32 id) { + ::Image::PNGDecoder png; + ::Image::JPEGDecoder jpg; + const Graphics::Surface *img; + Picture *pic; + + // Check if the picture is already in the store + pic = retrieve(id, false); + if (pic) + return pic; + + Common::File f; + if (f.open(Common::String::format("PIC%lu.png", id))) { + png.loadStream(f); + img = png.getSurface(); + } else if (f.open(Common::String::format("PIC%lu.jpg", id))) { + jpg.loadStream(f); + img = jpg.getSurface(); + } + + pic = new Picture(); + pic->_refCount = 1; + pic->_id = id; + pic->_scaled = false; + + store(pic); + return pic; } /*--------------------------------------------------------------------------*/ @@ -40,16 +134,11 @@ void Picture::increment() { void Picture::decrement() { if (_refCount > 0 && --_refCount == 0) { - free(); + // No longer any references to this picture, so remove it delete this; } } -Picture *Picture::load(uint32 id) { - // TODO: gli_picture_load - return nullptr; -} - Picture *Picture::scale(int sx, int sy) { // TODO: gli_picture_scale return nullptr; |