- Timestamp:
- 06/02/13 22:33:59 (12 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/image.cc
r89 r90 5 5 #include "nv/gfx/image.hh" 6 6 7 #include < cstring>7 #include <algorithm> 8 8 9 9 using namespace nv; … … 15 15 } 16 16 17 image::image( image_data* data ) 18 : m_size( data->get_size() ), m_depth( data->get_depth() ), m_data( data->release_data() ) 19 { 20 NV_ASSERT( m_data, "image created from empty image_data!" ); 21 } 22 23 17 24 image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed ) 18 25 : m_size( size ), m_depth( depth ), m_data( nullptr ) 19 26 { 27 std::size_t bsize = m_size.x * m_size.y * m_depth; 20 28 m_data = new uint8[ m_size.x * m_size.y * m_depth ]; 21 29 22 30 if ( reversed ) 23 31 { 24 for( int i = 0; i < size.y; ++i ) 32 std::size_t bline = m_size.x * m_depth; 33 for( int i = 0; i < m_size.y; ++i ) 25 34 { 26 memcpy( m_data + size.x * ( size.y - i - 1) * m_depth, data + i * size.x * m_depth, m_size.x * m_depth);35 std::copy( data + i * bline, data + (i + 1) * bline, m_data + bsize - ( i + 1 ) * bline ); 27 36 } 28 37 … … 30 39 else 31 40 { 32 memcpy( m_data, data, m_size.x * m_size.y * m_depth);41 std::copy( data, data + bsize, m_data ); 33 42 } 34 43 } … … 36 45 void image::fill( uint8 value ) 37 46 { 38 memset( m_data, value, m_size.x * m_size.y * m_depth);47 std::fill( m_data, m_data + m_size.x * m_size.y * m_depth, value ); 39 48 } 40 49 41 50 void image::set_region( region r, const uint8 * data, size_t stride ) 42 51 { 43 if ( stride == 0 ) stride = r.size.x; 52 if ( stride == 0 ) stride = r.size.x * m_depth; 53 54 std::size_t bpos = (r.pos.y*m_size.x + r.pos.x ) * m_depth; 55 std::size_t bline = m_size.x*m_depth; 44 56 45 57 for( int i = 0; i < r.size.y; ++i ) 46 58 { 47 memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth, 48 data + (i*stride), r.size.x * m_depth ); 59 // TODO: test if same as old: 60 // memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth, 61 // data + (i*stride), r.size.x * m_depth ); 62 std::copy( data + i*stride, data + (i+1)*stride, m_data + bpos + bline * i ); 49 63 } 50 64 } -
trunk/src/gl/gl_device.cc
r70 r90 11 11 #include "nv/logging.hh" 12 12 #include "nv/lib/sdl12.hh" 13 #include "nv/lib/sdl_image.hh" 13 14 14 15 using namespace nv; … … 67 68 } 68 69 70 // this is a temporary function that will be removed once we find a way to 71 // pass binary file data around 72 image_data* nv::gl_device::create_image_data( const std::string& filename ) 73 { 74 load_sdl_image_library(); 75 SDL_Surface* image = IMG_Load( filename.c_str() ); 76 image_data* data = new image_data( glm::ivec2( image->w, image->h ), image->format->BytesPerPixel, (nv::uint8*)image->pixels ); 77 return data; 78 } 79 69 80 texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ ) 70 81 {
Note: See TracChangeset
for help on using the changeset viewer.