Skip to content

Commit

Permalink
further dissection of bmp headers
Browse files Browse the repository at this point in the history
  • Loading branch information
fzp0 committed May 14, 2024
1 parent 6c72a7b commit e04e018
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 10.2.1
)
FETCHCONTENT_MAKEAVAILABLE(fmt)
FetchContent_MakeAvailable(fmt)

add_executable(steganography main.cpp
read_picture.h
Expand Down
4 changes: 2 additions & 2 deletions dib_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct BITMAPINFOHEADER {
uint32_t header_size;
int width;
int height;
uint16_t num_color_planes;
uint16_t bits_per_pixel; // wikipedia says must be 1
uint16_t num_color_planes; // wikipedia says must be 1
uint16_t bytes_per_pixel;
uint32_t compression_method;
uint32_t raw_bitmap_data_size;
int horizontal_resolution;
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void display_file_info(std::filesystem::path const& file) {
fmt::println("Size: {} bytes",file_size(file));
std::string extension = file.extension().string();
if(extension == ".bmp"){
fmt::println("Extension: {} - The BMP file format or bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device (such as a graphics adapter), especially on Microsoft Windows[2] and OS/2[3] operating systems.", file.extension().string());
fmt::println("Extension: {} - The BMP file format or bitmap,\nis a raster graphics image file format used to store bitmap digital images, independently of the display device\n(such as a graphics adapter), especially on Microsoft Windows[2] and OS/2[3] operating systems.", file.extension().string());
auto bmp_info = bmp_reader::read_bmp(file);
}
else if(extension == ".ppm"){
Expand Down
25 changes: 25 additions & 0 deletions read_picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ void bmp_reader::parse_header(std::ifstream& stream, file_header& header) {
void bmp_reader::parse_dib(std::ifstream &stream, dib_header &dib) {
stream.read((char*)&dib.dib_size, 4);
fmt::println("DIB Header size: {}", dib.dib_size);
auto pos = stream.tellg();
pos -= 4;
stream.seekg(pos);

switch(dib.dib_size) {
case 12: // BITMAPCOREHEADER OS21XBITMAPHEADER

Expand All @@ -28,6 +32,27 @@ void bmp_reader::parse_dib(std::ifstream &stream, dib_header &dib) {

break;
case 40: // BITMAPINFOHEADER
fmt::println("Bitmap header type: BITMAPINFOHEADER");
BITMAPINFOHEADER header;
stream.read((char*)&header, 40);
fmt::println("Bitmap Width: {}\nBitmap Height: {}", header.width, header.height);
fmt::println("Color planes: {}", header.num_color_planes);
fmt::println("Bytes per pixel: {}", header.bytes_per_pixel);
fmt::println("Compression method: {}", header.compression_method);
fmt::println("Bitmap data size: {}", header.raw_bitmap_data_size);
fmt::println("Horizontal resolution: {}", header.horizontal_resolution);
fmt::println("Vertical resolution: {}", header.vertical_resolution);
fmt::println("Color pallette: {}", header.num_palette_colors);
fmt::println("Important colors: {}", header.num_important_colors);

// Current offset from file start ->52 = 12 (bmp header) + 40 (DIB BITMAPINFOHEADER)

if(header.compression_method != 0){
fmt::println("Unsupported bitmap compression method: {}", header.compression_method);
exit(-1);
}

stream.seekg(stream.tellg()+())

break;
case 52: // BITMAPV2INFOHEADER
Expand Down
3 changes: 3 additions & 0 deletions read_picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace bmp_reader {
void parse_header(std::ifstream& stream, file_header& header);
void parse_dib(std::ifstream& stream, dib_header& dib);


auto parse_bitmapinfoheader(std::ifstream& stream) -> BITMAPINFOHEADER;

auto read_bmp(std::filesystem::path const& file) -> bmp_data;
}

0 comments on commit e04e018

Please sign in to comment.