Skip to content

Commit

Permalink
Release v1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Nov 28, 2020
1 parent a62da25 commit 63f9617
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 77 deletions.
35 changes: 15 additions & 20 deletions 3rdparty/plutovg/plutovg-blend.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,17 @@ static void composition_destination_out(uint32_t* dest, int length, const uint32
}
}

typedef void(*composition_function_solid_t)(uint32_t* dest, int length, uint32_t color, uint32_t const_alpha);
typedef void(*composition_solid_function_t)(uint32_t* dest, int length, uint32_t color, uint32_t const_alpha);
typedef void(*composition_function_t)(uint32_t* dest, int length, const uint32_t* src, uint32_t const_alpha);

static const composition_function_solid_t function_for_mode_solid[] = {
static const composition_solid_function_t composition_solid_map[] = {
composition_solid_source,
composition_solid_source_over,
composition_solid_destination_in,
composition_solid_destination_out
};

static const composition_function_t function_for_mode[] = {
static const composition_function_t composition_map[] = {
composition_source,
composition_source_over,
composition_destination_in,
Expand All @@ -383,9 +383,9 @@ static const composition_function_t function_for_mode[] = {

static void blend_solid(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, uint32_t solid)
{
composition_function_solid_t func = function_for_mode_solid[op];
composition_solid_function_t func = composition_solid_map[op];
int count = rle->spans.size;
const plutovg_span_t* spans= rle->spans.data;
const plutovg_span_t* spans = rle->spans.data;
while(count--)
{
uint32_t* target = (uint32_t*)(surface->data + spans->y * surface->stride) + spans->x;
Expand All @@ -398,7 +398,7 @@ static void blend_solid(plutovg_surface_t* surface, plutovg_operator_t op, const
#define BUFFER_SIZE 1024
static void blend_linear_gradient(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, const gradient_data_t* gradient)
{
composition_function_t func = function_for_mode[op];
composition_function_t func = composition_map[op];
unsigned int buffer[BUFFER_SIZE];

linear_gradient_values_t v;
Expand Down Expand Up @@ -435,7 +435,7 @@ static void blend_linear_gradient(plutovg_surface_t* surface, plutovg_operator_t

static void blend_radial_gradient(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, const gradient_data_t* gradient)
{
composition_function_t func = function_for_mode[op];
composition_function_t func = composition_map[op];
unsigned int buffer[BUFFER_SIZE];

radial_gradient_values_t v;
Expand Down Expand Up @@ -474,7 +474,7 @@ static void blend_radial_gradient(plutovg_surface_t* surface, plutovg_operator_t
#define FIXED_SCALE (1 << 16)
static void blend_transformed_argb(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, const texture_data_t* texture)
{
composition_function_t func = function_for_mode[op];
composition_function_t func = composition_map[op];
uint32_t buffer[BUFFER_SIZE];

int image_width = texture->width;
Expand Down Expand Up @@ -524,7 +524,7 @@ static void blend_transformed_argb(plutovg_surface_t* surface, plutovg_operator_

static void blend_untransformed_argb(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, const texture_data_t* texture)
{
composition_function_t func = function_for_mode[op];
composition_function_t func = composition_map[op];

const int image_width = texture->width;
const int image_height = texture->height;
Expand Down Expand Up @@ -564,7 +564,7 @@ static void blend_untransformed_argb(plutovg_surface_t* surface, plutovg_operato

static void blend_untransformed_tiled_argb(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, const texture_data_t* texture)
{
composition_function_t func = function_for_mode[op];
composition_function_t func = composition_map[op];

int image_width = texture->width;
int image_height = texture->height;
Expand Down Expand Up @@ -610,7 +610,7 @@ static void blend_untransformed_tiled_argb(plutovg_surface_t* surface, plutovg_o

static void blend_transformed_tiled_argb(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, const texture_data_t* texture)
{
composition_function_t func = function_for_mode[op];
composition_function_t func = composition_map[op];
uint32_t buffer[BUFFER_SIZE];

int image_width = texture->width;
Expand Down Expand Up @@ -723,18 +723,14 @@ void plutovg_blend_gradient(plutovg_t* pluto, const plutovg_rle_t* rle, const pl

int dist, idist, pos = 0;
int i;
int alpha = 0;
int nstop = gradient->stops.size;
const plutovg_gradient_stop_t *curr, *next, *start;
uint32_t curr_color, next_color;
double delta, t, incr, fpos;
double opacity = state->opacity * gradient->opacity;

if(opacity != 1.0) alpha = 1;

start = gradient->stops.data;
curr = start;
if(curr->color.a != 0.0) alpha = 1;
curr_color = premultiply_color(&curr->color, opacity);
incr = 1.0 / COLOR_TABLE_SIZE;
fpos = 1.5 * incr;
Expand All @@ -753,7 +749,6 @@ void plutovg_blend_gradient(plutovg_t* pluto, const plutovg_rle_t* rle, const pl
curr = (start + i);
next = (start + i + 1);
delta = 1.0 / (next->offset - curr->offset);
if(next->color.a != 0.0) alpha = 1;
next_color = premultiply_color(&next->color, opacity);
while(fpos < next->offset && pos < COLOR_TABLE_SIZE)
{
Expand All @@ -768,10 +763,10 @@ void plutovg_blend_gradient(plutovg_t* pluto, const plutovg_rle_t* rle, const pl
curr_color = next_color;
}

for(;pos < COLOR_TABLE_SIZE;++pos) data.colortable[pos] = curr_color;
data.colortable[COLOR_TABLE_SIZE - 1] = curr_color;
data.spread = gradient->spread;
for(;pos < COLOR_TABLE_SIZE;++pos)
data.colortable[pos] = curr_color;

data.spread = gradient->spread;
data.matrix = gradient->matrix;
plutovg_matrix_multiply(&data.matrix, &data.matrix, &state->matrix);
plutovg_matrix_invert(&data.matrix);
Expand All @@ -796,7 +791,7 @@ void plutovg_blend_texture(plutovg_t* pluto, const plutovg_rle_t* rle, const plu
plutovg_matrix_multiply(&data.matrix, &data.matrix, &state->matrix);
plutovg_matrix_invert(&data.matrix);

const plutovg_matrix_t* matrix = &texture->matrix;
const plutovg_matrix_t* matrix = &data.matrix;
int translating = (matrix->m00==1.0 && matrix->m10==0.0 && matrix->m01==0.0 && matrix->m11==1.0);
if(translating)
{
Expand Down
42 changes: 21 additions & 21 deletions 3rdparty/plutovg/plutovg-geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,20 +448,20 @@ int plutovg_path_empty(const plutovg_path_t* path)

plutovg_path_t* plutovg_path_clone(const plutovg_path_t* path)
{
plutovg_path_t* p = plutovg_path_create();
plutovg_path_t* result = plutovg_path_create();

plutovg_array_ensure(p->elements, path->elements.size);
plutovg_array_ensure(p->points, path->points.size);
plutovg_array_ensure(result->elements, path->elements.size);
plutovg_array_ensure(result->points, path->points.size);

memcpy(p->elements.data, path->elements.data, (size_t)path->elements.size * sizeof(plutovg_path_element_t));
memcpy(p->points.data, path->points.data, (size_t)path->points.size * sizeof(plutovg_point_t));
memcpy(result->elements.data, path->elements.data, (size_t)path->elements.size * sizeof(plutovg_path_element_t));
memcpy(result->points.data, path->points.data, (size_t)path->points.size * sizeof(plutovg_point_t));

p->elements.size = path->elements.size;
p->points.size = path->points.size;
p->contours = path->contours;
p->start = path->start;
result->elements.size = path->elements.size;
result->points.size = path->points.size;
result->contours = path->contours;
result->start = path->start;

return p;
return result;
}

typedef struct {
Expand Down Expand Up @@ -492,7 +492,7 @@ static inline void split(const bezier_t* b, bezier_t* first, bezier_t* second)
first->y4 = second->y1 = (first->y3 + second->y2) * 0.5;
}

static void flatten_curve(plutovg_path_t* path, const plutovg_point_t* p0, const plutovg_point_t* p1, const plutovg_point_t* p2, const plutovg_point_t* p3)
static void flatten(plutovg_path_t* path, const plutovg_point_t* p0, const plutovg_point_t* p1, const plutovg_point_t* p2, const plutovg_point_t* p3)
{
bezier_t beziers[32];
beziers[0].x1 = p0->x;
Expand All @@ -513,7 +513,7 @@ static void flatten_curve(plutovg_path_t* path, const plutovg_point_t* p0, const
double x4x1 = b->x4 - b->x1;
double l = fabs(x4x1) + fabs(y4y1);
double d;
if(l > 1.)
if(l > 1.0)
{
d = fabs((x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2)) + fabs((x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3));
}
Expand All @@ -538,38 +538,38 @@ static void flatten_curve(plutovg_path_t* path, const plutovg_point_t* p0, const

plutovg_path_t* plutovg_path_clone_flat(const plutovg_path_t* path)
{
plutovg_path_t* p = plutovg_path_create();
plutovg_path_t* result = plutovg_path_create();

plutovg_array_ensure(p->elements, path->elements.size);
plutovg_array_ensure(p->points, path->points.size);
plutovg_array_ensure(result->elements, path->elements.size);
plutovg_array_ensure(result->points, path->points.size);

plutovg_point_t* points = path->points.data;
for(int i = 0;i < path->elements.size;i++)
{
switch(path->elements.data[i])
{
case plutovg_path_element_move_to:
plutovg_path_move_to(p, points[0].x, points[0].y);
plutovg_path_move_to(result, points[0].x, points[0].y);
points += 1;
break;
case plutovg_path_element_line_to:
plutovg_path_line_to(p, points[0].x, points[0].y);
plutovg_path_line_to(result, points[0].x, points[0].y);
points += 1;
break;
case plutovg_path_element_close:
plutovg_path_line_to(p, points[0].x, points[0].y);
plutovg_path_line_to(result, points[0].x, points[0].y);
points += 1;
break;
case plutovg_path_element_cubic_to:
{
plutovg_point_t p0;
plutovg_path_get_current_point(p, &p0.x, &p0.y);
flatten_curve(p, &p0, points, points + 1, points + 2);
plutovg_path_get_current_point(result, &p0.x, &p0.y);
flatten(result, &p0, points, points + 1, points + 2);
points += 3;
break;
}
}
}

return p;
return result;
}
21 changes: 9 additions & 12 deletions 3rdparty/plutovg/plutovg-paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,25 @@ plutovg_paint_t* plutovg_paint_create_rgba(double r, double g, double b, double

plutovg_paint_t* plutovg_paint_create_linear(double x1, double y1, double x2, double y2)
{
plutovg_paint_t* paint = malloc(sizeof(plutovg_paint_t));
paint->ref = 1;
paint->type = plutovg_paint_type_gradient;
paint->gradient = plutovg_gradient_create_linear(x1, y1, x2, y2);
plutovg_gradient_t* gradient = plutovg_gradient_create_linear(x1, y1, x2, y2);
plutovg_paint_t* paint = plutovg_paint_create_gradient(gradient);
plutovg_gradient_destroy(gradient);
return paint;
}

plutovg_paint_t* plutovg_paint_create_radial(double cx, double cy, double cr, double fx, double fy, double fr)
{
plutovg_paint_t* paint = malloc(sizeof(plutovg_paint_t));
paint->ref = 1;
paint->type = plutovg_paint_type_gradient;
paint->gradient = plutovg_gradient_create_radial(cx, cy, cr, fx, fy, fr);
plutovg_gradient_t* gradient = plutovg_gradient_create_radial(cx, cy, cr, fx, fy, fr);
plutovg_paint_t* paint = plutovg_paint_create_gradient(gradient);
plutovg_gradient_destroy(gradient);
return paint;
}

plutovg_paint_t* plutovg_paint_create_for_surface(plutovg_surface_t* surface)
{
plutovg_paint_t* paint = malloc(sizeof(plutovg_paint_t));
paint->ref = 1;
paint->type = plutovg_paint_type_texture;
paint->texture = plutovg_texture_create(surface);
plutovg_texture_t* texture = plutovg_texture_create(surface);
plutovg_paint_t* paint = plutovg_paint_create_texture(texture);
plutovg_texture_destroy(texture);
return paint;
}

Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/plutovg/plutovg-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ void plutovg_blend_texture(plutovg_t* pluto, const plutovg_rle_t* rle, const plu

#define plutovg_array_ensure(array, count) \
do { \
if(array.size + count < array.capacity) \
break; \
if(array.size + count > array.capacity) { \
int capacity = array.size + count; \
int newcapacity = array.capacity == 0 ? 8 : array.capacity; \
while(newcapacity < capacity) { newcapacity *= 2; } \
array.data = realloc(array.data, (size_t)newcapacity * sizeof(array.data[0])); \
array.capacity = newcapacity; \
} \
} while(0)

#endif // PLUTOVG_PRIVATE_H
39 changes: 19 additions & 20 deletions 3rdparty/plutovg/plutovg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
plutovg_surface_t* plutovg_surface_create(int width, int height)
{
plutovg_surface_t* surface = malloc(sizeof(plutovg_surface_t));
const size_t size = (size_t)(width * height * 4);
surface->ref = 1;
surface->owndata = 1;
surface->data = malloc(size);
memset(surface->data, 0, size);
surface->data = malloc((size_t)(width * height * 4));
memset(surface->data, 0, (size_t)(width * height * 4));
surface->width = width;
surface->height = height;
surface->stride = width * 4;
Expand Down Expand Up @@ -438,6 +437,23 @@ void plutovg_clip(plutovg_t* pluto)
plutovg_new_path(pluto);
}

void plutovg_paint(plutovg_t* pluto)
{
plutovg_state_t* state = pluto->state;
if(state->clippath==NULL && pluto->clippath==NULL)
{
plutovg_path_t* path = plutovg_path_create();
plutovg_path_add_rect(path, pluto->clip.x, pluto->clip.y, pluto->clip.w, pluto->clip.h);
plutovg_matrix_t matrix;
plutovg_matrix_init_identity(&matrix);
pluto->clippath = plutovg_rasterize(path, &matrix, &pluto->clip, NULL, plutovg_fill_rule_non_zero);
plutovg_path_destroy(path);
}

plutovg_rle_t* rle = state->clippath ? state->clippath : pluto->clippath;
plutovg_blend(pluto, rle);
}

void plutovg_fill_preserve(plutovg_t* pluto)
{
plutovg_state_t* state = pluto->state;
Expand Down Expand Up @@ -470,20 +486,3 @@ void plutovg_clip_preserve(plutovg_t* pluto)
state->clippath = rle;
}
}

void plutovg_paint(plutovg_t* pluto)
{
plutovg_state_t* state = pluto->state;
if(state->clippath==NULL && pluto->clippath==NULL)
{
plutovg_path_t* path = plutovg_path_create();
plutovg_path_add_rect(path, pluto->clip.x, pluto->clip.y, pluto->clip.w, pluto->clip.h);
plutovg_matrix_t matrix;
plutovg_matrix_init_identity(&matrix);
pluto->clippath = plutovg_rasterize(path, &matrix, &pluto->clip, NULL, plutovg_fill_rule_non_zero);
plutovg_path_destroy(path);
}

plutovg_rle_t* rle = state->clippath ? state->clippath : pluto->clippath;
plutovg_blend(pluto, rle);
}
2 changes: 1 addition & 1 deletion 3rdparty/plutovg/plutovg.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ plutovg_path_t* plutovg_get_path(const plutovg_t* pluto);
void plutovg_fill(plutovg_t* pluto);
void plutovg_stroke(plutovg_t* pluto);
void plutovg_clip(plutovg_t* pluto);
void plutovg_paint(plutovg_t* pluto);

void plutovg_fill_preserve(plutovg_t* pluto);
void plutovg_stroke_preserve(plutovg_t* pluto);
void plutovg_clip_preserve(plutovg_t* pluto);
void plutovg_paint(plutovg_t* pluto);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.3)

project(lunasvg VERSION 1.4.0 LANGUAGES CXX C)
project(lunasvg VERSION 1.4.1 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)
Expand Down

0 comments on commit 63f9617

Please sign in to comment.