indie-raster

...is a small raster graphics library.

  • (platform-independent C program) + wrappers
  • no dependencies — not even for drawing text!

Features

  • draw images
  • draw UPC barcodes
  • draw text via pre-rendered fonts

Limitations

  • Only black and white so far. Grayscale and color support should be pretty easy to add.

Pre-rendered fonts

PRF1 is a trivial file format indie-raster made up for pre-rendered fonts. See docs/PRF1.md

Ruby Wrapper


require 'indie-raster'

s = IndieRasterSession.new

HEADER = 10
FOOTER = 11
BIG_FONT = 20
s.loadImage :id => HEADER, <b>:path</b> => "images/header.pbm"
s.loadImage :id => FOOTER, <b>:data</b> => footer_pbm_bytes
s.loadFont :id => BIG_FONT, :path => "fonts/dsm-24.prf1"

s.createBlank :id => 1, :w => 576, :h => 1000

s.drawImage :id => HEADER, :x => 100, :y => 100<b>, :on => 1</b>
s.drawImage :id => FOOTER, :x => 100, :y => 900
# (<b>:on</b> defaults to 1)

s.drawText :text => "Taxi:", :font => BIG_FONT, <b>:x</b> => 20,         :y => 200
s.drawText :text => "1729",  :font => BIG_FONT, <b>:toLeftOf</b> => 560, :y => 200

s.drawUPC :upc => "123456123456", :x => 10, :y => 500, :w => 475, :h => 70

result_pbm = s.exportP4

C program


cat commands | indie-raster > result.pbm

Example Commands File


createBlank   1 576 1000
drawBarcode   1 10 200 123456123456 475 70 10 0 0
exportP4      1

Example 2


# if a line is blank or starts with "#", it is ignored
# line ending: \n
#-----------------------------------------------------------
#             (dest id)       (w)        (h)
createBlank       1           576       1000
#-----------------------------------------------------------
#             (dest id)    (num bytes)
loadImage         2            1729
...raw image bytes...
#-----------------------------------------------------------
#             (dest id)    (num bytes)
loadFont          3            3176
...PRF1 bytes...
#-----------------------------------------------------------
#             (dest id)   (x)  (y)    (src id)
drawImage         1        0    0         2
#-----------------------------------------------------------
#             (dest id)   (x)  (y)    (font id)   (num chars)
drawText          1        10   100       3           5
..."¿123?", UTF-32-little-endian-encoded...
# (bytes: BF 00 00 00 31 00 00 00 32 00 00 00 33 00 00 00 3F 00 00 00)
#-----------------------------------------------------------
#             (dest id)   (x)  (y)  (12-digit string) (w)  (h)   (guard bar extra h)  (middle font)  (side font)
drawBarcode       1        10   200   123456123456    475   70             0                0             0
# (a font ID of 0 means no text)
#-----------------------------------------------------------
#             (src id)
exportP4          1
#-----------------------------------------------------------