-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathImage.cpp
executable file
·102 lines (84 loc) · 1.71 KB
/
Image.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Created by Vaclav Samec on 4/21/15 AD.
// Copyright (c) 2015 Venca. All rights reserved.
//
#include "Image.h"
#include "IO.h"
std::vector<unsigned char>* Image::m_buffer = nullptr;
Image::Image() :
m_data(new std::vector<unsigned char>()),
m_size(0)
{
if (!Image::m_buffer)
{
Image::m_buffer = new std::vector<unsigned char>();
}
}
Image::Image(const std::vector<unsigned char>& data) :
m_data(new std::vector<unsigned char>()),
m_size(0)
{
// copy data
*m_data = data;
}
void Image::clone(const Image& copy)
{
m_data = new std::vector<unsigned char>(*copy.m_data);
m_width = copy.m_width;
m_height = copy.m_height;
m_size = copy.m_size;
m_encoded = copy.m_encoded;
}
Image::~Image()
{
delete m_data;
}
bool Image::loadFile(const std::string& fileName)
{
if (IO::readBinaryFile(fileName, *m_data))
{
m_size = m_data->size();
return true;
}
return false;
}
bool Image::saveFile(const std::string& fileName)
{
return IO::writeBinaryFile(fileName, *m_data, m_size);
}
void Image::swapBuffers()
{
auto tmp = m_data;
m_data = m_buffer;
m_buffer = tmp;
}
bool Image::resize()
{
return false;
}
void Image::setData(unsigned char* data, unsigned int size, int width, int height)
{
m_data->clear();
m_data->assign(data, data + size);
m_size = size;
m_width = width;
m_height = height;
m_encoded = false;
}
bool Image::load(const std::string& fileName)
{
m_encoded = true;
if (loadFile(fileName))
{
return decode();
}
return false;
}
bool Image::save(const std::string& fileName, int compressionRatio)
{
if (!m_encoded)
{
encode(compressionRatio);
}
return saveFile(fileName);
}