-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.cpp
106 lines (88 loc) · 1.92 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
103
104
105
106
#include <stdlib.h>
#include <iostream>
#include "image.h"
#include <cmath>
using namespace std;
Image::Image()
{
N = 0;
M = 0;
Q = 0;
pixelVal = NULL;
}
Image::Image(int numRows, int numCols, int grayLevels)
{
N = numRows;
M = numCols;
Q = grayLevels;
pixelVal = new int *[N];
for(int i = 0; i < N; i++)
{
pixelVal[i] = new int [M];
for(int j = 0; j < M; j++)
pixelVal[i][j] = 0;
}
}
Image::~Image()
{
N = 0;
M = 0;
Q = 0;
for(int i = 0; i < N; i++)
delete pixelVal [N];
delete pixelVal;
}
Image::Image(const Image& oldImage)
{
N = oldImage.N;
M = oldImage.M;
Q = oldImage.Q;
pixelVal = new int* [N];
for(int i = 0; i < N; i++)
{
pixelVal[i] = new int [M];
for(int j = 0; j < M; j++)
pixelVal[i][j] = oldImage.pixelVal[i][j];
}
}
void Image::operator=(const Image& oldImage)
{
N = oldImage.N;
M = oldImage.M;
Q = oldImage.Q;
pixelVal = new int* [N];
for(int i = 0; i < N; i++)
{
pixelVal[i] = new int [M];
for(int j = 0; j < M; j++)
pixelVal[i][j] = oldImage.pixelVal[i][j];
}
}
void Image::setImageInfo(int numRows, int numCols, int maxVal)
{
N = numRows;
M = numCols;
Q = maxVal;
}
void Image::getImageInfo(int &numRows, int &numCols, int &maxVal)
{
numRows = N;
numCols = M;
maxVal = Q;
}
int Image::getPixelVal(int row, int col)
{
return pixelVal[row][col];
}
void Image::setPixelVal(int row, int col, int value)
{
pixelVal[row][col] = value;
}
bool Image::inBounds(int row, int col)
/*checks to see if a pixel is within the image, returns true or false*/
{
if(row >= N || row < 0 || col >=M || col < 0)
return false;
//else
return true;
}