This commit is contained in:
Aaron Liu 2024-02-01 18:30:28 -05:00
parent dedaa1b7c2
commit ca97659f83
No known key found for this signature in database
GPG key ID: 2D4DA57B12065A35

View file

@ -424,7 +424,7 @@ int best_index(int value, const int STEPS[], int count) {
return result;
}
void emit_color(const int &flags, int r, int g, int b) {
void printTermColor(const int &flags, int r, int g, int b) {
r = clamp_byte(r);
g = clamp_byte(g);
b = clamp_byte(b);
@ -461,7 +461,7 @@ void emit_color(const int &flags, int r, int g, int b) {
std::cout << (bg ? "\x1B[48;5;" : "\u001B[38;5;") << color_index << "m";
}
void emitCodepoint(int codepoint) {
void printCodepoint(int codepoint) {
if (codepoint < 128) {
std::cout << static_cast<char>(codepoint);
} else if (codepoint < 0x7ff) {
@ -481,7 +481,7 @@ void emitCodepoint(int codepoint) {
}
}
void emit_image(const cimg_library::CImg<unsigned char> &image,
void printImage(const cimg_library::CImg<unsigned char> &image,
const int &flags) {
GetPixelFunction get_pixel = [&](int x, int y,
int channel) -> unsigned char {
@ -496,12 +496,12 @@ void emit_image(const cimg_library::CImg<unsigned char> &image,
? createCharData(get_pixel, x, y, 0x2584, 0x0000ffff)
: findCharData(get_pixel, x, y, flags);
if (x == 0 || charData.bgColor != lastCharData.bgColor)
emit_color(flags | FLAG_BG, charData.bgColor[0],
printTermColor(flags | FLAG_BG, charData.bgColor[0],
charData.bgColor[1], charData.bgColor[2]);
if (x == 0 || charData.fgColor != lastCharData.fgColor)
emit_color(flags | FLAG_FG, charData.fgColor[0],
printTermColor(flags | FLAG_FG, charData.fgColor[0],
charData.fgColor[1], charData.fgColor[2]);
emitCodepoint(charData.codePoint);
printCodepoint(charData.codePoint);
lastCharData = charData;
}
std::cout << "\x1b[0m" << std::endl;
@ -549,7 +549,7 @@ cimg_library::CImg<unsigned char> load_rgb_CImg(const char *const &filename) {
}
// Implements --help
void emit_usage() {
void printUsage() {
std::cerr << R"(
Terminal Image Viewer v1.2.1
usage: tiv [options] <image> [<image>...]
@ -586,7 +586,7 @@ int main(int argc, char *argv[]) {
int ret = EX_OK; // The return code for the program
if (argc <= 1) {
emit_usage();
printUsage();
return EX_USAGE;
}
@ -620,7 +620,7 @@ int main(int argc, char *argv[]) {
} else if (arg == "--256" || arg == "-2" || arg == "-256") {
flags |= FLAG_MODE_256;
} else if (arg == "--help" || arg == "-help") {
emit_usage();
printUsage();
} else if (arg == "-x") {
flags |= FLAG_TELETEXT;
} else if (arg[0] == '-') {
@ -692,7 +692,7 @@ int main(int argc, char *argv[]) {
5);
}
// the acutal magic which generates the output
emit_image(image, flags);
printImage(image, flags);
} catch (cimg_library::CImgIOException &e) {
std::cerr << "Error: '" << filename
<< "' has an unrecognized file format" << std::endl;
@ -732,7 +732,7 @@ int main(int argc, char *argv[]) {
// Probably no image; ignore.
}
}
if (count) emit_image(image, flags);
if (count) printImage(image, flags);
std::cout << sb << std::endl << std::endl;
}
}