summary refs log tree commit diff
path: root/src/Image
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-10 16:23:26 +0200
committerMel <einebeere@gmail.com>2022-10-10 16:23:26 +0200
commitcb3ddae385c03a8830d39dc37fcd5bf273524d5e (patch)
tree0ccddcd6b32838b8fc2b65805a4fba96c4c0ff39 /src/Image
parent799c06e0387e01bdb8a10019be6192f9db00a824 (diff)
downloadmeowcraft-cb3ddae385c03a8830d39dc37fcd5bf273524d5e.tar.zst
meowcraft-cb3ddae385c03a8830d39dc37fcd5bf273524d5e.zip
Try to add second VBO
Diffstat (limited to 'src/Image')
-rw-r--r--src/Image/PPMParser.cpp11
-rw-r--r--src/Image/RawImage.cpp16
-rw-r--r--src/Image/RawImage.hpp15
3 files changed, 26 insertions, 16 deletions
diff --git a/src/Image/PPMParser.cpp b/src/Image/PPMParser.cpp
index 0a9da54..d7d8c6a 100644
--- a/src/Image/PPMParser.cpp
+++ b/src/Image/PPMParser.cpp
@@ -8,8 +8,6 @@ namespace MC::Image {
 RawImage PPMParser::parse() {
     auto header = parse_header();
 
-    std::cout << header.type << " " << header.width << " " << header.height << " " << (uint64_t)header.max_color << std::endl;
-
     if (header.max_color != 255) {
         throw std::logic_error("PPM max color values other than 255 are not implemented.");
     }
@@ -20,7 +18,7 @@ RawImage PPMParser::parse() {
 
     auto pixel_count = header.width * header.height;
 
-    RawImage image(pixel_count);
+    RawImage image(pixel_count, header.width, header.height, 3);
     for (uint64_t pixel_index = 0; pixel_index < pixel_count; pixel_index++) {
         RawImage::Pixel pixel = parse_pixel(header.max_color);
         image.add(pixel);
@@ -97,16 +95,10 @@ uint64_t PPMParser::chomp_number() {
 
         uint8_t digit = digit_ascii - '0';
 
-        std::cout << "digit_ascii: " << digit_ascii << std::endl;
-        std::cout << "digit: " << (uint64_t)digit << std::endl;
-
         number *= 10;
         number += digit;
-
-        std::cout << "number: " << (uint64_t)number << std::endl;
     }
 
-    std::cout << "chomp number: " << number << std::endl;
     return number;
 }
 
@@ -125,7 +117,6 @@ std::string_view PPMParser::chomp_part() {
     auto part = m_source.substr(m_cursor, length);
     m_cursor += length;
 
-    std::cout << "chomped: " << part << std::endl;
     return part;
 }
 
diff --git a/src/Image/RawImage.cpp b/src/Image/RawImage.cpp
index 50478ad..00bfb0c 100644
--- a/src/Image/RawImage.cpp
+++ b/src/Image/RawImage.cpp
@@ -6,12 +6,24 @@ void RawImage::add(RawImage::Pixel pixel) {
     m_pixels.push_back(pixel);
 }
 
-size_t RawImage::size() {
+size_t RawImage::size() const {
     return m_pixels.size();
 }
 
-uint8_t* RawImage::raw() {
+uint8_t* RawImage::raw() const {
     return (uint8_t*)m_pixels.data();
 }
 
+uint32_t RawImage::width() const {
+    return m_width;
+}
+
+uint32_t RawImage::height() const {
+    return m_height;
+}
+
+uint8_t RawImage::channels() const {
+    return m_channels;
+}
+
 }
\ No newline at end of file
diff --git a/src/Image/RawImage.hpp b/src/Image/RawImage.hpp
index 4414ee0..6c4b122 100644
--- a/src/Image/RawImage.hpp
+++ b/src/Image/RawImage.hpp
@@ -8,9 +8,10 @@ namespace MC::Image {
 
 class RawImage {
 public:
-    RawImage() : m_pixels() {};
+    RawImage() : m_pixels(), m_width(0), m_height(0), m_channels(0) {};
 
-    explicit RawImage(size_t pixel_count) : m_pixels() {
+    explicit RawImage(size_t pixel_count, uint32_t width, uint32_t height, uint8_t channels)
+        : m_pixels(), m_width(width), m_height(height), m_channels(channels) {
         m_pixels.reserve(pixel_count);
     }
 
@@ -20,11 +21,17 @@ public:
 
     void add(Pixel pixel);
 
-    size_t size();
-    uint8_t* raw();
+    size_t size() const;
+    uint8_t* raw() const;
 
+    uint32_t width() const;
+    uint32_t height() const;
+    uint8_t channels() const;
 private:
     std::vector<Pixel> m_pixels;
+
+    uint32_t m_width, m_height;
+    uint8_t m_channels;
 };
 
 }