コード例 #1
0
ファイル: thin3d.cpp プロジェクト: beaumanvienna/native
// TODO: Remove the code duplication between this and LoadFromFileData
Thin3DTexture *Thin3DContext::CreateTextureFromFileData(const uint8_t *data, int size, T3DImageType type) {
	int width[16], height[16], zim_flags = 0;
	uint8_t *image[16] = { nullptr };

	int num_levels = 0;
	T3DImageFormat fmt;

	if (type == DETECT) {
		type = DetectImageFileType(data, size);
	}
	if (type == TYPE_UNKNOWN) {
		ELOG("File has unknown format");
		return nullptr;
	}

	switch (type) {
	case ZIM:
		num_levels = LoadZIMPtr((const uint8_t *)data, size, width, height, &zim_flags, image);
		fmt = ZimToT3DFormat(zim_flags & ZIM_FORMAT_MASK);
		break;

	case PNG:
		if (1 != pngLoadPtr((const unsigned char *)data, size, &width[0], &height[0], &image[0], false)) {
			return NULL;
		}
		num_levels = 1;
		fmt = RGBA8888;
		break;

	default:
		ELOG("Unknown image format");
		return nullptr;
	}

	if (num_levels == 0) {
		return NULL;
	}

	Thin3DTexture *tex = CreateTexture(LINEAR2D, fmt, width[0], height[0], 1, num_levels);
	for (int i = 0; i < num_levels; i++) {
		tex->SetImageData(0, 0, 0, width[i], height[i], 1, i, width[i] * 4, image[i]);
		free(image[i]);
	}

	tex->Finalize(zim_flags);
	return tex;
}
コード例 #2
0
ファイル: thin3d.cpp プロジェクト: Edvaderprime33/native
// TODO: Remove the code duplication between this and LoadFromFileData
Thin3DTexture *Thin3DContext::CreateTextureFromFileData(const uint8_t *data, int size, T3DImageType type) {
	int width[16], height[16];
	int num_levels = 0;
	int zim_flags = 0;
	T3DImageFormat fmt;
	uint8_t *image[16] = { nullptr };

	if (!LoadTextureLevels(data, size, type, width, height, &num_levels, &fmt, image, &zim_flags)) {
		return NULL;
	}

	Thin3DTexture *tex = CreateTexture(LINEAR2D, fmt, width[0], height[0], 1, num_levels);
	for (int i = 0; i < num_levels; i++) {
		tex->SetImageData(0, 0, 0, width[i], height[i], 1, i, width[i] * 4, image[i]);
		free(image[i]);
	}

	tex->Finalize(zim_flags);
	return tex;
}