updated BMP.cc to avoid compiler warnings
git-svn-id: svn://anubis/fart/trunk@65 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
47dd5a31fe
commit
c5ac957dff
17
main/BMP.cc
17
main/BMP.cc
@ -26,11 +26,12 @@ BMP::~BMP()
|
||||
|
||||
bool BMP::open(const char * fileName)
|
||||
{
|
||||
size_t bytes_read;
|
||||
m_fp = fopen(fileName, "r+");
|
||||
if (m_fp != NULL)
|
||||
{
|
||||
// read file header
|
||||
fread(&m_header, sizeof(m_header), 1, m_fp);
|
||||
bytes_read = fread(&m_header, sizeof(m_header), 1, m_fp);
|
||||
if (m_header.id[0] != 'B' || m_header.id[1] != 'M')
|
||||
{
|
||||
cerr << fileName << " does not appear to be a BMP file." << endl;
|
||||
@ -38,7 +39,7 @@ bool BMP::open(const char * fileName)
|
||||
m_fp = NULL;
|
||||
}
|
||||
// read image information
|
||||
fread(&m_info, sizeof(m_info), 1, m_fp);
|
||||
bytes_read = fread(&m_info, sizeof(m_info), 1, m_fp);
|
||||
}
|
||||
return (m_fp != NULL);
|
||||
}
|
||||
@ -46,6 +47,7 @@ bool BMP::open(const char * fileName)
|
||||
bool BMP::create(const char * fileName, int width, int height,
|
||||
unsigned char * data)
|
||||
{
|
||||
size_t bytes_written;
|
||||
m_fp = fopen(fileName, "w+");
|
||||
if (m_fp != NULL)
|
||||
{
|
||||
@ -76,16 +78,16 @@ bool BMP::create(const char * fileName, int width, int height,
|
||||
m_info.num_important_colors = 0;
|
||||
|
||||
/* write them to the file */
|
||||
fwrite(&m_header, sizeof(m_header), 1, m_fp);
|
||||
fwrite(&m_info, sizeof(m_info), 1, m_fp);
|
||||
bytes_written = fwrite(&m_header, sizeof(m_header), 1, m_fp);
|
||||
bytes_written = fwrite(&m_info, sizeof(m_info), 1, m_fp);
|
||||
|
||||
unsigned int zero = 0;
|
||||
unsigned char * data_ptr = data + (3 * width) * (height - 1);
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
fwrite(data_ptr, 3 * width, 1, m_fp);
|
||||
bytes_written = fwrite(data_ptr, 3 * width, 1, m_fp);
|
||||
if (row_padding)
|
||||
fwrite(&zero, row_padding, 1, m_fp);
|
||||
bytes_written = fwrite(&zero, row_padding, 1, m_fp);
|
||||
data_ptr -= 3 * width;
|
||||
}
|
||||
}
|
||||
@ -94,6 +96,7 @@ bool BMP::create(const char * fileName, int width, int height,
|
||||
|
||||
void BMP::read(unsigned char * buf)
|
||||
{
|
||||
size_t bytes_read;
|
||||
if (m_fp != NULL)
|
||||
{
|
||||
int row_data_bytes = 3 * m_info.width;
|
||||
@ -108,7 +111,7 @@ void BMP::read(unsigned char * buf)
|
||||
unsigned char * data_ptr = buf + row_data_bytes * (m_info.height - 1);
|
||||
for (int i = 0; i < m_info.height; i++)
|
||||
{
|
||||
fread(data_ptr, row_data_bytes, 1, m_fp);
|
||||
bytes_read = fread(data_ptr, row_data_bytes, 1, m_fp);
|
||||
if (row_padding)
|
||||
fseek(m_fp, row_padding, SEEK_CUR);
|
||||
data_ptr -= row_data_bytes;
|
||||
|
Loading…
x
Reference in New Issue
Block a user