Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-12-06 21:33:34 +0000
committerStijn Buys <ingar@osirion.org>2010-12-06 21:33:34 +0000
commitc50095cab023e91ba2a4fec8dcb290e6d817124b (patch)
treee9511df876d45faffb428ee7ae342a8aabab4194 /src/render/image.cc
parent8c7fa7dd3258e8d3e112fb9780249dd0d0ef008a (diff)
Re-enabled environment mapping with the skybox as cubemap.
Diffstat (limited to 'src/render/image.cc')
-rw-r--r--src/render/image.cc61
1 files changed, 58 insertions, 3 deletions
diff --git a/src/render/image.cc b/src/render/image.cc
index 98898ef..9019daf 100644
--- a/src/render/image.cc
+++ b/src/render/image.cc
@@ -4,10 +4,17 @@
the terms of the GNU General Public License version 2
*/
-#include <stdlib.h>
-#include <string.h>
+#include <string>
+
+#include <cstdlib>
+#include <cstring>
+
+#include "sys/sys.h"
#include "render/image.h"
+#include "render/tgafile.h"
+#include "render/pngfile.h"
+#include "render/jpgfile.h"
namespace render
{
@@ -69,7 +76,7 @@ void Image::pad()
image_data = image_new;
}
-void Image::flip()
+void Image::flip_vertical()
{
unsigned char line[image_width*image_channels];
for (size_t y = 0; y < image_height / 2; y++) {
@@ -85,5 +92,53 @@ void Image::flip()
}
}
+void Image::flip_horizontal()
+{
+ unsigned char pixel_data[image_channels];
+ for (size_t y = 0; y < image_height; y++) {
+ for (size_t x = 0; x < image_width / 2; x++) {
+ void *src = pixel(x,y); // &image_data[(y * image_width + x) * image_channels];
+ void *dst = pixel(image_width - x - 1, y); // (&image_data[((y+1) * image_width - x - 1) * image_channels];
+ memcpy(pixel_data, dst, image_channels);
+ memcpy(dst, src, image_channels);
+ memcpy(src, pixel_data, image_channels);
+ }
+ }
+}
+
+Image *Image::load(const std::string & name)
+{
+ std::string filename;
+ Image *image = 0;
+
+ if (!image) {
+ // try the png version
+ filename.assign(name);
+ filename.append(".png");
+ image = PNG::load(filename.c_str());
+ }
+
+ if (!image) {
+ // try the tga version
+ filename.assign(name);
+ filename.append(".tga");
+ image = TGA::load(filename.c_str());
+ }
+
+ if (!image) {
+ // try the jpg version
+ filename.assign(name);
+ filename.append(".jpg");
+ image = JPG::load(filename.c_str());
+ }
+
+ if (!image) {
+ con_warn << "Could not open image " << name << std::endl;
+ return 0;
+ }
+
+ return image;
+}
+
}