summaryrefslogtreecommitdiff
path: root/thirdparty/etcpak/Bitmap.hpp
blob: fae8c936ed55fa6d4bd6493361c4690241772f1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef __DARKRL__BITMAP_HPP__
#define __DARKRL__BITMAP_HPP__

#include <future>
#include <memory>
#include <mutex>
#include <stdint.h>

#include "Semaphore.hpp"
#include "Vector.hpp"

enum class Channels
{
    RGB,
    Alpha
};

class Bitmap
{
public:
    Bitmap( const char* fn, unsigned int lines, bool bgr );
    Bitmap( const v2i& size );
    virtual ~Bitmap();

    void Write( const char* fn );

    uint32_t* Data() { if( m_load.valid() ) m_load.wait(); return m_data; }
    const uint32_t* Data() const { if( m_load.valid() ) m_load.wait(); return m_data; }
    const v2i& Size() const { return m_size; }
    bool Alpha() const { return m_alpha; }

    const uint32_t* NextBlock( unsigned int& lines, bool& done );

protected:
    Bitmap( const Bitmap& src, unsigned int lines );

    uint32_t* m_data;
    uint32_t* m_block;
    unsigned int m_lines;
    unsigned int m_linesLeft;
    v2i m_size;
    bool m_alpha;
    Semaphore m_sema;
    std::mutex m_lock;
    std::future<void> m_load;
};

typedef std::shared_ptr<Bitmap> BitmapPtr;

#endif