Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BraceWrapping:
AfterNamespace: true
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterObjCDeclaration: false
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ __pycache__/

# CMake
build/
vcpkg_installed/
vcpkg*

# dependencies
include/argparse/
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ SRC_TSF_OTHER = src/transformation/other/overlay.cpp \


OBJ = $(SRC:.cpp=.o)
NAME = vc

NAME = video-code
BUILD_DIR = build

# >>> Rules <<<

Expand Down Expand Up @@ -150,7 +150,15 @@ debug: fclean
format:
clang-format -i **/*.cpp **/*.hpp


.PHONY: docs
docs:
./vc --generate
./docs/readme/generate.sh


.PHONY: cmake
cmake:
cmake -B $(BUILD_DIR)
$(MAKE) -C $(BUILD_DIR)
cp $(BUILD_DIR)/video-code .
74 changes: 74 additions & 0 deletions include/input/Iterable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
** EPITECH PROJECT, 2025
** video-code
** File description:
** Iterable
*/

#pragma once

#include <nlohmann/json.hpp>

#include "input/IInput.hpp"

using json = nlohmann::json;

class IterableInput
{
public:

IterableInput(std::shared_ptr<IInput> input, json startTime, json endTime, int framerate)
: _input(input)
{
///< The start and end of time are floats, they represent seconds.

///< Start/Begin Index
if (startTime.is_null()) {
_beginIndex = 0;
}
else if (startTime < 0.0f) {
_beginIndex = startTime.get<float>() * framerate + static_cast<int>(input->size());
}
else {
_beginIndex = startTime.get<float>() * framerate;
}

///< End Index
if (endTime.is_null()) {
_endIndex = input->size();
}
else if (endTime < 0.0f) {
_endIndex = endTime.get<float>() * framerate + static_cast<int>(input->size());
}
else {
_endIndex = endTime.get<float>() * framerate;
}

_size = _endIndex - _beginIndex;

_beginIterator = input->begin() + _beginIndex;
_endIterator = input->begin() + _endIndex;
}

~IterableInput() = default;

std::vector<Frame>::iterator begin() { return _beginIterator; }

std::vector<Frame>::iterator end() { return _endIterator; }

IInput* operator->() { return _input.get(); }

size_t nbFrames() { return _size; };

private:

std::shared_ptr<IInput> _input;

size_t _beginIndex;
size_t _endIndex;
size_t _size;

///< Different begin and start than the size of the frames of the input
std::vector<Frame>::iterator _beginIterator;
std::vector<Frame>::iterator _endIterator;
};
2 changes: 1 addition & 1 deletion include/input/concrete/text/Text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Text final : public ABCConcreteInput
{
public:

Text(const std::string &text, double fontSize, int fontThickness, const std::vector<int> &color, int font = cv::FONT_HERSHEY_SIMPLEX);
Text(const std::string &text, double fontSize, int fontThickness, const std::vector<int> &color, float duration, int framerate, int font = cv::FONT_HERSHEY_SIMPLEX);
~Text() = default;

private:
Expand Down
7 changes: 3 additions & 4 deletions include/transformation/transformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

#include <nlohmann/json.hpp>

#include "input/Iterable.hpp"
#include "vm/Register.hpp"

using json = nlohmann::json;

#define transformation(t) void t(std::shared_ptr<IInput> input, Register &reg, const json::object_t &args)
#define transformation(t) void t(IterableInput input, const json::object_t &args)

namespace transformation
{
Expand All @@ -27,22 +28,20 @@ namespace transformation
transformation(move);

// Other
transformation(overlay);
transformation(repeat);
/***
TODO: transformation(concat);
TODO: transformation(merge);
***/

static const std::map<std::string, std::function<void(std::shared_ptr<IInput>, Register &, const json::object_t &)>> map{
static const std::map<std::string, std::function<void(IterableInput input, const json::object_t &args)>> map{
// Color
{"grayscale", grayscale},
{"fade", fade},
// Position
{"translate", translate},
{"move", move},
// Other
{"overlay", overlay},
{"repeat", repeat},
};
};
5 changes: 4 additions & 1 deletion include/vm/Register.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Register

private:

///< frame rate
const int _framerate{24};

///< Variables representing the Inputs currently used in the program
std::vector<std::shared_ptr<IInput>> _inputs{};

Expand All @@ -49,7 +52,7 @@ class Register
{"Video", [this](const json::object_t &args) { _inputs.push_back(std::make_shared<Video>(args.at("filepath"))); }},
{"Copy", [this](const json::object_t &args) { _inputs.push_back(std::shared_ptr<IInput>(_inputs[args.at("input")]->copy())); }},
{"Slice", [this](const json::object_t &args) { _inputs.push_back(std::make_shared<Slice>(_inputs[args.at("input")], args.at("start"), args.at("stop"))); }},
{"Text", [this](const json::object_t &args) { _inputs.push_back(std::make_shared<Text>(args.at("text"), args.at("fontSize"), args.at("fontThickness"), args.at("color"))); }},
{"Text", [this](const json::object_t &args) { _inputs.push_back(std::make_shared<Text>(args.at("text"), args.at("fontSize"), args.at("fontThickness"), args.at("color"), args.at("duration"), _framerate)); }},
/// TODO: Shapes (Circle, Square)
/// TODO: Formula (not important)
};
Expand Down
2 changes: 1 addition & 1 deletion include/vm/VideoCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class VideoCode
private:

///< TODO: frame rate
const int _frameRate{24};
const int _framerate{24};

///< Window size
const int _width;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/generateVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <cstdio>
#include <format>

#include "compiler/Compiler.hpp"
#include "opencv2/core/matx.hpp"
Expand Down
7 changes: 5 additions & 2 deletions src/input/concrete/text/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "input/Frame.hpp"
#include "opencv2/core/types.hpp"

Text::Text(const std::string &text, double fontSize, int fontThickness, const std::vector<int> &color, int font)
Text::Text(const std::string &text, double fontSize, int fontThickness, const std::vector<int> &color, float duration, int framerate, int font)
: _text(text)
{
int baseLine = 0;
Expand All @@ -24,5 +24,8 @@ Text::Text(const std::string &text, double fontSize, int fontThickness, const st

cv::putText(bg, text, cv::Point(0, size.height), font, fontSize, cv::Scalar(color[0], color[1], color[2], color[3]), fontThickness, cv::LINE_AA);

_frames.push_back(Frame(std::move(bg)));
for (size_t i = framerate * duration; i; i--)
{
_frames.push_back(Frame(bg.clone()));
}
}
45 changes: 16 additions & 29 deletions src/transformation/color/fade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,46 @@

#include "transformation/transformation.hpp"

void transformation::fade(std::shared_ptr<IInput> input, [[maybe_unused]] Register& reg, const json::object_t& args)
void transformation::fade(IterableInput input, const json::object_t& args)
{
const json::array_t& sides = args.at("sides");
const int nbFrames = input->size();
const bool affectTransparentPixel = args.at("affectTransparentPixel");
const float startOpacity = args.at("startOpacity");
const float endOpacity = args.at("endOpacity");
const bool affectTransparentPixel = args.at("affectTransparentPixel");
const int nbFrames = input.nbFrames();

int frameIndex = 0;
for (auto& [frame, _] : *input)
{
for (auto& [frame, _] : input) {
int cols = frame.cols;
int rows = frame.rows;
float currentOpacity = startOpacity + (endOpacity - startOpacity) * (static_cast<float>(frameIndex) / (nbFrames - 1));

for (int y = 0; y < rows; y++)
{
for (int x = 0; x < cols; x++)
{
if (frame.at<cv::Vec4b>(y, x)[3] == 0 && affectTransparentPixel == false)
{
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
if (frame.at<cv::Vec4b>(y, x)[3] == 0 && affectTransparentPixel == false) {
continue;
}

float alpha = currentOpacity;

for (const auto& side : sides)
{
if (side == "left")
{
if (cols > 1)
{
for (const auto& side : sides) {
if (side == "left") {
if (cols > 1) {
alpha *= 1 - static_cast<float>(x) / (cols - 1) * (1 - static_cast<float>(frameIndex) / (nbFrames - 1));
}
}
else if (side == "right")
{
if (cols > 1)
{
else if (side == "right") {
if (cols > 1) {
alpha *= 1 - static_cast<float>(cols - 1 - x) / (cols - 1) * (1 - static_cast<float>(frameIndex) / (nbFrames - 1));
}
}
else if (side == "up")
{
if (rows > 1)
{
else if (side == "up") {
if (rows > 1) {
alpha *= 1 - static_cast<float>(y) / (rows - 1) * (1 - static_cast<float>(frameIndex) / (nbFrames - 1));
}
}
else if (side == "down")
{
if (rows > 1)
{
else if (side == "down") {
if (rows > 1) {
alpha *= 1 - static_cast<float>(rows - 1 - y) / (rows - 1) * (1 - static_cast<float>(frameIndex) / (nbFrames - 1));
}
}
Expand Down
Loading
Loading