Ejemplo n.º 1
0
Texture *Texture::create(const Common::UString &name) {
	::Aurora::FileType type = ::Aurora::kFileTypeNone;
	ImageDecoder *image = 0;
	ImageDecoder *layers[6] = { 0, 0, 0, 0, 0, 0 };
	TXI *txi = 0;

	try {
		txi = loadTXI(name);

		const bool isFileCubeMap = txi && txi->getFeatures().cube && (txi->getFeatures().fileRange == 6);
		if (isFileCubeMap) {
			// A cube map with each side a separate image file

			for (size_t i = 0; i < 6; i++) {
				const Common::UString side = name + Common::composeString(i);
				Common::SeekableReadStream *imageStream = ResMan.getResource(::Aurora::kResourceImage, side, &type);
				if (!imageStream)
					throw Common::Exception("No such cube side image resource \"%s\"", side.c_str());

				layers[i] = loadImage(imageStream, type, txi);
			}

			image = new CubeMapCombiner(layers);

		} else {
			Common::SeekableReadStream *imageStream = ResMan.getResource(::Aurora::kResourceImage, name, &type);
			if (!imageStream)
				throw Common::Exception("No such image resource \"%s\"", name.c_str());

			// PLT needs extra handling, since they're their own Texture class
			if (type == ::Aurora::kFileTypePLT) {
				delete txi;

				return createPLT(name, imageStream);
			}

			image = loadImage(imageStream, type, txi);
		}

	} catch (Common::Exception &e) {
		delete txi;
		delete image;

		for (size_t i = 0; i < ARRAYSIZE(layers); i++)
			delete layers[i];

		e.add("Failed to create texture \"%s\" (%d)", name.c_str(), type);
		throw;
	}

	return new Texture(name, image, type, txi);
}
Ejemplo n.º 2
0
void Cursor::load() {
	::Aurora::FileType type;

	Common::SeekableReadStream *img = ResMan.getResource(::Aurora::kResourceCursor, _name, &type);
	if (!img)
		throw Common::Exception("No such cursor resource \"%s\"", _name.c_str());

	_hotspotX = 0;
	_hotspotY = 0;

	ImageDecoder *image;
	// Loading the different image formats
	if      (type == ::Aurora::kFileTypeTGA)
		image = new TGA(*img);
	else if (type == ::Aurora::kFileTypeDDS)
		image = new DDS(*img);
	else if (type == ::Aurora::kFileTypeCUR) {
		WinIconImage *cursor = new WinIconImage(*img);

		if (_hotspotX < 0)
			_hotspotX = cursor->getHotspotX();
		if (_hotspotY < 0)
			_hotspotY = cursor->getHotspotY();

		image = cursor;
	} else {
		delete img;
		throw Common::Exception("Unsupported cursor resource type %d", (int) type);
	}

	delete img;

	_width  = image->getMipMap(0).width;
	_height = image->getMipMap(0).height;

	TXI txi;
	txi.getFeatures().filter = false;

	try {
		Texture *texture = new Texture(image, &txi);

		image = 0;

		try {
			_texture = TextureMan.add(texture, _name);
		} catch(...) {
			delete texture;
			throw;
		}

	} catch (...) {
		delete image;
		throw;
	}

	_hotspotX = CLIP(_hotspotX, 0, _width  - 1);
	_hotspotY = CLIP(_hotspotY, 0, _height - 1);
}