BaseSurface *BaseSurfaceStorage::addSurface(const Common::String &filename, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime, bool keepLoaded) {
	for (uint32 i = 0; i < _surfaces.size(); i++) {
		if (scumm_stricmp(_surfaces[i]->getFileName(), filename.c_str()) == 0) {
			_surfaces[i]->_referenceCount++;
			return _surfaces[i];
		}
	}

	if (!BaseFileManager::getEngineInstance()->hasFile(filename)) {
		if (filename.size()) {
			_gameRef->LOG(0, "Missing image: '%s'", filename.c_str());
		}
		if (_gameRef->_debugDebugMode) {
			return addSurface("invalid_debug.bmp", defaultCK, ckRed, ckGreen, ckBlue, lifeTime, keepLoaded);
		} else {
			return addSurface("invalid.bmp", defaultCK, ckRed, ckGreen, ckBlue, lifeTime, keepLoaded);
		}
	}

	BaseSurface *surface;
	surface = _gameRef->_renderer->createSurface();

	if (!surface) {
		return NULL;
	}

	if (DID_FAIL(surface->create(filename, defaultCK, ckRed, ckGreen, ckBlue, lifeTime, keepLoaded))) {
		delete surface;
		return NULL;
	} else {
		surface->_referenceCount = 1;
		_surfaces.push_back(surface);
		return surface;
	}
}
Example #2
0
void BaseSurface::flipHorizontal(BaseSurface &dest) {
	dest.create(this->w, this->h);
	for (int y = 0; y < h; ++y) {
		const byte *pSrc = (const byte *)getBasePtr(this->w - 1, y);
		byte *pDest = (byte *)dest.getBasePtr(0, y);

		for (int x = 0; x < w; ++x, --pSrc, ++pDest)
			*pDest = *pSrc;
	}
}