11#pragma once
22
3- #include < fstream> // std::*fstream
4- #include < vector> // std::vector
5- #include < memory> // std::unique_ptr
6- #include < algorithm> // std::fill
7- #include < cstdint> // std::int*_t
8- #include < cstddef> // std::size_t
9- #include < string> // std::string
10- #include < cstring> // std::memcmp
11- #include < stdexcept> // std::runtime_error
12- #include < utility> // std::exchange
3+ #include < fstream> // std::*fstream
4+ #include < vector> // std::vector
5+ #include < memory> // std::unique_ptr
6+ #include < algorithm> // std::fill
7+ #include < cstdint> // std::int*_t
8+ #include < cstddef> // std::size_t
9+ #include < string> // std::string
10+ #include < cstring> // std::memcmp
11+ #include < filesystem> // std::filesystem::path
12+ #include < stdexcept> // std::runtime_error
13+ #include < utility> // std::exchange
1314
1415namespace bmp {
1516 // Magic number for Bitmap .bmp 24 bpp files (24/8 = 3 = rgb colors only)
@@ -469,7 +470,7 @@ namespace bmp {
469470 * Saves Bitmap pixels into a file
470471 * @throws bmp::Exception on error
471472 */
472- void save (const std::string &filename) const {
473+ void save (const std::filesystem::path &filename) const {
473474 // Calculate row and bitmap size
474475 const std::int32_t row_size = m_width * 3 + m_width % 4 ;
475476 const std::uint32_t bitmap_size = row_size * m_height;
@@ -516,14 +517,14 @@ namespace bmp {
516517 // Close File
517518 ofs.close ();
518519 } else
519- throw Exception (" Bitmap::Save(\" " + filename + " \" ): Failed to save pixels to file." );
520+ throw Exception (" Bitmap::Save(\" " + filename. string () + " \" ): Failed to save pixels to file." );
520521 }
521522
522523 /* *
523524 * Loads Bitmap from file
524525 * @throws bmp::Exception on error
525526 */
526- void load (const std::string &filename) {
527+ void load (const std::filesystem::path &filename) {
527528 m_pixels.clear ();
528529
529530 if (std::ifstream ifs{filename, std::ios::binary}) {
@@ -534,12 +535,12 @@ namespace bmp {
534535 // Check if Bitmap file is valid
535536 if (header->magic != BITMAP_BUFFER_MAGIC) {
536537 ifs.close ();
537- throw Exception (" Bitmap::Load(\" " + filename + " \" ): Unrecognized file format." );
538+ throw Exception (" Bitmap::Load(\" " + filename. string () + " \" ): Unrecognized file format." );
538539 }
539540 // Check if the Bitmap file has 24 bits per pixel (for now supporting only 24bpp bitmaps)
540541 if (header->bits_per_pixel != 24 ) {
541542 ifs.close ();
542- throw Exception (" Bitmap::Load(\" " + filename + " \" ): Only 24 bits per pixel bitmaps supported." );
543+ throw Exception (" Bitmap::Load(\" " + filename. string () + " \" ): Only 24 bits per pixel bitmaps supported." );
543544 }
544545
545546 // Seek the beginning of the pixels data
@@ -573,7 +574,7 @@ namespace bmp {
573574 // Close file
574575 ifs.close ();
575576 } else
576- throw Exception (" Bitmap::Load(\" " + filename + " \" ): Failed to load bitmap pixels from file." );
577+ throw Exception (" Bitmap::Load(\" " + filename. string () + " \" ): Failed to load bitmap pixels from file." );
577578 }
578579
579580 private: /* Utils */
0 commit comments