Compare commits
10 Commits
f8dc17242e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b01bcce2d | |||
| f3c10b807d | |||
| adc81e0a0a | |||
| e35c4043bf | |||
| 071eb7b61d | |||
| 8a675f15dd | |||
| 74e93cc050 | |||
| e7725e6e24 | |||
| e72c4db0ca | |||
| 19e7524809 |
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Build directories
|
||||||
|
build/
|
||||||
|
build-win/
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# CMake files
|
||||||
|
CMakeFiles/
|
||||||
|
CMakeCache.txt
|
||||||
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
main
|
||||||
|
ccolors
|
||||||
|
ccolor.exe
|
||||||
|
|
||||||
|
# JSON output
|
||||||
|
palette.json
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(ccolors)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
add_executable(ccolors main.cpp)
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 muwat0
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# ccolors
|
||||||
|
|
||||||
|
Small CLI tool to extract dominant color palettes from images.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- JPEG / PNG support
|
||||||
|
- Terminal color preview
|
||||||
|
- HEX output
|
||||||
|
- JSON export
|
||||||
|
- No external dependencies
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
### Linux / macOS
|
||||||
|
```bash
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```bash
|
||||||
|
./ccolors image.jpg
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output
|
||||||
|
- Prints color swatches + hex
|
||||||
|
- Writes palette.json
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
- stb_image.h (included)
|
||||||
|
|
||||||
|
## License
|
||||||
|
MIT
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
This project uses stb_image.h by Sean Barrett.
|
||||||
|
|
||||||
|
stb_image.h is licensed under the MIT license or placed in the public domain.
|
||||||
|
|
||||||
|
Source:
|
||||||
|
https://github.com/nothings/stb
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#!/usr/bin/bash
|
|
||||||
g++ -std=c++17 main.cpp -O2 -o main
|
|
||||||
@@ -30,18 +30,26 @@ int main(int argc, char *argv[]) {
|
|||||||
for (int i = 0; i <= argc - 1; i++) {
|
for (int i = 0; i <= argc - 1; i++) {
|
||||||
std::string arg = argv[i];
|
std::string arg = argv[i];
|
||||||
if (arg == "--help" || arg == "-h") {
|
if (arg == "--help" || arg == "-h") {
|
||||||
cout << "help flag detected!";
|
cout <<
|
||||||
|
"ccolors - extract color palette from images\n\n"
|
||||||
|
"Usage:\n"
|
||||||
|
" " << argv[0] << " <image>\n\n"
|
||||||
|
"Options:\n"
|
||||||
|
" -h, --help Show this help page\n\n"
|
||||||
|
"Output:\n"
|
||||||
|
" Prints dominant colors as HEX and terminal swatches\n"
|
||||||
|
" Also writes palette.json\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
cout << "Please specify image file. " << argv[0] << " imagefile.jpg";
|
cout << "Please specify a image file. " << argv[0] << " imagefile.jpg"
|
||||||
|
<< "\nTry \"" << argv[0] << " --help\" for more information.";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string imagefile = argv[1];
|
std::string imagefile = argv[1];
|
||||||
cout << "File: " << imagefile << "\n";
|
|
||||||
|
|
||||||
if (!fs::is_regular_file(imagefile)) {
|
if (!fs::is_regular_file(imagefile)) {
|
||||||
std::cout << "File not found: " << imagefile << "\n";
|
std::cout << "File not found: " << imagefile << "\n";
|
||||||
@@ -58,11 +66,11 @@ int main(int argc, char *argv[]) {
|
|||||||
file.read(reinterpret_cast<char*>(header), 8);
|
file.read(reinterpret_cast<char*>(header), 8);
|
||||||
|
|
||||||
if (is_png(header)) {
|
if (is_png(header)) {
|
||||||
cout << "PNG detected\n";
|
cout << "PNG file detected!\n";
|
||||||
} else if (is_jpeg(header)) {
|
} else if (is_jpeg(header)) {
|
||||||
cout << "JPEG detected\n";
|
cout << "JPEG file detected!\n";
|
||||||
} else {
|
} else {
|
||||||
cout << "Unkown format!\n";
|
cout << "Unkown image file format!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,14 +85,17 @@ int main(int argc, char *argv[]) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
cout << "Failed to load image\n";
|
cout << "Failed to load image!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cout << "**********\n";
|
||||||
cout << "Loaded image:\n";
|
cout << "Loaded image:\n";
|
||||||
cout << "Width: " << width << "\n";
|
cout << "Width: " << width << "\n";
|
||||||
cout << "Height: " << height << "\n";
|
cout << "Height: " << height << "\n";
|
||||||
cout << "Channels: " << channels << "\n";
|
cout << "Channels: " << channels << "\n";
|
||||||
|
cout << "**********\n";
|
||||||
|
|
||||||
std::vector<Pixel> samples;
|
std::vector<Pixel> samples;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user