diff options
-rw-r--r-- | engines/sword25/gfx/image/art.cpp | 60 | ||||
-rw-r--r-- | engines/sword25/gfx/image/art.h | 145 | ||||
-rw-r--r-- | engines/sword25/gfx/image/vectorimagerenderer.cpp | 24 |
3 files changed, 84 insertions, 145 deletions
diff --git a/engines/sword25/gfx/image/art.cpp b/engines/sword25/gfx/image/art.cpp index d30460901d..69f9425a53 100644 --- a/engines/sword25/gfx/image/art.cpp +++ b/engines/sword25/gfx/image/art.cpp @@ -1041,7 +1041,7 @@ static void art_pri_free(ArtPriQ *pq) { free(pq); } -static art_boolean art_pri_empty(ArtPriQ *pq) { +static bool art_pri_empty(ArtPriQ *pq) { return pq->n_items == 0; } @@ -1122,7 +1122,7 @@ static int art_svp_writer_rewind_add_segment(ArtSvpWriter *self, int wind_left, ArtSvpWriterRewind *swr = (ArtSvpWriterRewind *)self; ArtSVP *svp; ArtSVPSeg *seg; - art_boolean left_filled = 0, right_filled = 0; + bool left_filled = 0, right_filled = 0; int wind_right = wind_left + delta_wind; int seg_num; const int init_n_points_max = 4; @@ -1459,7 +1459,7 @@ static ArtActiveSeg *art_svp_intersect_add_point(ArtIntersectCtx *ctx, double x, ArtActiveSeg *seg, ArtBreakFlags break_flags) { ArtActiveSeg *left, *right; double x_min = x, x_max = x; - art_boolean left_live, right_live; + bool left_live, right_live; double d; double new_x; ArtActiveSeg *test, *result = NULL; @@ -1490,9 +1490,9 @@ static ArtActiveSeg *art_svp_intersect_add_point(ArtIntersectCtx *ctx, double x, left = left->left; left_live = (left != NULL); } else - left_live = ART_FALSE; + left_live = false; } else - left_live = ART_FALSE; + left_live = false; } else if (right_live) { if (x >= right->x[(right->flags & ART_ACTIVE_FLAGS_BNEG) ^ 1] && /* It may be that one of these conjuncts turns out to be always @@ -1510,9 +1510,9 @@ static ArtActiveSeg *art_svp_intersect_add_point(ArtIntersectCtx *ctx, double x, right = right->right; right_live = (right != NULL); } else - right_live = ART_FALSE; + right_live = false; } else - right_live = ART_FALSE; + right_live = false; } } @@ -1571,7 +1571,7 @@ static void art_svp_intersect_swap_active(ArtIntersectCtx *ctx, * Return value: True if the intersection took place at the current * scan line, indicating further iteration is needed. **/ -static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, +static bool art_svp_intersect_test_cross(ArtIntersectCtx *ctx, ArtActiveSeg *left_seg, ArtActiveSeg *right_seg, ArtBreakFlags break_flags) { double left_x0, left_y0, left_x1; @@ -1597,17 +1597,17 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (left_x1 < right_seg->x[(right_seg->flags & ART_ACTIVE_FLAGS_BNEG) ^ 1] || left_y1 == right_seg->y0) - return ART_FALSE; + return false; d = left_x1 * right_seg->a + left_y1 * right_seg->b + right_seg->c; if (d < -EPSILON_A) - return ART_FALSE; + return false; else if (d < EPSILON_A) { /* I'm unsure about the break flags here. */ double right_x1 = art_svp_intersect_break(ctx, right_seg, left_x1, left_y1, ART_BREAK_RIGHT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else if (left_y1 > right_y1) { /* Test right (x1, y1) against left segment */ @@ -1615,27 +1615,27 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (right_x1 > left_seg->x[left_seg->flags & ART_ACTIVE_FLAGS_BNEG] || right_y1 == left_seg->y0) - return ART_FALSE; + return false; d = right_x1 * left_seg->a + right_y1 * left_seg->b + left_seg->c; if (d > EPSILON_A) - return ART_FALSE; + return false; else if (d > -EPSILON_A) { /* See above regarding break flags. */ left_x1 = art_svp_intersect_break(ctx, left_seg, right_x1, right_y1, ART_BREAK_LEFT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else { /* left_y1 == right_y1 */ left_x1 = left_seg->x[1]; double right_x1 = right_seg->x[1]; if (left_x1 <= right_x1) - return ART_FALSE; + return false; } art_svp_intersect_swap_active(ctx, left_seg, right_seg); - return ART_TRUE; + return true; } if (left_y1 < right_y1) { @@ -1645,16 +1645,16 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (left_x1 < right_seg->x[(right_seg->flags & ART_ACTIVE_FLAGS_BNEG) ^ 1] || left_y1 == right_seg->y0) - return ART_FALSE; + return false; d = left_x1 * right_seg->a + left_y1 * right_seg->b + right_seg->c; if (d < -EPSILON_A) - return ART_FALSE; + return false; else if (d < EPSILON_A) { double right_x1 = art_svp_intersect_break(ctx, right_seg, left_x1, left_y1, ART_BREAK_RIGHT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else if (left_y1 > right_y1) { /* Test right (x1, y1) against left segment */ @@ -1662,23 +1662,23 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (right_x1 > left_seg->x[left_seg->flags & ART_ACTIVE_FLAGS_BNEG] || right_y1 == left_seg->y0) - return ART_FALSE; + return false; d = right_x1 * left_seg->a + right_y1 * left_seg->b + left_seg->c; if (d > EPSILON_A) - return ART_FALSE; + return false; else if (d > -EPSILON_A) { left_x1 = art_svp_intersect_break(ctx, left_seg, right_x1, right_y1, ART_BREAK_LEFT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else { /* left_y1 == right_y1 */ left_x1 = left_seg->x[1]; double right_x1 = right_seg->x[1]; if (left_x1 <= right_x1) - return ART_FALSE; + return false; } /* The segments cross. Find the intersection point. */ @@ -1748,7 +1748,7 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, winner->horiz_delta_wind -= loser->delta_wind; art_svp_intersect_swap_active(ctx, left_seg, right_seg); - return ART_TRUE; + return true; } } else if (y == right_seg->y0) { art_svp_intersect_push_pt(ctx, left_seg, x, y); @@ -1764,7 +1764,7 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if ((break_flags & ART_BREAK_RIGHT) && right_seg->right != NULL) art_svp_intersect_add_point(ctx, x, y, right_seg->right, break_flags); } - return ART_FALSE; + return false; } /** @@ -1885,7 +1885,7 @@ static void art_svp_intersect_horiz(ArtIntersectCtx *ctx, ArtActiveSeg *seg, if (x0 > x1) { ArtActiveSeg *left; - art_boolean first = ART_TRUE; + bool first = true; for (left = seg->left; left != NULL; left = seg->left) { int left_bneg = left->flags & ART_ACTIVE_FLAGS_BNEG; @@ -1902,12 +1902,12 @@ static void art_svp_intersect_horiz(ArtIntersectCtx *ctx, ArtActiveSeg *seg, if (first && left->right != NULL) { art_svp_intersect_test_cross(ctx, left, left->right, ART_BREAK_RIGHT); - first = ART_FALSE; + first = false; } } } else { ArtActiveSeg *right; - art_boolean first = ART_TRUE; + bool first = true; for (right = seg->right; right != NULL; right = seg->right) { int right_bneg = right->flags & ART_ACTIVE_FLAGS_BNEG; @@ -1925,7 +1925,7 @@ static void art_svp_intersect_horiz(ArtIntersectCtx *ctx, ArtActiveSeg *seg, if (first && right->left != NULL) { art_svp_intersect_test_cross(ctx, right->left, right, ART_BREAK_RIGHT); - first = ART_FALSE; + first = false; } } } @@ -2231,7 +2231,7 @@ void art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out) { typedef double artfloat; -struct _ArtSVPRenderAAIter { +struct ArtSVPRenderAAIter { const ArtSVP *svp; int x0, x1; int y; diff --git a/engines/sword25/gfx/image/art.h b/engines/sword25/gfx/image/art.h index 90baa770cf..fe3bbd4982 100644 --- a/engines/sword25/gfx/image/art.h +++ b/engines/sword25/gfx/image/art.h @@ -42,10 +42,6 @@ namespace Sword25 { -typedef byte art_u8; -typedef uint16 art_u16; -typedef uint32 art_u32; - /* These aren't, strictly speaking, configuration macros, but they're damn handy to have around, and may be worth playing with for debugging. */ @@ -55,95 +51,55 @@ typedef uint32 art_u32; /* This one must be used carefully - in particular, p and max should be variables. They can also be pstruct->el lvalues. */ -#define art_expand(p, type, max) do { if(max) { p = art_renew (p, type, max <<= 1); } else { max = 1; p = art_new(type, 1); } } while (0) - -typedef int art_boolean; -#define ART_FALSE 0 -#define ART_TRUE 1 - -/* define pi */ -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif /* M_PI */ - -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#endif /* M_SQRT2 */ - -/* Provide macros to feature the GCC function attribute. - */ -#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)) -#define ART_GNUC_PRINTF( format_idx, arg_idx ) \ - __attribute__((__format__ (__printf__, format_idx, arg_idx))) -#define ART_GNUC_NORETURN \ - __attribute__((__noreturn__)) -#else /* !__GNUC__ */ -#define ART_GNUC_PRINTF( format_idx, arg_idx ) -#define ART_GNUC_NORETURN -#endif /* !__GNUC__ */ - -void ART_GNUC_NORETURN -art_die(const char *fmt, ...) ART_GNUC_PRINTF(1, 2); - -void -art_warn(const char *fmt, ...) ART_GNUC_PRINTF(1, 2); - -typedef struct _ArtDRect ArtDRect; -typedef struct _ArtIRect ArtIRect; - -struct _ArtDRect { +#define art_expand(p, type, max) \ + do { \ + if(max) {\ + p = art_renew(p, type, max <<= 1); \ + } else { \ + max = 1; \ + p = art_new(type, 1); \ + } \ + } while (0) + +struct ArtDRect { /*< public >*/ double x0, y0, x1, y1; }; -struct _ArtIRect { - /*< public >*/ - int x0, y0, x1, y1; -}; - -typedef struct _ArtPoint ArtPoint; - -struct _ArtPoint { +struct ArtPoint { /*< public >*/ double x, y; }; /* Basic data structures and constructors for sorted vector paths */ -typedef struct _ArtSVP ArtSVP; -typedef struct _ArtSVPSeg ArtSVPSeg; - -struct _ArtSVPSeg { +struct ArtSVPSeg { int n_points; int dir; /* == 0 for "up", 1 for "down" */ ArtDRect bbox; ArtPoint *points; }; -struct _ArtSVP { +struct ArtSVP { int n_segs; ArtSVPSeg segs[1]; }; -void -art_svp_free(ArtSVP *svp); +void art_svp_free(ArtSVP *svp); -int -art_svp_seg_compare(const void *s1, const void *s2); +int art_svp_seg_compare(const void *s1, const void *s2); /* Basic data structures and constructors for bezier paths */ -typedef enum { +enum ArtPathcode { ART_MOVETO, ART_MOVETO_OPEN, ART_CURVETO, ART_LINETO, ART_END -} ArtPathcode; - -typedef struct _ArtBpath ArtBpath; +}; -struct _ArtBpath { +struct ArtBpath { /*< public >*/ ArtPathcode code; double x1; @@ -156,10 +112,8 @@ struct _ArtBpath { /* Basic data structures and constructors for simple vector paths */ -typedef struct _ArtVpath ArtVpath; - /* CURVETO is not allowed! */ -struct _ArtVpath { +struct ArtVpath { ArtPathcode code; double x; double y; @@ -167,8 +121,7 @@ struct _ArtVpath { /* Some of the functions need to go into their own modules */ -void -art_vpath_add_point(ArtVpath **p_vpath, int *pn_points, int *pn_points_max, +void art_vpath_add_point(ArtVpath **p_vpath, int *pn_points, int *pn_points_max, ArtPathcode code, double x, double y); ArtVpath *art_bez_path_to_vec(const ArtBpath *bez, double flatness); @@ -177,57 +130,49 @@ ArtVpath *art_bez_path_to_vec(const ArtBpath *bez, double flatness); #ifndef ART_WIND_RULE_DEFINED #define ART_WIND_RULE_DEFINED -typedef enum { +enum ArtWindRule { ART_WIND_RULE_NONZERO, ART_WIND_RULE_INTERSECT, ART_WIND_RULE_ODDEVEN, ART_WIND_RULE_POSITIVE -} ArtWindRule; +}; #endif -typedef struct _ArtSvpWriter ArtSvpWriter; - -struct _ArtSvpWriter { +struct ArtSvpWriter { int (*add_segment)(ArtSvpWriter *self, int wind_left, int delta_wind, double x, double y); void (*add_point)(ArtSvpWriter *self, int seg_id, double x, double y); void (*close_segment)(ArtSvpWriter *self, int seg_id); }; -ArtSvpWriter * -art_svp_writer_rewind_new(ArtWindRule rule); +ArtSvpWriter *art_svp_writer_rewind_new(ArtWindRule rule); -ArtSVP * -art_svp_writer_rewind_reap(ArtSvpWriter *self); +ArtSVP *art_svp_writer_rewind_reap(ArtSvpWriter *self); -int -art_svp_seg_compare(const void *s1, const void *s2); +int art_svp_seg_compare(const void *s1, const void *s2); -void -art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out); +void art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out); /* Sort vector paths into sorted vector paths. */ -ArtSVP * -art_svp_from_vpath(ArtVpath *vpath); +ArtSVP *art_svp_from_vpath(ArtVpath *vpath); /* Sort vector paths into sorted vector paths. */ -typedef enum { +enum ArtPathStrokeJoinType { ART_PATH_STROKE_JOIN_MITER, ART_PATH_STROKE_JOIN_ROUND, ART_PATH_STROKE_JOIN_BEVEL -} ArtPathStrokeJoinType; +}; -typedef enum { +enum ArtPathStrokeCapType { ART_PATH_STROKE_CAP_BUTT, ART_PATH_STROKE_CAP_ROUND, ART_PATH_STROKE_CAP_SQUARE -} ArtPathStrokeCapType; +}; -ArtSVP * -art_svp_vpath_stroke(ArtVpath *vpath, +ArtSVP *art_svp_vpath_stroke(ArtVpath *vpath, ArtPathStrokeJoinType join, ArtPathStrokeCapType cap, double line_width, @@ -235,8 +180,7 @@ art_svp_vpath_stroke(ArtVpath *vpath, double flatness); /* This version may have winding numbers exceeding 1. */ -ArtVpath * -art_svp_vpath_stroke_raw(ArtVpath *vpath, +ArtVpath *art_svp_vpath_stroke_raw(ArtVpath *vpath, ArtPathStrokeJoinType join, ArtPathStrokeCapType cap, double line_width, @@ -246,27 +190,22 @@ art_svp_vpath_stroke_raw(ArtVpath *vpath, /* The spiffy antialiased renderer for sorted vector paths. */ -typedef struct _ArtSVPRenderAAStep ArtSVPRenderAAStep; -typedef struct _ArtSVPRenderAAIter ArtSVPRenderAAIter; - -struct _ArtSVPRenderAAStep { +struct ArtSVPRenderAAStep { int x; int delta; /* stored with 16 fractional bits */ }; -ArtSVPRenderAAIter * -art_svp_render_aa_iter(const ArtSVP *svp, +struct ArtSVPRenderAAIter; + +ArtSVPRenderAAIter *art_svp_render_aa_iter(const ArtSVP *svp, int x0, int y0, int x1, int y1); -void -art_svp_render_aa_iter_step(ArtSVPRenderAAIter *iter, int *p_start, +void art_svp_render_aa_iter_step(ArtSVPRenderAAIter *iter, int *p_start, ArtSVPRenderAAStep **p_steps, int *p_n_steps); -void -art_svp_render_aa_iter_done(ArtSVPRenderAAIter *iter); +void art_svp_render_aa_iter_done(ArtSVPRenderAAIter *iter); -void -art_svp_render_aa(const ArtSVP *svp, +void art_svp_render_aa(const ArtSVP *svp, int x0, int y0, int x1, int y1, void (*callback)(void *callback_data, int y, diff --git a/engines/sword25/gfx/image/vectorimagerenderer.cpp b/engines/sword25/gfx/image/vectorimagerenderer.cpp index 7587aab4e5..e8acd08909 100644 --- a/engines/sword25/gfx/image/vectorimagerenderer.cpp +++ b/engines/sword25/gfx/image/vectorimagerenderer.cpp @@ -48,7 +48,7 @@ namespace Sword25 { -void art_rgb_fill_run1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int n) { +void art_rgb_fill_run1(byte *buf, byte r, byte g, byte b, int n) { int i; if (r == g && g == b && r == 255) { @@ -62,7 +62,7 @@ void art_rgb_fill_run1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int n) { } } -void art_rgb_run_alpha1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int alpha, int n) { +void art_rgb_run_alpha1(byte *buf, byte r, byte g, byte b, int alpha, int n) { int i; int v; @@ -82,8 +82,8 @@ typedef struct _ArtRgbSVPAlphaData ArtRgbSVPAlphaData; struct _ArtRgbSVPAlphaData { int alphatab[256]; - art_u8 r, g, b, alpha; - art_u8 *buf; + byte r, g, b, alpha; + byte *buf; int rowstride; int x0, x1; }; @@ -91,12 +91,12 @@ struct _ArtRgbSVPAlphaData { static void art_rgb_svp_alpha_callback1(void *callback_data, int y, int start, ArtSVPRenderAAStep *steps, int n_steps) { ArtRgbSVPAlphaData *data = (ArtRgbSVPAlphaData *)callback_data; - art_u8 *linebuf; + byte *linebuf; int run_x0, run_x1; - art_u32 running_sum = start; + uint32 running_sum = start; int x0, x1; int k; - art_u8 r, g, b; + byte r, g, b; int *alphatab; int alpha; @@ -146,12 +146,12 @@ static void art_rgb_svp_alpha_opaque_callback1(void *callback_data, int y, int start, ArtSVPRenderAAStep *steps, int n_steps) { ArtRgbSVPAlphaData *data = (ArtRgbSVPAlphaData *)callback_data; - art_u8 *linebuf; + byte *linebuf; int run_x0, run_x1; - art_u32 running_sum = start; + uint32 running_sum = start; int x0, x1; int k; - art_u8 r, g, b; + byte r, g, b; int *alphatab; int alpha; @@ -216,7 +216,7 @@ static void art_rgb_svp_alpha_opaque_callback1(void *callback_data, int y, void art_rgb_svp_alpha1(const ArtSVP *svp, int x0, int y0, int x1, int y1, uint32 color, - art_u8 *buf, int rowstride) { + byte *buf, int rowstride) { ArtRgbSVPAlphaData data; byte r, g, b, alpha; int i; @@ -320,7 +320,7 @@ ArtVpath *art_vpath_reverse_free(ArtVpath *a) { return dest; } -void drawBez(ArtBpath *bez1, ArtBpath *bez2, art_u8 *buffer, int width, int height, int deltaX, int deltaY, double scaleX, double scaleY, double penWidth, unsigned int color) { +void drawBez(ArtBpath *bez1, ArtBpath *bez2, byte *buffer, int width, int height, int deltaX, int deltaY, double scaleX, double scaleY, double penWidth, unsigned int color) { ArtVpath *vec = NULL; ArtVpath *vec1 = NULL; ArtVpath *vec2 = NULL; |