From 7cf6ccee8c6b59d8aac17ab6e4673bcb69f5e8d2 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 4 Apr 2011 23:35:45 +0200 Subject: Le Roi est mort, vive le Roi! The run-together words are dead! Long live the underscores! The postscript inspired naming convention of using all run-together words has served us well, but it is now time for more readable code. In this commit I have also added the sed script, rename.sed, that I used to convert the source. Use it on your patches and application code. --- draw/draw_mesh.c | 195 +++++++++++++++++++++++++++---------------------------- 1 file changed, 97 insertions(+), 98 deletions(-) (limited to 'draw/draw_mesh.c') diff --git a/draw/draw_mesh.c b/draw/draw_mesh.c index 79437505..eeebf0a1 100644 --- a/draw/draw_mesh.c +++ b/draw/draw_mesh.c @@ -6,7 +6,7 @@ enum { IN, OUT, ENTER, LEAVE }; enum { MAXV = 3 + 4 }; -enum { MAXN = 2 + FZ_MAXCOLORS }; +enum { MAXN = 2 + FZ_MAX_COLORS }; static int clipx(float val, int ismax, float *v1, float *v2, int n) { @@ -68,13 +68,13 @@ static int clipy(float val, int ismax, float *v1, float *v2, int n) } } -static inline void copyvert(float *dst, float *src, int n) +static inline void copy_vert(float *dst, float *src, int n) { while (n--) *dst++ = *src++; } -static int clippoly(float src[MAXV][MAXN], +static int clip_poly(float src[MAXV][MAXN], float dst[MAXV][MAXN], int len, int n, float val, int isy, int ismax) { @@ -88,8 +88,8 @@ static int clippoly(float src[MAXV][MAXN], for (v2 = 0; v2 < len; v2++) { - copyvert(cv1, src[v1], n); - copyvert(cv2, src[v2], n); + copy_vert(cv1, src[v1], n); + copy_vert(cv2, src[v2], n); if (isy) r = clipy(val, ismax, cv1, cv2, n); @@ -99,16 +99,16 @@ static int clippoly(float src[MAXV][MAXN], switch (r) { case IN: - copyvert(dst[cp++], cv2, n); + copy_vert(dst[cp++], cv2, n); break; case OUT: break; case LEAVE: - copyvert(dst[cp++], cv2, n); + copy_vert(dst[cp++], cv2, n); break; case ENTER: - copyvert(dst[cp++], cv1, n); - copyvert(dst[cp++], cv2, n); + copy_vert(dst[cp++], cv1, n); + copy_vert(dst[cp++], cv2, n); break; } v1 = v2; @@ -122,11 +122,11 @@ static int clippoly(float src[MAXV][MAXN], */ static inline void -paintscan(fz_pixmap *pix, int y, int x1, int x2, int *v1, int *v2, int n) +paint_scan(fz_pixmap *pix, int y, int x1, int x2, int *v1, int *v2, int n) { unsigned char *p = pix->samples + ((y - pix->y) * pix->w + (x1 - pix->x)) * pix->n; - int v[FZ_MAXCOLORS]; - int dv[FZ_MAXCOLORS]; + int v[FZ_MAX_COLORS]; + int dv[FZ_MAX_COLORS]; int w = x2 - x1; int k; @@ -157,7 +157,7 @@ paintscan(fz_pixmap *pix, int y, int x1, int x2, int *v1, int *v2, int n) } static inline int -findnext(int gel[MAXV][MAXN], int len, int a, int *s, int *e, int d) +find_next(int gel[MAXV][MAXN], int len, int a, int *s, int *e, int d) { int b; @@ -187,7 +187,7 @@ findnext(int gel[MAXV][MAXN], int len, int a, int *s, int *e, int d) } static inline void -loadedge(int gel[MAXV][MAXN], int s, int e, int *ael, int *del, int n) +load_edge(int gel[MAXV][MAXN], int s, int e, int *ael, int *del, int n) { int swp, k, dy; @@ -208,7 +208,7 @@ loadedge(int gel[MAXV][MAXN], int s, int e, int *ael, int *del, int n) } static inline void -stepedge(int *ael, int *del, int n) +step_edge(int *ael, int *del, int n) { int k; ael[0] += del[0]; @@ -217,7 +217,7 @@ stepedge(int *ael, int *del, int n) } static void -fz_painttriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, fz_bbox bbox) +fz_paint_triangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, fz_bbox bbox) { float poly[MAXV][MAXN]; float temp[MAXV][MAXN]; @@ -234,14 +234,14 @@ fz_painttriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, fz_bbox int i, k; - copyvert(poly[0], av, n); - copyvert(poly[1], bv, n); - copyvert(poly[2], cv, n); + copy_vert(poly[0], av, n); + copy_vert(poly[1], bv, n); + copy_vert(poly[2], cv, n); - len = clippoly(poly, temp, 3, n, cx0, 0, 0); - len = clippoly(temp, poly, len, n, cx1, 0, 1); - len = clippoly(poly, temp, len, n, cy0, 1, 0); - len = clippoly(temp, poly, len, n, cy1, 1, 1); + len = clip_poly(poly, temp, 3, n, cx0, 0, 0); + len = clip_poly(temp, poly, len, n, cx1, 0, 1); + len = clip_poly(poly, temp, len, n, cy0, 1, 0); + len = clip_poly(temp, poly, len, n, cy1, 1, 1); if (len < 3) return; @@ -268,13 +268,13 @@ fz_painttriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, fz_bbox y = gel[top][1]; - if (findnext(gel, len, top, &s0, &e0, 1)) + if (find_next(gel, len, top, &s0, &e0, 1)) return; - if (findnext(gel, len, top, &s1, &e1, -1)) + if (find_next(gel, len, top, &s1, &e1, -1)) return; - loadedge(gel, s0, e0, ael[0], del[0], n); - loadedge(gel, s1, e1, ael[1], del[1], n); + load_edge(gel, s0, e0, ael[0], del[0], n); + load_edge(gel, s1, e1, ael[1], del[1], n); while (1) { @@ -282,32 +282,32 @@ fz_painttriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, fz_bbox int x1 = ael[1][0] >> 16; if (ael[0][0] < ael[1][0]) - paintscan(pix, y, x0, x1, ael[0]+2, ael[1]+2, n-2); + paint_scan(pix, y, x0, x1, ael[0]+2, ael[1]+2, n-2); else - paintscan(pix, y, x1, x0, ael[1]+2, ael[0]+2, n-2); + paint_scan(pix, y, x1, x0, ael[1]+2, ael[0]+2, n-2); - stepedge(ael[0], del[0], n); - stepedge(ael[1], del[1], n); + step_edge(ael[0], del[0], n); + step_edge(ael[1], del[1], n); y ++; if (y >= gel[e0][1]) { - if (findnext(gel, len, e0, &s0, &e0, 1)) + if (find_next(gel, len, e0, &s0, &e0, 1)) return; - loadedge(gel, s0, e0, ael[0], del[0], n); + load_edge(gel, s0, e0, ael[0], del[0], n); } if (y >= gel[e1][1]) { - if (findnext(gel, len, e1, &s1, &e1, -1)) + if (find_next(gel, len, e1, &s1, &e1, -1)) return; - loadedge(gel, s1, e1, ael[1], del[1], n); + load_edge(gel, s1, e1, ael[1], del[1], n); } } } static void -fz_paintquad(fz_pixmap *pix, +fz_paint_quad(fz_pixmap *pix, fz_point p0, fz_point p1, fz_point p2, fz_point p3, float c0, float c1, float c2, float c3, int n, fz_bbox bbox) @@ -330,8 +330,8 @@ fz_paintquad(fz_pixmap *pix, v[3][1] = p3.y; v[3][2] = c3; - fz_painttriangle(pix, v[0], v[2], v[3], n, bbox); - fz_painttriangle(pix, v[0], v[3], v[1], n, bbox); + fz_paint_triangle(pix, v[0], v[2], v[3], n, bbox); + fz_paint_triangle(pix, v[0], v[3], v[1], n, bbox); } /* @@ -342,7 +342,7 @@ fz_paintquad(fz_pixmap *pix, #define RADSEGS 32 /* how many segments to generate for radial meshes */ static fz_point -fz_pointoncircle(fz_point p, float r, float theta) +fz_point_on_circle(fz_point p, float r, float theta) { p.x = p.x + cosf(theta) * r; p.y = p.y + sinf(theta) * r; @@ -351,7 +351,7 @@ fz_pointoncircle(fz_point p, float r, float theta) } static void -fz_paintlinear(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) +fz_paint_linear(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) { fz_point p0, p1; fz_point v0, v1, v2, v3; @@ -360,21 +360,21 @@ fz_paintlinear(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) p0.x = shade->mesh[0]; p0.y = shade->mesh[1]; - p0 = fz_transformpoint(ctm, p0); + p0 = fz_transform_point(ctm, p0); p1.x = shade->mesh[3]; p1.y = shade->mesh[4]; - p1 = fz_transformpoint(ctm, p1); + p1 = fz_transform_point(ctm, p1); theta = atan2f(p1.y - p0.y, p1.x - p0.x); theta += (float)M_PI * 0.5f; - v0 = fz_pointoncircle(p0, HUGENUM, theta); - v1 = fz_pointoncircle(p1, HUGENUM, theta); - v2 = fz_pointoncircle(p0, -HUGENUM, theta); - v3 = fz_pointoncircle(p1, -HUGENUM, theta); + v0 = fz_point_on_circle(p0, HUGENUM, theta); + v1 = fz_point_on_circle(p1, HUGENUM, theta); + v2 = fz_point_on_circle(p0, -HUGENUM, theta); + v3 = fz_point_on_circle(p1, -HUGENUM, theta); - fz_paintquad(dest, v0, v1, v2, v3, 0, 255, 0, 255, 3, bbox); + fz_paint_quad(dest, v0, v1, v2, v3, 0, 255, 0, 255, 3, bbox); if (shade->extend[0]) { @@ -384,7 +384,7 @@ fz_paintlinear(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) e1.x = v2.x - (p1.x - p0.x) * HUGENUM; e1.y = v2.y - (p1.y - p0.y) * HUGENUM; - fz_paintquad(dest, e0, e1, v0, v2, 0, 0, 0, 0, 3, bbox); + fz_paint_quad(dest, e0, e1, v0, v2, 0, 0, 0, 0, 3, bbox); } if (shade->extend[1]) @@ -395,12 +395,12 @@ fz_paintlinear(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) e1.x = v3.x + (p1.x - p0.x) * HUGENUM; e1.y = v3.y + (p1.y - p0.y) * HUGENUM; - fz_paintquad(dest, e0, e1, v1, v3, 255, 255, 255, 255, 3, bbox); + fz_paint_quad(dest, e0, e1, v1, v3, 255, 255, 255, 255, 3, bbox); } } static void -fz_paintannulus(fz_matrix ctm, +fz_paint_annulus(fz_matrix ctm, fz_point p0, float r0, float c0, fz_point p1, float r1, float c1, fz_pixmap *dest, fz_bbox bbox) @@ -414,31 +414,31 @@ fz_paintannulus(fz_matrix ctm, for (i = 0; i < RADSEGS / 2; i++) { - t0 = fz_pointoncircle(p0, r0, theta + i * step); - t1 = fz_pointoncircle(p0, r0, theta + i * step + step); - t2 = fz_pointoncircle(p1, r1, theta + i * step); - t3 = fz_pointoncircle(p1, r1, theta + i * step + step); - b0 = fz_pointoncircle(p0, r0, theta - i * step); - b1 = fz_pointoncircle(p0, r0, theta - i * step - step); - b2 = fz_pointoncircle(p1, r1, theta - i * step); - b3 = fz_pointoncircle(p1, r1, theta - i * step - step); - - t0 = fz_transformpoint(ctm, t0); - t1 = fz_transformpoint(ctm, t1); - t2 = fz_transformpoint(ctm, t2); - t3 = fz_transformpoint(ctm, t3); - b0 = fz_transformpoint(ctm, b0); - b1 = fz_transformpoint(ctm, b1); - b2 = fz_transformpoint(ctm, b2); - b3 = fz_transformpoint(ctm, b3); - - fz_paintquad(dest, t0, t1, t2, t3, c0, c0, c1, c1, 3, bbox); - fz_paintquad(dest, b0, b1, b2, b3, c0, c0, c1, c1, 3, bbox); + t0 = fz_point_on_circle(p0, r0, theta + i * step); + t1 = fz_point_on_circle(p0, r0, theta + i * step + step); + t2 = fz_point_on_circle(p1, r1, theta + i * step); + t3 = fz_point_on_circle(p1, r1, theta + i * step + step); + b0 = fz_point_on_circle(p0, r0, theta - i * step); + b1 = fz_point_on_circle(p0, r0, theta - i * step - step); + b2 = fz_point_on_circle(p1, r1, theta - i * step); + b3 = fz_point_on_circle(p1, r1, theta - i * step - step); + + t0 = fz_transform_point(ctm, t0); + t1 = fz_transform_point(ctm, t1); + t2 = fz_transform_point(ctm, t2); + t3 = fz_transform_point(ctm, t3); + b0 = fz_transform_point(ctm, b0); + b1 = fz_transform_point(ctm, b1); + b2 = fz_transform_point(ctm, b2); + b3 = fz_transform_point(ctm, b3); + + fz_paint_quad(dest, t0, t1, t2, t3, c0, c0, c1, c1, 3, bbox); + fz_paint_quad(dest, b0, b1, b2, b3, c0, c0, c1, c1, 3, bbox); } } static void -fz_paintradial(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) +fz_paint_radial(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) { fz_point p0, p1; float r0, r1; @@ -464,10 +464,10 @@ fz_paintradial(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) e.y = p0.y + (p1.y - p0.y) * rs; er = r0 + (r1 - r0) * rs; - fz_paintannulus(ctm, e, er, 0, p0, r0, 0, dest, bbox); + fz_paint_annulus(ctm, e, er, 0, p0, r0, 0, dest, bbox); } - fz_paintannulus(ctm, p0, r0, 0, p1, r1, 255, dest, bbox); + fz_paint_annulus(ctm, p0, r0, 0, p1, r1, 255, dest, bbox); if (shade->extend[1]) { @@ -480,12 +480,12 @@ fz_paintradial(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) e.y = p1.y + (p0.y - p1.y) * rs; er = r1 + (r0 - r1) * rs; - fz_paintannulus(ctm, p1, r1, 255, e, er, 255, dest, bbox); + fz_paint_annulus(ctm, p1, r1, 255, e, er, 255, dest, bbox); } } static void -fz_paintmesh(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) +fz_paint_mesh(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) { float tri[3][MAXN]; fz_point p; @@ -495,10 +495,10 @@ fz_paintmesh(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) mesh = shade->mesh; - if (shade->usefunction) - ntris = shade->meshlen / 9; + if (shade->use_function) + ntris = shade->mesh_len / 9; else - ntris = shade->meshlen / ((2 + shade->colorspace->n) * 3); + ntris = shade->mesh_len / ((2 + shade->colorspace->n) * 3); while (ntris--) { @@ -506,45 +506,45 @@ fz_paintmesh(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) { p.x = *mesh++; p.y = *mesh++; - p = fz_transformpoint(ctm, p); + p = fz_transform_point(ctm, p); tri[k][0] = p.x; tri[k][1] = p.y; - if (shade->usefunction) + if (shade->use_function) tri[k][2] = *mesh++ * 255; else { - fz_convertcolor(shade->colorspace, mesh, dest->colorspace, tri[k] + 2); + fz_convert_color(shade->colorspace, mesh, dest->colorspace, tri[k] + 2); for (i = 0; i < dest->colorspace->n; i++) tri[k][i + 2] *= 255; mesh += shade->colorspace->n; } } - fz_painttriangle(dest, tri[0], tri[1], tri[2], 2 + dest->colorspace->n, bbox); + fz_paint_triangle(dest, tri[0], tri[1], tri[2], 2 + dest->colorspace->n, bbox); } } void -fz_paintshade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) +fz_paint_shade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) { - unsigned char clut[256][FZ_MAXCOLORS]; + unsigned char clut[256][FZ_MAX_COLORS]; fz_pixmap *temp, *conv; - float color[FZ_MAXCOLORS]; + float color[FZ_MAX_COLORS]; int i, k; ctm = fz_concat(shade->matrix, ctm); - if (shade->usefunction) + if (shade->use_function) { for (i = 0; i < 256; i++) { - fz_convertcolor(shade->colorspace, shade->function[i], dest->colorspace, color); + fz_convert_color(shade->colorspace, shade->function[i], dest->colorspace, color); for (k = 0; k < dest->colorspace->n; k++) clut[i][k] = color[k] * 255; clut[i][k] = shade->function[i][shade->colorspace->n] * 255; } - conv = fz_newpixmapwithrect(dest->colorspace, bbox); - temp = fz_newpixmapwithrect(fz_devicegray, bbox); - fz_clearpixmap(temp); + conv = fz_new_pixmap_with_rect(dest->colorspace, bbox); + temp = fz_new_pixmap_with_rect(fz_device_gray, bbox); + fz_clear_pixmap(temp); } else { @@ -553,12 +553,12 @@ fz_paintshade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) switch (shade->type) { - case FZ_LINEAR: fz_paintlinear(shade, ctm, temp, bbox); break; - case FZ_RADIAL: fz_paintradial(shade, ctm, temp, bbox); break; - case FZ_MESH: fz_paintmesh(shade, ctm, temp, bbox); break; + case FZ_LINEAR: fz_paint_linear(shade, ctm, temp, bbox); break; + case FZ_RADIAL: fz_paint_radial(shade, ctm, temp, bbox); break; + case FZ_MESH: fz_paint_mesh(shade, ctm, temp, bbox); break; } - if (shade->usefunction) + if (shade->use_function) { unsigned char *s = temp->samples; unsigned char *d = conv->samples; @@ -571,9 +571,8 @@ fz_paintshade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) *d++ = fz_mul255(clut[v][k], a); *d++ = a; } - fz_paintpixmap(dest, conv, 255); - fz_droppixmap(conv); - fz_droppixmap(temp); + fz_paint_pixmap(dest, conv, 255); + fz_drop_pixmap(conv); + fz_drop_pixmap(temp); } } - -- cgit v1.2.3