Add API functions for all edge coloring algorithms & error correction algorithms

This commit is contained in:
KitsuneAlex 2024-05-13 06:15:26 +02:00
parent 2b6745f491
commit 4974fb7203
No known key found for this signature in database
GPG Key ID: 6B0CE864BB69B7D0
2 changed files with 128 additions and 22 deletions

View File

@ -252,7 +252,7 @@ MSDF_API int msdf_shape_orient_contours(msdf_shape_handle shape) {
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
MSDF_API int msdf_shape_simple_edge_colors(msdf_shape_handle shape, const double angle_threshold) { MSDF_API int msdf_shape_edge_colors_simple(msdf_shape_handle shape, const double angle_threshold) {
if(shape == nullptr) { if(shape == nullptr) {
return MSDF_ERR_INVALID_ARG; return MSDF_ERR_INVALID_ARG;
} }
@ -260,6 +260,22 @@ MSDF_API int msdf_shape_simple_edge_colors(msdf_shape_handle shape, const double
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
MSDF_API int msdf_shape_edge_colors_ink_trap(msdf_shape_handle shape, const double angle_threshold) {
if(shape == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
msdfgen::edgeColoringInkTrap(*reinterpret_cast<msdfgen::Shape*>(shape), angle_threshold);
return MSDF_SUCCESS;
}
MSDF_API int msdf_shape_edge_colors_by_distance(msdf_shape_handle shape, const double angle_threshold) {
if(shape == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
msdfgen::edgeColoringByDistance(*reinterpret_cast<msdfgen::Shape*>(shape), angle_threshold);
return MSDF_SUCCESS;
}
MSDF_API void msdf_shape_free(msdf_shape_handle shape) { MSDF_API void msdf_shape_free(msdf_shape_handle shape) {
delete reinterpret_cast<msdfgen::Shape*>(shape); delete reinterpret_cast<msdfgen::Shape*>(shape);
} }
@ -548,9 +564,73 @@ MSDF_API void msdf_segment_free(msdf_segment_handle segment) {
} }
} }
// Error correction functions
MSDF_API int msdf_error_correction(msdf_bitmap_t* bitmap, msdf_shape_const_handle shape, const msdf_transform_t* transform) {
if(bitmap == nullptr || shape == nullptr || transform == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
const msdfgen::Projection projection(*reinterpret_cast<const msdfgen::Vector2*>(&transform->scale),
*reinterpret_cast<const msdfgen::Vector2*>(&transform->translation));
const msdfgen::SDFTransformation actual_transform(projection, *reinterpret_cast<const msdfgen::Range*>(&transform->distance_mapping));
switch(bitmap->type) {
case MSDF_BITMAP_TYPE_MSDF:
msdfgen::msdfErrorCorrection(*static_cast<MSDFBitmap*>(bitmap->handle), *reinterpret_cast<const msdfgen::Shape*>(shape),
actual_transform);
break;
case MSDF_BITMAP_TYPE_MTSDF:
msdfgen::msdfErrorCorrection(*static_cast<MTSDFBitmap*>(bitmap->handle), *reinterpret_cast<const msdfgen::Shape*>(shape),
actual_transform);
break;
default:
return MSDF_ERR_INVALID_TYPE;
}
return MSDF_SUCCESS;
}
MSDF_API int msdf_error_correction_fast_distance(msdf_bitmap_t* bitmap, const msdf_transform_t* transform) {
if(bitmap == nullptr || transform == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
const msdfgen::Projection projection(*reinterpret_cast<const msdfgen::Vector2*>(&transform->scale),
*reinterpret_cast<const msdfgen::Vector2*>(&transform->translation));
const msdfgen::SDFTransformation actual_transform(projection, *reinterpret_cast<const msdfgen::Range*>(&transform->distance_mapping));
switch(bitmap->type) {
case MSDF_BITMAP_TYPE_MSDF:
msdfgen::msdfFastDistanceErrorCorrection(*static_cast<MSDFBitmap*>(bitmap->handle), actual_transform);
break;
case MSDF_BITMAP_TYPE_MTSDF:
msdfgen::msdfFastDistanceErrorCorrection(*static_cast<MTSDFBitmap*>(bitmap->handle), actual_transform);
break;
default:
return MSDF_ERR_INVALID_TYPE;
}
return MSDF_SUCCESS;
}
MSDF_API int msdf_error_correction_fast_edge(msdf_bitmap_t* bitmap, const msdf_transform_t* transform) {
if(bitmap == nullptr || transform == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
const msdfgen::Projection projection(*reinterpret_cast<const msdfgen::Vector2*>(&transform->scale),
*reinterpret_cast<const msdfgen::Vector2*>(&transform->translation));
const msdfgen::SDFTransformation actual_transform(projection, *reinterpret_cast<const msdfgen::Range*>(&transform->distance_mapping));
switch(bitmap->type) {
case MSDF_BITMAP_TYPE_MSDF:
msdfgen::msdfFastEdgeErrorCorrection(*static_cast<MSDFBitmap*>(bitmap->handle), actual_transform);
break;
case MSDF_BITMAP_TYPE_MTSDF:
msdfgen::msdfFastEdgeErrorCorrection(*static_cast<MTSDFBitmap*>(bitmap->handle), actual_transform);
break;
default:
return MSDF_ERR_INVALID_TYPE;
}
return MSDF_SUCCESS;
}
// Main msdfgen APIs // Main msdfgen APIs
int msdf_generate_sdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) { MSDF_API int msdf_generate_sdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) {
if(output == nullptr || shape == nullptr || transform == nullptr) { if(output == nullptr || shape == nullptr || transform == nullptr) {
return MSDF_ERR_INVALID_ARG; return MSDF_ERR_INVALID_ARG;
} }
@ -564,7 +644,7 @@ int msdf_generate_sdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, cons
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
int msdf_generate_psdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) { MSDF_API int msdf_generate_psdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) {
if(output == nullptr || shape == nullptr || transform == nullptr) { if(output == nullptr || shape == nullptr || transform == nullptr) {
return MSDF_ERR_INVALID_ARG; return MSDF_ERR_INVALID_ARG;
} }
@ -578,7 +658,7 @@ int msdf_generate_psdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, con
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
int msdf_generate_msdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) { MSDF_API int msdf_generate_msdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) {
if(output == nullptr || shape == nullptr || transform == nullptr) { if(output == nullptr || shape == nullptr || transform == nullptr) {
return MSDF_ERR_INVALID_ARG; return MSDF_ERR_INVALID_ARG;
} }
@ -592,7 +672,7 @@ int msdf_generate_msdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, con
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
int msdf_generate_mtsdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) { MSDF_API int msdf_generate_mtsdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, const msdf_transform_t* transform) {
if(output == nullptr || shape == nullptr || transform == nullptr) { if(output == nullptr || shape == nullptr || transform == nullptr) {
return MSDF_ERR_INVALID_ARG; return MSDF_ERR_INVALID_ARG;
} }
@ -606,7 +686,7 @@ int msdf_generate_mtsdf(msdf_bitmap_t* output, msdf_shape_const_handle shape, co
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
int msdf_generate_sdf_with_config(msdf_bitmap_t* output, MSDF_API int msdf_generate_sdf_with_config(msdf_bitmap_t* output,
msdf_shape_const_handle shape, msdf_shape_const_handle shape,
const msdf_transform_t* transform, const msdf_transform_t* transform,
const msdf_config_t* config) { const msdf_config_t* config) {
@ -625,7 +705,7 @@ int msdf_generate_sdf_with_config(msdf_bitmap_t* output,
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
int msdf_generate_psdf_with_config(msdf_bitmap_t* output, MSDF_API int msdf_generate_psdf_with_config(msdf_bitmap_t* output,
msdf_shape_const_handle shape, msdf_shape_const_handle shape,
const msdf_transform_t* transform, const msdf_transform_t* transform,
const msdf_config_t* config) { const msdf_config_t* config) {
@ -644,7 +724,7 @@ int msdf_generate_psdf_with_config(msdf_bitmap_t* output,
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
int msdf_generate_msdf_with_config(msdf_bitmap_t* output, MSDF_API int msdf_generate_msdf_with_config(msdf_bitmap_t* output,
msdf_shape_const_handle shape, msdf_shape_const_handle shape,
const msdf_transform_t* transform, const msdf_transform_t* transform,
const msdf_multichannel_config_t* config) { const msdf_multichannel_config_t* config) {
@ -667,7 +747,7 @@ int msdf_generate_msdf_with_config(msdf_bitmap_t* output,
return MSDF_SUCCESS; return MSDF_SUCCESS;
} }
int msdf_generate_mtsdf_with_config(msdf_bitmap_t* output, MSDF_API int msdf_generate_mtsdf_with_config(msdf_bitmap_t* output,
msdf_shape_const_handle shape, msdf_shape_const_handle shape,
const msdf_transform_t* transform, const msdf_transform_t* transform,
const msdf_multichannel_config_t* config) { const msdf_multichannel_config_t* config) {

View File

@ -280,7 +280,25 @@ MSDF_API int msdf_shape_orient_contours(msdf_shape_handle shape);
* @param angle_threshold The threshold angle in degrees. * @param angle_threshold The threshold angle in degrees.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode. * @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/ */
MSDF_API int msdf_shape_simple_edge_colors(msdf_shape_handle shape, double angle_threshold); MSDF_API int msdf_shape_edge_colors_simple(msdf_shape_handle shape, double angle_threshold);
/**
* Colors the edges of the given shape using the default MSDF colors specified by the
* MSDF_COLOR_ prefixed constants using the ink trap algorithm.
* @param shape A pointer to a shape whose edges to color with the default MSDF colors.
* @param angle_threshold The threshold angle in degrees.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_shape_edge_colors_ink_trap(msdf_shape_handle shape, double angle_threshold);
/**
* Colors the edges of the given shape using the default MSDF colors specified by the
* MSDF_COLOR_ prefixed constants using the distance.
* @param shape A pointer to a shape whose edges to color with the default MSDF colors.
* @param angle_threshold The threshold angle in degrees.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_shape_edge_colors_by_distance(msdf_shape_handle shape, double angle_threshold);
/** /**
* Calls the destructor of the given bitmap and frees its memory using the * Calls the destructor of the given bitmap and frees its memory using the
@ -493,6 +511,14 @@ MSDF_API int msdf_segment_move_end_point(msdf_segment_handle segment, const msdf
*/ */
MSDF_API void msdf_segment_free(msdf_segment_handle segment); MSDF_API void msdf_segment_free(msdf_segment_handle segment);
// Error correction functions
MSDF_API int msdf_error_correction(msdf_bitmap_t* bitmap, msdf_shape_const_handle shape, const msdf_transform_t* transform);
MSDF_API int msdf_error_correction_fast_distance(msdf_bitmap_t* bitmap, const msdf_transform_t* transform);
MSDF_API int msdf_error_correction_fast_edge(msdf_bitmap_t* bitmap, const msdf_transform_t* transform);
// msdfgen-core API functions // msdfgen-core API functions
/** /**