Skip to content

nickscha/imagine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imagine

A C89 standard compliant, single header, nostdlib (no C Standard Library) Image Library (IMAGINE).

For more information please look at the "imagine.h" file or take a look at the "examples" or "tests" folder.

Warning

THIS PROJECT IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! USE THIS PROJECT AT YOUR OWN RISK!

Latest Release Downloads License C Standard nostdlib

Features

  • C89 compliant — portable and legacy-friendly
  • Single-header API — just include imagine.h
  • nostdlib — no dependency on the C Standard Library
  • Minimal binary size — optimized for small executables
  • Cross-platform — Windows, Linux, MacOs
  • Strict compilation — built with aggressive warnings & safety checks

Supported Image Formats

Family Format Extension(s) ASCII / Binary Color Types Supported
Netpbm P1 .pbm ASCII 1-bit monochrome
Netpbm P2 .pgm ASCII Grayscale (8-bit, scaled to 255)
Netpbm P3 .ppm ASCII RGB (8-bit, scaled to 255)
Netpbm P4 .pbm Binary 1-bit monochrome
Netpbm P5 .pgm Binary Grayscale (8-bit, scaled to 255)
Netpbm P6 .ppm Binary RGB (8-bit, scaled to 255)
Netpbm P7 .pam Binary RGB, Grayscale (limited support, no alpha yet)
BMP v3 .bmp Binary Monochrome (1-bit), Indexed (4/8-bit palette), RGB (16/24-bit), RGBA (32-bit)
TGA v1 .tga Binary Grayscale (8-bit), RGB (24-bit), RGBA (32-bit, alpha ignored)
PCX ZSoft .pcx Binary Grayscale (8-bit), RGB (24-bit)
ICO Win32 .ico Binary BMP-based icons only (PNG-in-ICO unsupported)
DDS DirectDraw .dds Binary RGB (24-bit), RGBA (32-bit, alpha ignored), Grayscale (8-bit)

Quick Start

Download or clone imagine.h and include it in your project.

#include "imagine.h" /* Image Library */

int main() {

    #define BUF_SIZE 128 * 128
    unsigned char pixels[BUF_SIZE];

    /* Create a new imagine instance with a pixel buffer large enough to store the image data */
    imagine img = {0};
    img.pixels = pixels;
    img.pixels_capacity = BUF_SIZE;

    /* Load the image from the user provided image file binary and the size of the binary */
    if (!imagine_load(&img, binary_buffer, binary_buffer_size)) {
      return 1;
    }

    return 0;
}

Run Example: nostdlib, freestsanding

In this repo you will find the "examples/imagine_win32_nostdlib.c" with the corresponding "build.bat" file which creates an executable only linked to "kernel32" and is not using the C standard library and executes the program afterwards.

"nostdlib" Motivation & Purpose

nostdlib is a lightweight, minimalistic approach to C development that removes dependencies on the standard library. The motivation behind this project is to provide developers with greater control over their code by eliminating unnecessary overhead, reducing binary size, and enabling deployment in resource-constrained environments.

Many modern development environments rely heavily on the standard library, which, while convenient, introduces unnecessary bloat, security risks, and unpredictable dependencies. nostdlib aims to give developers fine-grained control over memory management, execution flow, and system calls by working directly with the underlying platform.

Benefits

Minimal overhead

By removing the standard library, nostdlib significantly reduces runtime overhead, allowing for faster execution and smaller binary sizes.

Increased security

Standard libraries often include unnecessary functions that increase the attack surface of an application. nostdlib mitigates security risks by removing unused and potentially vulnerable components.

Reduced binary size

Without linking to the standard library, binaries are smaller, making them ideal for embedded systems, bootloaders, and operating systems where storage is limited.

Enhanced performance

Direct control over system calls and memory management leads to performance gains by eliminating abstraction layers imposed by standard libraries.

Better portability

By relying only on fundamental system interfaces, nostdlib allows for easier porting across different platforms without worrying about standard library availability.