Skip to content

Commit

Permalink
Changed the ints in the imageWriter to std::size_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
wermos committed Feb 27, 2024
1 parent aec8be0 commit 159c8d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
51 changes: 26 additions & 25 deletions Celerity/include/imageWriters/imageWriter.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#pragma once

#include <iostream>
#include <cstddef>
#include <string>

#include "color.hpp"
#include "stb_image_write.h"

class imageWriter {
public:
imageWriter(const int imageWidth, const int imageHeight);
imageWriter(const std::size_t imageWidth, const std::size_t imageHeight);

void writeToPNGBuffer(const color c) {
m_pngData[m_pngDataCounter++] = static_cast<uint8_t>(c.r());
m_pngData[m_pngDataCounter++] = static_cast<uint8_t>(c.g());
m_pngData[m_pngDataCounter++] = static_cast<uint8_t>(c.b());
}

void writeToPNGBuffer(int index, const color c) {
m_pngData[index++] = static_cast<uint8_t>(c.r());
m_pngData[index++] = static_cast<uint8_t>(c.g());
m_pngData[index] = static_cast<uint8_t>(c.b());
void writeToPNGBuffer(std::size_t idx, const color c) {
m_pngData[idx++] = static_cast<uint8_t>(c.r());
m_pngData[idx++] = static_cast<uint8_t>(c.g());
m_pngData[idx] = static_cast<uint8_t>(c.b());
}

void writeToJPGBuffer(const color c) {
Expand All @@ -28,39 +28,40 @@ class imageWriter {
m_jpgData[m_jpgDataCounter++] = static_cast<uint8_t>(c.b());
}

void writeToJPGBuffer(int index, const color c) {
m_jpgData[index++] = static_cast<uint8_t>(c.r());
m_jpgData[index++] = static_cast<uint8_t>(c.g());
m_jpgData[index] = static_cast<uint8_t>(c.b());
void writeToJPGBuffer(std::size_t idx, const color c) {
m_jpgData[idx++] = static_cast<uint8_t>(c.r());
m_jpgData[idx++] = static_cast<uint8_t>(c.g());
m_jpgData[idx] = static_cast<uint8_t>(c.b());
}

//TODO: Explore the stbi_write_png_func and stbi_write_jpg_func functions
//which might not require having the entire image in memory while writing
//it.
// TODO: Explore the stbi_write_png_func and stbi_write_jpg_func functions
// which might not require having the entire image in memory while writing
// it.
int writePNG() {
return stbi_write_png(m_pngFileName.c_str(), m_imageWidth,
m_imageHeight, m_pngComp, m_pngData, m_strideInBytes);
return stbi_write_png(m_pngFileName.c_str(), static_cast<int>(m_imageWidth),
static_cast<int>(m_imageHeight), static_cast<int>(m_pngComp), m_pngData, m_strideInBytes);
}

int writeJPG() {
return stbi_write_jpg(m_jpgFileName.c_str(), m_imageWidth,
m_imageHeight, m_jpgComp, m_jpgData, 80);
return stbi_write_jpg(m_jpgFileName.c_str(), static_cast<int>(m_imageWidth),
static_cast<int>(m_imageHeight), static_cast<int>(m_jpgComp), m_jpgData, 80);
}

~imageWriter();
private:
//Image File Data
const int m_jpgComp = 3; //number of channels in the JPG image
const int m_pngComp = 3; //number of channels in the PNG image
const int m_imageWidth, m_imageHeight;
// Image File Data
static constexpr std::size_t m_jpgComp = 3; // number of channels in the JPG image
static constexpr std::size_t m_pngComp = 3; // number of channels in the PNG image
const std::size_t m_imageWidth;
const std::size_t m_imageHeight;

const std::string m_jpgFileName = "pic.jpg";
const std::string m_pngFileName = "pic.png";
static constexpr std::string m_jpgFileName{"pic.jpg"};
static constexpr std::string m_pngFileName{"pic.png"};
const int m_strideInBytes;

//Constant pointer to non-const data
// Constant pointer to non-const data
uint8_t* const m_jpgData;
uint8_t* const m_pngData;

int m_jpgDataCounter, m_pngDataCounter;
std::size_t m_jpgDataCounter, m_pngDataCounter;
};
4 changes: 2 additions & 2 deletions Celerity/src/imageWriters/imageWriter.cxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "imageWriters/imageWriter.hpp"

imageWriter::imageWriter(const int imageWidth, const int imageHeight) :
imageWriter::imageWriter(const std::size_t imageWidth, const std::size_t imageHeight) :
m_imageWidth(imageWidth), m_imageHeight(imageHeight),
m_strideInBytes(m_imageWidth * m_pngComp),
m_strideInBytes(static_cast<int>(m_imageWidth * m_pngComp)),
m_jpgData(new uint8_t[m_imageWidth * m_imageHeight * m_jpgComp]),
m_pngData(new uint8_t[m_imageWidth * m_imageHeight * m_pngComp]),
m_jpgDataCounter(0), m_pngDataCounter(0)
Expand Down

0 comments on commit 159c8d4

Please sign in to comment.