|
|
|
@ -8,14 +8,26 @@ |
|
|
|
|
#include <sstream> |
|
|
|
|
#include <limits> |
|
|
|
|
|
|
|
|
|
/** Application parameters **/ |
|
|
|
|
|
|
|
|
|
constexpr unsigned int WIDTH = 1920; |
|
|
|
|
constexpr unsigned int HEIGHT = 1080; |
|
|
|
|
constexpr unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT)); |
|
|
|
|
constexpr bool OFFSCREEN = false; |
|
|
|
|
constexpr const char* OUTPUT_FILENAME = "font-demo.mkv"; |
|
|
|
|
constexpr const int VA_HW_DEVICE_INDEX = 0; |
|
|
|
|
constexpr double FPS = 60; |
|
|
|
|
|
|
|
|
|
/** Visualization parameters **/ |
|
|
|
|
|
|
|
|
|
constexpr float FONT_SIZE = 40.0f; |
|
|
|
|
constexpr float MAX_STAR_SIZE = 1.0f; |
|
|
|
|
constexpr int MIN_STAR_COUNT = 1000; |
|
|
|
|
constexpr int MAX_STAR_COUNT = 3000; |
|
|
|
|
constexpr float MIN_STAR_LIGHTNESS = 1.0f; |
|
|
|
|
constexpr int MIN_STAR_ALPHA = 5; |
|
|
|
|
// Intensity of glow defined by kernel size. The default scales with the image diagonal.
|
|
|
|
|
constexpr int GLOW_KERNEL_SIZE = std::max(int(DIAG / 138 % 2 == 0 ? DIAG / 138 + 1 : DIAG / 138), 1); |
|
|
|
|
|
|
|
|
|
using std::cerr; |
|
|
|
|
using std::endl; |
|
|
|
@ -52,14 +64,14 @@ int main(int argc, char **argv) { |
|
|
|
|
cerr << "OpenGL Version: " << gl::get_info() << endl; |
|
|
|
|
cerr << "OpenCL Platforms: " << endl << cl::get_info() << endl; |
|
|
|
|
|
|
|
|
|
//BGRA frame buffer and warped image
|
|
|
|
|
cv::UMat frameBuffer, warped; |
|
|
|
|
//BGR video frame.
|
|
|
|
|
//BGRA
|
|
|
|
|
cv::UMat frameBuffer, stars, warped; |
|
|
|
|
//BGR
|
|
|
|
|
cv::UMat videoFrame; |
|
|
|
|
|
|
|
|
|
//The text to display
|
|
|
|
|
string text = cv::getBuildInformation(); |
|
|
|
|
//Create a istringstream that we will read and the rewind. over again.
|
|
|
|
|
//Create a istringstream that we will read and then rewind. over again.
|
|
|
|
|
std::istringstream iss(text); |
|
|
|
|
//Count the number of lines.
|
|
|
|
|
off_t numLines = std::count(text.begin(), text.end(), '\n'); |
|
|
|
@ -68,6 +80,34 @@ int main(int argc, char **argv) { |
|
|
|
|
vector<cv::Point2f> src = {{0,0},{WIDTH,0},{WIDTH,HEIGHT},{0,HEIGHT}}; |
|
|
|
|
vector<cv::Point2f> dst = {{WIDTH/3,0},{WIDTH/1.5,0},{WIDTH,HEIGHT},{0,HEIGHT}}; |
|
|
|
|
cv::Mat M = cv::getPerspectiveTransform(src, dst); |
|
|
|
|
cv::RNG rng(cv::getTickCount()); |
|
|
|
|
|
|
|
|
|
//Activate the OpenCL context for OpenGL.
|
|
|
|
|
gl::bind(); |
|
|
|
|
//Begin a nanovg frame.
|
|
|
|
|
nvg::begin(); |
|
|
|
|
nvg::clear(0,0,0,1); |
|
|
|
|
{ |
|
|
|
|
//draw stars
|
|
|
|
|
using kb::nvg::vg; |
|
|
|
|
int numStars = rng.uniform(MIN_STAR_COUNT, MAX_STAR_COUNT); |
|
|
|
|
for(int i = 0; i < numStars; ++i) { |
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
nvgStrokeWidth(vg, rng.uniform(0.5f, MAX_STAR_SIZE)); |
|
|
|
|
nvgStrokeColor(vg, nvgHSLA(0, 1, rng.uniform(MIN_STAR_LIGHTNESS, 1.0f), rng.uniform(MIN_STAR_ALPHA, 255))); |
|
|
|
|
nvgCircle(vg, rng.uniform(0, WIDTH) , rng.uniform(0, HEIGHT), MAX_STAR_SIZE); |
|
|
|
|
nvgStroke(vg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//End a nanovg frame
|
|
|
|
|
nvg::end(); |
|
|
|
|
|
|
|
|
|
//Aquire frame buffer from OpenGL.
|
|
|
|
|
gl::acquire_from_gl(frameBuffer); |
|
|
|
|
//Copy the star rendering.
|
|
|
|
|
frameBuffer.copyTo(stars); |
|
|
|
|
//Release frame buffer to OpenGL.
|
|
|
|
|
gl::release_to_gl(frameBuffer); |
|
|
|
|
|
|
|
|
|
//Frame count.
|
|
|
|
|
size_t cnt = 0; |
|
|
|
@ -76,15 +116,14 @@ int main(int argc, char **argv) { |
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
y = 0; |
|
|
|
|
|
|
|
|
|
//Activate the OpenCL context for OpenGL.
|
|
|
|
|
gl::bind(); |
|
|
|
|
//Begin a nanovg frame.
|
|
|
|
|
nvg::begin(); |
|
|
|
|
//Clear the screen with black. The clear color can be specified.
|
|
|
|
|
nvg::clear(); |
|
|
|
|
//Clear the screen with black.
|
|
|
|
|
nvg::clear(0,0,0,0); |
|
|
|
|
{ |
|
|
|
|
using kb::nvg::vg; |
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
nvgFontSize(vg, FONT_SIZE); |
|
|
|
|
nvgFontFace(vg, "serif"); |
|
|
|
|
nvgFillColor(vg, nvgHSLA(0.15, 1, 0.5, 255)); |
|
|
|
@ -106,7 +145,7 @@ int main(int argc, char **argv) { |
|
|
|
|
for (std::string line; std::getline(iss, line); ) { |
|
|
|
|
//Check if all yet-to-crawl lines have been skipped.
|
|
|
|
|
if(skipLines == 0) { |
|
|
|
|
//Check if the current lines fits in the page.
|
|
|
|
|
//Check if the current line fits in the page.
|
|
|
|
|
if(((translateY + y) / FONT_SIZE) < pageLines) { |
|
|
|
|
nvgText(vg, WIDTH/2.0, y, line.c_str(), line.c_str() + line.size()); |
|
|
|
|
y += FONT_SIZE; |
|
|
|
@ -135,10 +174,10 @@ int main(int argc, char **argv) { |
|
|
|
|
gl::acquire_from_gl(frameBuffer); |
|
|
|
|
//Pseudo 3D text effect.
|
|
|
|
|
cv::warpPerspective(frameBuffer, warped, M, videoFrame.size(), cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar()); |
|
|
|
|
//Copy back to frame buffer
|
|
|
|
|
warped.copyTo(frameBuffer); |
|
|
|
|
//Combine layers
|
|
|
|
|
cv::add(stars, warped, frameBuffer); |
|
|
|
|
//Color-conversion from BGRA to RGB. OpenCV/OpenCL.
|
|
|
|
|
cv::cvtColor(warped, videoFrame, cv::COLOR_BGRA2RGB); |
|
|
|
|
cv::cvtColor(frameBuffer, videoFrame, cv::COLOR_BGRA2RGB); |
|
|
|
|
//Transfer buffer ownership back to OpenGL.
|
|
|
|
|
gl::release_to_gl(frameBuffer); |
|
|
|
|
|
|
|
|
|