diff options
author | Strangerke | 2011-07-12 07:24:20 +0200 |
---|---|---|
committer | Strangerke | 2011-07-12 07:24:20 +0200 |
commit | dab96401ad352512a8ffa8c1d7baeb431ade7b8c (patch) | |
tree | 8f5a019d1702c9ad626de5c1ffde2cb481c38380 /engines/cge/bitmap.cpp | |
parent | 9ba5e2b304e6ba7ca9d0b782ad8e5dfd98317b02 (diff) | |
download | scummvm-rg350-dab96401ad352512a8ffa8c1d7baeb431ade7b8c.tar.gz scummvm-rg350-dab96401ad352512a8ffa8c1d7baeb431ade7b8c.tar.bz2 scummvm-rg350-dab96401ad352512a8ffa8c1d7baeb431ade7b8c.zip |
CGE: Implement snGhost by splitting _m field in two. Some cleanup.
Diffstat (limited to 'engines/cge/bitmap.cpp')
-rw-r--r-- | engines/cge/bitmap.cpp | 317 |
1 files changed, 150 insertions, 167 deletions
diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index a8264e6c3f..48bfe1fafb 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -46,7 +46,7 @@ void Bitmap::deinit() { } #pragma argsused -Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { +Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { char pat[MAXPATH]; forceExt(pat, fname, ".VBM"); @@ -78,7 +78,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { } -Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) { +Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0) { if (map) code(); } @@ -90,7 +90,8 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) : _w((w + 3) & ~3), // only full uint32 allowed! _h(h), - _m(NULL) { + _m(NULL), + _map(0) { uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = _h * lsiz; // - last gape, but + plane trailer @@ -128,7 +129,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) } -Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { +Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { uint8 *v0 = bmp._v; if (v0) { uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); @@ -143,20 +144,9 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { Bitmap::~Bitmap() { - if (memType(_m) == FAR_MEM) + if (_m) free(_m); - - switch (memType(_v)) { - case NEAR_MEM : - delete[](uint8 *) _v; - break; - case FAR_MEM : - delete[] _v; - default: - warning("Unhandled MemType in Bitmap destructor"); - break; - break; - } + delete[] _v; } @@ -165,6 +155,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _w = bmp._w; _h = bmp._h; _m = NULL; + _map = 0; if (memType(_v) == FAR_MEM) free(_v); if (v0 == NULL) @@ -197,128 +188,120 @@ uint16 Bitmap::moveVmap(uint8 *buf) { BMP_PTR Bitmap::code() { - if (_m) { - uint16 i, cnt; - - if (_v) { // old X-map exists, so remove it - switch (memType(_v)) { - case NEAR_MEM : - delete[](uint8 *) _v; - break; - case FAR_MEM : - delete[] _v; - break; - default: - warning("Unhandled MemType in Bitmap::Code()"); - break; - } - _v = NULL; - } + if (!_m) + return false; - while (true) { // at most 2 times: for (V == NULL) & for allocated block; - uint8 *im = _v + 2; - uint16 *cp = (uint16 *) _v; - int bpl; + uint16 i, cnt; - if (_v) { // 2nd pass - fill the hide table - for (i = 0; i < _h; i++) { - _b[i].skip = 0xFFFF; - _b[i].hide = 0x0000; - } + if (_v) { // old X-map exists, so remove it + delete[] _v; + _v = NULL; + } + + while (true) { // at most 2 times: for (V == NULL) & for allocated block; + uint8 *im = _v + 2; + uint16 *cp = (uint16 *) _v; + int bpl; + + if (_v) { // 2nd pass - fill the hide table + for (i = 0; i < _h; i++) { + _b[i].skip = 0xFFFF; + _b[i].hide = 0x0000; } - for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane - uint8 *bm = _m; - bool skip = (bm[bpl] == TRANS); - uint16 j; - - cnt = 0; - for (i = 0; i < _h; i++) { // once per each line - uint8 pix; - for (j = bpl; j < _w; j += 4) { - pix = bm[j]; - if (_v && pix != TRANS) { - if (j < _b[i].skip) - _b[i].skip = j; - - if (j >= _b[i].hide) - _b[i].hide = j + 1; - } - if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block - cnt |= (skip) ? SKP : CPY; - if (_v) - *cp = cnt; // store block description uint16 - - cp = (uint16 *) im; - im += 2; - skip = (pix == TRANS); - cnt = 0; - } - if (! skip) { - if (_v) - *im = pix; - ++ im; - } - ++ cnt; + } + for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane + uint8 *bm = _m; + bool skip = (bm[bpl] == TRANS); + uint16 j; + + cnt = 0; + for (i = 0; i < _h; i++) { // once per each line + uint8 pix; + for (j = bpl; j < _w; j += 4) { + pix = bm[j]; + if (_v && pix != TRANS) { + if (j < _b[i].skip) + _b[i].skip = j; + + if (j >= _b[i].hide) + _b[i].hide = j + 1; } - - bm += _w; - if (_w < SCR_WID) { - if (skip) { - cnt += (SCR_WID - j + 3) / 4; - } else { - cnt |= CPY; - if (_v) - *cp = cnt; - - cp = (uint16 *) im; - im += 2; - skip = true; - cnt = (SCR_WID - j + 3) / 4; - } + if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block + cnt |= (skip) ? SKP : CPY; + if (_v) + *cp = cnt; // store block description uint16 + + cp = (uint16 *) im; + im += 2; + skip = (pix == TRANS); + cnt = 0; } + if (! skip) { + if (_v) + *im = pix; + ++ im; + } + ++ cnt; } - if (cnt && ! skip) { - cnt |= CPY; - if (_v) - *cp = cnt; - cp = (uint16 *) im; - im += 2; + bm += _w; + if (_w < SCR_WID) { + if (skip) { + cnt += (SCR_WID - j + 3) / 4; + } else { + cnt |= CPY; + if (_v) + *cp = cnt; + + cp = (uint16 *) im; + im += 2; + skip = true; + cnt = (SCR_WID - j + 3) / 4; + } } + } + if (cnt && ! skip) { + cnt |= CPY; if (_v) - *cp = EOI; + *cp = cnt; + cp = (uint16 *) im; im += 2; } if (_v) - break; + *cp = EOI; + cp = (uint16 *) im; + im += 2; + } + if (_v) + break; - uint16 sizV = (uint16)(im - 2 - _v); - _v = new uint8[sizV + _h * sizeof(*_b)]; - if (!_v) - error("No core"); + uint16 sizV = (uint16)(im - 2 - _v); + _v = new uint8[sizV + _h * sizeof(*_b)]; + if (!_v) + error("No core"); - _b = (HideDesc *)(_v + sizV); - } - cnt = 0; - for (i = 0; i < _h; i++) { - if (_b[i].skip == 0xFFFF) { // whole line is skipped - _b[i].skip = (cnt + SCR_WID) >> 2; - cnt = 0; - } else { - uint16 s = _b[i].skip & ~3; - uint16 h = (_b[i].hide + 3) & ~3; - _b[i].skip = (cnt + s) >> 2; - _b[i].hide = (h - s) >> 2; - cnt = SCR_WID - h; - } + _b = (HideDesc *)(_v + sizV); + } + cnt = 0; + for (i = 0; i < _h; i++) { + if (_b[i].skip == 0xFFFF) { // whole line is skipped + _b[i].skip = (cnt + SCR_WID) >> 2; + cnt = 0; + } else { + uint16 s = _b[i].skip & ~3; + uint16 h = (_b[i].hide + 3) & ~3; + _b[i].skip = (cnt + s) >> 2; + _b[i].hide = (h - s) >> 2; + cnt = SCR_WID - h; } } + return this; } -bool Bitmap::solidAt(int x, int y) { +bool Bitmap::solidAt(int16 x, int16 y) { uint8 *m; uint16 r, n, n0; @@ -447,58 +430,58 @@ bool Bitmap::loadVBM(XFile *f) { } bool Bitmap::loadBMP(XFile *f) { - struct { - char BM[2]; - union { int16 len; int32 len_; }; - union { int16 _06; int32 _06_; }; - union { int16 hdr; int32 hdr_; }; - union { int16 _0E; int32 _0E_; }; - union { int16 wid; int32 wid_; }; - union { int16 hig; int32 hig_; }; - union { int16 _1A; int32 _1A_; }; - union { int16 _1E; int32 _1E_; }; - union { int16 _22; int32 _22_; }; - union { int16 _26; int32 _26_; }; - union { int16 _2A; int32 _2A_; }; - union { int16 _2E; int32 _2E_; }; - union { int16 _32; int32 _32_; }; - } hea; - - Bgr4 bpal[256]; - - f->read((byte *)&hea, sizeof(hea)); - if (f->_error == 0) { - if (hea.hdr == 0x436L) { - int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); - f->read((byte *)&bpal, sizeof(bpal)); - if (f->_error == 0) { - if (_pal) { - for (i = 0; i < 256; i ++) { - _pal[i]._r = bpal[i]._R; - _pal[i]._g = bpal[i]._G; - _pal[i]._b = bpal[i]._B; + struct { + char BM[2]; + union { int16 len; int32 len_; }; + union { int16 _06; int32 _06_; }; + union { int16 hdr; int32 hdr_; }; + union { int16 _0E; int32 _0E_; }; + union { int16 wid; int32 wid_; }; + union { int16 hig; int32 hig_; }; + union { int16 _1A; int32 _1A_; }; + union { int16 _1E; int32 _1E_; }; + union { int16 _22; int32 _22_; }; + union { int16 _26; int32 _26_; }; + union { int16 _2A; int32 _2A_; }; + union { int16 _2E; int32 _2E_; }; + union { int16 _32; int32 _32_; }; + } hea; + + Bgr4 bpal[256]; + + f->read((byte *)&hea, sizeof(hea)); + if (f->_error == 0) { + if (hea.hdr == 0x436L) { + int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); + f->read((byte *)&bpal, sizeof(bpal)); + if (f->_error == 0) { + if (_pal) { + for (i = 0; i < 256; i ++) { + _pal[i]._r = bpal[i]._R; + _pal[i]._g = bpal[i]._G; + _pal[i]._b = bpal[i]._B; + } + _pal = NULL; + } + _h = hea.hig; + _w = hea.wid; + if ((_m = farnew(byte, _h * _w)) != NULL) { + int16 r = (4 - (hea.wid & 3)) % 4; + byte buf[3]; + for (i = _h - 1; i >= 0; i--) { + f->read(_m + (_w * i), _w); + if (r && f->_error == 0) + f->read(buf, r); + if (f->_error) + break; + } + if (i < 0) + return true; + } } - _pal = NULL; - } - _h = hea.hig; - _w = hea.wid; - if ((_m = farnew(byte, _h * _w)) != NULL) { - int16 r = (4 - (hea.wid & 3)) % 4; - byte buf[3]; - for (i = _h - 1; i >= 0; i--) { - f->read(_m + (_w * i), _w); - if (r && f->_error == 0) - f->read(buf, r); - if (f->_error) - break; - } - if (i < 0) - return true; } - } } - } - return false; + return false; } } // End of namespace CGE |