Skip to content

example: add ManyImages sample#32

Merged
hermet merged 1 commit into
mainfrom
hermet/manyimages
Mar 31, 2026
Merged

example: add ManyImages sample#32
hermet merged 1 commit into
mainfrom
hermet/manyimages

Conversation

@hermet
Copy link
Copy Markdown
Member

@hermet hermet commented Mar 30, 2026

Summary

  • add a ManyImages example that loads 500 PNG pictures and randomizes their transforms
  • animate translate, scale, and rotation updates across the picture set
  • register the sample in Meson so it builds with the other examples

Copilot AI review requested due to automatic review settings March 30, 2026 09:52
@hermet hermet added the enhancement Improve examples label Mar 30, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new ThorVG example program (“ManyImages”) and wires it into the Meson build so it is built alongside the other sample executables.

Changes:

  • Register ManyImages.cpp in src/meson.build’s source_file list.
  • Add src/ManyImages.cpp, an example that renders and randomly transforms many tvg::Picture instances.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/meson.build Includes ManyImages.cpp in the set of example executables built by Meson.
src/ManyImages.cpp New example that creates 500 images and randomizes their transforms each update tick.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ManyImages.cpp
Comment thread src/ManyImages.cpp Outdated
@wenjieshen wenjieshen changed the title added ManyImages example: add ManyImages sample Mar 30, 2026
Copilot AI review requested due to automatic review settings March 30, 2026 18:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ManyImages.cpp Outdated
Comment thread src/ManyImages.cpp Outdated
Comment thread src/ManyImages.cpp
Copilot AI review requested due to automatic review settings March 31, 2026 01:58
@hermet hermet force-pushed the hermet/manyimages branch from 84fe257 to f82dee4 Compare March 31, 2026 01:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ManyImages.cpp
Comment on lines +37 to +43
auto p = tvg::Picture::gen();
p->load(EXAMPLE_DIR"/image/test.png");
p->origin(0.5f, 0.5f);
p->translate(rand() % CANVAS_SIZE, rand() % CANVAS_SIZE);
p->scale(float(10 + rand() % 90) * 0.005f);
p->rotate(float(rand() % 360));
canvas->add(p);
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p->load(EXAMPLE_DIR"/image/test.png") ignores the return value. Other picture examples in this repo typically fail the example early when load() fails (e.g., PicturePng.cpp:44). Consider using tvgexam::verify(...) and returning false (or skipping the picture) so the sample doesn't silently run with missing/invalid content when the asset path is wrong or the loader fails.

Copilot uses AI. Check for mistakes.
Comment thread src/ManyImages.cpp
{
for (auto i : canvas->paints()) {
auto p = static_cast<tvg::Picture*>(i);
p->translate(rand() % 1650, rand() % 1650);
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update() hardcodes 1650 for the random translate bounds while the rest of the file defines CANVAS_SIZE. Please use CANVAS_SIZE here as well (or w/h if you want it to follow the window size) to avoid accidental inconsistencies if the canvas size changes later.

Suggested change
p->translate(rand() % 1650, rand() % 1650);
p->translate(rand() % CANVAS_SIZE, rand() % CANVAS_SIZE);

Copilot uses AI. Check for mistakes.
Comment thread src/ManyImages.cpp
Comment on lines +36 to +44
for (int i = 0; i < PIC_COUNT; ++i) {
auto p = tvg::Picture::gen();
p->load(EXAMPLE_DIR"/image/test.png");
p->origin(0.5f, 0.5f);
p->translate(rand() % CANVAS_SIZE, rand() % CANVAS_SIZE);
p->scale(float(10 + rand() % 90) * 0.005f);
p->rotate(float(rand() % 360));
canvas->add(p);
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loads the same PNG from disk PIC_COUNT times. For an example suite this can significantly increase startup time and I/O without changing the rendering stress much. Consider loading once (or loading the file into memory once) and then creating the remaining instances via duplicate() (see Duplicate.cpp:104-115) so you still render 500 pictures but avoid repeated decoding/reads.

Copilot uses AI. Check for mistakes.
@hermet hermet merged commit 801d6d1 into main Mar 31, 2026
5 of 6 checks passed
@hermet hermet deleted the hermet/manyimages branch March 31, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improve examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants