From 0cd22f3bd27c442929c0de7a4573addf75cd1570 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Sat, 5 Mar 2022 16:15:00 +0100 Subject: [PATCH] Project setup, and high-level class --- Exec/CMakeLists.txt | 19 +++++++++++++++++++ Exec/main.cpp | 9 +++++++++ Src/BMP.cpp | 29 +++++++++++++++++++++++++++++ Src/BMP.h | 25 +++++++++++++++++++++++++ Src/CMakeLists.txt | 2 ++ Src/Colormodes.h | 13 +++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 Exec/CMakeLists.txt create mode 100644 Exec/main.cpp create mode 100644 Src/BMP.cpp create mode 100644 Src/BMP.h create mode 100644 Src/Colormodes.h diff --git a/Exec/CMakeLists.txt b/Exec/CMakeLists.txt new file mode 100644 index 0000000..2e8335f --- /dev/null +++ b/Exec/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.16) +project(BmpPP_exec) + +set(CMAKE_CXX_STANDARD 17) + +ADD_COMPILE_DEFINITIONS(_EULE_NO_INTRINSICS_) + +INCLUDE_DIRECTORIES(../Src/Eule/) +INCLUDE_DIRECTORIES(../Src/) + +FILE(GLOB Eule ../Src/Eule/Eule/*.cpp) +FILE(GLOB BmpPP ../Src/*.cpp) + +add_executable(BmpPP_exec + ${Eule} + ${BmpPP} + + main.cpp +) diff --git a/Exec/main.cpp b/Exec/main.cpp new file mode 100644 index 0000000..877f742 --- /dev/null +++ b/Exec/main.cpp @@ -0,0 +1,9 @@ +#include + +using namespace Leonetienne::BmpPP; + +int main() { + BMP bmp({800, 600}); + + return 0; +} diff --git a/Src/BMP.cpp b/Src/BMP.cpp new file mode 100644 index 0000000..6ad450a --- /dev/null +++ b/Src/BMP.cpp @@ -0,0 +1,29 @@ +#include "BMP.h" +#include + +namespace Leonetienne::BmpPP { + + BMP::BMP(const Eule::Vector2i &size, const Colormode& colormode) + : + size { size } + { + + pixelBuffer.clear(); + pixelBuffer.resize(size.x * size.y * ColormodeToPixelSize(colormode)); + + return; + } + + int BMP::ColormodeToPixelSize(const Colormode &colormode) { + + switch (colormode) { + case Colormode::RGB: + return 3; + case Colormode::RGBA: + return 4; + + // Unreachable + } + } + +} diff --git a/Src/BMP.h b/Src/BMP.h new file mode 100644 index 0000000..7defadc --- /dev/null +++ b/Src/BMP.h @@ -0,0 +1,25 @@ +#ifndef BMPPP_BMP_H +#define BMPPP_BMP_H + +#include +#include +#include +#include "Colormodes.h" + +namespace Leonetienne::BmpPP { + + class BMP { + public: + explicit BMP(const Eule::Vector2i& size, const Colormode& colormode = Colormode::RGBA); + + private: + //! Will return the corresponding pixel size (in bytes) of a colormode. Like, 3 for RGB and 4 for RGBA. + static int ColormodeToPixelSize(const Colormode& colormode); + + Eule::Vector2i size; + std::vector pixelBuffer; + }; + +} + +#endif //BMPPP_BMP_H diff --git a/Src/CMakeLists.txt b/Src/CMakeLists.txt index 8a4f2d3..a45f554 100644 --- a/Src/CMakeLists.txt +++ b/Src/CMakeLists.txt @@ -9,4 +9,6 @@ FILE(GLOB Eule ./Eule/Eule/*.cpp) add_library(BmpPP ${Eule} + + BMP.cpp ) diff --git a/Src/Colormodes.h b/Src/Colormodes.h new file mode 100644 index 0000000..5f49df7 --- /dev/null +++ b/Src/Colormodes.h @@ -0,0 +1,13 @@ +#ifndef BMPPP_COLORMODES_H +#define BMPPP_COLORMODES_H + +namespace Leonetienne { + namespace BmpPP { + enum class Colormode { + RGB, + RGBA + }; + } +} + +#endif //BMPPP_COLORMODES_H