source: trunk/src/gl/image.cc @ 25

Last change on this file since 25 was 21, checked in by epyon, 12 years ago
  • bugfixes
  • missing files added
File size: 1.3 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/gl/image.hh"
6
7#include <cstring>
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( 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( size_t 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
36void image::fill( uint8 value )
37{
38        memset( m_data, value, m_size.x * m_size.y * m_depth );
39}
40
41void image::set_region( region r, const uint8 * data, size_t stride )
42{
43        if ( stride == 0 ) stride = r.size.x;
44
45    for( size_t 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
52image::~image()
53{
54        delete[] m_data;
55}
56
57
Note: See TracBrowser for help on using the repository browser.