56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
#ifndef TWO_PERSON_SEQUENCE_H
|
|
#define TWO_PERSON_SEQUENCE_H
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
// Deterministic 640x480 RGB sequence from two copies of the repository's
|
|
// sample_rgb.bin portrait (A, left; B, right). Integer nearest-neighbour
|
|
// sampling, no randomness or external image downloads. Synthetic subjects,
|
|
// not a recording of two independent moving people.
|
|
namespace two_person_sequence {
|
|
constexpr int kWidth = 640;
|
|
constexpr int kHeight = 480;
|
|
constexpr int kFramesPerStage = 4;
|
|
struct Stage {
|
|
int a_height;
|
|
int b_height;
|
|
};
|
|
constexpr Stage kStages[] = {
|
|
{360, 140}, {330, 220}, {220, 330}, {140, 360},
|
|
{60, 380}, {360, 120}};
|
|
|
|
struct Image {
|
|
int width;
|
|
int height;
|
|
std::vector<uint8_t> rgb;
|
|
};
|
|
|
|
inline std::vector<uint8_t> compose(const Image& a, const Image& b,
|
|
const Stage& stage) {
|
|
std::vector<uint8_t> rgb(kWidth * kHeight * 3, 32);
|
|
const Image* images[] = {&a, &b};
|
|
const int heights[] = {stage.a_height, stage.b_height};
|
|
const int centers[] = {160, 480};
|
|
for (int person = 0; person < 2; ++person) {
|
|
const Image& source = *images[person];
|
|
const int height = heights[person];
|
|
const int width = source.width * height / source.height;
|
|
const int left = centers[person] - width / 2;
|
|
const int top = 460 - height;
|
|
for (int y = 0; y < height; ++y) {
|
|
for (int x = 0; x < width; ++x) {
|
|
const int sx = x * source.width / width;
|
|
const int sy = y * source.height / height;
|
|
const auto src = (static_cast<size_t>(sy) * source.width + sx) * 3;
|
|
const auto dst = (static_cast<size_t>(top + y) * kWidth + left + x) * 3;
|
|
std::copy_n(source.rgb.data() + src, 3, rgb.data() + dst);
|
|
}
|
|
}
|
|
}
|
|
return rgb;
|
|
}
|
|
}
|
|
#endif
|