Skip to content

Commit 63f9617

Browse files
committed
Release v1.4.1
1 parent a62da25 commit 63f9617

7 files changed

+68
-77
lines changed

3rdparty/plutovg/plutovg-blend.c

+15-20
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,17 @@ static void composition_destination_out(uint32_t* dest, int length, const uint32
364364
}
365365
}
366366

367-
typedef void(*composition_function_solid_t)(uint32_t* dest, int length, uint32_t color, uint32_t const_alpha);
367+
typedef void(*composition_solid_function_t)(uint32_t* dest, int length, uint32_t color, uint32_t const_alpha);
368368
typedef void(*composition_function_t)(uint32_t* dest, int length, const uint32_t* src, uint32_t const_alpha);
369369

370-
static const composition_function_solid_t function_for_mode_solid[] = {
370+
static const composition_solid_function_t composition_solid_map[] = {
371371
composition_solid_source,
372372
composition_solid_source_over,
373373
composition_solid_destination_in,
374374
composition_solid_destination_out
375375
};
376376

377-
static const composition_function_t function_for_mode[] = {
377+
static const composition_function_t composition_map[] = {
378378
composition_source,
379379
composition_source_over,
380380
composition_destination_in,
@@ -383,9 +383,9 @@ static const composition_function_t function_for_mode[] = {
383383

384384
static void blend_solid(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, uint32_t solid)
385385
{
386-
composition_function_solid_t func = function_for_mode_solid[op];
386+
composition_solid_function_t func = composition_solid_map[op];
387387
int count = rle->spans.size;
388-
const plutovg_span_t* spans= rle->spans.data;
388+
const plutovg_span_t* spans = rle->spans.data;
389389
while(count--)
390390
{
391391
uint32_t* target = (uint32_t*)(surface->data + spans->y * surface->stride) + spans->x;
@@ -398,7 +398,7 @@ static void blend_solid(plutovg_surface_t* surface, plutovg_operator_t op, const
398398
#define BUFFER_SIZE 1024
399399
static void blend_linear_gradient(plutovg_surface_t* surface, plutovg_operator_t op, const plutovg_rle_t* rle, const gradient_data_t* gradient)
400400
{
401-
composition_function_t func = function_for_mode[op];
401+
composition_function_t func = composition_map[op];
402402
unsigned int buffer[BUFFER_SIZE];
403403

404404
linear_gradient_values_t v;
@@ -435,7 +435,7 @@ static void blend_linear_gradient(plutovg_surface_t* surface, plutovg_operator_t
435435

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

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

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

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

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

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

569569
int image_width = texture->width;
570570
int image_height = texture->height;
@@ -610,7 +610,7 @@ static void blend_untransformed_tiled_argb(plutovg_surface_t* surface, plutovg_o
610610

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

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

724724
int dist, idist, pos = 0;
725725
int i;
726-
int alpha = 0;
727726
int nstop = gradient->stops.size;
728727
const plutovg_gradient_stop_t *curr, *next, *start;
729728
uint32_t curr_color, next_color;
730729
double delta, t, incr, fpos;
731730
double opacity = state->opacity * gradient->opacity;
732731

733-
if(opacity != 1.0) alpha = 1;
734-
735732
start = gradient->stops.data;
736733
curr = start;
737-
if(curr->color.a != 0.0) alpha = 1;
738734
curr_color = premultiply_color(&curr->color, opacity);
739735
incr = 1.0 / COLOR_TABLE_SIZE;
740736
fpos = 1.5 * incr;
@@ -753,7 +749,6 @@ void plutovg_blend_gradient(plutovg_t* pluto, const plutovg_rle_t* rle, const pl
753749
curr = (start + i);
754750
next = (start + i + 1);
755751
delta = 1.0 / (next->offset - curr->offset);
756-
if(next->color.a != 0.0) alpha = 1;
757752
next_color = premultiply_color(&next->color, opacity);
758753
while(fpos < next->offset && pos < COLOR_TABLE_SIZE)
759754
{
@@ -768,10 +763,10 @@ void plutovg_blend_gradient(plutovg_t* pluto, const plutovg_rle_t* rle, const pl
768763
curr_color = next_color;
769764
}
770765

771-
for(;pos < COLOR_TABLE_SIZE;++pos) data.colortable[pos] = curr_color;
772-
data.colortable[COLOR_TABLE_SIZE - 1] = curr_color;
773-
data.spread = gradient->spread;
766+
for(;pos < COLOR_TABLE_SIZE;++pos)
767+
data.colortable[pos] = curr_color;
774768

769+
data.spread = gradient->spread;
775770
data.matrix = gradient->matrix;
776771
plutovg_matrix_multiply(&data.matrix, &data.matrix, &state->matrix);
777772
plutovg_matrix_invert(&data.matrix);
@@ -796,7 +791,7 @@ void plutovg_blend_texture(plutovg_t* pluto, const plutovg_rle_t* rle, const plu
796791
plutovg_matrix_multiply(&data.matrix, &data.matrix, &state->matrix);
797792
plutovg_matrix_invert(&data.matrix);
798793

799-
const plutovg_matrix_t* matrix = &texture->matrix;
794+
const plutovg_matrix_t* matrix = &data.matrix;
800795
int translating = (matrix->m00==1.0 && matrix->m10==0.0 && matrix->m01==0.0 && matrix->m11==1.0);
801796
if(translating)
802797
{

3rdparty/plutovg/plutovg-geometry.c

+21-21
Original file line numberDiff line numberDiff line change
@@ -448,20 +448,20 @@ int plutovg_path_empty(const plutovg_path_t* path)
448448

449449
plutovg_path_t* plutovg_path_clone(const plutovg_path_t* path)
450450
{
451-
plutovg_path_t* p = plutovg_path_create();
451+
plutovg_path_t* result = plutovg_path_create();
452452

453-
plutovg_array_ensure(p->elements, path->elements.size);
454-
plutovg_array_ensure(p->points, path->points.size);
453+
plutovg_array_ensure(result->elements, path->elements.size);
454+
plutovg_array_ensure(result->points, path->points.size);
455455

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

459-
p->elements.size = path->elements.size;
460-
p->points.size = path->points.size;
461-
p->contours = path->contours;
462-
p->start = path->start;
459+
result->elements.size = path->elements.size;
460+
result->points.size = path->points.size;
461+
result->contours = path->contours;
462+
result->start = path->start;
463463

464-
return p;
464+
return result;
465465
}
466466

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

495-
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)
495+
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)
496496
{
497497
bezier_t beziers[32];
498498
beziers[0].x1 = p0->x;
@@ -513,7 +513,7 @@ static void flatten_curve(plutovg_path_t* path, const plutovg_point_t* p0, const
513513
double x4x1 = b->x4 - b->x1;
514514
double l = fabs(x4x1) + fabs(y4y1);
515515
double d;
516-
if(l > 1.)
516+
if(l > 1.0)
517517
{
518518
d = fabs((x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2)) + fabs((x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3));
519519
}
@@ -538,38 +538,38 @@ static void flatten_curve(plutovg_path_t* path, const plutovg_point_t* p0, const
538538

539539
plutovg_path_t* plutovg_path_clone_flat(const plutovg_path_t* path)
540540
{
541-
plutovg_path_t* p = plutovg_path_create();
541+
plutovg_path_t* result = plutovg_path_create();
542542

543-
plutovg_array_ensure(p->elements, path->elements.size);
544-
plutovg_array_ensure(p->points, path->points.size);
543+
plutovg_array_ensure(result->elements, path->elements.size);
544+
plutovg_array_ensure(result->points, path->points.size);
545545

546546
plutovg_point_t* points = path->points.data;
547547
for(int i = 0;i < path->elements.size;i++)
548548
{
549549
switch(path->elements.data[i])
550550
{
551551
case plutovg_path_element_move_to:
552-
plutovg_path_move_to(p, points[0].x, points[0].y);
552+
plutovg_path_move_to(result, points[0].x, points[0].y);
553553
points += 1;
554554
break;
555555
case plutovg_path_element_line_to:
556-
plutovg_path_line_to(p, points[0].x, points[0].y);
556+
plutovg_path_line_to(result, points[0].x, points[0].y);
557557
points += 1;
558558
break;
559559
case plutovg_path_element_close:
560-
plutovg_path_line_to(p, points[0].x, points[0].y);
560+
plutovg_path_line_to(result, points[0].x, points[0].y);
561561
points += 1;
562562
break;
563563
case plutovg_path_element_cubic_to:
564564
{
565565
plutovg_point_t p0;
566-
plutovg_path_get_current_point(p, &p0.x, &p0.y);
567-
flatten_curve(p, &p0, points, points + 1, points + 2);
566+
plutovg_path_get_current_point(result, &p0.x, &p0.y);
567+
flatten(result, &p0, points, points + 1, points + 2);
568568
points += 3;
569569
break;
570570
}
571571
}
572572
}
573573

574-
return p;
574+
return result;
575575
}

3rdparty/plutovg/plutovg-paint.c

+9-12
Original file line numberDiff line numberDiff line change
@@ -287,28 +287,25 @@ plutovg_paint_t* plutovg_paint_create_rgba(double r, double g, double b, double
287287

288288
plutovg_paint_t* plutovg_paint_create_linear(double x1, double y1, double x2, double y2)
289289
{
290-
plutovg_paint_t* paint = malloc(sizeof(plutovg_paint_t));
291-
paint->ref = 1;
292-
paint->type = plutovg_paint_type_gradient;
293-
paint->gradient = plutovg_gradient_create_linear(x1, y1, x2, y2);
290+
plutovg_gradient_t* gradient = plutovg_gradient_create_linear(x1, y1, x2, y2);
291+
plutovg_paint_t* paint = plutovg_paint_create_gradient(gradient);
292+
plutovg_gradient_destroy(gradient);
294293
return paint;
295294
}
296295

297296
plutovg_paint_t* plutovg_paint_create_radial(double cx, double cy, double cr, double fx, double fy, double fr)
298297
{
299-
plutovg_paint_t* paint = malloc(sizeof(plutovg_paint_t));
300-
paint->ref = 1;
301-
paint->type = plutovg_paint_type_gradient;
302-
paint->gradient = plutovg_gradient_create_radial(cx, cy, cr, fx, fy, fr);
298+
plutovg_gradient_t* gradient = plutovg_gradient_create_radial(cx, cy, cr, fx, fy, fr);
299+
plutovg_paint_t* paint = plutovg_paint_create_gradient(gradient);
300+
plutovg_gradient_destroy(gradient);
303301
return paint;
304302
}
305303

306304
plutovg_paint_t* plutovg_paint_create_for_surface(plutovg_surface_t* surface)
307305
{
308-
plutovg_paint_t* paint = malloc(sizeof(plutovg_paint_t));
309-
paint->ref = 1;
310-
paint->type = plutovg_paint_type_texture;
311-
paint->texture = plutovg_texture_create(surface);
306+
plutovg_texture_t* texture = plutovg_texture_create(surface);
307+
plutovg_paint_t* paint = plutovg_paint_create_texture(texture);
308+
plutovg_texture_destroy(texture);
312309
return paint;
313310
}
314311

3rdparty/plutovg/plutovg-private.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ void plutovg_blend_texture(plutovg_t* pluto, const plutovg_rle_t* rle, const plu
148148

149149
#define plutovg_array_ensure(array, count) \
150150
do { \
151-
if(array.size + count < array.capacity) \
152-
break; \
151+
if(array.size + count > array.capacity) { \
153152
int capacity = array.size + count; \
154153
int newcapacity = array.capacity == 0 ? 8 : array.capacity; \
155154
while(newcapacity < capacity) { newcapacity *= 2; } \
156155
array.data = realloc(array.data, (size_t)newcapacity * sizeof(array.data[0])); \
157156
array.capacity = newcapacity; \
157+
} \
158158
} while(0)
159159

160160
#endif // PLUTOVG_PRIVATE_H

3rdparty/plutovg/plutovg.c

+19-20
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
plutovg_surface_t* plutovg_surface_create(int width, int height)
44
{
55
plutovg_surface_t* surface = malloc(sizeof(plutovg_surface_t));
6-
const size_t size = (size_t)(width * height * 4);
76
surface->ref = 1;
87
surface->owndata = 1;
9-
surface->data = malloc(size);
10-
memset(surface->data, 0, size);
8+
surface->data = malloc((size_t)(width * height * 4));
9+
memset(surface->data, 0, (size_t)(width * height * 4));
1110
surface->width = width;
1211
surface->height = height;
1312
surface->stride = width * 4;
@@ -438,6 +437,23 @@ void plutovg_clip(plutovg_t* pluto)
438437
plutovg_new_path(pluto);
439438
}
440439

440+
void plutovg_paint(plutovg_t* pluto)
441+
{
442+
plutovg_state_t* state = pluto->state;
443+
if(state->clippath==NULL && pluto->clippath==NULL)
444+
{
445+
plutovg_path_t* path = plutovg_path_create();
446+
plutovg_path_add_rect(path, pluto->clip.x, pluto->clip.y, pluto->clip.w, pluto->clip.h);
447+
plutovg_matrix_t matrix;
448+
plutovg_matrix_init_identity(&matrix);
449+
pluto->clippath = plutovg_rasterize(path, &matrix, &pluto->clip, NULL, plutovg_fill_rule_non_zero);
450+
plutovg_path_destroy(path);
451+
}
452+
453+
plutovg_rle_t* rle = state->clippath ? state->clippath : pluto->clippath;
454+
plutovg_blend(pluto, rle);
455+
}
456+
441457
void plutovg_fill_preserve(plutovg_t* pluto)
442458
{
443459
plutovg_state_t* state = pluto->state;
@@ -470,20 +486,3 @@ void plutovg_clip_preserve(plutovg_t* pluto)
470486
state->clippath = rle;
471487
}
472488
}
473-
474-
void plutovg_paint(plutovg_t* pluto)
475-
{
476-
plutovg_state_t* state = pluto->state;
477-
if(state->clippath==NULL && pluto->clippath==NULL)
478-
{
479-
plutovg_path_t* path = plutovg_path_create();
480-
plutovg_path_add_rect(path, pluto->clip.x, pluto->clip.y, pluto->clip.w, pluto->clip.h);
481-
plutovg_matrix_t matrix;
482-
plutovg_matrix_init_identity(&matrix);
483-
pluto->clippath = plutovg_rasterize(path, &matrix, &pluto->clip, NULL, plutovg_fill_rule_non_zero);
484-
plutovg_path_destroy(path);
485-
}
486-
487-
plutovg_rle_t* rle = state->clippath ? state->clippath : pluto->clippath;
488-
plutovg_blend(pluto, rle);
489-
}

3rdparty/plutovg/plutovg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ plutovg_path_t* plutovg_get_path(const plutovg_t* pluto);
270270
void plutovg_fill(plutovg_t* pluto);
271271
void plutovg_stroke(plutovg_t* pluto);
272272
void plutovg_clip(plutovg_t* pluto);
273+
void plutovg_paint(plutovg_t* pluto);
273274

274275
void plutovg_fill_preserve(plutovg_t* pluto);
275276
void plutovg_stroke_preserve(plutovg_t* pluto);
276277
void plutovg_clip_preserve(plutovg_t* pluto);
277-
void plutovg_paint(plutovg_t* pluto);
278278

279279
#ifdef __cplusplus
280280
}

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.3)
22

3-
project(lunasvg VERSION 1.4.0 LANGUAGES CXX C)
3+
project(lunasvg VERSION 1.4.1 LANGUAGES CXX C)
44

55
set(CMAKE_CXX_STANDARD 11)
66
set(CMAKE_C_STANDARD 11)

0 commit comments

Comments
 (0)