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;
            }
        }
    }
Exemple #2
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());
}