feat(01-bmpmafia): added nerdybmp program
This commit is contained in:
2
01-bmpmafia/.gitignore
vendored
Normal file
2
01-bmpmafia/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
build
|
||||||
|
samples
|
||||||
6
01-bmpmafia/Makefile
Normal file
6
01-bmpmafia/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
BUILD_DIR = build
|
||||||
|
CXX = g++
|
||||||
|
|
||||||
|
nerdybmp: src/nerdybmp/main.cpp
|
||||||
|
@mkdir -p $(BUILD_DIR)
|
||||||
|
$(CXX) -o build/nerdybmp src/nerdybmp/main.cpp
|
||||||
19
01-bmpmafia/README.md
Normal file
19
01-bmpmafia/README.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# BMPMAFIA
|
||||||
|
|
||||||
|
> working with michaelsoft binbows® bitmap format
|
||||||
|
|
||||||
|
## 🤓 `nerdybmp`
|
||||||
|
|
||||||
|
just prints out some basic `.bmp` file properties
|
||||||
|
|
||||||
|
### build
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make nerdybmp
|
||||||
|
```
|
||||||
|
|
||||||
|
### usage
|
||||||
|
|
||||||
|
```sh
|
||||||
|
build/nerdybmp some/path/to/file.bmp
|
||||||
|
```
|
||||||
31
01-bmpmafia/include/bmp.hpp
Normal file
31
01-bmpmafia/include/bmp.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef BMP_HPP
|
||||||
|
#define BMP_HPP
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
namespace bmp {
|
||||||
|
struct FileHeader {
|
||||||
|
uint16_t type;
|
||||||
|
uint32_t size;
|
||||||
|
uint16_t reserved1;
|
||||||
|
uint16_t reserved2;
|
||||||
|
uint32_t offBits;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct InfoHeader {
|
||||||
|
uint32_t size;
|
||||||
|
int32_t width;
|
||||||
|
int32_t height;
|
||||||
|
uint16_t planes;
|
||||||
|
uint16_t bitCount;
|
||||||
|
uint32_t compression;
|
||||||
|
uint32_t sizeImage;
|
||||||
|
int32_t xPixelsPerMeter;
|
||||||
|
int32_t yPixelsPerMeter;
|
||||||
|
uint32_t colorsUsed;
|
||||||
|
uint32_t colorsImportant;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#pragma pack(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
38
01-bmpmafia/src/nerdybmp/main.cpp
Normal file
38
01-bmpmafia/src/nerdybmp/main.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "../../include/bmp.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
std::cout << "🤓 nerdybmp\n";
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
std::cerr << "🚬 " << argc << " args? we must have more!!\n";
|
||||||
|
std::cerr << "usage:\n";
|
||||||
|
std::cerr << "nerdybmp <input_bmp_file>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream file(argv[1], std::ios_base::binary);
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
std::cerr << "💀 unable to read the file.. ok bye\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmp::FileHeader fileHeader;
|
||||||
|
file.read((char *)&fileHeader, sizeof(fileHeader));
|
||||||
|
|
||||||
|
if (fileHeader.type != 0x4D42) {
|
||||||
|
std::cerr << "💀 we are not cooking: this is NOT a BMP file...\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmp::InfoHeader infoHeader;
|
||||||
|
file.read((char *)&infoHeader, sizeof(infoHeader));
|
||||||
|
|
||||||
|
std::cout << "📂 opened " << argv[1] << '\n';
|
||||||
|
std::cout << "🖼️ hello guys today we have a list of top 3 bmp facts:\n";
|
||||||
|
std::cout << " \033[2mwidth:\033[0m " << infoHeader.width << '\n';
|
||||||
|
std::cout << " \033[2mheight:\033[0m " << infoHeader.height << '\n';
|
||||||
|
std::cout << " \033[2mbit count:\033[0m " << infoHeader.bitCount << '\n';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user