summaryrefslogtreecommitdiff
path: root/src/search/Thumbnail.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-03 13:07:39 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-03 13:07:39 (GMT)
commit73c5082cbcdd3a986765723bd4182e45386ce766 (patch)
tree99a0040636c9700a893044ebc36d949fa1da5873 /src/search/Thumbnail.cpp
parentefddc12e5d2aadc5eee1927245ad38b9dee89aed (diff)
downloadpowder-73c5082cbcdd3a986765723bd4182e45386ce766.zip
powder-73c5082cbcdd3a986765723bd4182e45386ce766.tar.gz
Super, megaheavyweight thumbnail renderer
Diffstat (limited to 'src/search/Thumbnail.cpp')
-rw-r--r--src/search/Thumbnail.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/search/Thumbnail.cpp b/src/search/Thumbnail.cpp
new file mode 100644
index 0000000..2fcd34a
--- /dev/null
+++ b/src/search/Thumbnail.cpp
@@ -0,0 +1,81 @@
+/*
+ * Thumbnail.cpp
+ *
+ * Created on: Apr 3, 2012
+ * Author: Simon
+ */
+
+#include "Thumbnail.h"
+#include "simulation/Simulation.h"
+#include "simulation/SaveLoader.h"
+#include "Renderer.h"
+
+Thumbnail::Thumbnail(const Thumbnail & thumb):
+ ID(thumb.ID),
+ Datestamp(thumb.Datestamp),
+ Data(thumb.Data),
+ Size(thumb.Size)
+{
+ //Ensure the actual thumbnail data is copied
+ if(thumb.Data)
+ {
+ Data = (pixel *)malloc((thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
+ memcpy(Data, thumb.Data, (thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
+ }
+ else
+ {
+ Data = NULL;
+ }
+}
+
+Thumbnail::Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size):
+ ID(_id),
+ Datestamp(_datestamp),
+ Data(_data),
+ Size(_size)
+{
+}
+
+Thumbnail::Thumbnail(Save * save):
+ ID(0),
+ Datestamp(0),
+ Data(NULL),
+ Size(XRES+BARSIZE, YRES+MENUSIZE)
+{
+ Graphics * g = new Graphics();
+ Simulation * sim = new Simulation();
+ Renderer * ren = new Renderer(g, sim);
+ sim->Load(save->GetData(), save->GetDataLength());
+ ren->render_parts();
+
+ int width, height;
+
+ pixel * dst;
+ pixel * src = g->vid;
+
+ if(SaveLoader::Info(save->GetData(), save->GetDataLength(), width, height))
+ goto fail;
+
+ dst = Data = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL)));
+
+ for(int i = 0; i < height*CELL; i++)
+ {
+ memcpy(dst, src, (width*CELL)*PIXELSIZE);
+ dst+=(width*CELL);///PIXELSIZE;
+ src+=XRES+BARSIZE;
+ }
+
+ Size = ui::Point(width*CELL, height*CELL);
+fail:
+ delete ren;
+ delete sim;
+ delete g;
+}
+
+Thumbnail::~Thumbnail()
+{
+ if(Data)
+ {
+ free(Data);
+ }
+}