summaryrefslogtreecommitdiff
path: root/src/dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dump.c')
-rw-r--r--src/dump.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/dump.c b/src/dump.c
new file mode 100644
index 0000000..ed56a00
--- /dev/null
+++ b/src/dump.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+#include "libnsfb_event.h"
+#include "nsfb.h"
+#include "surface.h"
+
+/* exported interface documented in libnsfb.h */
+bool
+nsfb_dump(nsfb_t *nsfb, int fd)
+{
+ FILE *outf;
+ int x;
+ int y;
+
+ outf = fdopen(dup(fd), "w");
+ if (outf == NULL) {
+ return false;
+ }
+
+ fprintf(outf,"P3\n#libnsfb buffer dump\n%d %d\n255\n",
+ nsfb->width, nsfb->height);
+ for (y=0; y < nsfb->height; y++) {
+ for (x=0; x < nsfb->width; x++) {
+ fprintf(outf,"%d %d %d ",
+ *(nsfb->ptr + (((nsfb->width * y) + x) * 4) + 2),
+ *(nsfb->ptr + (((nsfb->width * y) + x) * 4) + 1),
+ *(nsfb->ptr + (((nsfb->width * y) + x) * 4) + 0));
+
+ }
+ fprintf(outf,"\n");
+ }
+
+ fclose(outf);
+
+ return true;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * End:
+ */