Home Features Getting Started Examples Documentation Contributing Sponsorship Usage

dlib is a general-purpose library written in D language for game and graphics developers. It provides basic building blocks for writing graphics-intensive applications: containers, data streams, linear algebra and image decoders.

dlib is cross-platform, it supports Windows, Linux and all POSIX-compliant systems. It has no external dependencies aside D's standard library.

dlib is distributed under the Boost Software License, Version 1.0. You are free to use, copy, modify and redistribute dlib, even in closed-source products. The only requirement is to keep the license and copyright notice in all source code copies.

This project is not related to dlib for C++ in any way, it just has the same name by coincidence.

Features

Currently dlib contains the following packages:

Getting started

Head on to releases page and get the latest source tarball. You may also use dub package instead - add the following dependency to your dub.json:


"dlib": "~>1.3.0"

A simple introductory tutorial on setting up a workspace for D projects can be found here.

Examples

Load PNG image and save its resized copy:


import dlib;

void main()
{
    loadPNG("input.png").resampleBilinear(240, 320).savePNG("output.png");
}

Transform a vector with 4x4 affine matrix:


import dlib;

void main()
{
    Vector3f v1 = Vector3f(1, 0, 0);
    Vector3f v2 = v1 * translationMatrix(Vector3f(0, 2, 0));
}

A simple 'Hello, world' HTTP server:


module main;

import std.stdio;
import dlib.network;

void main()
{
    StreamSocket listener = new StreamSocket(AddressFamily.INET);
    listener.bind(new InternetAddress("127.0.0.1", 8192));
    listener.listen(5);
    ubyte[] inputBuffer = new ubyte[1024];
    while(true)
    {
        ConnectedSocket connection = listener.accept();
        if (connection)
        {
            auto numBytesReceived = connection.receive(inputBuffer);
            string receivedStr = cast(string)inputBuffer[0..numBytesReceived];
            writeln(receivedStr);

            string responce = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nHello, world!\r\n";
            connection.send(cast(ubyte[])responce);

            connection.close();
        }
    }
}

Working with filesystem without garbage collection:


import dlib.core.memory;
import dlib.filesystem;
import dlib.text.str;
import json;

void main()
{
    StdFileSystem fs = New!StdFileSystem();
    
    foreach(path, entry; fs.traverseDir("./", true))
    {
        writeln(path);
        writeln(entry.isFile);
    }
    
    FileStat s;
    if (fs.stat("dub.json", s)) // otherwise doesn't exist
    {
        writeln(s.creationTimestamp);
        if (s.permissions & PRead)
        {
            StdInFileStream strm = fs.openForInput("dub.json");
            String text = String(strm);
            Delete(strm);
            writeln(text);
            text.free();
        }
    }
    
    Delete(fs);
}

Documentation

There is ddox documentation generated from source code. Be aware that it is currently incomplete, we are working towards making it more comprehensive. For support and overall discussions, use our Gitter chat room.

Articles on dlib:

Contributing

If you want to contribute code to dlib, send pull requests to the project repository. Please, read Contributing Guidelines first.

Found a bug? Please, create an issue here.

dlib was created by Timur Gafarov, Martin Cejp, Andrey Penechko, Vadim Lopatin, Nick Papanastasiou, Oleg Baharev, Roman Chistokhodov, Eugene Wissner, Roman Vlasov, Basile Burg, Valeriy Fedotov, Ferhat Kurtulmuş.

Sponsorship

If you like dlib, please support its development on Patreon and get a reward depending on your donation amount. Supporters who donate $10 and more will be listed on this page as Sponsors. You can also make donation via PayPal.

Big thanks to these awesome people for supporting dlib: Daniel Laburthe, Rafał Ziemniewski, Kumar Sookram, Aleksandr Kovalev, Robert Georges, Jan Jurzitza (WebFreak), Rais Safiullin (SARFEX), Benas Cernevicius, Koichi Takio.

Usage

Some interesting projects that use dlib:

Fork me on GitHub