Skip to content

Commit

Permalink
C++ Bitmap Image Reader Writer Library http://partow.net/programming/…
Browse files Browse the repository at this point in the history
  • Loading branch information
ArashPartow committed Sep 3, 2019
1 parent 94af1e2 commit 14377d1
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions bitmap_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ class bitmap_image

if (!stream)
{
std::cerr << "bitmap_image::save_image(): Error - Could not open file " << file_name << " for writing!" << std::endl;
std::cerr << "bitmap_image::save_image(): Error - Could not open file "
<< file_name << " for writing!" << std::endl;
return;
}

Expand Down Expand Up @@ -1511,7 +1512,8 @@ class bitmap_image

if (!stream)
{
std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - file " << file_name_ << " not found!" << std::endl;
std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - "
<< "file " << file_name_ << " not found!" << std::endl;
return;
}

Expand All @@ -1529,36 +1531,41 @@ class bitmap_image

if (bfh.type != 19778)
{
std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - "
<< "Invalid type value " << bfh.type << " expected 19778." << std::endl;

bfh.clear();
bih.clear();

stream.close();

std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Invalid type value " << bfh.type << " expected 19778." << std::endl;
return;
}

if (bih.bit_count != 24)
{
std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - "
<< "Invalid bit depth " << bih.bit_count << " expected 24." << std::endl;

bfh.clear();
bih.clear();

stream.close();

std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Invalid bit depth " << bih.bit_count << " expected 24." << std::endl;

return;
}

if (bih.size != bih.struct_size())
{
std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - "
<< "Invalid BIH size " << bih.size
<< " expected " << bih.struct_size() << std::endl;

bfh.clear();
bih.clear();

stream.close();

std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Invalid BIH size " << bih.size << " expected " << bih.struct_size() << std::endl;

return;
}

Expand All @@ -1568,7 +1575,7 @@ class bitmap_image
bytes_per_pixel_ = bih.bit_count >> 3;

unsigned int padding = (4 - ((3 * width_) % 4)) % 4;
char padding_data[4] = {0,0,0,0};
char padding_data[4] = { 0, 0, 0, 0 };

std::size_t bitmap_file_size = file_size(file_name_);

Expand All @@ -1584,9 +1591,10 @@ class bitmap_image

stream.close();

std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Mismatch between logical and physical sizes of bitmap. " <<
"Logical: " << bitmap_logical_size << " " <<
"Physical: " << bitmap_file_size << std::endl;
std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - "
<< "Mismatch between logical and physical sizes of bitmap. "
<< "Logical: " << bitmap_logical_size << " "
<< "Physical: " << bitmap_file_size << std::endl;

return;
}
Expand Down

0 comments on commit 14377d1

Please sign in to comment.