Index: trunk/nv/common.hh
===================================================================
--- trunk/nv/common.hh	(revision 89)
+++ trunk/nv/common.hh	(revision 90)
@@ -7,9 +7,4 @@
 #ifndef NV_COMMON_HH
 #define NV_COMMON_HH
-
-#include <typeinfo>
-#include <cstddef>
-#include <cassert>
-#include <nv/logging.hh>
 
 // NV Library version
@@ -114,6 +109,26 @@
 #endif
 
+
+#if NV_COMPILER == NV_MSVC 
+#pragma warning(disable: 4201)
+#undef _SCL_SECURE_NO_WARNINGS // to prevent redefinig
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include <typeinfo>
+#include <cstddef>
+#include <cassert>
+#include <nv/logging.hh>
+
 #define NV_STRINGIZE_DETAIL(x) #x
 #define NV_STRINGIZE(x) NV_STRINGIZE_DETAIL(x)
+
+#if NV_COMPILER == NV_MSVC
+#define NV_DEPRECATED(func) __declspec(deprecated) func
+#elif NV_COMPILER == NV_GNUC
+#define NV_DEPRECATED(func) func __attribute__ ((deprecated))
+#else 
+#define NV_DEPRECATED(func) func
+#endif 
 
 #define NV_ASSERT(cond, msg) assert( (cond) && msg )
@@ -122,8 +137,4 @@
 	throw eobj( __VA_ARGS__ ); \
 } 
-
-#if NV_COMPILER == NV_MSVC 
-#pragma warning(disable: 4201)
-#endif
 
 namespace nv
Index: trunk/nv/gfx/image.hh
===================================================================
--- trunk/nv/gfx/image.hh	(revision 89)
+++ trunk/nv/gfx/image.hh	(revision 90)
@@ -9,4 +9,5 @@
 
 #include <nv/common.hh>
+#include <nv/interface/image_data.hh>
 #include <glm/glm.hpp>
 
@@ -30,5 +31,5 @@
 	 * By an image we understand a group of pixels, limited to X and Y
 	 * dimensions, of a certain depth (by depth we mean how rich
-	 * the colours are.
+	 * the colors are.
 	 */
 	class image
@@ -42,4 +43,10 @@
 		 */
 		image( glm::ivec2 size, size_t depth );
+		/**
+		 * Constructor
+		 *
+		 * @arg[in] data : image data to be used - will be released, but not deleted!
+		 */
+		explicit image( image_data* data );
 		/**
 		 * Full constructor.
Index: trunk/nv/gl/gl_device.hh
===================================================================
--- trunk/nv/gl/gl_device.hh	(revision 89)
+++ trunk/nv/gl/gl_device.hh	(revision 90)
@@ -26,4 +26,5 @@
 		virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr );
 		virtual vertex_array* create_vertex_array();
+		virtual image_data* create_image_data( const std::string& filename ); // temporary
 		virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr );
 		virtual ~gl_device();
Index: trunk/nv/interface/device.hh
===================================================================
--- trunk/nv/interface/device.hh	(revision 89)
+++ trunk/nv/interface/device.hh	(revision 90)
@@ -18,4 +18,5 @@
 #include <nv/interface/vertex_buffer.hh>
 #include <nv/interface/texture2d.hh>
+#include <nv/interface/image_data.hh>
 
 namespace nv
@@ -32,4 +33,5 @@
 		virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0;
 		virtual vertex_array* create_vertex_array() = 0;
+		virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary
 		virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0;
 
Index: trunk/nv/interface/image_data.hh
===================================================================
--- trunk/nv/interface/image_data.hh	(revision 90)
+++ trunk/nv/interface/image_data.hh	(revision 90)
@@ -0,0 +1,44 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file image_data.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief Image data struct
+ */
+
+#ifndef NV_IMAGE_DATA_HH
+#define NV_IMAGE_DATA_HH
+
+#include <algorithm>
+#include <nv/common.hh>
+#include <glm/glm.hpp>
+
+namespace nv
+{
+	class image_data
+	{
+	public:
+		image_data( glm::ivec2 size, size_t depth, const uint8 * data ) 
+			: m_size( size ), m_depth( depth ), m_data( nullptr )
+		{ 
+			std::size_t bsize = m_size.x * m_size.y * m_depth;
+			m_data = new uint8[ bsize ]; 
+			std::copy( data, data + bsize, m_data );
+		}
+		uint8* release_data() { uint8* r = m_data; m_data = nullptr; return r; }
+		const uint8 * get_data()    const { return m_data; }
+		const glm::ivec2 get_size() const { return m_size; }
+		const size_t get_depth()    const { return m_depth; }
+		~image_data() {	if (m_data) delete m_data; }
+	private:
+		glm::ivec2 m_size;  //< Defines the size of the image as a vector
+		size_t     m_depth; //< Defines the depth of the image
+		uint8*     m_data;  //< Holder for data
+	};
+}
+
+#endif // NV_IMAGE_DATA_HH
Index: trunk/src/gfx/image.cc
===================================================================
--- trunk/src/gfx/image.cc	(revision 89)
+++ trunk/src/gfx/image.cc	(revision 90)
@@ -5,5 +5,5 @@
 #include "nv/gfx/image.hh"
 
-#include <cstring>
+#include <algorithm>
 
 using namespace nv;
@@ -15,14 +15,23 @@
 }
 
+image::image( image_data* data )
+	: m_size( data->get_size() ), m_depth( data->get_depth() ), m_data( data->release_data() )
+{
+	NV_ASSERT( m_data, "image created from empty image_data!" );
+}
+
+
 image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed )
 	: m_size( size ), m_depth( depth ), m_data( nullptr )
 {
+	std::size_t bsize = m_size.x * m_size.y * m_depth;
 	m_data = new uint8[ m_size.x * m_size.y * m_depth ];
 
 	if ( reversed )
 	{
-		for( int i = 0; i < size.y; ++i )
+		std::size_t bline = m_size.x * m_depth;
+		for( int i = 0; i < m_size.y; ++i )
 		{
-			memcpy( m_data + size.x * ( size.y - i - 1) * m_depth, data + i * size.x * m_depth, m_size.x * m_depth );
+			std::copy( data + i * bline, data + (i + 1) * bline, m_data + bsize - ( i + 1 ) * bline );
 		}
 
@@ -30,5 +39,5 @@
 	else 
 	{
-		memcpy( m_data, data, m_size.x * m_size.y * m_depth );
+		std::copy( data, data + bsize, m_data );
 	}
 }
@@ -36,15 +45,20 @@
 void image::fill( uint8 value )
 {
-	memset( m_data, value, m_size.x * m_size.y * m_depth );
+	std::fill( m_data, m_data + m_size.x * m_size.y * m_depth, value );
 }
 
 void image::set_region( region r, const uint8 * data, size_t stride )
 {
-	if ( stride == 0 ) stride = r.size.x;
+	if ( stride == 0 ) stride = r.size.x * m_depth;
+	
+	std::size_t bpos  = (r.pos.y*m_size.x + r.pos.x ) * m_depth;
+	std::size_t bline = m_size.x*m_depth;
 
 	for( int i = 0; i < r.size.y; ++i )
  	{
-		memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth, 
-			data + (i*stride), r.size.x * m_depth );
+// TODO: test if same as old:
+//		memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth, 
+//			data + (i*stride), r.size.x * m_depth );
+		std::copy( data + i*stride, data + (i+1)*stride, m_data + bpos + bline * i );
 	}
 }
Index: trunk/src/gl/gl_device.cc
===================================================================
--- trunk/src/gl/gl_device.cc	(revision 89)
+++ trunk/src/gl/gl_device.cc	(revision 90)
@@ -11,4 +11,5 @@
 #include "nv/logging.hh"
 #include "nv/lib/sdl12.hh"
+#include "nv/lib/sdl_image.hh"
 
 using namespace nv;
@@ -67,4 +68,14 @@
 }
 
+// this is a temporary function that will be removed once we find a way to 
+// pass binary file data around
+image_data* nv::gl_device::create_image_data( const std::string& filename )
+{
+	load_sdl_image_library();
+	SDL_Surface* image = IMG_Load( filename.c_str() );
+	image_data* data = new image_data( glm::ivec2( image->w, image->h ), image->format->BytesPerPixel, (nv::uint8*)image->pixels );
+	return data;
+}
+
 texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
 {
Index: trunk/tests/render_test/rl.cc
===================================================================
--- trunk/tests/render_test/rl.cc	(revision 89)
+++ trunk/tests/render_test/rl.cc	(revision 90)
@@ -1,4 +1,3 @@
 #include <nv/lib/sdl12.hh>
-#include <nv/lib/sdl_image.hh>
 #include <nv/interface/vertex_buffer.hh>
 #include <nv/gl/gl_device.hh>
@@ -87,9 +86,8 @@
 	m_window = m_device->create_window( 800, 600 );
 	
-	nv::load_sdl_image_library();
-	SDL_Surface* texture = IMG_Load( "spritesheet.png" );
-	nv::image sprites( glm::ivec2( texture->w, texture->h ), 4, (nv::uint8*)texture->pixels );
+	nv::image_data* sprites = m_device->create_image_data( "spritesheet.png" );
 	nv::sampler sampler( nv::sampler::NEAREST, nv::sampler::REPEAT );
-	m_texture = m_device->create_texture2d( sprites.get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)sprites.get_data() );
+	m_texture = m_device->create_texture2d( sprites->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)sprites->get_data() );
+	delete sprites;
 
 	m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
