• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    C
  • License
    zlib License
  • Created almost 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🌀 Compact and embeddable RGBA/HSLA library that supports WEBP, JPG, progressive JPG, PNG, TGA, DDS DXT1/2/3/4/5, BMP, PSD, GIF, PVR2/3 (ETC1/PVRTC), KTX (ETC1/PVRTC), PKM (ETC1), HDR, PIC, PNM (PPM/PGM), CRN, PUG, FLIF, CCZ, EXR and vectorial SVG files (C++11)

Sp🌀t

  • Spot is a compact and embeddable pixel/image library (C++11).
  • Spot supports both RGBA/HSLA pixel types.
  • Spot provides both pixel and image algebra for pixel/image manipulation.
  • Spot loads WEBP, JPG, progressive JPG, PNG, TGA, DDS DXT1/2/3/4/5, BMP, PSD, GIF, PVR2/3 (ETC1/PVRTC), KTX (ETC1/PVRTC), PKM (ETC1), HDR, PIC, PNM (PPM/PGM), CRN, PUG, FLIF, CCZ, EXR and vectorial SVG files.
  • Spot saves WEBP, JPG, PNG, TGA, BMP, DDS, PVR3 (PVRTC), KTX (ETC1), PKM (ETC1), CCZ and PUG files.
  • Spot is self-contained. All libraries are included and amalgamated.
  • Spot is tiny. A couple of source files.
  • Spot is cross-platform.
  • Spot is zlib/libpng licensed.

File format support

File format Read Write
BMP files yes yes
CCZ (PVR2) files yes* yes*
CRN files yes no
DDS DXT1/2/3/4/5 files yes yes
EXR files yes no
FLIF files yes no
GIF files yes no
HDR files yes no
JPG files (progressive) yes no
JPG files yes yes
KTX (ETC1) files yes* yes*
KTX (PVRTC) files yes* no
PIC files yes no
PKM (ETC1) files yes yes
PNG files yes yes
PNM (PPM/PGM) files yes no
PSD files yes no
PUG files yes yes
PVR2 (PVRTC) files yes* no
PVR3 (ETC1) files yes* no
PVR3 (PVRTC) files yes* yes*
SVG files (rasterized) yes no
TGA files yes yes
WEBP files yes yes

(*) partial support, preliminary, warning, caution, atchung, beware of dog

todo

  • document api
  • create more image filters
  • clean up code
template<typename color>
class image : public std::vector<color>
{
    public:

    size_t w, h, d;
    float delay; // frame delay, when loading an animation

    image();
    image( size_t w, size_t h, size_t d = 0, const color &filler = color::hsla() );
    explicit image( const std::string &filename, bool mirror_w = false, bool mirror_h = false );
    explicit image( const void *ptr, size_t len, bool mirror_w = false, bool mirror_h = false );

    bool load( const void *ptr, size_t len, bool mirror_w = false, bool mirror_h = false );
    bool load( const std::string &filename, bool mirror_w = false, bool mirror_h = false );

    bool save( const std::string &filename ) const;

    bool save_as_bmp( const std::string &filename ) const;
    bool save_as_dds( const std::string &filename ) const;
    bool save_as_tga( const std::string &filename ) const;
    bool save_as_png( const std::string &filename, unsigned stride = 4 ) const;
    bool save_as_pug( const std::string &filename, unsigned quality = 90 ) const;
    bool save_as_jpg( const std::string &filename, unsigned quality = 90 ) const;
    bool save_as_webp(const std::string &filename, unsigned quality = 90 ) const;
    bool save_as_ktx( const std::string &filename, unsigned quality = 90 ) const;
    bool save_as_pvr( const std::string &filename, unsigned quality = 90 ) const;
    bool save_as_pkm( const std::string &filename, unsigned quality = 90 ) const;
    bool save_as_ccz( const std::string &filename, unsigned quality = 90 ) const;

    std::string encode_as_png( unsigned stride = 4 ) const;
    std::string encode_as_pug( unsigned quality = 90 ) const;
    std::string encode_as_jpg( unsigned quality = 90 ) const;
    std::string encode_as_webp(unsigned quality = 90 ) const;
    std::string encode_as_ktx( unsigned quality = 90 ) const;
    std::string encode_as_pvr( unsigned quality = 90 ) const;
    std::string encode_as_pvr( unsigned quality = 90 ) const;
    std::string encode_as_pkm( unsigned quality = 90 ) const;
    std::string encode_as_ccz( unsigned quality = 90 ) const;

    inline const size_t size() const;
    bool loaded() const;

    inline color &at( size_t offset );
    inline color &at( size_t x, size_t y );
    inline color &at( size_t x, size_t y, size_t z );
    inline color &atf( float x01 );
    inline color &atf( float x01, float y01 );
    inline color &atf( float x01, float y01, float z01 );

    inline const color &at( size_t offset ) const;
    inline const color &at( size_t x, size_t y ) const;
    inline const color &at( size_t x, size_t y, size_t z ) const;
    inline const color &atf( float x01 ) const;
    inline const color &atf( float x01, float y01 ) const;
    inline const color &atf( float x01, float y01, float z01 ) const;

    image copy( size_t ox, size_t oy, size_t w = ~0, size_t h = ~0 ) const;
    image paste( size_t at_x, size_t at_y, const image &other ) const;
    image crop( size_t left, size_t right, size_t top, size_t bottom ) const; // each param is number of row/cols to crop

    image flip_w() const;
    image flip_h() const;
    image rotate_left() const;
    image rotate_right() const;

    image operator *( const color &other ) const;
    image operator /( const color &other ) const;
    image operator +( const color &other ) const;
    image operator -( const color &other ) const;

    image &operator *=( const color &other );
    image &operator /=( const color &other );
    image &operator +=( const color &other );
    image &operator -=( const color &other );

    image to_rgba() const;
    image to_hsla() const;

    image to_premultiplied_alpha() const;
    image to_straight_alpha() const;

    std::vector<unsigned int>  rgba32() const;
    std::vector<unsigned char> rgbx( unsigned char ) const;
    std::vector<unsigned char> bgrx( unsigned char ) const;
    std::vector<unsigned char> rgba() const;
    std::vector<unsigned char> bgra() const;
    std::vector<unsigned char> rgb() const;
    std::vector<unsigned char> bgr() const;
    std::vector<unsigned char> ya() const;
    std::vector<unsigned char> y() const;
};

sample

    spot::image img( filename );

    spot::image saturated = img * spot::hsla( 1, 2, 1, 1 );
    spot::image desaturated = img * spot::hsla( 1, 0.5f, 1, 1 );
    spot::image gray = img * spot::hsla( 1, 0, 1, 1 );
    spot::image light = img * spot::hsla( 1, 1, 1.75f, 1 );
    spot::image hue = img + spot::hsla( 0.5f, 0, 0, 0 );
    spot::image warmer = img + spot::hsla( -0.08f, 0, 0, 0 );
    spot::image colder = img + spot::hsla(  0.08f, 0, 0, 0 );

    img.save_as_bmp("collage.bmp");
    img.save_as_dds("collage.dds");
    img.save_as_jpg("collage.jpg", 80);
    img.save_as_ktx("collage.ktx", 10);
    img.save_as_pkm("collage.pkm", 10);
    img.save_as_png("collage.png");
    img.save_as_pug("collage.pug", 80);
    img.save_as_pvr("collage.pvr", 10);
    img.save_as_webp("collage.webp", 80);

possible output

image

23/04/2015  21:05           786.486 collage.bmp
23/04/2015  21:05           262.272 collage.dds
23/04/2015  21:05            55.018 collage.jpg
23/04/2015  21:05           131.140 collage.ktx
23/04/2015  21:05           131.088 collage.pkm
23/04/2015  21:05           296.619 collage.png
23/04/2015  21:05            55.227 collage.pug
23/04/2015  21:05           131.128 collage.pvr
23/04/2015  21:05            42.272 collage.webp

color transfer sample

image

todos

  • clean ups
  • integrate metrics
  • dds/dxt and bc5/6/7
  • better crn handling
  • endianness issues

licenses

  • spot (ZLIB license).
  • crn2dds by r-lyeh, SpartanJ and Evan Parker (Public Domain).
  • crnlib, by Rich Geldreich (ZLIB license).
  • DDS writer by Jonathan Dummer (Public Domain).
  • etc1utils by Google Inc (Apache 2.0 license).
  • etcpak by Bartosz Taudul (BSD-3 license).
  • flif by Jon Sneyers and Pieter Wuille (Apache 2.0 license).
  • jpge by Rich Geldreich (Public Domain).
  • libwebp by Google Inc (BSD license).
  • lodepng by Lode Vandevenne (ZLIB license).
  • nanosvg by Mikko Mononen (ZLIB license).
  • pngrim alpha bleeding algorithm by F-Genesis (Public Domain).
  • pug (Public Domain).
  • pvrtccompressor by Jeffrey Lim (BSD-3 license).
  • rg_etc1 by Rich Geldreich (ZLIB license).
  • soil2 by Martin Lucas Golini and Jonathan Dummer (Public Domain).
  • stb_image by Sean Barrett (Public Domain).
  • tinyexr by Syoyo Fujita (BSD3 license).
  • unifont (ZLIB license).

notes

  • Samples are Public Domain licensed. Samples use CImg.h by David Tschumperle (CeCILL-C license) to display images.
  • gcc users may need strict aliasing disabled if using CRN textures: add -fno-strict-aliasing compilation flag.

changelog

  • v2.1.4 (2018/11/16): bump up soil2, stb_image(s), cimg
  • v2.1.3 (2016/07/01): ccz loading and saving support (pvr.ccz); bump soil2 and stb_image
  • v2.1.2 (2016/02/04): flif and exr loading support
  • v2.1.1 (2016/02/01): update nanosvg; add small optimizations
  • v2.1.0 (2015/09/28): faster image pasting
  • v2.0.9 (2015/05/12): safer decoding on invalid images
  • v2.0.8 (2015/05/07): faster etc1 encoding on low quality settings (using custom etcpak library)
  • v2.0.7 (2015/05/06): stb image library defined as static (fixes multiple symbol definitions in large projects); upgraded tools
  • v2.0.6 (2015/05/05): print() method added
  • v2.0.5 (2015/04/27): pvrtc encoder; c++0x support
  • v2.0.4 (2015/04/27): fixed etc1 encoder; fixed ya()/a() vector size
  • v2.0.3 (2015/04/24): pvrtc encoder
  • v2.0.2 (2015/04/23): better ktx/pvr3 file support; pvrtc decode stream support; android support (again); increased tests
  • v2.0.1 (2015/04/23): bugfixed monochromatic images
  • v2.0.0 (2015/04/22): etc1 encode/decode stream support; pvr3/ktx/pkm load/save file support; a few optimizations

More Repositories

1

bundle

📦 Bundle, an embeddable compression library: DEFLATE, LZMA, LZIP, BZIP2, ZPAQ, LZ4, ZSTD, BROTLI, BSC, CSC, BCM, MCM, ZMOLLY, ZLING, TANGELO, SHRINKER, CRUSH, LZJB and SHOCO streams in a ZIP file (C++03)(C++11)
C++
623
star
2

scriptorium

📜 Game Scripting Languages benchmarked
C
486
star
3

statvs

Hopefully updated status of all my github repositories
344
star
4

AVA

A tiny unlicensed 3D game engine in C; with C++ and Lua interfaces. Written in 32 random ̷d̷a̷y̷s̷ m̷o̷n̷t̷h̷s̷ years.
C
336
star
5

getopt

Simple command-line options handler (C++11)
C++
327
star
6

sole

🍩 Sole is a lightweight C++11 library to generate universally unique identificators (UUID), both v1 and v4.
C++
296
star
7

fsm

📑 Simple and lightweight Hierarchical/Finite-State Machine (H-FSM) class (C++11)
C++
229
star
8

tracey

:squirrel: Tracey is a lightweight and simple C++ memory leak finder with no dependencies.
C++
226
star
9

ltalloc

LightweighT Almost Lock-Less Oriented for C++ programs memory allocator
C++
164
star
10

kult

🔮 Lightweight entity/component/system library (C++11)
C++
127
star
11

dessert

🍰 Lightweight unit-testing framework (C++11).
C++
87
star
12

img2sky

🌒 A vertex-color mesh builder tool for skyboxes and static geometry, as seen in HomeWorld 2 .HOD files
C
76
star
13

dollar

💰 A portable CPU profiler with ASCII,CSV,TSV,Markdown,chrome://tracing support (C++11)
C++
64
star
14

base

Base91 / Base85 / Base64 de/encoders (C++03)
C++
61
star
15

trie

Trie is a lightweight and simple autocompletion data structure written in C++11.
C++
43
star
16

attila

🔥 Attila is a tiny atlas texture-packer (tool)
C++
40
star
17

quant

🍥 Tiny quantization suite supporting conversion to/from half-floats, s/unorm bytes, quaternions and vectors (C++03).
C++
39
star
18

wire

🔌 Wire is a drop-in std::string replacement with extended functionality and safe C/C++ formatters (C++11).
C++
39
star
19

tween

👯 Tween is a lightweight easing library. Written in C++03
C++
35
star
20

apathy

💾 Apathy is a lightweight path/file/mstream/mmap IO library (C++03)
C++
35
star
21

pug

🐶 pug, png with a twist: lossy image format
33
star
22

malloc-survey

📈 Allocation benchmarks
C++
30
star
23

mINI

▫️ A very minimal .INI reader/writer (C++11)
C++
29
star
24

id

:suspect: ID, a compile-time string hasher and sequential ID generator (C++11)
C++
27
star
25

LRU

A lightweight LRU cache structure for list<T> and map<K,V> containers. Written in C++11
C++
27
star
26

bubble

💬 A simple and lightweight C++11 dialog library (for Windows)
C++
25
star
27

knot

Knot is a lightweight and simple TCP networking C++ library with no dependencies.
C++
25
star
28

sqlight

🔦 SQLight is a lightweight MySQL client written in C++11. Based on code by Ladislav Nevery
C++
25
star
29

DrEcho

💊 Dr Echo spices your terminal up (C++11)
C++
24
star
30

cocoa

🍫 Cocoa is an uniform hashing library with no dependencies that provides interface for CRC32, CRC64, GCRC, RS, JS, PJW, ELF, BKDR, SBDM, DJB, DJB2, BP, FNV, FNV1a, AP, BJ1, MH2, SHA1, SFH (C++11)
C++
24
star
31

fmt11

Tiny format/mustache templating library (C++11)
C++
22
star
32

auth

Simple, lightweight and safe client-server authentication system. Written in C++
C++
22
star
33

bundler

📦 Command-line archiver: DEFLATE, LZMA, LZIP, BZIP2, ZPAQ, LZ4, ZSTD, BROTLI, BSC, CSC, BCM, MCM, ZMOLLY, ZLING, TANGELO, SHRINKER, CRUSH, LZJB and SHOCO streams in a ZIP file.
C++
21
star
34

moon9

a game framework. warning: wip, dev, unstable, radiation hazard, defcon 3
C++
21
star
35

assume

🙈 Assume is a smarter assert replacement (C++03)
C++
21
star
36

bourne

😏 Bourne is a lightweight JSON de/serializer (C++11).
C++
21
star
37

unify

🔗 A C++11 function to normalize resource identificators
C++
20
star
38

collage

✂️ A lightweight C++ library to diff and patch arbitrary data
C++
20
star
39

metrics

📊 Pretty table metrics w/ benchmarking, unit conversions in CSV,TSV,ASCII,markdown (C++11)
C++
19
star
40

sand

⌛ Sand is a lightweight time controller (C++11)
C++
19
star
41

hertz

⌚ Hertz, simple framerate locker (C++11)
C++
18
star
42

frodo

💍 A lightweight ring dependency system (C++11)
C++
18
star
43

giant

🗿 Giant is a tiny C++11 library to handle little/big endianness.
C++
18
star
44

vle

Simple variable-length encoder/decoder (C99)(C++03)
C++
15
star
45

heal

💉 Heal is a lightweight C++ library to aid and debug applications. Heal requires C++11 (or C++03 with boost at least).
C++
15
star
46

live

🎭 Automatic reloader of constants during runtime, featuring type inference. Written in C++11.
C++
15
star
47

crawler

Crawler, a quick prototiping platform for Windows (C++11)
C
14
star
48

units

fork of http://calumgrant.net/units (unavailable) + new units + c++0x support + markdown documentation (C++03)
C++
14
star
49

unifont

Embeddable console 1bpp font that supports many european/eastern unicode codepoints. Aimed to gamedev (C++11).
C
13
star
50

warp

♻️ A handy string interpolator (C++11)
C++
13
star
51

flow

🎈 Lightweight C++ network downloader with native fallbacks. Aimed to gamedev.
C++
13
star
52

burg

Simple burg linear predictor (C++11)
C++
13
star
53

oak

🌳 A simple and lightweight tree container (C++03)
C++
13
star
54

memo

📌 Simple and lightweight factory class, featuring automatic type casting. Written in C++11
C++
12
star
55

journey

🐫 Lightweight append-only, header-less, journaling file format (C++11)
C++
12
star
56

route66

⛽ Lightweight embeddable HTTP server. Written in C++11 (or C++03 w/boost).
C++
12
star
57

duty

Duty is a lightweight C++11 task manager for parallel coroutines and serial jobs. Duty requires no dependencies.
C++
10
star
58

unlzma

A very compact LZMA decoder (C++03)
C++
9
star
59

sentry

Sentry is a lightweight data monitor (C++11)
C++
9
star
60

vitae

📄 My self-compilable C++ resume
C++
9
star
61

codex

Codex is a lightweight and simple C++ library to escape, unescape, read, write and convert from/to different encoding charsets. Codex requires no dependencies.
C++
8
star
62

flare

✨ Lightweight C++ API to deal with digital signals/logical buttons (C++03).
C++
7
star
63

solace-wip

Solace is a modern console replacement. Written in C++03
C++
6
star
64

error64

Handle custom 64-bit error codes, with extended meta-info (C, C++)
C
6
star
65

fortfont

💱 Collection of western, CJK and iconographic fonts free for commercial usage
CSS
5
star
66

cash-of-clans

a free re-implementation of a working game economy system
C++
5
star
67

gpulib

C++
4
star
68

rgb332

custom uniform RGB332 palette
C++
4
star
69

hyde

🎮 Hyde is a lightweight and simple Human Inferface Device (HID) C++ framework with no dependencies.
C++
4
star
70

bridge

A standard C++11 <--> C++03/boost compatibility layer, plus a few utils
C++
3
star
71

pitch

📒 A forkable game pitch template (CC0, Markdown)
3
star
72

unordered_map

Portable header for std::unordered_map<K,V> template
C++
3
star
73

variant

Variant is a varying C++11 class that clones javascript behaviour as much as possible
C++
2
star
74

emojis

:octocat: Emojis, atlased and indexed
2
star
75

CLDR

Compact data from the Unicode Common Locale Data Repository
C++
2
star
76

blender-wip

An agnostic keyframe interpolation and animation controller. Written in C++11.
C++
2
star
77

atom-wip

A small library to multiplex, to interweave, to sort, to split and to join (sub)streams of binary data (C++11).
C++
2
star
78

depot

asset depository for all my repos
C++
2
star
79

vision

a few assorted premises and thoughts
2
star
80

jabba-wip

jabba, the hud engine. yet another generic hud/ui engine
C++
2
star
81

JXMLex

JXMLex description format
1
star
82

watchmen-wip

Dependency system for your libraries of game assets in run-time
C++
1
star
83

JXML

JXML is a loss-less representation of JSON in XML, so data can be reused with XML tools.
1
star
84

rescle

Automatically exported from code.google.com/p/rescle
C++
1
star
85

tint-wip

Colorful logging tool
C++
1
star
86

stringbase

Stringbase is a collaborative effort aimed to translate common texts found in videogames and regular apps. Free to use. Commits welcome!
1
star