diff --git a/cs677/pa3/BMP.cc b/cs677/pa3/BMP.cc index 7753df4..6682b36 100644 --- a/cs677/pa3/BMP.cc +++ b/cs677/pa3/BMP.cc @@ -8,12 +8,12 @@ #include using namespace std; -BMP::BMP(char * fileName) +BMP::BMP(const char * fileName) { open(fileName); } -BMP::BMP(char * fileName, int width, int height, unsigned char * data) +BMP::BMP(const char * fileName, int width, int height, unsigned char * data) { create(fileName, width, height, data); } @@ -24,7 +24,7 @@ BMP::~BMP() close(); } -bool BMP::open(char * fileName) +bool BMP::open(const char * fileName) { m_fp = fopen(fileName, "r+"); if (m_fp != NULL) @@ -43,7 +43,7 @@ bool BMP::open(char * fileName) return (m_fp != NULL); } -bool BMP::create(char * fileName, int width, int height, unsigned char * data) +bool BMP::create(const char * fileName, int width, int height, unsigned char * data) { m_fp = fopen(fileName, "w+"); if (m_fp != NULL) @@ -102,7 +102,7 @@ void BMP::read(unsigned char * buf) fseek(m_fp, (m_header.offset != 0 ? m_header.offset - : sizeof(m_header) + sizeof(m_info)) + : sizeof(m_header) + sizeof(m_info)), SEEK_SET); unsigned char * data_ptr = buf + row_data_bytes * (m_info.height - 1); for (int i = 0; i < m_info.height; i++) diff --git a/cs677/pa3/BMP.h b/cs677/pa3/BMP.h index fb93836..e4ac9bd 100644 --- a/cs677/pa3/BMP.h +++ b/cs677/pa3/BMP.h @@ -31,8 +31,8 @@ public: int num_important_colors; } __attribute__ ((packed)) info_t; - BMP(char * fileName); - BMP(char * fileName, int width, int height, unsigned char * data); + BMP(const char * fileName); + BMP(const char * fileName, int width, int height, unsigned char * data); ~BMP(); void read(unsigned char * buf); int getWidth() { return m_info.width; } @@ -43,7 +43,7 @@ private: header_t m_header; info_t m_info; - bool open(char * fileName); - bool create(char * fileName, int width, int height, unsigned char * data); + bool open(const char * fileName); + bool create(const char * fileName, int width, int height, unsigned char * data); void close(); }; diff --git a/cs677/pa3/edge-detect.cc b/cs677/pa3/edge-detect.cc index 8b5cb41..29749c8 100644 --- a/cs677/pa3/edge-detect.cc +++ b/cs677/pa3/edge-detect.cc @@ -1,9 +1,18 @@ #include +#include #include "BMP.h" using namespace std; int main(int argc, char * argv[]) { - cout << "edge-detect" << endl; + BMP readfrom(argv[1]); + unsigned char * data = new unsigned char[readfrom.getWidth() * readfrom.getHeight() * 3]; + readfrom.read(data); + + BMP bmp_create((string(argv[1], strlen(argv[1]) - 4) + "-2.bmp").c_str(), + readfrom.getWidth(), + readfrom.getHeight(), + data); + delete[] data; }