From c656ef2ccf0ad1ae8053d76600c1379a84a9d8a7 Mon Sep 17 00:00:00 2001 From: murat Date: Sat, 31 Jan 2026 16:56:33 +0300 Subject: [PATCH] moving image file to the RAM and getting width, height, channels values --- main.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/main.cpp b/main.cpp index add2021..afc0da6 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,8 @@ #include #include #include +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" using std::cout; namespace fs = std::filesystem; @@ -46,8 +48,31 @@ int main(int argc, char *argv[]) { cout << "JPEG detected\n"; } else { cout << "Unkown format!\n"; + return 1; } + int width, height, channels; + + unsigned char* data = stbi_load( + argv[1], + &width, + &height, + &channels, + 3 //forcing to RGB + ); + + if (!data) { + cout << "Failed to load image\n"; + return 1; + } + + cout << "Loaded image:\n"; + cout << "Width: " << width << "\n"; + cout << "Height: " << height << "\n"; + cout << "Channels: " << channels << "\n"; + + stbi_image_free(data); + return 0; }