-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputImage.cc
73 lines (60 loc) · 1.33 KB
/
InputImage.cc
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
// Manage a text file with a black-white image
// George F. Riley, Georgia Tech, Fall 2009
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include "InputImage.h"
#include "Complex.h"
using namespace std;
InputImage::InputImage(const char* fileName)
{
ifstream ifs(fileName);
if (!ifs)
{
cout << "Can't open image file " << fileName << endl;
exit(1);
}
ifs >> w >> h;
data = new Complex[w * h]; // Allocate the data array
for (int r = 0; r < h; ++r)
{ // For each row
for (int c = 0; c < w; ++c)
{
double real;
ifs >> real;
data[r * w + c] = Complex((double)real);
}
}
}
int InputImage::GetWidth() const
{
return w;
}
int InputImage::GetHeight() const
{
return h;
}
Complex* InputImage::GetImageData() const
{
return data;
}
void InputImage::SaveImageData(const char* newFileName, Complex* d,
int w, int h)
{
ofstream ofs(newFileName);
if (!ofs)
{
cout << "Can't create output image " << newFileName << endl;
return;
}
ofs << w << " " << h << endl;
for (int r = 0; r < h; ++r)
{ // for each row
for (int c = 0; c < w; ++c)
{ // for each column
ofs << d[r * w + c].Mag() << " ";
}
ofs << endl;
}
}