explicit OutputStream(IAllocator& allocator)
			: allocator(allocator)
		{
			data = (uint8*)allocator.allocate(sizeof(uint8) * 4096);
			capacity = 4096;
			size = 0;
		}
示例#2
0
	String StringStream::string(IAllocator& alloc) const {
		size_t len = buffer_.size();
		char* buffer = (char*)alloc.allocate(len, 1);
		char* end = buffer + len;
		buffer_.copy_to(buffer, end);
		return String::take_ownership(alloc, buffer, len);
	}
示例#3
0
unsigned int Texture::compareTGA(IAllocator& allocator,
								 FS::IFile* file1,
								 FS::IFile* file2,
								 int difference)
{
	TGAHeader header1, header2;
	file1->read(&header1, sizeof(header1));
	file2->read(&header2, sizeof(header2));

	if (header1.bitsPerPixel != header2.bitsPerPixel ||
		header1.width != header2.width || header1.height != header2.height ||
		header1.dataType != header2.dataType ||
		header1.imageDescriptor != header2.imageDescriptor)
	{
		g_log_error.log("Renderer")
			<< "Trying to compare textures with different formats";
		return 0;
	}

	int color_mode = header1.bitsPerPixel / 8;
	if (header1.dataType != 2)
	{
		g_log_error.log("Renderer") << "Unsupported texture format";
		return 0;
	}

	int different_pixel_count = 0;
	size_t pixel_count = header1.width * header1.height;
	uint8* img1 = (uint8*)allocator.allocate(pixel_count * color_mode);
	uint8* img2 = (uint8*)allocator.allocate(pixel_count * color_mode);

	file1->read(img1, pixel_count * color_mode);
	file2->read(img2, pixel_count * color_mode);

	for (size_t i = 0; i < pixel_count * color_mode; i += color_mode)
	{
		for (int j = 0; j < color_mode; ++j)
		{
			if (Math::abs(img1[i + j] - img2[i + j]) > difference)
			{
				++different_pixel_count;
				break;
			}
		}
	}

	allocator.deallocate(img1);
	allocator.deallocate(img2);

	return different_pixel_count;
}
示例#4
0
bool Texture::saveTGA(IAllocator& allocator,
					  FS::IFile* file,
					  int width,
					  int height,
					  int bytes_per_pixel,
					  const uint8_t* image_dest,
					  const Path& path)
{
	if (bytes_per_pixel != 4)
	{
		g_log_error.log("renderer")
			<< "Texture " << path.c_str()
			<< " could not be saved, unsupported TGA format";
		return false;
	}

	uint8_t* data = (uint8_t*)allocator.allocate(width * height * 4);

	TGAHeader header;
	memset(&header, 0, sizeof(header));
	header.bitsPerPixel = (char)(bytes_per_pixel * 8);
	header.height = (short)height;
	header.width = (short)width;
	header.dataType = 2;

	file->write(&header, sizeof(header));

	for (long y = 0; y < header.height; y++)
	{
		long read_index = y * header.width * 4;
		long write_index = ((header.imageDescriptor & 32) != 0)
							   ? read_index
							   : y * header.width * 4;
		for (long x = 0; x < header.width; x++)
		{
			data[write_index + 0] = image_dest[write_index + 2];
			data[write_index + 1] = image_dest[write_index + 1];
			data[write_index + 2] = image_dest[write_index + 0];
			data[write_index + 3] = image_dest[write_index + 3];
			write_index += 4;
		}
	}

	file->write(data, width * height * 4);

	allocator.deallocate(data);

	return true;
}
示例#5
0
OutputBlob::OutputBlob(const OutputBlob& blob, IAllocator& allocator)
    : m_allocator(&allocator)
    , m_pos(blob.m_pos)
{
    if (blob.m_size > 0)
    {
        m_data = allocator.allocate(blob.m_size);
        copyMemory(m_data, blob.m_data, blob.m_size);
        m_size = blob.m_size;
    }
    else
    {
        m_data = nullptr;
        m_size = 0;
    }
}
示例#6
0
	OutputBlob::OutputBlob(const InputBlob& blob, IAllocator& allocator)
		: m_allocator(&allocator)
		, m_pos(blob.getSize())
	{
		if (blob.getSize() > 0)
		{
			m_data = allocator.allocate(blob.getSize());
			copyMemory(m_data, blob.getData(), blob.getSize());
			m_size = blob.getSize();
		}
		else
		{
			m_data = nullptr;
			m_size = 0;
		}
	}