inline std::string key_qvalue_pairs(array_view<kv_pair> pairs)
{
    std::string buffer;
    // Ensure string is large enough for our use, to avoid useless internal resize
    size_t maj = std::accumulate(pairs.begin(), pairs.end(), size_t{0},
        [](size_t acc, kv_pair p){return acc + p.key.size()+p.value.size()+8;});
    // reserve some space for 8 quoted chars inside value
    // if there is more string is on it's own and will spend slightly more time
    buffer.reserve(maj+8);
    return key_qvalue_pairs(buffer, pairs);
}
Beispiel #2
0
    bool operator == (const array_view & other) const noexcept
    {
        // Pointers to same memory (or both null).
        if (data() == other.data())
        {
            return true;
        }

        // Different sizes, whole sequence can't be identical.
        if (size() != other.size())
        {
            return false;
        }

        // Compare each element:
        return std::equal(begin(), end(), other.begin());
    }
Beispiel #3
0
static bitmap make_bitmap_level (const array_view<std::uint8_t>& data, const array_view<bitmap::value_type>& colormap, int level, const wal_header& header) {

    auto div1 = 1 << level;
    
    auto width = header.width / div1 ;
    auto height = header.height / div1 ;
    
    auto buffer = std::make_unique<bitmap::value_type[]> (width*height);
    
    auto data_view = array_view<std::uint8_t> {
        data.begin () + header.offset [level],
        data.begin () + header.offset [level] + width*height
    };
    
    for (auto i = 0; i < width*height; ++i) {
        buffer [i] = colormap [data_view [i]];
    }
    
    return bitmap (std::move (buffer), width, height);
};
Beispiel #4
0
 explicit mdarray(const array_view<ATYPE> &view):
     _imap(map_utils<map_type>::create(view.template shape<shape_t>())),
     _data(container_utils<storage_type>::create(view.size()))
 {
     std::copy(view.begin(),view.end(),_data.begin());
 }
Beispiel #5
0
bitmap xtk::pcx_decode (const array_view<std::uint8_t>& data) {

    static_assert (sizeof (pcx_header) == 128, "Header length incorrect");

    const auto& header = *(const pcx_header*)data.data();
    
    auto width  = header.xmax - header.xmin + 1;
    auto height = header.ymax - header.ymin + 1;
    
    __xtk_assert (std::invalid_argument, header.vendor_id == 0x0A && header.version >= 5);
    
    xtk::Debug::log(
        "load_pcx: \n"
        "\tversion = %d\n"
        "\tbits_per_pixel = %d\n"
        "\tcolor_planes = %d\n"
        "\twidth = %u\n"
        "\theight = %u\n"
        ,
        header.version,
        header.bits_per_pixel,
        header.color_planes,
        width,
        height
    );
    
    __xtk_assert(std::invalid_argument,
        header.bits_per_pixel == 8 &&
        header.color_planes == 0);
    
    auto buffer = std::make_unique<bitmap::value_type []> (width*height);
    
    auto stream = array_view<const std::uint8_t> {data.begin() + sizeof (header), data.end()};

    auto next_pixel = 0u;
    auto next_sbyte = stream.begin ();
        
    auto palette = xtk::array_view<glm::tvec3<std::uint8_t>> {
        (const glm::tvec3<std::uint8_t> *)data.end () - 256,
        (const glm::tvec3<std::uint8_t> *)data.end ()
    };
    
    while (next_sbyte < stream.end ()) {
        auto rle = *next_sbyte;
        
        ++next_sbyte;
        
        if (rle >= 0xc0) {
            rle &= 0x3f;
            auto pixel = bitmap::value_type (palette [*next_sbyte], 255);
            ++next_sbyte;
            for (auto j = 0; j < rle; ++j) {
                buffer [next_pixel] = pixel;
                ++next_pixel;
                __xtk_assert (std::overflow_error, next_pixel <= width*height);
            }
        }
        else {
            buffer [next_pixel] = bitmap::value_type (palette [rle], 255);
            ++next_pixel;
            __xtk_assert (std::overflow_error, next_pixel <= width*height);
        }
        
        if (next_pixel >= width*height) {
            break;
        }
    }
    
    __xtk_assert (std::invalid_argument, next_pixel == width*height);
    
    return bitmap (std::move (buffer), width, height);
}