Skip to content

Commit

Permalink
CHANGE: updated to Blend2D version 0.10.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Aug 18, 2023
1 parent 78b258f commit e2bcf80
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Rebol-Blend2D.nest
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ github: @asmjit
github: @blend2d
;github: blend2d/blend2d-samples

version: 0.0.18 ;; clang allows only x.y.z version naming!
version: 0.10.4 ;; clang allows only x.y.z version naming!

compiler: gcc
needs: cmake
Expand Down
33 changes: 20 additions & 13 deletions src/blend2d-command-draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {
REBDEC font_size = 10.0;
REBDEC point[4] = { 0,0,1.0,1.0 }; // default size of the point is 2px

BLPoint origin = {0};

blPathInit(&path);
blImageInit(&img_target);
blImageInit(&img_pattern);
Expand All @@ -58,7 +60,7 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {
RXA_ARG(frm, 1).height = h;
RXA_ARG(frm, 1).image = reb_img;

r = blImageCreateFromData(&img_target, w, h, BL_FORMAT_PRGB32, reb_img->data, (intptr_t)w * 4, NULL, NULL);
r = blImageCreateFromData(&img_target, w, h, BL_FORMAT_PRGB32, reb_img->data, (intptr_t)w * 4, BL_DATA_ACCESS_WRITE, NULL, NULL);
if (r != BL_SUCCESS) {
RXA_SERIES(frm,1) = "Blend2D's blImageCreateFromData failed!";
return RXR_ERROR;
Expand Down Expand Up @@ -90,7 +92,7 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {

RESOLVE_ARG(0)
if (RXT_TUPLE == type) {
debug_print("Fill color: %u\n", TUPLE_TO_COLOR(arg[0]));
//debug_print("Fill color: %u\n", TUPLE_TO_COLOR(arg[0]));
blContextSetFillStyleRgba32(&ctx, TUPLE_TO_COLOR(arg[0]));
has_fill = TRUE;
}
Expand All @@ -103,7 +105,7 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {
goto pattern_mode;
} else if (type == RXT_IMAGE) {
blImageReset(&img_pattern);
r = blImageCreateFromData(&img_pattern, arg[0].width, arg[0].height, BL_FORMAT_PRGB32, ((REBSER*)arg[0].series)->data, (intptr_t)arg[0].width * 4, NULL, NULL);
r = blImageCreateFromData(&img_pattern, arg[0].width, arg[0].height, BL_FORMAT_PRGB32, ((REBSER*)arg[0].series)->data, (intptr_t)arg[0].width * 4, BL_DATA_ACCESS_READ, NULL, NULL);
if (r != BL_SUCCESS) goto error;
current_img = &img_pattern;
pattern_mode:
Expand Down Expand Up @@ -159,7 +161,7 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {
if(!arg[0].int32a) has_stroke = FALSE;
} else if (type == RXT_IMAGE) {
blImageInit(&img_pattern);
r = blImageCreateFromData(&img_pattern, arg[0].width, arg[0].height, BL_FORMAT_PRGB32, ((REBSER*)arg[0].series)->data, (intptr_t)arg[0].width * 4, NULL, NULL);
r = blImageCreateFromData(&img_pattern, arg[0].width, arg[0].height, BL_FORMAT_PRGB32, ((REBSER*)arg[0].series)->data, (intptr_t)arg[0].width * 4, BL_DATA_ACCESS_READ, NULL, NULL);
if (r != BL_SUCCESS) {
trace("failed to init pattern image!");
goto error;
Expand Down Expand Up @@ -233,7 +235,7 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {
}
}
} else goto error;
blContextStrokePathD(&ctx, &path);
blContextStrokePathD(&ctx, &origin, &path);
blPathReset(&path);
}
break;
Expand Down Expand Up @@ -310,8 +312,8 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {
);
index += 3;
}
if (has_fill) blContextFillPathD(&ctx, &path);
if (has_stroke) blContextStrokePathD(&ctx, &path);
if (has_fill) blContextFillPathD(&ctx, &origin, &path);
if (has_stroke) blContextStrokePathD(&ctx, &origin, &path);

blPathReset(&path);
break;
Expand Down Expand Up @@ -625,30 +627,34 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {
blFontGetTextMetrics(&font, &gb, &tm);
debug_print("siz: %f %f %f %f\n", tm.boundingBox.x0, tm.boundingBox.y0, tm.boundingBox.x1, tm.boundingBox.y1);

blContextFillTextD(&ctx, &pt, &font, SERIES_DATA(str), SERIES_TAIL(str), SERIES_WIDE(str)==1?BL_TEXT_ENCODING_LATIN1:BL_TEXT_ENCODING_UTF16);
if (SERIES_WIDE(str)==1) {
blContextFillUtf8TextD(&ctx, &pt, &font, SERIES_DATA(str), SERIES_TAIL(str));
} else {
blContextFillUtf16TextD(&ctx, &pt, &font, SERIES_DATA(str), SERIES_TAIL(str));
}
blGlyphBufferReset(&gb);

break;

case W_B2D_CMD_SCALE:
RESOLVE_NUMBER_OR_PAIR_ARG(0, 0);
blContextMatrixOp(&ctx, BL_MATRIX2D_OP_POST_SCALE, doubles);
blContextApplyTransformOp(&ctx, BL_TRANSFORM_OP_POST_SCALE, doubles);
break;

case W_B2D_CMD_ROTATE:
RESOLVE_NUMBER_ARG(0, 0);
TO_RADIANS(doubles[0]);
RESOLVE_PAIR_ARG_OPTIONAL(1, 1);
blContextMatrixOp(&ctx, type ? BL_MATRIX2D_OP_POST_ROTATE_PT : BL_MATRIX2D_OP_POST_ROTATE, doubles);
blContextApplyTransformOp(&ctx, type ? BL_TRANSFORM_OP_POST_ROTATE_PT : BL_TRANSFORM_OP_POST_ROTATE, doubles);
break;

case W_B2D_CMD_TRANSLATE:
RESOLVE_PAIR_ARG(0, 0);
blContextMatrixOp(&ctx, BL_MATRIX2D_OP_POST_TRANSLATE, doubles);
blContextApplyTransformOp(&ctx, BL_TRANSFORM_OP_POST_TRANSLATE, doubles);
break;

case W_B2D_CMD_RESET_MATRIX:
blContextMatrixOp(&ctx, BL_MATRIX2D_OP_RESET, NULL);
blContextApplyTransformOp(&ctx, BL_TRANSFORM_OP_RESET, NULL);
break;

case W_B2D_CMD_ALPHA:
Expand Down Expand Up @@ -738,7 +744,8 @@ int cmd_draw(RXIFRM *frm, void *reb_ctx) {

end_ctx:
// END ...
//trace("Cleaning...");
trace("Cleaning...");
// blContextFlush(&ctx, BL_CONTEXT_FLUSH_SYNC);
blContextEnd(&ctx);
blImageReset(&img_target);
//blImageReset(&img_pattern);
Expand Down
4 changes: 2 additions & 2 deletions src/blend2d-command-image.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BLResult b2d_init_image_from_file(BLImageCore* image, REBSER* fileName) {
return blImageReadFromFile(image, SERIES_TEXT(fileName), &codecs);
}
BLResult b2d_init_image_from_image(BLImageCore* image, void* data, REBINT width, REBINT height) {
return blImageCreateFromData(image, width, height, BL_FORMAT_PRGB32, data, (intptr_t)width * 4, NULL, NULL);
return blImageCreateFromData(image, width, height, BL_FORMAT_PRGB32, data, (intptr_t)width * 4, BL_DATA_ACCESS_RW, NULL, NULL);
}

BLResult b2d_init_image_from_arg(BLImageCore* image, RXIARG arg, REBCNT type) {
Expand All @@ -31,7 +31,7 @@ BLResult b2d_init_image_from_arg(BLImageCore* image, RXIARG arg, REBCNT type) {
// return BL_SUCCESS;
case RXT_IMAGE:
blImageReset(image);
return blImageCreateFromData(image, arg.width, arg.height, BL_FORMAT_PRGB32, ((REBSER*)arg.series)->data, (intptr_t)arg.width * 4, NULL, NULL);
return blImageCreateFromData(image, arg.width, arg.height, BL_FORMAT_PRGB32, ((REBSER*)arg.series)->data, (intptr_t)arg.width * 4, BL_DATA_ACCESS_RW, NULL, NULL);
case RXT_FILE:
blImageReset(image);
return b2d_init_image_from_file(image, (REBSER*)arg.series);
Expand Down
6 changes: 5 additions & 1 deletion test/examples.r3
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ parse raw-src [
)
]

total-time: 0:0:0

foreach [file code] examples [
out: rejoin [%assets/gen/ file %.png]
print [as-red "Drawing example:" as-green mold out]
Expand All @@ -668,7 +670,7 @@ foreach [file code] examples [
]
]

img: draw 480x480 code
total-time: total-time + delta-time [img: draw 480x480 code]
save out img

append page rejoin [
Expand All @@ -677,6 +679,8 @@ foreach [file code] examples [
][ print system/state/last-error ]
]

print ["Time:" total-time]

append page {
* * * *
This file was generated using [examples.r3](examples.r3) script.
Expand Down

0 comments on commit e2bcf80

Please sign in to comment.