BMP copying working

git-svn-id: svn://anubis/gvsu@203 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-10-20 02:40:19 +00:00
parent f834d1c481
commit 5cd2b95b00
3 changed files with 19 additions and 10 deletions

View File

@ -8,12 +8,12 @@
#include <iostream>
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++)

View File

@ -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();
};

View File

@ -1,9 +1,18 @@
#include <iostream>
#include <string.h>
#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;
}