downscaling pixels

This commit is contained in:
2026-01-31 17:11:45 +03:00
parent c656ef2ccf
commit e17f005791
+22
View File
@@ -4,6 +4,7 @@
#include <fstream>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <vector>
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<Pixel> 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;