Skip to content

Instantly share code, notes, and snippets.

@fowlmouth
Created May 23, 2014 03:55
Show Gist options
  • Save fowlmouth/950c998b7de5f9663af5 to your computer and use it in GitHub Desktop.
Save fowlmouth/950c998b7de5f9663af5 to your computer and use it in GitHub Desktop.
type
Bitmap = ref PBitmap
PBitmap = ptr object
w,h: int
proc load_bitmap_pvt (file:cstring): PBitmap {.importc:"bitmap_load".}
proc destroy (bmp:PBitmap) {.importc:"bitmap_destroy".}
proc free (B:Bitmap) =
destroy B.bmp
proc load_bitmap (file:string): Bitmap =
var b = load_bitmap_pvt(file)
if not b.isNil:
new(result, free)
result[] = b
let b = load_bitmap("ello.bmp")
echo b.w,"x",b.h
# we can define this so Bitmap converts automatically to PBitmap
converter tobmp (b:Bitmap):PBitmap = b[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment