No description
Find a file
2021-01-23 14:49:57 +07:00
.github/workflows add msvc/vcc compiler test 2021-01-23 14:49:57 +07:00
manual fix linguist detection 2017-04-13 12:00:55 +07:00
tests add msvc/vcc compiler test 2021-01-23 14:49:57 +07:00
.appveyor.yml add msvc/vcc compiler test 2021-01-23 14:49:57 +07:00
.gitattributes modify nimBMP.nimble 2017-05-19 21:36:58 +07:00
.gitignore add ci tests 2018-10-09 12:12:59 +07:00
.travis.yml add msvc/vcc compiler test 2021-01-23 14:49:57 +07:00
nimBMP.nim Merge pull request #6 from jangko/fix_invalid_datasize 2020-07-17 15:55:59 +07:00
nimBMP.nimble add msvc/vcc compiler test 2021-01-23 14:49:57 +07:00
readme.md add github action 2020-12-15 21:36:10 +07:00

nimBMP

BMP Encoder and Decoder written in Nim

Build Status (Travis) Windows build status (Appveyor) nimble license Github action

supported standard color mode:

  • 1 bit
  • 4 bit uncompressed and compressed
  • 8 bit uncompressed and compressed
  • 16 bit with color mask
  • 24 bit
  • 32 bit with color mask

both inverted(top-down) and non inverted mode supported

Supported color conversions:

  • 32/24bit to 1, 4, 8, 24 bit
  • automatic palette generation

Basic Usage

import nimBMP

let bmp24 = loadBMP24("image24.bmp") #load bmp as RGB 24 bit
let bmp32 = loadBMP32("image32.bmp") #load bmp as RGBX 32 bit

# the default container is string,
# if you want the output container is seq[uint8],
# you can specify it as second param
let bmp24seq = loadBMP24("image24.bmp", seq[uint8]) #load bmp as RGB 24 bit into seq[uint8]
let bmp32seq = loadBMP32("image32.bmp", seq[uint8]) #load bmp as RGBX 32 bit into seq[uint8]

the returned object from loadBMP24 or loadBMP32 have fields:

  • bmp.width -> the width of the decoded image
  • bmp.height -> the height of the decoded image
  • bmp.data -> contigous pixels stored in Nim string
    • loadBMP24 will produce r1,g1,b1,r2,g2,b2,...,rn,gn,bn
    • loadBMP32 will produce r1,g1,b1,x1,...,rn,gn,bn,xn

Create BMP from raw pixels

import nimBMP

saveBMP32("image32.bmp", rgbx_pixels, width, height)
saveBMP24("image24.bmp", rgb_pixels, width, height)
saveBMP8("image8.bmp", gray_pixels, width, height)

The second param to saveBMPxx is raw input pixel. The input pixels can be a sequence of bytes in string container or seq[uint8] container

The internal algorithm of saveBMP will choose the best target format after it analyze the image's content.

Installation via nimble

nimble install nimBMP