PageRenderTime 38ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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. use freeimage
  9. import freeimage/[IOHandler, Bitmap]
  10. import io/FileReader
  11. hread: func (buffer: Pointer, size: UInt, count: UInt, handle: FStream) -> UInt {
  12. fread(buffer, size, count, handle)
  13. }
  14. hseek: func (handle: FStream, offset: Long, origin: Int) -> Int {
  15. fseek(handle, offset, origin)
  16. }
  17. htell: func (handle: FStream) -> Long {
  18. ftell(handle)
  19. }
  20. main: func {
  21. io := IOHandler new(hread, null, hseek, htell)
  22. bitmap := Bitmap new(io&, stdin)
  23. if(!bitmap) {
  24. "Couldn't load the bitmap!" println()
  25. return 1
  26. }
  27. "%ix%i bpp: %i" format(bitmap width, bitmap height, bitmap bpp) println()
  28. return 0
  29. }