summaryrefslogtreecommitdiff
path: root/src/Format.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-17 22:09:48 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-17 22:09:48 (GMT)
commit5b51e670447ea175fb9b0b7035403b274e16972e (patch)
tree6f9c9d0a6eb6434ba26eb2f03b5e8e3d8ec179f4 /src/Format.cpp
parent706bd0fa97b5f3da67d44f570a18f9f45ae4fad7 (diff)
downloadpowder-5b51e670447ea175fb9b0b7035403b274e16972e.zip
powder-5b51e670447ea175fb9b0b7035403b274e16972e.tar.gz
PPM screen recording
Diffstat (limited to 'src/Format.cpp')
-rw-r--r--src/Format.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Format.cpp b/src/Format.cpp
index ef0050d..c290e71 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -2,7 +2,10 @@
#include <ctime>
#include <string>
#include <stdexcept>
+#include <iostream>
+#include <iterator>
#include <zlib.h>
+#include <stdio.h>
#include "Format.h"
#include "graphics/Graphics.h"
@@ -37,6 +40,30 @@ std::string format::UnixtimeToDateMini(time_t unixtime)
}
}
+std::vector<char> format::VideoBufferToPPM(const VideoBuffer & vidBuf)
+{
+ std::vector<char> data;
+ char buffer[256];
+ sprintf(buffer, "P6\n%d %d\n255\n", vidBuf.Width, vidBuf.Height);
+ data.insert(data.end(), buffer, buffer+strlen(buffer));
+
+ unsigned char * currentRow = new unsigned char[vidBuf.Width*3];
+ for(int y = 0; y < vidBuf.Height; y++)
+ {
+ int rowPos = 0;
+ for(int x = 0; x < vidBuf.Width; x++)
+ {
+ currentRow[rowPos++] = PIXR(vidBuf.Buffer[(y*vidBuf.Width)+x]);
+ currentRow[rowPos++] = PIXG(vidBuf.Buffer[(y*vidBuf.Width)+x]);
+ currentRow[rowPos++] = PIXB(vidBuf.Buffer[(y*vidBuf.Width)+x]);
+ }
+ data.insert(data.end(), currentRow, currentRow+(vidBuf.Width*3));
+ }
+ delete currentRow;
+
+ return data;
+}
+
struct PNGChunk
{
int Length;