From e17f0057918a4f7b8120396b69c904a22f59c31d Mon Sep 17 00:00:00 2001 From: murat Date: Sat, 31 Jan 2026 17:11:45 +0300 Subject: [PATCH] downscaling pixels --- main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main.cpp b/main.cpp index afc0da6..97f54ad 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" +#include using std::cout; namespace fs = std::filesystem; @@ -11,6 +12,10 @@ namespace fs = std::filesystem; bool is_jpeg(const unsigned char* buf); bool is_png(const unsigned char* buf); +struct Pixel { + unsigned char r, g, b; +}; + int main(int argc, char *argv[]) { for (int i = 0; i <= argc - 1; i++) { std::string arg = argv[i]; @@ -71,6 +76,23 @@ int main(int argc, char *argv[]) { cout << "Height: " << height << "\n"; cout << "Channels: " << channels << "\n"; + std::vector samples; + + int step = 10; //downsample rate + for (int y = 0; y< height; y += step) { + for (int x = 0; x < width; x+= step) { + int idx = (y * width + x) * 3; + + Pixel p; + p.r = data[idx]; + p.g = data[idx + 1]; + p.b = data[idx + 2]; + samples.push_back(p); + } + } + + cout << "Sampled pixels: " << samples.size() << "\n"; + stbi_image_free(data); return 0;