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/gl/image.hh"
|
---|
6 |
|
---|
7 | #include <cstring>
|
---|
8 |
|
---|
9 | using namespace nv;
|
---|
10 |
|
---|
11 | image::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 |
|
---|
17 | image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed )
|
---|
18 | : m_size( size ), m_depth( depth ), m_data( nullptr )
|
---|
19 | {
|
---|
20 | m_data = new uint8[ m_size.x * m_size.y * m_depth ];
|
---|
21 |
|
---|
22 | if ( reversed )
|
---|
23 | {
|
---|
24 | for( int i = 0; i < size.y; ++i )
|
---|
25 | {
|
---|
26 | memcpy( m_data + size.x * ( size.y - i - 1) * m_depth, data + i * size.x * m_depth, m_size.x * m_depth );
|
---|
27 | }
|
---|
28 |
|
---|
29 | }
|
---|
30 | else
|
---|
31 | {
|
---|
32 | memcpy( m_data, data, m_size.x * m_size.y * m_depth );
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | void image::fill( uint8 value )
|
---|
37 | {
|
---|
38 | memset( m_data, value, m_size.x * m_size.y * m_depth );
|
---|
39 | }
|
---|
40 |
|
---|
41 | void image::set_region( region r, const uint8 * data, size_t stride )
|
---|
42 | {
|
---|
43 | if ( stride == 0 ) stride = r.size.x;
|
---|
44 |
|
---|
45 | for( int i = 0; i < r.size.y; ++i )
|
---|
46 | {
|
---|
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 );
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | image::~image()
|
---|
53 | {
|
---|
54 | delete[] m_data;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|