Compare commits

...

11 Commits

Author SHA1 Message Date
crouvpony47
bbc34345a1 output redirection and color calculation fixes; minor improvements
fix: no longer accessing unexisting element of color_per_count;
fix: improved redirection handing;
fix: don't print empty rows in thumbs mode.
2019-05-22 11:11:39 +02:00
Stefan Haustein
53dff6f5b9
Update README.md 2019-03-26 21:35:23 +01:00
Stefan Haustein
12089c098a
Update README.md 2019-03-26 21:32:58 +01:00
Stefan Haustein
1cdfc4d9db
Update README.md 2019-03-26 21:30:28 +01:00
cabelo
128e106b82 Redirect STDOUT to file 2019-03-26 21:26:43 +01:00
cabelo
5ef1f70a3a Redirect STDOUT to file 2019-03-26 21:26:43 +01:00
Stefan Haustein
f055e5b675 Revert "Persistence options"
This reverts commit aef2fbccdc.
2019-03-23 22:33:28 +01:00
Stefan Haustein
d749d51042 Revert "Constant standard output stream"
This reverts commit 543cebef37.
2019-03-23 22:33:28 +01:00
Stefan Haustein
cd2805d33d Revert "null values"
This reverts commit 9717adc840.
2019-03-23 22:33:28 +01:00
Stefan Haustein
7e5b9d94ee Revert "null values"
This reverts commit 28e9f5e40e.
2019-03-23 22:33:28 +01:00
Stefan Haustein
0973fbd76c Revert "null values"
This reverts commit 3e57ebb80c.
2019-03-23 22:33:28 +01:00
2 changed files with 24 additions and 27 deletions

View File

@ -15,6 +15,7 @@ See the difference by disabling this optimization using the `-0` option. Or just
## News
- 2019-03-26: Exciting week: @Cableo has fixed output redirection, @boretom has added cross-compilation support to the build file and @AlanDeSmet has fixed tall thumbnails and greyscale images.
- 2019-01-14: Install via snap: `sudo snap install --edge tiv`
## Installation
@ -31,6 +32,8 @@ See the difference by disabling this optimization using the `-0` option. Or just
make
sudo make install
Note: On MacOS, you'll need to install GCC because of this issue: https://stackoverflow.com/q/42633477. Find some more details here: https://github.com/stefanhaustein/TerminalImageViewer/issues/36
## Usage
tiv [options] <filename(s)>
@ -66,8 +69,3 @@ The top image was generated with the character optimization disabled via the `-0
![Comparison](https://i.imgur.com/OzdCeh6.png)
## Save file
Saving the disk image for use in other processes or softwares via the -o option
![Persistence](https://i.imgur.com/LMb5KBX.png)

View File

@ -17,7 +17,6 @@ const int FLAG_BG = 2;
const int FLAG_MODE_256 = 4;
const int FLAG_24BIT = 8;
const int FLAG_NOOPT = 16;
const int FLAG_SAVE = 32;
const int COLOR_STEP_COUNT = 6;
const int COLOR_STEPS[COLOR_STEP_COUNT] = {0, 0x5f, 0x87, 0xaf, 0xd7, 0xff};
@ -196,8 +195,7 @@ CharData getCharData(const cimg_library::CImg<unsigned char> & image, int x0, in
int count2 = iter->first;
long max_count_color_1 = iter->second;
long max_count_color_2 = max_count_color_1;
if (iter != color_per_count.rend()) {
++iter;
if ((++iter) != color_per_count.rend()) {
count2 += iter->first;
max_count_color_2 = iter->second;
}
@ -331,7 +329,7 @@ void emit_color(int flags, int r, int g, int b) {
int gq = COLOR_STEPS[gi];
int bq = COLOR_STEPS[bi];
int gray = std::round(r * 0.2989f + g * 0.5870f + b * 0.1140f);
int gray = static_cast<int>(std::round(r * 0.2989f + g * 0.5870f + b * 0.1140f));
int gri = best_index(gray, GRAYSCALE_STEPS, GRAYSCALE_STEP_COUNT);
int grq = GRAYSCALE_STEPS[gri];
@ -419,7 +417,6 @@ void emit_usage() {
std::cerr << " -help : Display this help text." << std::endl;
std::cerr << " -h <num> : Set the maximum height to <num> lines." << std::endl;
std::cerr << " -w <num> : Set the maximum width to <num> characters." << std::endl << std::endl;
std::cerr << " -o <name> : Output file name." << std::endl << std::endl;
}
enum Mode {AUTO, THUMBNAILS, FULL_SIZE};
@ -442,20 +439,27 @@ cimg_library::CImg<unsigned char> load_rgb_CImg(const char * const filename) {
}
int main(int argc, char* argv[]) {
int maxWidth = 80;
int maxHeight = 24;
bool sizeDetectionSuccessful = true;
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
//If redirect STDOUT to one file ( col and row == 0 )
if(w.ws_col == 0 && w.ws_row == 0) {
ioctl(0, TIOCGWINSZ, &w);
int ioStatus = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
// If redirecting STDOUT to one file ( col or row == 0, or the previous ioctl call's failed )
if (ioStatus != 0 || (w.ws_col | w.ws_row) == 0) {
ioStatus = ioctl(STDIN_FILENO, TIOCGWINSZ, &w);
if (ioStatus != 0 || (w.ws_col | w.ws_row) == 0) {
std::cerr << "Warning: failed to determine most reasonable size, defaulting to 80x24" << std::endl;
sizeDetectionSuccessful = false;
}
}
if (sizeDetectionSuccessful)
{
maxWidth = w.ws_col * 4;
maxHeight = w.ws_row * 8;
}
int maxWidth = w.ws_col * 4;
int maxHeight = w.ws_row * 8;
int flags = 0;
Mode mode = AUTO;
int columns = 3;
std::string output_file;
std::vector<std::string> file_names;
int error = 0;
@ -469,9 +473,6 @@ int main(int argc, char* argv[]) {
std::string arg(argv[i]);
if (arg == "-0") {
flags |= FLAG_NOOPT;
} else if (arg == "-o") {
output_file = argv[++i];
flags |= FLAG_SAVE;
} else if (arg == "-c") {
columns = std::stoi(argv[++i]);
} else if (arg == "-d") {
@ -501,9 +502,7 @@ int main(int argc, char* argv[]) {
}
}
if ((flags & FLAG_SAVE) != 0) {
freopen(output_file.c_str(),"w",stdout);
}
if (mode == FULL_SIZE || (mode == AUTO && file_names.size() == 1)) {
for (unsigned int i = 0; i < file_names.size(); i++) {
try {
@ -536,7 +535,7 @@ int main(int argc, char* argv[]) {
std::string name = file_names[index++];
try {
cimg_library::CImg<unsigned char> original = load_rgb_CImg(name.c_str());
unsigned int cut = name.find_last_of("/");
auto cut = name.find_last_of("/");
sb += cut == std::string::npos ? name : name.substr(cut + 1);
size newSize = size(original).fitted_within(maxThumbSize);
original.resize(newSize.width, newSize.height, 1, -100, 5);
@ -549,7 +548,7 @@ int main(int argc, char* argv[]) {
// Probably no image; ignore.
}
}
emit_image(image, flags);
if (count) emit_image(image, flags);
std::cout << sb << std::endl << std::endl;
}
}