Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | #include "fitz.h" |
2 | |||
3 | fz_shade * |
||
4 | fz_keep_shade(fz_shade *shade) |
||
5 | { |
||
6 | shade->refs ++; |
||
7 | return shade; |
||
8 | } |
||
9 | |||
10 | void |
||
11 | fz_drop_shade(fz_shade *shade) |
||
12 | { |
||
13 | if (shade && --shade->refs == 0) |
||
14 | { |
||
15 | if (shade->colorspace) |
||
16 | fz_drop_colorspace(shade->colorspace); |
||
17 | fz_free(shade->mesh); |
||
18 | fz_free(shade); |
||
19 | } |
||
20 | } |
||
21 | |||
22 | fz_rect |
||
23 | fz_bound_shade(fz_shade *shade, fz_matrix ctm) |
||
24 | { |
||
25 | float *v; |
||
26 | fz_rect r; |
||
27 | fz_point p; |
||
28 | int i, ncomp, nvert; |
||
29 | |||
30 | ctm = fz_concat(shade->matrix, ctm); |
||
31 | ncomp = shade->use_function ? 3 : 2 + shade->colorspace->n; |
||
32 | nvert = shade->mesh_len / ncomp; |
||
33 | v = shade->mesh; |
||
34 | |||
35 | if (shade->type == FZ_LINEAR) |
||
36 | return fz_infinite_rect; |
||
37 | if (shade->type == FZ_RADIAL) |
||
38 | return fz_infinite_rect; |
||
39 | |||
40 | if (nvert == 0) |
||
41 | return fz_empty_rect; |
||
42 | |||
43 | p.x = v[0]; |
||
44 | p.y = v[1]; |
||
45 | v += ncomp; |
||
46 | p = fz_transform_point(ctm, p); |
||
47 | r.x0 = r.x1 = p.x; |
||
48 | r.y0 = r.y1 = p.y; |
||
49 | |||
50 | for (i = 1; i < nvert; i++) |
||
51 | { |
||
52 | p.x = v[0]; |
||
53 | p.y = v[1]; |
||
54 | p = fz_transform_point(ctm, p); |
||
55 | v += ncomp; |
||
56 | if (p.x < r.x0) r.x0 = p.x; |
||
57 | if (p.y < r.y0) r.y0 = p.y; |
||
58 | if (p.x > r.x1) r.x1 = p.x; |
||
59 | if (p.y > r.y1) r.y1 = p.y; |
||
60 | } |
||
61 | |||
62 | return r; |
||
63 | } |
||
64 | |||
65 | void |
||
66 | fz_debug_shade(fz_shade *shade) |
||
67 | { |
||
68 | int i, j, n; |
||
69 | float *vertex; |
||
70 | int triangle; |
||
71 | |||
72 | printf("shading {\n"); |
||
73 | |||
74 | switch (shade->type) |
||
75 | { |
||
76 | case FZ_LINEAR: printf("\ttype linear\n"); break; |
||
77 | case FZ_RADIAL: printf("\ttype radial\n"); break; |
||
78 | case FZ_MESH: printf("\ttype mesh\n"); break; |
||
79 | } |
||
80 | |||
81 | printf("\tbbox [%g %g %g %g]\n", |
||
82 | shade->bbox.x0, shade->bbox.y0, |
||
83 | shade->bbox.x1, shade->bbox.y1); |
||
84 | |||
85 | printf("\tcolorspace %s\n", shade->colorspace->name); |
||
86 | |||
87 | printf("\tmatrix [%g %g %g %g %g %g]\n", |
||
88 | shade->matrix.a, shade->matrix.b, shade->matrix.c, |
||
89 | shade->matrix.d, shade->matrix.e, shade->matrix.f); |
||
90 | |||
91 | if (shade->use_background) |
||
92 | { |
||
93 | printf("\tbackground ["); |
||
94 | for (i = 0; i < shade->colorspace->n; i++) |
||
95 | printf("%s%g", i == 0 ? "" : " ", shade->background[i]); |
||
96 | printf("]\n"); |
||
97 | } |
||
98 | |||
99 | if (shade->use_function) |
||
100 | { |
||
101 | printf("\tfunction\n"); |
||
102 | n = 3; |
||
103 | } |
||
104 | else |
||
105 | n = 2 + shade->colorspace->n; |
||
106 | |||
107 | printf("\tvertices: %d\n", shade->mesh_len); |
||
108 | |||
109 | vertex = shade->mesh; |
||
110 | triangle = 0; |
||
111 | i = 0; |
||
112 | while (i < shade->mesh_len) |
||
113 | { |
||
114 | printf("\t%d:(%g, %g): ", triangle, vertex[0], vertex[1]); |
||
115 | |||
116 | for (j = 2; j < n; j++) |
||
117 | printf("%s%g", j == 2 ? "" : " ", vertex[j]); |
||
118 | printf("\n"); |
||
119 | |||
120 | vertex += n; |
||
121 | i++; |
||
122 | if (i % 3 == 0) |
||
123 | triangle++; |
||
124 | } |
||
125 | |||
126 | printf("}\n"); |
||
127 | }>>>>>> |