Beispiel #1
0
bool SavedataParam::CreatePNGIcon(u8* pngData, int pngSize, SaveFileInfo& info)
{
	unsigned char *textureData;
	int w,h;

	int success = pngLoadPtr(pngData, (int)pngSize, &w, &h, &textureData, false);

	u32 texSize = w*h*4;
	u32 atlasPtr;
	if (success)
		atlasPtr = kernelMemory.Alloc(texSize, true, "SaveData Icon");
	if (success && atlasPtr != -1)
	{
		info.textureData = atlasPtr;
		Memory::Memcpy(atlasPtr, textureData, texSize);
		free(textureData);
		info.textureWidth = w;
		info.textureHeight = h;
	}
	else
	{
		WARN_LOG(HLE, "Unable to load PNG data for savedata.");
		return false;
	}
	return true;
}
Beispiel #2
0
// 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;
}
Beispiel #3
0
static bool LoadTextureLevels(const uint8_t *data, size_t size, T3DImageType type, int width[16], int height[16], int *num_levels, T3DImageFormat *fmt, uint8_t *image[16], int *zim_flags) {
	if (type == DETECT) {
		type = DetectImageFileType(data, size);
	}
	if (type == TYPE_UNKNOWN) {
		ELOG("File has unknown format");
		return false;
	}

	*num_levels = 0;
	*zim_flags = 0;

	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)) {
			*num_levels = 1;
			*fmt = RGBA8888;
		}
		break;

	case JPEG:
		{
			int actual_components = 0;
			unsigned char *jpegBuf = jpgd::decompress_jpeg_image_from_memory(data, (int)size, &width[0], &height[0], &actual_components, 4);
			if (jpegBuf) {
				*num_levels = 1;
				*fmt = RGBA8888;
				image[0] = (uint8_t *)jpegBuf;
			}
		}
		break;

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

	return *num_levels > 0;
}
Beispiel #4
0
	HBITMAP LoadImageFromResource(HINSTANCE hInstance,LPCTSTR pszResourceName, LPCTSTR lpType)
	{
		HRSRC hrsrc = FindResource(hInstance, pszResourceName, lpType);
		if (!hrsrc)
			return FALSE;
		DWORD dwlen = SizeofResource(hInstance, hrsrc);
		BYTE *lpRsrc = (BYTE*)LoadResource(hInstance, hrsrc);
		if (!lpRsrc)
			return FALSE;
		int width, height;
		unsigned char *image_data = 0;
		bool bResult = pngLoadPtr(lpRsrc, dwlen, &width, &height, &image_data, false) != 0;
		FreeResource(lpRsrc);
		if (!bResult)
			return 0;
		HBITMAP hbm = CreateBitmap(width, height, 1, 32, image_data);
		free(image_data);
		return hbm;
	}
Beispiel #5
0
bool Texture::LoadPNG(const uint8_t *data, size_t size, bool genMips) {
	unsigned char *image_data;
	if (1 != pngLoadPtr(data, size, &width_, &height_, &image_data, false)) {
		return false;
	}
	GL_CHECK();
	// TODO: should check for power of 2 tex size and disallow genMips when not.
	glGenTextures(1, &id_);
	glBindTexture(GL_TEXTURE_2D, id_);
	SetTextureParameters(genMips ? ZIM_GEN_MIPS : ZIM_CLAMP);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
	if (genMips) {
		if (gl_extensions.FBO_ARB) {
			glGenerateMipmap(GL_TEXTURE_2D);
		} else {
#ifndef USING_GLES2
			glGenerateMipmapEXT(GL_TEXTURE_2D);
#endif
		}
	}
	GL_CHECK();
	free(image_data);
	return true;
}