Exemplo n.º 1
0
void TXB::readData(Common::SeekableReadStream &txb, bool needDeSwizzle) {
    for (std::vector<MipMap *>::iterator mipMap = _mipMaps.begin(); mipMap != _mipMaps.end(); ++mipMap) {

        // If the texture width is a power of two, the texture memory layout is "swizzled"
        const bool widthPOT = ((*mipMap)->width & ((*mipMap)->width - 1)) == 0;
        const bool swizzled = needDeSwizzle && widthPOT;

        (*mipMap)->data = new byte[(*mipMap)->size];

        if (swizzled) {
            byte *tmp = new byte[(*mipMap)->size];

            if (txb.read(tmp, (*mipMap)->size) != (*mipMap)->size)
                throw Common::Exception(Common::kReadError);

            deSwizzle((*mipMap)->data, tmp, (*mipMap)->width, (*mipMap)->height);

            delete[] tmp;

        } else {
            if (txb.read((*mipMap)->data, (*mipMap)->size) != (*mipMap)->size)
                throw Common::Exception(Common::kReadError);
        }

    }
}
Exemplo n.º 2
0
void TPC::readData(Common::SeekableReadStream &tpc, byte encoding) {
	for (std::vector<MipMap *>::iterator mipMap = _mipMaps.begin(); mipMap != _mipMaps.end(); ++mipMap) {

		// If the texture width is a power of two, the texture memory layout is "swizzled"
		const bool widthPOT = ((*mipMap)->width & ((*mipMap)->width - 1)) == 0;
		const bool swizzled = (encoding == kEncodingSwizzledBGRA) && widthPOT;

		(*mipMap)->data = new byte[(*mipMap)->size];

		if (swizzled) {
			std::vector<byte> tmp((*mipMap)->size);

			if (tpc.read(&tmp[0], (*mipMap)->size) != (*mipMap)->size)
				throw Common::Exception(Common::kReadError);

			deSwizzle((*mipMap)->data, &tmp[0], (*mipMap)->width, (*mipMap)->height);

		} else {
			if (tpc.read((*mipMap)->data, (*mipMap)->size) != (*mipMap)->size)
				throw Common::Exception(Common::kReadError);

			// Unpacking 8bpp grayscale data into RGB
			if (encoding == kEncodingGray) {
				byte *dataGray = (*mipMap)->data;

				(*mipMap)->size = (*mipMap)->width * (*mipMap)->height * 3;
				(*mipMap)->data = new byte[(*mipMap)->size];

				for (int i = 0; i < ((*mipMap)->width * (*mipMap)->height); i++)
					memset((*mipMap)->data + i * 3, dataGray[i], 3);

				delete[] dataGray;
			}
		}

	}
}