Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
  3.  *
  4.  * This file is part of libnsfb, http://www.netsurf-browser.org/
  5.  * Licenced under the MIT License,
  6.  *                http://www.opensource.org/licenses/mit-license.php
  7.  */
  8.  
  9. #include <stdbool.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13.  
  14. #include "libnsfb.h"
  15. #include "libnsfb_plot.h"
  16. #include "libnsfb_event.h"
  17. #include "nsfb.h"
  18. #include "surface.h"
  19.  
  20. /* exported interface documented in libnsfb.h */
  21. bool
  22. nsfb_dump(nsfb_t *nsfb, int fd)
  23. {
  24.     FILE *outf;
  25.     int x;
  26.     int y;
  27.  
  28.     outf = fdopen(dup(fd), "w");
  29.     if (outf == NULL) {
  30.             return false;
  31.     }
  32.  
  33.     fprintf(outf,"P3\n#libnsfb buffer dump\n%d %d\n255\n",
  34.             nsfb->width, nsfb->height);
  35.     for (y=0; y < nsfb->height; y++) {
  36.         for (x=0; x < nsfb->width; x++) {
  37.             fprintf(outf,"%d %d %d ",
  38.                     *(nsfb->ptr + (((nsfb->width * y) + x) * 4) + 2),
  39.                     *(nsfb->ptr + (((nsfb->width * y) + x) * 4) + 1),
  40.                     *(nsfb->ptr + (((nsfb->width * y) + x) * 4) + 0));
  41.            
  42.         }
  43.         fprintf(outf,"\n");
  44.     }
  45.  
  46.     fclose(outf);
  47.  
  48.     return true;
  49. }
  50.  
  51. /*
  52.  * Local variables:
  53.  *  c-basic-offset: 4
  54.  *  tab-width: 8
  55.  * End:
  56.  */
  57.