dlib is a general-purpose library for D language. It implements such common functionality as image manipulation, OpenGL-friendly linear algebra, multithreading, networking, stream-based I/O, memory management, etc. dlib is an ideal solution for writing game engines and rendering pipelines, building simple web apps, quickly prototyping new ideas and algorithms.

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

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

Currently dlib contains the following packages:

  • dlib.core - basic functionality used by other modules (manual memory management, streams, OOP for structs, etc.)
  • dlib.container - generic data structures (GC-free dynamic and associative arrays and more)
  • dlib.filesystem - abstract FS interface and its implementations for Windows and POSIX filesystems
  • dlib.functional - some functional programming idioms (HOFs, combiners, quantifiers, etc.)
  • dlib.math - linear algebra and numerical analysis (vectors, matrices, quaternions, linear system solvers etc.)
  • dlib.geometry - computational geometry (ray casting, primitives, intersection, etc.)
  • dlib.image - image processing (8-bit, 16-bit and 32-bit floating point channels, common filters and convolution kernels, resizing, FFT, HDRI, animation, vector graphics rendering, image formats I/O: JPEG, PNG/APNG, BMP, TGA, HDR)
  • dlib.audio - sound processing (8 and 16 bits per sample, synthesizers, WAV export and import)
  • dlib.network - cross-platform sockets and other network functionality
  • dlib.memory - allocators and memory management functions
  • dlib.text - text processing
  • dlib.serialization - data serialization (currently includes lightweight XML parser)
  • dlib.coding - various data compression and coding algorithms.

Download

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": "0.16.0"

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

Documentation

Refer to GitHub wiki. Be aware that documentation is currently incomplete. For support and overall discussions, use our Gitter chat room.

License

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.

Found a bug?

Please, create an issue here. PRs are welcome.

Become a Patron!

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 one-time donation via PayPal. Thanks in advance!

Worth checking out

  • Dagon, a 3D game engine that uses dlib
  • dmech, a physics engine built on top of dlib.math and dlib.geometry
  • Atrium, a game that uses dlib and dmech
  • DlangUI, native UI toolkit for D - uses dlib.image
  • Voxelman, voxel game engine - uses dlib.image and dlib.math
  • dlib-webp, WebP loader for dlib.image.