Skip to content

Commit a666abe

Browse files
committed
Add output of successful image displays.
1 parent c8b6754 commit a666abe

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/svg-image-source.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ bool SVGImageSource::LoadAndScale(const DisplayOptions &opts, int, int) {
5050
orig_height_ = svg_height.length;
5151
}
5252

53+
// Filter out suspicious dimensions
54+
if (orig_width_ <= 0 || orig_width_ > 1e6 ||
55+
orig_height_ <= 0 || orig_height_ > 1e6) {
56+
g_object_unref(svg);
57+
return false;
58+
}
59+
5360
int target_width;
5461
int target_height;
5562
CalcScaleToFitDisplay(orig_width_, orig_height_, opts, false, &target_width,
@@ -72,6 +79,7 @@ bool SVGImageSource::LoadAndScale(const DisplayOptions &opts, int, int) {
7279
};
7380

7481
bool success = rsvg_handle_render_document(svg, cr, &viewport, nullptr);
82+
7583
cairo_destroy(cr);
7684
cairo_surface_destroy(surface);
7785
g_object_unref(svg);

src/timg.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ bool AppendToFileList(const std::string &filelist_file,
307307
return true;
308308
}
309309

310-
static void PresentImages(LoadedImageSources *loaded_sources,
311-
const timg::DisplayOptions &display_opts,
312-
const timg::PresentationOptions &present,
313-
timg::BufferedWriteSequencer *sequencer,
314-
bool *any_animations_seen) {
310+
static int PresentImages(LoadedImageSources *loaded_sources,
311+
const timg::DisplayOptions &display_opts,
312+
const timg::PresentationOptions &present,
313+
timg::BufferedWriteSequencer *sequencer,
314+
bool *any_animations_seen) {
315315
using timg::ThreadPool;
316316
std::unique_ptr<ThreadPool> compression_pool;
317317
std::unique_ptr<TerminalCanvas> canvas;
@@ -374,10 +374,12 @@ static void PresentImages(LoadedImageSources *loaded_sources,
374374

375375
// Showing them in order of files on the command line.
376376
bool is_first = true;
377+
int valid_images = 0;
377378
for (auto &source_future : *loaded_sources) {
378379
if (interrupt_received) break;
379380
std::unique_ptr<timg::ImageSource> source(source_future.get());
380381
if (!source) continue;
382+
valid_images++;
381383
*any_animations_seen |= source->IsAnimationBeforeFrameLimit();
382384
before_image_show(is_first);
383385
source->SendFrames(present.duration_per_image, present.loops,
@@ -389,6 +391,7 @@ static void PresentImages(LoadedImageSources *loaded_sources,
389391
is_first = false;
390392
}
391393
sequencer->Flush();
394+
return valid_images;
392395
}
393396

394397
static std::optional<Pixelation> ParsePixelation(const char *as_text) {
@@ -943,6 +946,10 @@ int main(int argc, char *argv[]) {
943946

944947
// Asynconrous image loading (filelist.size()) and terminal query (+1)
945948
thread_count = (thread_count > 0 ? thread_count : kDefaultThreadCount);
949+
950+
// Note: this thread pool will be leaked explicitly to not unnecessarily
951+
// have to wait on potentially blocking cleanup at program exit where it
952+
// does not matter.
946953
timg::ThreadPool *const pool =
947954
new timg::ThreadPool(std::min(thread_count, (int)filelist.size() + 1));
948955

@@ -1012,8 +1019,9 @@ int main(int argc, char *argv[]) {
10121019
output_fd, buffer_allow_skipping, kAsyncWriteQueueSize,
10131020
debug_no_frame_delay, interrupt_received);
10141021
const Time start_show = Time::Now();
1015-
PresentImages(&loaded_sources, display_opts, present, &sequencer,
1016-
&cell_size_warning_needed);
1022+
const int successful_images =
1023+
PresentImages(&loaded_sources, display_opts, present, &sequencer,
1024+
&cell_size_warning_needed);
10171025
const Time end_show = Time::Now();
10181026

10191027
// Error messages have been collected to not clutter the image output
@@ -1093,9 +1101,10 @@ int main(int argc, char *argv[]) {
10931101
const uint64_t written_bytes =
10941102
sequencer.bytes_total() - sequencer.bytes_skipped();
10951103
fprintf(stderr,
1096-
"%d file%s; %s written (%s/s) "
1104+
"%d file%s (%d successful); %s written (%s/s) "
10971105
"%" PRId64 " frames",
10981106
(int)filelist.size(), filelist.size() == 1 ? "" : "s",
1107+
successful_images,
10991108
timg::HumanReadableByteValue(written_bytes).c_str(),
11001109
timg::HumanReadableByteValue(written_bytes / d).c_str(),
11011110
sequencer.frames_total());

0 commit comments

Comments
 (0)