Exemplo n.º 1
0
    RegisterAllocator::RegisterAllocator(CompileNode const & root,
                                         unsigned rowCount,
                                         unsigned registerBase,
                                         unsigned registerCount,
                                         IAllocator& allocator)
        : m_rowCount(rowCount),
          m_registerCount(registerCount),
          m_registerBase(registerBase)
    {
        m_rows = reinterpret_cast<Entry*>(allocator.Allocate(sizeof(Entry)
                                                             * m_rowCount));
        for (unsigned i = 0 ; i < m_rowCount; ++i)
        {
            new (m_rows + i) Entry(i);
        }

        m_abstractRows =
            reinterpret_cast<AbstractRow*>(allocator.Allocate(sizeof(AbstractRow)
                                                              * m_rowCount));

        CollectRows(root, 0, 1);

        std::sort(m_rows, m_rows + m_rowCount);

        // Generate mapping from abstract row id to position in register
        // allocation sort. The first positions in this sort will be allocated
        // to registers.
        m_mapping = reinterpret_cast<unsigned*>(allocator.Allocate(sizeof(unsigned)
                                                                   * m_rowCount));
        for (unsigned i = 0 ; i < m_rowCount; ++i)
        {
            m_mapping[m_rows[i].GetId()] = i;
        }

        // Generate a mapping from register number (starting at 0) to abstract
        // row id.
        m_registersAllocated = 0;
        m_rowIdsByRegister = reinterpret_cast<unsigned*>(allocator.Allocate(sizeof(unsigned)
                                                                            * m_registerCount));
        for (unsigned i = 0; i < m_rowCount && i < m_registerCount; ++i)
        {
            if (m_rows[i].IsUsed())
            {
                m_rowIdsByRegister[m_registersAllocated++] = m_rows[i].GetId();
            }
            else
            {
                break;
            }
        }
    }
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
		explicit OutputStream(IAllocator& allocator)
			: allocator(allocator)
		{
			data = (uint8*)allocator.allocate(sizeof(uint8) * 4096);
			capacity = 4096;
			size = 0;
		}
Exemplo n.º 5
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);
	}
Exemplo n.º 6
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;
    }
}
Exemplo n.º 7
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;
		}
	}
Exemplo n.º 8
0
void MLVLoader::Load(uint8_t *data, unsigned size, OCImage& image, IAllocator& allocator)
{
    // TODO: Add handlng of endianess

    processed = false;

    unsigned int bufferPosition = 0;
    mlv_file_hdr_t mlvHeader = ReadHeader(data, bufferPosition);

    unsigned int blockHeaderSize = sizeof(mlv_hdr_t);
    mlv_rawi_hdr_t blockRAWI;
    mlv_vidf_hdr_t blockVIDF;

    // TODO: Check if switch can be replaced by hash map of func<>
    while (bufferPosition < size)
    {
        mlv_hdr_t blockHeader = ReadBlockHeader(data, bufferPosition);
        switch (blockHeader.blockType)
        {
        case BlockType_RAWI:
        {
            blockRAWI = ReadRAWI(data, bufferPosition, blockHeader);
        }
            break;
        case BlockType_VIDF:
        {
            blockVIDF= ReadVIDF(data, bufferPosition, blockHeader);
        }
            break;
        case BlockType_NULL:
        {
            // Jump over this padding block
            bufferPosition += blockHeader.blockSize - blockHeaderSize;
        }
            break;
        default:
        {
            std::string s( reinterpret_cast<char const*>(&blockHeader.blockType), 4 ) ;
            std::cout << "No processing implemented for block. Type: " << s << " Size: " << blockHeader.blockSize <<" bytes"<<std::endl;

            // Jump over the block
            bufferPosition += blockHeader.blockSize - blockHeaderSize;
        }
        }
    }

    // TODO: Move to ImageProvider, so it's not instantiated several times
    std::unique_ptr<BayerFramePreProcessor> frameProcessor(new BayerFramePreProcessor());

    unsigned int dataSize = blockRAWI.xRes * blockRAWI.yRes;
    image.SetWidth(blockRAWI.xRes);
    image.SetHeight(blockRAWI.yRes);
    image.SetBayerPattern(BayerPattern::RGGB);

    image.SetRedChannel(allocator.Allocate(dataSize));
    image.SetGreenChannel(allocator.Allocate(dataSize));
    image.SetBlueChannel(allocator.Allocate(dataSize));

    ImageFormat imageFormat = ImageFormat::Integer12;
    switch(blockRAWI.rawInfo.bits_per_pixel)
    {
    case 14:
        imageFormat = ImageFormat::Integer14;
        break;
    }

    frameProcessor->SetData(sourceData, image, imageFormat);
    //frameProcessor->SetLinearizationData(linearizationTable, linearizationLength);
    frameProcessor->Process();

    image.SetRedChannel(frameProcessor->GetDataRed());
    image.SetGreenChannel(frameProcessor->GetDataGreen());
    image.SetBlueChannel(frameProcessor->GetDataBlue());
}