Esempio n. 1
0
			/**
			 * Returns the pointer to the data of the given block
			 * location. Only valid for block compressed formats.
			 * @param x The x position.
			 * @param y The y position.
			 * @param z The z position.
			 * @param face The face to use.
			 * @param mipmap The mipmap level to use.
			 * @return The pointer to the data.
			 */
			inline const void* get_block_data(const Uint32 x,
				const Uint32 y, const Uint32 z,
				const Uint16 face, const Uint16 mipmap) const
			{
				return static_cast<const Uint8* const>(
					get_buffer()->get_ptr()) +
					get_block_offset(x, y, z, face, mipmap);
			}
Esempio n. 2
0
int gbcso :: decompress_sector(unsigned sector)
{
	//sector decription based on BOOSTER cso compressor sample
	unsigned get_size, is_plain, read_position, compare_size;
	int status;

	if(inflateInit2(&dec,-15) != Z_OK)
		return 0;

	unsigned current_index = get_block_offset(sector);
	is_plain = current_index & 0x80000000;
	current_index = current_index & 0x7fffffff;
	read_position = current_index << (info.align); //alignment

	if(!is_plain)
	{
		unsigned next_index = get_block_offset(sector + 1) & 0x7fffffff;
		get_size = (next_index - current_index) << (info.align);
	}
	else 
		get_size = info.block_size;

	fseek(stream, read_position, SEEK_SET); //seek to sector block
	dec.avail_in = fread(read_buffer, 1, get_size, stream); //read block
	
	if(is_plain)
	{
		memcpy(buffer, read_buffer, get_size); //copy plain data
		compare_size = get_size;
	}
	else
	{
		dec.next_out = buffer;
		dec.avail_out = info.block_size;
		dec.next_in = read_buffer;

		status = inflate(&dec, Z_FULL_FLUSH); //decompress data
		compare_size = info.block_size - dec.avail_out;
		if((status != Z_STREAM_END) || (compare_size != info.block_size))
			return 0;
	};

	return inflateEnd(&dec) == Z_OK;
};
Esempio n. 3
0
			/**
			 * Returns the pointer to the data of the given
			 * location.
			 * @param x The x position.
			 * @param y The y position.
			 * @param z The z position.
			 * @param face The face to use.
			 * @param mipmap The mipmap level to use.
			 * @return The pointer to the data.
			 */
			inline const void* const get_data(const Uint32 x,
				const Uint32 y, const Uint32 z,
				const Uint16 face, const Uint16 mipmap) const
			{
				if (get_compressed())
				{
					return static_cast<const Uint8*>(
						get_buffer()->get_ptr()) +
						get_block_offset(x, y,z, face,
							mipmap);
				}

				return static_cast<const Uint8*>(get_buffer(
					)->get_ptr()) + get_pixel_offset(x, y,
						z, face, mipmap);
			}
Esempio n. 4
0
void get_neighbour_values(uint8_t nvalues[4], uint8_t *cdata, uint8_t *ncdata[4], uint8_t defval,
		const uint8_t rbx, const uint8_t rbz, const uint8_t y, const uint8_t rotate)
{
	nvalues[TOP] = rbz > 0 ? cdata[get_block_offset(rbx, rbz - 1, y, rotate)] :
			(ncdata[TOP] == NULL ? defval :
					ncdata[TOP][get_block_offset(rbx, MAX_CHUNK_BLOCK, y, rotate)]);

	nvalues[RIGHT] = rbx < MAX_CHUNK_BLOCK ? cdata[get_block_offset(rbx + 1, rbz, y, rotate)] :
			(ncdata[RIGHT] == NULL ? defval :
					ncdata[RIGHT][get_block_offset(0, rbz, y, rotate)]);

	nvalues[BOTTOM] = rbz < MAX_CHUNK_BLOCK ? cdata[get_block_offset(rbx, rbz + 1, y, rotate)] :
			(ncdata[BOTTOM] == NULL ? defval :
					ncdata[BOTTOM][get_block_offset(rbx, 0, y, rotate)]);

	nvalues[LEFT] = rbx > 0 ? cdata[get_block_offset(rbx - 1, rbz, y, rotate)] :
			(ncdata[LEFT] == NULL ? defval :
					ncdata[LEFT][get_block_offset(MAX_CHUNK_BLOCK, rbz, y, rotate)]);
}