source: trunk/src/gfx/image.cc @ 95

Last change on this file since 95 was 90, checked in by epyon, 12 years ago
  • common - windows SCL warnings proper suppression
  • common - NV_DEPRECATED added
  • interface/image_data added
  • image constructible from image_data by ownership transfer
  • device - create_image_data added (temporary)
  • gl_device - create_image_data implementation (temporary)
File size: 1.8 KB
Line 
1// Copyright (C) 2011 Kornel Kisielewicz
2// This file is part of NV Libraries.
3// For conditions of distribution and use, see copyright notice in nv.hh
4
5#include "nv/gfx/image.hh"
6
7#include <algorithm>
8
9using namespace nv;
10
11image::image( glm::ivec2 size, size_t depth )
12        : m_size( size ), m_depth( depth ), m_data( nullptr )
13{
14        m_data = new uint8[ m_size.x * m_size.y * m_depth ];
15}
16
17image::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
24image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed )
25        : m_size( size ), m_depth( depth ), m_data( nullptr )
26{
27        std::size_t bsize = m_size.x * m_size.y * m_depth;
28        m_data = new uint8[ m_size.x * m_size.y * m_depth ];
29
30        if ( reversed )
31        {
32                std::size_t bline = m_size.x * m_depth;
33                for( int i = 0; i < m_size.y; ++i )
34                {
35                        std::copy( data + i * bline, data + (i + 1) * bline, m_data + bsize - ( i + 1 ) * bline );
36                }
37
38        }
39        else
40        {
41                std::copy( data, data + bsize, m_data );
42        }
43}
44
45void image::fill( uint8 value )
46{
47        std::fill( m_data, m_data + m_size.x * m_size.y * m_depth, value );
48}
49
50void image::set_region( region r, const uint8 * data, size_t stride )
51{
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;
56
57        for( int i = 0; i < r.size.y; ++i )
58        {
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 );
63        }
64}
65
66image::~image()
67{
68        delete[] m_data;
69}
70
71
Note: See TracBrowser for help on using the repository browser.