PageRenderTime 162ms CodeModel.GetById 61ms app.highlight 0ms RepoModel.GetById 100ms app.codeStats 0ms

/tests/iohandler.ooc

http://github.com/tsion/ooc-freeimage
Unknown | 36 lines | 29 code | 7 blank | 0 comment | 0 complexity | f134d9d479367da974d8bf7d7562823b MD5 | raw file
 1/*
 2 * This file uses IOHandler to load a bitmap from stdin. The reason
 3 * for this is that it can load bitmaps from any source that you can
 4 * define read, seek, and tell for. (It's also possible to write to
 5 * arbitrary resources.)
 6 * Run it with: ./iohandler < some/bitmap.png
 7 */
 8
 9use freeimage
10import freeimage/[IOHandler, Bitmap]
11import io/FileReader
12
13hread: func (buffer: Pointer, size: UInt, count: UInt, handle: FStream) -> UInt {
14    fread(buffer, size, count, handle)
15}
16
17hseek: func (handle: FStream, offset: Long, origin: Int) -> Int {
18    fseek(handle, offset, origin)
19}
20
21htell: func (handle: FStream) -> Long {
22    ftell(handle)
23}
24
25main: func {
26    io := IOHandler new(hread, null, hseek, htell)
27    bitmap := Bitmap new(io&, stdin)
28
29    if(!bitmap) {
30        "Couldn't load the bitmap!" println()
31        return 1
32    }
33
34    "%ix%i bpp: %i" format(bitmap width, bitmap height, bitmap bpp) println()
35    return 0
36}