Exemplo n.º 1
0
Color
PackedSurface::Reader::get_pixel(int x, int y) const
{
	if (!is_opened())
		return Color();

	if (x < 0)
		x = 0;
	if (x >= surface->width)
		x = surface->width-1;
	if (y < 0)
		y = 0;
	if (y >= surface->height)
		y = surface->height-1;

	if (cache)
	{
		int chunk_index = x/ChunkSize + y/ChunkSize*surface->chunks_width;
		x %= ChunkSize;
		y %= ChunkSize;
		CacheEntry *entry = chunks[chunk_index];
		if (!entry)
		{
			const void *data;
			int size;
			bool compressed;
			surface->get_compressed_chunk(chunk_index, data, size, compressed);
			if (!compressed)
				return surface->get_pixel(&((const char*)data)[x*surface->pixel_size + y*surface->chunk_row_size]);

			entry = last;
			if (entry->chunk_index >= 0)
				chunks[entry->chunk_index] = NULL;
			entry->chunk_index = chunk_index;
			chunks[chunk_index] = entry;
			zstreambuf::unpack(entry->data(), surface->chunk_size, data, size);
		}
		if (first != entry)
		{
			entry->prev->next = entry->next;
			(entry->next ? entry->next->prev : last) = entry->prev;

			first->prev = entry;
			entry->prev = NULL;
			entry->next = first;
			first = entry;
		}
		return surface->get_pixel(entry->data(x*surface->pixel_size + y*surface->chunk_row_size));
	}
	else
	if (surface->pixel_size)
	{
		return surface->get_pixel(&surface->data[x*surface->pixel_size + y*surface->row_size]);
	}
	return surface->constant;
}
Exemplo n.º 2
0
	void MemcachedCache::setValue(const QString& key, const CacheEntry& entry)
	{
		QWriteLocker lock(&m_lock);

		// Binary key
		const QByteArray rawKey(fullKey(key));

		// Binary data
		const quint64 dateTime(qToLittleEndian(static_cast<quint64>(entry.timeStamp().toTime_t())));
		QByteArray rawData(reinterpret_cast<const char*>(&dateTime), sizeof(quint64));
		rawData.append(entry.data());

		// Store in memcached
		memcached_return rt;
		rt = memcached_set(
			m_memcached,
			rawKey.constData(),
			rawKey.length(),
			rawData.constData(),
			rawData.length(),
			0, // expire
			0 // flags
		);
		if(rt != MEMCACHED_SUCCESS)
		{
			qFatal("Memcached error: %s", memcached_strerror(m_memcached, rt));
		}
	}