Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jun 30, 2024
1 parent 77a07fb commit d42838b
Show file tree
Hide file tree
Showing 67 changed files with 5,689 additions and 5,907 deletions.
6 changes: 3 additions & 3 deletions Linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,9 @@ set(SIV3D_INTERNAL_SOURCES
../Siv3D/src/ThirdParty/plutovg/plutovg-paint.c
../Siv3D/src/ThirdParty/plutovg/plutovg-rle.c
../Siv3D/src/ThirdParty/plutovg/plutovg.c
../Siv3D/src/ThirdParty/plutovg/sw_ft_math.c
../Siv3D/src/ThirdParty/plutovg/sw_ft_raster.c
../Siv3D/src/ThirdParty/plutovg/sw_ft_stroker.c
../Siv3D/src/ThirdParty/plutovg/plutovg-ft-math.c
../Siv3D/src/ThirdParty/plutovg/plutovg-ft-raster.c
../Siv3D/src/ThirdParty/plutovg/plutovg-ft-stroker.c

../Siv3D/src/ThirdParty/qr-code-generator-library/qrcodegen.cpp

Expand Down
3 changes: 2 additions & 1 deletion Siv3D/src/Siv3D/ImageFormat/SVG/SVGDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ namespace s3d

const int32 width = static_cast<int32>(std::ceil(document->width()));
const int32 height = static_cast<int32>(std::ceil(document->height()));
const lunasvg::Bitmap bitmap = document->renderToBitmap(width, height, 0x00000000);
lunasvg::Bitmap bitmap = document->renderToBitmap(width, height, 0x00000000);
bitmap.convert(0, 1, 2, 3, true);

Image image(bitmap.width(), bitmap.height());
assert(image.size_bytes() == (bitmap.stride() * bitmap.height()));
Expand Down
3 changes: 2 additions & 1 deletion Siv3D/src/Siv3D/SVG/SVGDetail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ namespace s3d
const int32 imageHeight = maxHeight.value_or_eval([&] { return static_cast<int32>(std::ceil(m_document->height())); });
const uint32 color = Color{ background.a, background.b, background.g, background.r }.asUint32();

const lunasvg::Bitmap bitmap = m_document->renderToBitmap(imageWidth, imageHeight, color);
lunasvg::Bitmap bitmap = m_document->renderToBitmap(imageWidth, imageHeight, color);
bitmap.convert(0, 1, 2, 3, true);

Image image{ bitmap.width(), bitmap.height() };
assert(image.size_bytes() == (bitmap.stride() * bitmap.height()));
Expand Down
95 changes: 21 additions & 74 deletions Siv3D/src/ThirdParty/lunasvg/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ static plutovg_fill_rule_t to_plutovg_fill_rule(WindRule winding);
static plutovg_operator_t to_plutovg_operator(BlendMode mode);
static plutovg_line_cap_t to_plutovg_line_cap(LineCap cap);
static plutovg_line_join_t to_plutovg_line_join(LineJoin join);
static plutovg_spread_method_t to_plutovg_spread_methood(SpreadMethod spread);
static plutovg_spread_method_t to_plutovg_spread_method(SpreadMethod spread);
static plutovg_texture_type_t to_plutovg_texture_type(TextureType type);
static void to_plutovg_stops(plutovg_gradient_t* gradient, const GradientStops& stops);
static void to_plutovg_path(plutovg_t* pluto, const Path& path);

Expand Down Expand Up @@ -59,43 +60,32 @@ Canvas::~Canvas()

void Canvas::setColor(const Color& color)
{
plutovg_set_source_rgba(pluto, color.r, color.g, color.b, color.a);
plutovg_set_rgba(pluto, color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0, color.alpha() / 255.0);
}

void Canvas::setLinearGradient(double x1, double y1, double x2, double y2, const GradientStops& stops, SpreadMethod spread, const Transform& transform)
{
auto gradient = plutovg_gradient_create_linear(x1, y1, x2, y2);
auto gradient = plutovg_set_linear_gradient(pluto, x1, y1, x2, y2);
auto matrix = to_plutovg_matrix(transform);
to_plutovg_stops(gradient, stops);
plutovg_gradient_set_spread(gradient, to_plutovg_spread_methood(spread));
plutovg_gradient_set_spread(gradient, to_plutovg_spread_method(spread));
plutovg_gradient_set_matrix(gradient, &matrix);
plutovg_set_source_gradient(pluto, gradient);
plutovg_gradient_destroy(gradient);
}

void Canvas::setRadialGradient(double cx, double cy, double r, double fx, double fy, const GradientStops& stops, SpreadMethod spread, const Transform& transform)
{
auto gradient = plutovg_gradient_create_radial(cx, cy, r, fx, fy, 0);
auto gradient = plutovg_set_radial_gradient(pluto, cx, cy, r, fx, fy, 0);
auto matrix = to_plutovg_matrix(transform);
to_plutovg_stops(gradient, stops);
plutovg_gradient_set_spread(gradient, to_plutovg_spread_methood(spread));
plutovg_gradient_set_spread(gradient, to_plutovg_spread_method(spread));
plutovg_gradient_set_matrix(gradient, &matrix);
plutovg_set_source_gradient(pluto, gradient);
plutovg_gradient_destroy(gradient);
}

void Canvas::setTexture(const Canvas* source, TextureType type, const Transform& transform)
{
auto texture = plutovg_texture_create(source->surface);
auto texture = plutovg_set_texture(pluto, source->surface, to_plutovg_texture_type(type));
auto matrix = to_plutovg_matrix(transform);
if(type == TextureType::Plain)
plutovg_texture_set_type(texture, plutovg_texture_type_plain);
else
plutovg_texture_set_type(texture, plutovg_texture_type_tiled);

plutovg_texture_set_matrix(texture, &matrix);
plutovg_set_source_texture(pluto, texture);
plutovg_texture_destroy(texture);
}

void Canvas::fill(const Path& path, const Transform& transform, WindRule winding, BlendMode mode, double opacity)
Expand Down Expand Up @@ -128,7 +118,7 @@ void Canvas::stroke(const Path& path, const Transform& transform, double width,

void Canvas::blend(const Canvas* source, BlendMode mode, double opacity)
{
plutovg_set_source_surface(pluto, source->surface, source->rect.x, source->rect.y);
plutovg_set_texture_surface(pluto, source->surface, source->rect.x, source->rect.y);
plutovg_set_operator(pluto, to_plutovg_operator(mode));
plutovg_set_opacity(pluto, opacity);
plutovg_set_matrix(pluto, &translation);
Expand All @@ -145,69 +135,23 @@ void Canvas::mask(const Rect& clip, const Transform& transform)
plutovg_add_path(pluto, path);
plutovg_path_destroy(path);

plutovg_set_source_rgba(pluto, 0, 0, 0, 0);
plutovg_set_rgba(pluto, 0, 0, 0, 0);
plutovg_set_fill_rule(pluto, plutovg_fill_rule_even_odd);
plutovg_set_operator(pluto, plutovg_operator_src);
plutovg_set_opacity(pluto, 0.0);
plutovg_set_matrix(pluto, &translation);
plutovg_fill(pluto);
}

void Canvas::clear(unsigned int value)
{
auto r = (value >> 24) & 0xFF;
auto g = (value >> 16) & 0xFF;
auto b = (value >> 8) & 0xFF;
auto a = (value >> 0) & 0xFF;

plutovg_set_source_rgba(pluto, r / 255.0, g / 255.0, b / 255.0, a / 255.0);
plutovg_set_opacity(pluto, 1.0);
plutovg_set_operator(pluto, plutovg_operator_src);
plutovg_paint(pluto);
}

void Canvas::rgba()
{
auto width = plutovg_surface_get_width(surface);
auto height = plutovg_surface_get_height(surface);
auto stride = plutovg_surface_get_stride(surface);
auto data = plutovg_surface_get_data(surface);
for(int y = 0;y < height;y++)
{
auto pixels = reinterpret_cast<uint32_t*>(data + stride * y);
for(int x = 0;x < width;x++)
{
auto pixel = pixels[x];
auto a = (pixel >> 24) & 0xFF;
if(a == 0)
continue;

auto r = (pixel >> 16) & 0xFF;
auto g = (pixel >> 8) & 0xFF;
auto b = (pixel >> 0) & 0xFF;
if(a != 255)
{
r = (r * 255) / a;
g = (g * 255) / a;
b = (b * 255) / a;
}

pixels[x] = (a << 24) | (b << 16) | (g << 8) | r;
}
}
}

void Canvas::luminance()
{
auto width = plutovg_surface_get_width(surface);
auto height = plutovg_surface_get_height(surface);
auto stride = plutovg_surface_get_stride(surface);
auto data = plutovg_surface_get_data(surface);
for(int y = 0;y < height;y++)
{
for(int y = 0; y < height; y++) {
auto pixels = reinterpret_cast<uint32_t*>(data + stride * y);
for(int x = 0;x < width;x++)
{
for(int x = 0; x < width; x++) {
auto pixel = pixels[x];
auto r = (pixel >> 16) & 0xFF;
auto g = (pixel >> 8) & 0xFF;
Expand Down Expand Up @@ -271,27 +215,30 @@ plutovg_line_join_t to_plutovg_line_join(LineJoin join)
return join == LineJoin::Miter ? plutovg_line_join_miter : join == LineJoin::Round ? plutovg_line_join_round : plutovg_line_join_bevel;
}

static plutovg_spread_method_t to_plutovg_spread_methood(SpreadMethod spread)
static plutovg_spread_method_t to_plutovg_spread_method(SpreadMethod spread)
{
return spread == SpreadMethod::Pad ? plutovg_spread_method_pad : spread == SpreadMethod::Reflect ? plutovg_spread_method_reflect : plutovg_spread_method_repeat;
}

static plutovg_texture_type_t to_plutovg_texture_type(TextureType type)
{
return type == TextureType::Plain ? plutovg_texture_type_plain : plutovg_texture_type_tiled;
}

static void to_plutovg_stops(plutovg_gradient_t* gradient, const GradientStops& stops)
{
for(const auto& stop : stops)
{
for(const auto& stop : stops) {
auto offset = std::get<0>(stop);
auto& color = std::get<1>(stop);
plutovg_gradient_add_stop_rgba(gradient, offset, color.r, color.g, color.b, color.a);
plutovg_gradient_add_stop_rgba(gradient, offset, color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0, color.alpha() / 255.0);
}
}

void to_plutovg_path(plutovg_t* pluto, const Path& path)
{
PathIterator it(path);
std::array<Point, 3> p;
while(!it.isDone())
{
while(!it.isDone()) {
switch(it.currentSegment(p)) {
case PathCommand::MoveTo:
plutovg_move_to(pluto, p[0].x, p[0].y);
Expand Down
15 changes: 5 additions & 10 deletions Siv3D/src/ThirdParty/lunasvg/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ using GradientStops = std::vector<GradientStop>;

using DashArray = std::vector<double>;

struct DashData
{
struct DashData {
DashArray array;
double offset{0.0};
};

enum class TextureType
{
enum class TextureType {
Plain,
Tiled
};

enum class BlendMode
{
enum class BlendMode {
Src,
Src_Over,
Dst_In,
Expand All @@ -35,8 +32,7 @@ enum class BlendMode

class CanvasImpl;

class Canvas
{
class Canvas {
public:
static std::shared_ptr<Canvas> create(unsigned char* data, unsigned int width, unsigned int height, unsigned int stride);
static std::shared_ptr<Canvas> create(double x, double y, double width, double height);
Expand All @@ -52,8 +48,6 @@ class Canvas
void blend(const Canvas* source, BlendMode mode, double opacity);
void mask(const Rect& clip, const Transform& transform);

void clear(unsigned int value);
void rgba();
void luminance();

unsigned int width() const;
Expand All @@ -63,6 +57,7 @@ class Canvas
Rect box() const;

~Canvas();

private:
Canvas(unsigned char* data, int width, int height, int stride);
Canvas(int x, int y, int width, int height);
Expand Down
6 changes: 3 additions & 3 deletions Siv3D/src/ThirdParty/lunasvg/clippathelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace lunasvg {

ClipPathElement::ClipPathElement()
: GraphicsElement(ElementId::ClipPath)
: GraphicsElement(ElementID::ClipPath)
{
}

Units ClipPathElement::clipPathUnits() const
{
auto& value = get(PropertyId::ClipPathUnits);
auto& value = get(PropertyID::ClipPathUnits);
return Parser::parseUnits(value, Units::UserSpaceOnUse);
}

Expand All @@ -21,7 +21,7 @@ std::unique_ptr<LayoutClipPath> ClipPathElement::getClipper(LayoutContext* conte
return nullptr;

LayoutBreaker layoutBreaker(context, this);
auto clipper = std::make_unique<LayoutClipPath>();
auto clipper = makeUnique<LayoutClipPath>();
clipper->units = clipPathUnits();
clipper->transform = transform();
clipper->clipper = context->getClipper(clip_path());
Expand Down
3 changes: 1 addition & 2 deletions Siv3D/src/ThirdParty/lunasvg/clippathelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace lunasvg {

class LayoutClipPath;

class ClipPathElement : public GraphicsElement
{
class ClipPathElement : public GraphicsElement {
public:
ClipPathElement();

Expand Down
2 changes: 1 addition & 1 deletion Siv3D/src/ThirdParty/lunasvg/defselement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace lunasvg {

DefsElement::DefsElement()
: GraphicsElement(ElementId::Defs)
: GraphicsElement(ElementID::Defs)
{
}

Expand Down
3 changes: 1 addition & 2 deletions Siv3D/src/ThirdParty/lunasvg/defselement.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

namespace lunasvg {

class DefsElement : public GraphicsElement
{
class DefsElement : public GraphicsElement {
public:
DefsElement();

Expand Down
Loading

0 comments on commit d42838b

Please sign in to comment.