58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
#include "Blend2D_Convert.h"
|
|
#include "blend2d/blend2d.h"
|
|
#include <algorithm>
|
|
|
|
namespace renderive {
|
|
|
|
namespace {
|
|
|
|
double normalized(std::uint8_t value) {
|
|
return static_cast<double>(value) / 255.0;
|
|
}
|
|
|
|
std::uint8_t byte_from_normalized(double value) {
|
|
auto clamped = std::clamp(value, 0.0, 1.0);
|
|
return static_cast<std::uint8_t>(clamped * 255.0 + 0.5);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
BLRgba Convert::to_bl(const Color& color) {
|
|
return BLRgba(normalized(color.r), normalized(color.g), normalized(color.b), normalized(color.a));
|
|
}
|
|
BLRgba Convert::to_bl_premultiplied(const Color& color) {
|
|
auto alpha = normalized(color.a);
|
|
return BLRgba(normalized(color.r) * alpha, normalized(color.g) * alpha, normalized(color.b) * alpha, alpha);
|
|
}
|
|
BLPoint Convert::to_bl(const PointF& point) {
|
|
return BLPoint(point.x, point.y);
|
|
}
|
|
BLRect Convert::to_bl(const RectF& rect) {
|
|
return BLRect(rect.x, rect.y, rect.width, rect.height);
|
|
}
|
|
Color Convert::from_bl(const BLRgba& rgba) {
|
|
return {
|
|
byte_from_normalized(rgba.r),
|
|
byte_from_normalized(rgba.g),
|
|
byte_from_normalized(rgba.b),
|
|
byte_from_normalized(rgba.a)
|
|
};
|
|
}
|
|
std::uint32_t Convert::blend2d_line_cap(Line_Cap cap) {
|
|
switch (cap) {
|
|
case Line_Cap::Butt: return BL_STROKE_CAP_BUTT;
|
|
case Line_Cap::Square: return BL_STROKE_CAP_SQUARE;
|
|
case Line_Cap::Round: return BL_STROKE_CAP_ROUND;
|
|
}
|
|
return BL_STROKE_CAP_BUTT;
|
|
}
|
|
std::uint32_t Convert::blend2d_line_join(Line_Join join) {
|
|
switch (join) {
|
|
case Line_Join::Miter: return BL_STROKE_JOIN_MITER_BEVEL;
|
|
case Line_Join::Bevel: return BL_STROKE_JOIN_BEVEL;
|
|
case Line_Join::Round: return BL_STROKE_JOIN_ROUND;
|
|
}
|
|
return BL_STROKE_JOIN_MITER_BEVEL;
|
|
}
|
|
} // namespace renderive
|