if (picture->load(buf) != tvg::Result::Success) return;
- picture->size(SIZE, SIZE);
+ //image scaling preserving its aspect ratio
+ float scale;
+ float shiftX = 0.0f, shiftY = 0.0f;
+ float w, h;
+ picture->size(&w, &h);
+
+ if (w > h) {
+ scale = SIZE / w;
+ shiftY = (SIZE - h * scale) * 0.5f;
+ } else {
+ scale = SIZE / h;
+ shiftX = (SIZE - w * scale) * 0.5f;
+ }
+
+ picture->scale(scale);
+ picture->translate(shiftX, shiftY);
if (canvas->push(move(picture)) != tvg::Result::Success) return;
if (picture->load(buf) != tvg::Result::Success) return;
- picture->size(SIZE, SIZE);
- picture->translate((xCnt % NUM_PER_LINE) * SIZE, SIZE * (xCnt / NUM_PER_LINE));
+ //image scaling preserving its aspect ratio
+ float scale;
+ float shiftX = 0.0f, shiftY = 0.0f;
+ float w, h;
+ picture->size(&w, &h);
+
+ if (w > h) {
+ scale = SIZE / w;
+ shiftY = (SIZE - h * scale) * 0.5f;
+ } else {
+ scale = SIZE / h;
+ shiftX = (SIZE - w * scale) * 0.5f;
+ }
+
+ picture->scale(scale);
+ picture->translate((xCnt % NUM_PER_LINE) * SIZE + shiftX, SIZE * (xCnt / NUM_PER_LINE) + shiftY);
++xCnt;
//Duplicates
for (int i = 0; i < NUM_PER_LINE - 1; i++) {
tvg::Picture* dup = static_cast<tvg::Picture*>(picture->duplicate());
- dup->translate((xCnt % NUM_PER_LINE) * SIZE, SIZE * (xCnt / NUM_PER_LINE));
+ dup->translate((xCnt % NUM_PER_LINE) * SIZE + shiftX, SIZE * (xCnt / NUM_PER_LINE) + shiftY);
pictures.push_back(dup);
++xCnt;
}