Esempio n. 1
0
static void init_key(const char* file_name, el_zip_file_entry_t* key,
	const Uint32 size, char* buffer)
{
	char* ptr;
	Uint32 src_idx, dst_idx, len, count;

	if ((key == 0) || (file_name == 0))
	{
		LOG_ERROR("Invalid key or file_name");

		return;
	}

	memset(key, 0, sizeof(el_zip_file_entry_t));
	memset(buffer, 0, size);

	len = strlen(file_name);
	src_idx = 0;
	dst_idx = 0;

	while ((src_idx < len) && (dst_idx < size))
	{
		ptr = strstr(file_name + src_idx, "./");

		if (ptr != 0)
		{
			count = ptr - file_name + src_idx;

			memcpy(buffer + dst_idx, file_name + src_idx,
				min2u(count, size - dst_idx - 1));
		}
		else
		{
			count = len - src_idx;

			memcpy(buffer + dst_idx, file_name + src_idx,
				min2u(count, size - dst_idx - 1));
		}

		dst_idx += count;
		src_idx += count + 2;
	}

	len = strlen(buffer);

	key->hash = mem_hash(buffer, len);
	key->file_name = buffer;
}
Esempio n. 2
0
static void decompress_block(el_file_ptr file, const Uint32 format,
	const Uint32 x, const Uint32 y, const Uint32 width, const Uint32 height,
	const Uint32 offset, Uint8 *dst)
{
	Uint8 values[64];
	Uint32 i, j, index, count_x, count_y;

	switch (format)
	{
		case DDSFMT_DXT1:
			read_and_decompress_dxt1_block(file, values);
			break;
		case DDSFMT_DXT2:
		case DDSFMT_DXT3:
			read_and_decompress_dxt3_block(file, values);
			break;
		case DDSFMT_DXT4:
		case DDSFMT_DXT5:
			read_and_decompress_dxt5_block(file, values);
			break;
		case DDSFMT_ATI1:
			read_and_decompress_ati1_block(file, values);
			break;
		case DDSFMT_ATI2:
			read_and_decompress_ati2_block(file, values);
			break;
	}

	count_x = min2u(width - x, 4);
	count_y = min2u(height - y, 4);

	// write 4x4 block to decompressed version
	for (i = 0; i < count_y; i++)
	{
		for (j = 0; j < count_x; j++)
		{
			index = offset + (y + i) * width + x + j;
			dst[index * 4 + 0] = values[(i * 4 + j) * 4 + 0];
			dst[index * 4 + 1] = values[(i * 4 + j) * 4 + 1];
			dst[index * 4 + 2] = values[(i * 4 + j) * 4 + 2];
			dst[index * 4 + 3] = values[(i * 4 + j) * 4 + 3];
		}
	}
}
Esempio n. 3
0
Uint32 load_dds(el_file_ptr file, const Uint32 compression,
	const Uint32 unpack, const Uint32 strip_mipmaps, Uint32 base_level,
	image_t* image)
{
	DdsHeader header;
	Uint32 format_unpack, mipmap_count, start_mipmap;

	if (file == 0)
	{
		return 0;
	}

	if (init_dds_image(file, &header) != 0)
	{
		start_mipmap = min2u(base_level, header.m_mipmap_count - 1);

		if (strip_mipmaps != 0)
		{
			mipmap_count = 1;
		}
		else
		{
			mipmap_count = header.m_mipmap_count - start_mipmap;
		}

		assert(mipmap_count > 0);
		assert(start_mipmap < header.m_mipmap_count);
		assert(mipmap_count <= header.m_mipmap_count);

		image->width = max2u(header.m_width >> start_mipmap, 1);
		image->height = max2u(header.m_height >> start_mipmap, 1);
		image->mipmaps = mipmap_count;
		image->format = detect_dds_file_format(&header, &image->alpha,
			&format_unpack);

		if (decompression_needed(&header, compression, unpack) == 1)
		{
			image->image = decompress_dds(file, &header,
				strip_mipmaps, start_mipmap);
			image->format = ift_rgba8;

			get_dds_sizes_and_offsets(&header, 1, 1,
				strip_mipmaps, start_mipmap, image);
		}
		else
		{
			if ((unpack != 0) || (format_unpack != 0))
			{
				image->image = unpack_dds(file, &header,
					strip_mipmaps, start_mipmap);
				image->format = ift_rgba8;

				get_dds_sizes_and_offsets(&header, 0, 1,
					strip_mipmaps, start_mipmap, image);
			}
			else
			{
				image->image = read_dds(file, &header,
					strip_mipmaps, start_mipmap);

				get_dds_sizes_and_offsets(&header, 0, 0,
					strip_mipmaps, start_mipmap, image);
			}
		}

		assert(image->width > 0);
		assert(image->width > 0);
		assert(image->sizes[0] > 0);
		assert(image->width > 0);
		assert(image->height > 0);
		assert(image->mipmaps > 0);

		if (image->image != 0)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}