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.
Currently dlib contains the following packages:
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.
Load PNG image and save its resized copy:
import dlib;
void main()
{
loadPNG("input.png").resampleBilinear(240, 320).savePNG("output.png");
}
Drawing on an image:
SuperImage img = image(512, 512, 4);
fillColor(img, color4(0x000000ff));
Color4f drawColor = color4(0x07e5f8ff);
img[256, 256] = drawColor;
drawLine(img, drawColor, 280, 280, 511, 511);
savePNG(img, "output.png");
Transform a vector with 4x4 affine matrix:
Vector3f v1 = Vector3f(1, 0, 0);
Vector3f v2 = v1 * translationMatrix(Vector3f(0, 2, 0));
Parsing JSON string:
JSONDocument doc = New!JSONDocument(jsonString);
writeln(doc.root.asObject["name"].asString);
Delete(doc);
A simple 'Hello, world' HTTP server:
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:
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);
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:
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ş.
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.
Some interesting projects that use dlib: