stuff-from-scratch/src/image/ImagePrimitives.h
2022-11-21 17:45:12 +00:00

41 lines
1.1 KiB
C++

#pragma once
#include <cstdint>
class ImagePrimitives
{
public:
static void drawCheckerboard(uint8_t* data, int width, int height, int offset = 0)
{
auto pixels = (uint32_t *)&(data)[offset];
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
if ((x + y / 8 * 8) % 16 < 8)
{
pixels[y * width + x] = 0xFF666666;
}
else
{
pixels[y * width + x] = 0xFFEEEEEE;
}
}
}
}
static void drawAlternatingStrips(std::vector<unsigned char>& data, unsigned width, unsigned height, unsigned channels, unsigned bytesPerRow)
{
for(unsigned jdx=0;jdx<height;jdx++)
{
const auto heightOffset = jdx*bytesPerRow;
for(unsigned idx=0;idx<width*channels;idx+=channels)
{
const auto index = heightOffset + idx;
data[index] = (idx%2 == 0) ? 255*jdx/(height+1) : 0;
data[index+1] = 0;
data[index+2] = 0;
}
}
}
};