-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.cpccImage.h
More file actions
111 lines (80 loc) · 3.01 KB
/
gui.cpccImage.h
File metadata and controls
111 lines (80 loc) · 3.01 KB
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
103
104
105
106
107
108
109
110
111
/* *****************************************
* File: cpccImage.h
* Version: see function getClassVersion()
* Purpose: Portable (cross-platform), light-weight library
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2014 StarMessage software.
* License: Free for opensource projects.
* Commercial license for closed source projects.
* Web: http://www.StarMessageSoftware.com/cpcclibrary
* Download: https://github.com/starmessage/cpcc
* email: sales -at- starmessage.info
* *****************************************
*/
#pragma once
#include <string>
#include "io.cpccFileSystemMini.h"
#if defined(__APPLE__)
#include "gui.cpccImageMac.h"
typedef cpccImageMacBmpRep ImageImpl;
#elif defined(_WIN32)
#include "gui.cpccImageWin.h"
typedef cpccImageWin ImageImpl;
#else
#error #4367: Unknown platform for TmioanImage
#endif
class cpccImage: public ImageImpl
{
public: // ctors
public: // functions
virtual void setPixel(const int x, const int y, const cpccColor &aColor) override
{
if (x<0 || x>=getWidth() || y<0 || y>=getHeight())
return;
ImageImpl::setPixel(x, y, aColor);
}
virtual cpccColor getPixel(const int x, const int y) const override
{
if (x<0 || x>=getWidth() || y<0 || y>=getHeight())
return cpccMoccasin;
return ImageImpl::getPixel( x, y);
}
virtual void resizeTo(const int newWidth, const int newHeight) override
{
if (newWidth==getWidth() && newHeight==getHeight())
return;
ImageImpl::resizeTo_impl(newWidth, newHeight);
}
virtual void cropTo(const int newTop, int newLeft, int newWidth, int newHeight) override
{
if ( newTop<0 || newTop >= getHeight() || newLeft<0 || newLeft >= getWidth() ||
newWidth>=getWidth() || newHeight>=getHeight() || newWidth<0 || newHeight<0)
return;
// ensure that the xy origin is smaller than the width or height of the original image
ImageImpl::cropTo_impl(newTop, newLeft, newWidth, newHeight);
}
virtual bool initWithFile(const cpcc_char* afullpathfilename, const bool hasTransparentCorner=false) override
{
if (!afullpathfilename)
{
warningLog().add( _T("cpccImage.initWithFile(): empty filename") );
return false;
}
if (!cpccFileSystemMini::fileExists(afullpathfilename))
{
warningLog().addf( _T("cpccImage.initWithFile: file does not exist:[%s]") , afullpathfilename);
return false;
}
if (!ImageImpl::initWithFile_impl(afullpathfilename, hasTransparentCorner))
{
warningLog().addf( _T("cpccImage.initWithFile() failed to load:[%s]") , afullpathfilename);
return false;
}
m_hasTrasparentColor=hasTransparentCorner;
if (m_hasTrasparentColor)
m_transparentColor = getPixel(0,0);
infoLog().addf(_T("cpccImage.initWithFile(%s) OK. W:%i H:%i"), afullpathfilename, getWidth(), getHeight());
return true;
}
};