Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jan 21, 2025
1 parent c9d7cb9 commit c700eb2
Show file tree
Hide file tree
Showing 31 changed files with 253 additions and 188 deletions.
15 changes: 8 additions & 7 deletions src/accelerator/ogl/image/image_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,14 @@ struct image_kernel::impl
coord.vertex_y += f_p[1];
};

auto const first_plane = params.pix_desc.planes.at(0);
if (params.geometry.mode() != core::frame_geometry::scale_mode::stretch && first_plane.width > 0 && first_plane.height > 0) {
auto width_scale = static_cast<double>(params.target_width) / static_cast<double>(first_plane.width);
auto height_scale = static_cast<double>(params.target_height) / static_cast<double>(first_plane.height);
auto const first_plane = params.pix_desc.planes.at(0);
if (params.geometry.mode() != core::frame_geometry::scale_mode::stretch && first_plane.width > 0 &&
first_plane.height > 0) {
auto width_scale = static_cast<double>(params.target_width) / static_cast<double>(first_plane.width);
auto height_scale = static_cast<double>(params.target_height) / static_cast<double>(first_plane.height);

double target_scale;
switch (params.geometry.mode()) {
switch (params.geometry.mode()) {
case core::frame_geometry::scale_mode::fit:
target_scale = std::min(width_scale, height_scale);
f_s[0] *= target_scale / width_scale;
Expand All @@ -253,8 +254,8 @@ struct image_kernel::impl
break;

default:;
}
}
}
}

int corner = 0;
for (auto& coord : coords) {
Expand Down
26 changes: 13 additions & 13 deletions src/accelerator/ogl/image/image_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ class image_renderer
return make_ready_future(array<const std::uint8_t>(buffer.data(), format_desc.size, true));
}

return flatten(ogl_->dispatch_async([=, layers = std::move(layers)]() mutable -> std::shared_future<array<const std::uint8_t>> {
auto target_texture = ogl_->create_texture(format_desc.width, format_desc.height, 4, depth_);
return flatten(ogl_->dispatch_async(
[=, layers = std::move(layers)]() mutable -> std::shared_future<array<const std::uint8_t>> {
auto target_texture = ogl_->create_texture(format_desc.width, format_desc.height, 4, depth_);

draw(target_texture, std::move(layers), format_desc);
draw(target_texture, std::move(layers), format_desc);

return ogl_->copy_async(target_texture);
}));
return ogl_->copy_async(target_texture);
}));
}

common::bit_depth depth() const { return depth_; }
Expand Down Expand Up @@ -228,14 +229,13 @@ class image_renderer
draw_params.target_width = format_desc.square_width;
draw_params.target_height = format_desc.square_height;
draw_params.pix_desc.format = core::pixel_format::bgra;
draw_params.pix_desc.planes = {
core::pixel_format_desc::plane(source_texture->width(), source_texture->height(), 4, source_texture->depth())
};
draw_params.textures = { spl::make_shared_ptr(source_texture) };
draw_params.transform = core::image_transform();
draw_params.blend_mode = blend_mode;
draw_params.background = target_texture;
draw_params.geometry = core::frame_geometry::get_default();
draw_params.pix_desc.planes = {core::pixel_format_desc::plane(
source_texture->width(), source_texture->height(), 4, source_texture->depth())};
draw_params.textures = {spl::make_shared_ptr(source_texture)};
draw_params.transform = core::image_transform();
draw_params.blend_mode = blend_mode;
draw_params.background = target_texture;
draw_params.geometry = core::frame_geometry::get_default();

kernel_.draw(std::move(draw_params));
}
Expand Down
11 changes: 7 additions & 4 deletions src/accelerator/ogl/util/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ struct device::impl : public std::enable_shared_from_this<impl>

auto task = task_type(std::forward<Func>(func));
auto future = task.get_future();
boost::asio::spawn(service_, std::move(task)
boost::asio::spawn(service_,
std::move(task)
#if BOOST_VERSION >= 108000
, [](std::exception_ptr e) {
if (e) std::rethrow_exception(e);
}
,
[](std::exception_ptr e) {
if (e)
std::rethrow_exception(e);
}
#endif
);
return future;
Expand Down
5 changes: 2 additions & 3 deletions src/common/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
#define CASPAR_VERIFY(expr) \
do { \
if (!(expr)) { \
CASPAR_LOG(warning) << "Assertion Failed: " << CASPAR_VERIFY_EXPR_STR(expr) << " " \
<< "file:" << __FILE__ << " " \
<< "line:" << __LINE__ << " "; \
CASPAR_LOG(warning) << "Assertion Failed: " << CASPAR_VERIFY_EXPR_STR(expr) << " " << "file:" << __FILE__ \
<< " " << "line:" << __LINE__ << " "; \
_CASPAR_DBG_BREAK; \
} \
} while (0);
Expand Down
2 changes: 1 addition & 1 deletion src/common/ptree.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

#include <boost/algorithm/string/replace.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/property_tree/exceptions.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/range/adaptor/transformed.hpp>

#include <map>
Expand Down
4 changes: 3 additions & 1 deletion src/core/consumer/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

#include <memory>

namespace caspar::diagnostics { class graph; }
namespace caspar::diagnostics {
class graph;
}

namespace caspar { namespace core {

Expand Down
3 changes: 2 additions & 1 deletion src/core/diagnostics/osd_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ auto& get_default_font()
if (auto pipe = popen(cmd.data(), "r")) {
char buf[128];
path.clear();
while (fgets(buf, sizeof(buf), pipe)) path += buf;
while (fgets(buf, sizeof(buf), pipe))
path += buf;
}
}
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/core/frame/draw_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ draw_frame::draw_frame(mutable_frame&& frame)
draw_frame::draw_frame(std::vector<draw_frame> frames)
{
auto frame_size = frames.size();
impl_ = std::make_unique<impl>(std::move(frames));
if (frame_size > 1) impl_->transform_.image_transform.layer_depth = 1;
impl_ = std::make_unique<impl>(std::move(frames));
if (frame_size > 1)
impl_->transform_.image_transform.layer_depth = 1;
}
draw_frame::~draw_frame() {}
draw_frame& draw_frame::operator=(draw_frame other)
Expand Down
83 changes: 41 additions & 42 deletions src/core/frame/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ bool frame_geometry::coord::operator==(const frame_geometry::coord& other) const

struct frame_geometry::impl
{
impl(frame_geometry::geometry_type type, frame_geometry::scale_mode mode, std::vector<coord> data) :
type_{type}, mode_{mode}
impl(frame_geometry::geometry_type type, frame_geometry::scale_mode mode, std::vector<coord> data)
: type_{type}
, mode_{mode}
{
if (type == geometry_type::quad && data.size() != 4)
CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("The number of coordinates needs to be 4"));
Expand All @@ -54,9 +55,10 @@ struct frame_geometry::impl
std::vector<coord> data_;
};

frame_geometry::frame_geometry(geometry_type type, scale_mode mode, std::vector<coord> data) :
impl_{new impl{type, mode, std::move(data)}}
{ }
frame_geometry::frame_geometry(geometry_type type, scale_mode mode, std::vector<coord> data)
: impl_{new impl{type, mode, std::move(data)}}
{
}

frame_geometry::geometry_type frame_geometry::type() const { return impl_->type_; }
frame_geometry::scale_mode frame_geometry::mode() const { return impl_->mode_; }
Expand All @@ -71,7 +73,7 @@ const frame_geometry frame_geometry::get_default(scale_mode mode)
{1.0, 1.0, 1.0, 1.0}, // lower right
{0.0, 1.0, 0.0, 1.0} // lower left
};
return frame_geometry{ frame_geometry::geometry_type::quad, mode, std::move(data) };
return frame_geometry{frame_geometry::geometry_type::quad, mode, std::move(data)};
}
const frame_geometry frame_geometry::get_default_vflip(scale_mode mode)
{
Expand All @@ -82,46 +84,43 @@ const frame_geometry frame_geometry::get_default_vflip(scale_mode mode)
{1.0, 1.0, 1.0, 0.0}, // lower right
{0.0, 1.0, 0.0, 0.0} // lower left
};
return frame_geometry{ frame_geometry::geometry_type::quad, mode, std::move(data) };
return frame_geometry{frame_geometry::geometry_type::quad, mode, std::move(data)};
}

frame_geometry::scale_mode scale_mode_from_string(const std::wstring& str) {
auto str2 = boost::to_lower_copy(str);
if (str2 == L"fit") {
return frame_geometry::scale_mode::fit;
}
else if (str2 == L"fill") {
return frame_geometry::scale_mode::fill;
}
else if (str2 == L"original") {
return frame_geometry::scale_mode::original;
}
else if (str2 == L"hfill") {
return frame_geometry::scale_mode::hfill;
}
else if (str2 == L"vfill") {
return frame_geometry::scale_mode::vfill;
}
else {
return frame_geometry::scale_mode::stretch;
}
frame_geometry::scale_mode scale_mode_from_string(const std::wstring& str)
{
auto str2 = boost::to_lower_copy(str);
if (str2 == L"fit") {
return frame_geometry::scale_mode::fit;
} else if (str2 == L"fill") {
return frame_geometry::scale_mode::fill;
} else if (str2 == L"original") {
return frame_geometry::scale_mode::original;
} else if (str2 == L"hfill") {
return frame_geometry::scale_mode::hfill;
} else if (str2 == L"vfill") {
return frame_geometry::scale_mode::vfill;
} else {
return frame_geometry::scale_mode::stretch;
}
}

std::wstring scale_mode_to_string(frame_geometry::scale_mode mode) {
switch (mode) {
case frame_geometry::scale_mode::fit:
return L"FIT";
case frame_geometry::scale_mode::fill:
return L"FILL";
case frame_geometry::scale_mode::original:
return L"ORIGINAL";
case frame_geometry::scale_mode::hfill:
return L"HFILL";
case frame_geometry::scale_mode::vfill:
return L"VFILL";
default:
return L"STRETCH";
}
std::wstring scale_mode_to_string(frame_geometry::scale_mode mode)
{
switch (mode) {
case frame_geometry::scale_mode::fit:
return L"FIT";
case frame_geometry::scale_mode::fill:
return L"FILL";
case frame_geometry::scale_mode::original:
return L"ORIGINAL";
case frame_geometry::scale_mode::hfill:
return L"HFILL";
case frame_geometry::scale_mode::vfill:
return L"VFILL";
default:
return L"STRETCH";
}
}

}} // namespace caspar::core
2 changes: 1 addition & 1 deletion src/core/frame/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ class frame_geometry
};

frame_geometry::scale_mode scale_mode_from_string(const std::wstring&);
std::wstring scale_mode_to_string(frame_geometry::scale_mode);
std::wstring scale_mode_to_string(frame_geometry::scale_mode);

}} // namespace caspar::core
84 changes: 63 additions & 21 deletions src/core/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,67 @@
*/
#pragma once

namespace caspar::accelerator { class accelerator; }
namespace caspar::accelerator::ogl { class device; }
namespace caspar::accelerator {
class accelerator;
}
namespace caspar::accelerator::ogl {
class device;
}

namespace caspar::core { class stage; }
namespace caspar::core { class mixer; }
namespace caspar::core { class output; }
namespace caspar::core { class image_mixer; }
namespace caspar::core { struct video_format_desc; }
namespace caspar::core { class frame_factory; }
namespace caspar::core { class frame_producer; }
namespace caspar::core { class frame_consumer; }
namespace caspar::core { class draw_frame; }
namespace caspar::core { class mutable_frame; }
namespace caspar::core { class const_frame; }
namespace caspar::core { class video_channel; }
namespace caspar::core { struct pixel_format_desc; }
namespace caspar::core { class cg_producer_registry; }
namespace caspar::core { struct frame_transform; }
namespace caspar::core { struct frame_producer_dependencies; }
namespace caspar::core { struct module_dependencies; }
namespace caspar::core { class frame_producer_registry; }
namespace caspar::core { class video_format_repository; }
namespace caspar::core {
class stage;
}
namespace caspar::core {
class mixer;
}
namespace caspar::core {
class output;
}
namespace caspar::core {
class image_mixer;
}
namespace caspar::core {
struct video_format_desc;
}
namespace caspar::core {
class frame_factory;
}
namespace caspar::core {
class frame_producer;
}
namespace caspar::core {
class frame_consumer;
}
namespace caspar::core {
class draw_frame;
}
namespace caspar::core {
class mutable_frame;
}
namespace caspar::core {
class const_frame;
}
namespace caspar::core {
class video_channel;
}
namespace caspar::core {
struct pixel_format_desc;
}
namespace caspar::core {
class cg_producer_registry;
}
namespace caspar::core {
struct frame_transform;
}
namespace caspar::core {
struct frame_producer_dependencies;
}
namespace caspar::core {
struct module_dependencies;
}
namespace caspar::core {
class frame_producer_registry;
}
namespace caspar::core {
class video_format_repository;
}
4 changes: 3 additions & 1 deletion src/core/mixer/audio/audio_mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

#include <cstdint>

namespace caspar::diagnostics { class graph; }
namespace caspar::diagnostics {
class graph;
}

namespace caspar { namespace core {

Expand Down
4 changes: 3 additions & 1 deletion src/core/mixer/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <core/fwd.h>
#include <core/monitor/monitor.h>

namespace caspar::diagnostics { class graph; }
namespace caspar::diagnostics {
class graph;
}

namespace caspar { namespace core {

Expand Down
Loading

0 comments on commit c700eb2

Please sign in to comment.