2 * This file is part of Libsvgtiny
3 * Licensed under the MIT License,
4 * http://opensource.org/licenses/mit-license.php
5 * Copyright 2008 James Bursa <james@semichrome.net>
15 #include "svgtiny_internal.h"
19 static svgtiny_code
svgtiny_parse_linear_gradient(dom_element
*linear
,
20 struct svgtiny_parse_state
*state
);
21 static float svgtiny_parse_gradient_offset(const char *s
);
22 static void svgtiny_path_bbox(float *p
, unsigned int n
,
23 float *x0
, float *y0
, float *x1
, float *y1
);
24 static void svgtiny_invert_matrix(float *m
, float *inv
);
28 * Find a gradient by id and parse it.
31 void svgtiny_find_gradient(const char *id
, struct svgtiny_parse_state
*state
)
33 dom_element
*gradient
;
34 dom_string
*id_str
, *name
;
38 fprintf(stderr
, "svgtiny_find_gradient: id \"%s\"\n", id
);
41 state
->linear_gradient_stop_count
= 0;
42 if (state
->gradient_x1
!= NULL
)
43 dom_string_unref(state
->gradient_x1
);
44 if (state
->gradient_y1
!= NULL
)
45 dom_string_unref(state
->gradient_y1
);
46 if (state
->gradient_x2
!= NULL
)
47 dom_string_unref(state
->gradient_x2
);
48 if (state
->gradient_y2
!= NULL
)
49 dom_string_unref(state
->gradient_y2
);
50 state
->gradient_x1
= dom_string_ref(state
->interned_zero_percent
);
51 state
->gradient_y1
= dom_string_ref(state
->interned_zero_percent
);
52 state
->gradient_x2
= dom_string_ref(state
->interned_hundred_percent
);
53 state
->gradient_y2
= dom_string_ref(state
->interned_zero_percent
);
54 state
->gradient_user_space_on_use
= false;
55 state
->gradient_transform
.a
= 1;
56 state
->gradient_transform
.b
= 0;
57 state
->gradient_transform
.c
= 0;
58 state
->gradient_transform
.d
= 1;
59 state
->gradient_transform
.e
= 0;
60 state
->gradient_transform
.f
= 0;
62 exc
= dom_string_create_interned((const uint8_t *) id
,
64 if (exc
!= DOM_NO_ERR
)
67 exc
= dom_document_get_element_by_id(state
->document
, id_str
,
69 dom_string_unref(id_str
);
70 if (exc
!= DOM_NO_ERR
|| gradient
== NULL
) {
72 fprintf(stderr
, "gradient \"%s\" not found\n", id
);
77 exc
= dom_node_get_node_name(gradient
, &name
);
78 if (exc
!= DOM_NO_ERR
) {
79 dom_node_unref(gradient
);
83 if (dom_string_isequal(name
, state
->interned_linearGradient
))
84 svgtiny_parse_linear_gradient(gradient
, state
);
86 dom_node_unref(gradient
);
87 dom_string_unref(name
);
90 fprintf(stderr
, "linear_gradient_stop_count %i\n",
91 state
->linear_gradient_stop_count
);
97 * Parse a <linearGradient> element node.
99 * http://www.w3.org/TR/SVG11/pservers#LinearGradients
102 svgtiny_code
svgtiny_parse_linear_gradient(dom_element
*linear
,
103 struct svgtiny_parse_state
*state
)
110 exc
= dom_element_get_attribute(linear
, state
->interned_href
, &attr
);
111 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
112 if (dom_string_data(attr
)[0] == (uint8_t) '#') {
113 char *s
= strndup(dom_string_data(attr
) + 1,
114 dom_string_byte_length(attr
) - 1);
115 svgtiny_find_gradient(s
, state
);
118 dom_string_unref(attr
);
121 exc
= dom_element_get_attribute(linear
, state
->interned_x1
, &attr
);
122 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
123 dom_string_unref(state
->gradient_x1
);
124 state
->gradient_x1
= attr
;
128 exc
= dom_element_get_attribute(linear
, state
->interned_y1
, &attr
);
129 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
130 dom_string_unref(state
->gradient_y1
);
131 state
->gradient_y1
= attr
;
135 exc
= dom_element_get_attribute(linear
, state
->interned_x2
, &attr
);
136 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
137 dom_string_unref(state
->gradient_x2
);
138 state
->gradient_x2
= attr
;
142 exc
= dom_element_get_attribute(linear
, state
->interned_y2
, &attr
);
143 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
144 dom_string_unref(state
->gradient_y2
);
145 state
->gradient_y2
= attr
;
149 exc
= dom_element_get_attribute(linear
, state
->interned_gradientUnits
,
151 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
152 state
->gradient_user_space_on_use
=
153 dom_string_isequal(attr
,
154 state
->interned_userSpaceOnUse
);
155 dom_string_unref(attr
);
158 exc
= dom_element_get_attribute(linear
,
159 state
->interned_gradientTransform
,
161 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
162 float a
= 1, b
= 0, c
= 0, d
= 1, e
= 0, f
= 0;
163 char *s
= strndup(dom_string_data(attr
),
164 dom_string_byte_length(attr
));
166 dom_string_unref(attr
);
167 return svgtiny_OUT_OF_MEMORY
;
169 svgtiny_parse_transform(s
, &a
, &b
, &c
, &d
, &e
, &f
);
171 #ifdef GRADIENT_DEBUG
172 fprintf(stderr
, "transform %g %g %g %g %g %g\n",
175 state
->gradient_transform
.a
= a
;
176 state
->gradient_transform
.b
= b
;
177 state
->gradient_transform
.c
= c
;
178 state
->gradient_transform
.d
= d
;
179 state
->gradient_transform
.e
= e
;
180 state
->gradient_transform
.f
= f
;
181 dom_string_unref(attr
);
184 exc
= dom_element_get_elements_by_tag_name(linear
,
185 state
->interned_stop
,
187 if (exc
== DOM_NO_ERR
&& stops
!= NULL
) {
188 uint32_t listlen
, stopnr
;
189 exc
= dom_nodelist_get_length(stops
, &listlen
);
190 if (exc
!= DOM_NO_ERR
) {
191 dom_nodelist_unref(stops
);
195 for (stopnr
= 0; stopnr
< listlen
; ++stopnr
) {
198 svgtiny_colour color
= svgtiny_TRANSPARENT
;
199 exc
= dom_nodelist_item(stops
, stopnr
,
200 (dom_node
**) (void *) &stop
);
201 if (exc
!= DOM_NO_ERR
)
203 exc
= dom_element_get_attribute(stop
,
204 state
->interned_offset
,
206 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
207 char *s
= strndup(dom_string_data(attr
),
208 dom_string_byte_length(attr
));
209 offset
= svgtiny_parse_gradient_offset(s
);
211 dom_string_unref(attr
);
213 exc
= dom_element_get_attribute(stop
,
214 state
->interned_stop_color
,
216 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
217 svgtiny_parse_color(attr
, &color
, state
);
218 dom_string_unref(attr
);
220 exc
= dom_element_get_attribute(stop
,
221 state
->interned_style
,
223 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
224 char *content
= strndup(dom_string_data(attr
),
225 dom_string_byte_length(attr
));
228 if ((s
= strstr(content
, "stop-color:"))) {
232 exc
= dom_string_create_interned(
236 if (exc
!= DOM_NO_ERR
&&
238 svgtiny_parse_color(value
,
241 dom_string_unref(value
);
245 dom_string_unref(attr
);
247 if (offset
!= -1 && color
!= svgtiny_TRANSPARENT
) {
248 #ifdef GRADIENT_DEBUG
249 fprintf(stderr
, "stop %g %x\n", offset
, color
);
251 state
->gradient_stop
[i
].offset
= offset
;
252 state
->gradient_stop
[i
].color
= color
;
255 dom_node_unref(stop
);
256 if (i
== svgtiny_MAX_STOPS
)
260 dom_nodelist_unref(stops
);
264 state
->linear_gradient_stop_count
= i
;
270 float svgtiny_parse_gradient_offset(const char *s
)
272 int num_length
= strspn(s
, "0123456789+-.");
273 const char *unit
= s
+ num_length
;
274 float n
= atof((const char *) s
);
278 else if (unit
[0] == '%')
292 * Add a path with a linear gradient fill to the svgtiny_diagram.
295 svgtiny_code
svgtiny_add_path_linear_gradient(float *p
, unsigned int n
,
296 struct svgtiny_parse_state
*state
)
301 float object_x0
, object_y0
, object_x1
, object_y1
;
302 float gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
,
303 gradient_dx
, gradient_dy
;
305 unsigned int steps
= 10;
306 float x0
= 0, y0
= 0, x0_trans
, y0_trans
, r0
; /* segment start point */
307 float x1
, y1
, x1_trans
, y1_trans
, r1
; /* segment end point */
308 /* segment control points (beziers only) */
309 float c0x
= 0, c0y
= 0, c1x
= 0, c1y
= 0;
310 float gradient_norm_squared
;
311 struct svgtiny_list
*pts
;
313 unsigned int min_pt
= 0;
315 unsigned int stop_count
;
316 unsigned int current_stop
;
318 float current_stop_r
;
319 int red0
, green0
, blue0
, red1
, green1
, blue1
;
320 unsigned int t
, a
, b
;
322 /* determine object bounding box */
323 svgtiny_path_bbox(p
, n
, &object_x0
, &object_y0
, &object_x1
, &object_y1
);
324 #ifdef GRADIENT_DEBUG
325 fprintf(stderr
, "object bbox: (%g %g) (%g %g)\n",
326 object_x0
, object_y0
, object_x1
, object_y1
);
329 if (!state
->gradient_user_space_on_use
) {
330 gradient_x0
= object_x0
+
331 svgtiny_parse_length(state
->gradient_x1
,
332 object_x1
- object_x0
, *state
);
333 gradient_y0
= object_y0
+
334 svgtiny_parse_length(state
->gradient_y1
,
335 object_y1
- object_y0
, *state
);
336 gradient_x1
= object_x0
+
337 svgtiny_parse_length(state
->gradient_x2
,
338 object_x1
- object_x0
, *state
);
339 gradient_y1
= object_y0
+
340 svgtiny_parse_length(state
->gradient_y2
,
341 object_y1
- object_y0
, *state
);
343 gradient_x0
= svgtiny_parse_length(state
->gradient_x1
,
344 state
->viewport_width
, *state
);
345 gradient_y0
= svgtiny_parse_length(state
->gradient_y1
,
346 state
->viewport_height
, *state
);
347 gradient_x1
= svgtiny_parse_length(state
->gradient_x2
,
348 state
->viewport_width
, *state
);
349 gradient_y1
= svgtiny_parse_length(state
->gradient_y2
,
350 state
->viewport_height
, *state
);
352 gradient_dx
= gradient_x1
- gradient_x0
;
353 gradient_dy
= gradient_y1
- gradient_y0
;
354 #ifdef GRADIENT_DEBUG
355 fprintf(stderr
, "gradient vector: (%g %g) => (%g %g)\n",
356 gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
);
359 /* show theoretical gradient strips for debugging */
360 /*unsigned int strips = 10;
361 for (unsigned int z = 0; z != strips; z++) {
362 float f0, fd, strip_x0, strip_y0, strip_dx, strip_dy;
363 f0 = (float) z / (float) strips;
364 fd = (float) 1 / (float) strips;
365 strip_x0 = gradient_x0 + f0 * gradient_dx;
366 strip_y0 = gradient_y0 + f0 * gradient_dy;
367 strip_dx = fd * gradient_dx;
368 strip_dy = fd * gradient_dy;
369 fprintf(stderr, "strip %i vector: (%g %g) + (%g %g)\n",
370 z, strip_x0, strip_y0, strip_dx, strip_dy);
372 float *p = malloc(13 * sizeof p[0]);
374 return svgtiny_OUT_OF_MEMORY;
375 p[0] = svgtiny_PATH_MOVE;
376 p[1] = strip_x0 + (strip_dy * 3);
377 p[2] = strip_y0 - (strip_dx * 3);
378 p[3] = svgtiny_PATH_LINE;
379 p[4] = p[1] + strip_dx;
380 p[5] = p[2] + strip_dy;
381 p[6] = svgtiny_PATH_LINE;
382 p[7] = p[4] - (strip_dy * 6);
383 p[8] = p[5] + (strip_dx * 6);
384 p[9] = svgtiny_PATH_LINE;
385 p[10] = p[7] - strip_dx;
386 p[11] = p[8] - strip_dy;
387 p[12] = svgtiny_PATH_CLOSE;
388 svgtiny_transform_path(p, 13, state);
389 struct svgtiny_shape *shape = svgtiny_add_shape(state);
392 return svgtiny_OUT_OF_MEMORY;
395 shape->path_length = 13;
396 shape->fill = svgtiny_TRANSPARENT;
397 shape->stroke = svgtiny_RGB(0, 0xff, 0);
398 state->diagram->shape_count++;
401 /* invert gradient transform for applying to vertices */
402 svgtiny_invert_matrix(&state
->gradient_transform
.a
, trans
);
403 #ifdef GRADIENT_DEBUG
404 fprintf(stderr
, "inverse transform %g %g %g %g %g %g\n",
405 trans
[0], trans
[1], trans
[2], trans
[3],
409 /* compute points on the path for triangle vertices */
410 /* r, r0, r1 are distance along gradient vector */
411 gradient_norm_squared
= gradient_dx
* gradient_dx
+
412 gradient_dy
* gradient_dy
;
413 pts
= svgtiny_list_create(sizeof (struct grad_point
));
415 return svgtiny_OUT_OF_MEMORY
;
416 for (j
= 0; j
!= n
; ) {
417 int segment_type
= (int) p
[j
];
418 struct grad_point
*point
;
421 if (segment_type
== svgtiny_PATH_MOVE
) {
428 assert(segment_type
== svgtiny_PATH_CLOSE
||
429 segment_type
== svgtiny_PATH_LINE
||
430 segment_type
== svgtiny_PATH_BEZIER
);
432 /* start point (x0, y0) */
433 x0_trans
= trans
[0]*x0
+ trans
[2]*y0
+ trans
[4];
434 y0_trans
= trans
[1]*x0
+ trans
[3]*y0
+ trans
[5];
435 r0
= ((x0_trans
- gradient_x0
) * gradient_dx
+
436 (y0_trans
- gradient_y0
) * gradient_dy
) /
437 gradient_norm_squared
;
438 point
= svgtiny_list_push(pts
);
440 svgtiny_list_free(pts
);
441 return svgtiny_OUT_OF_MEMORY
;
448 min_pt
= svgtiny_list_size(pts
) - 1;
451 /* end point (x1, y1) */
452 if (segment_type
== svgtiny_PATH_LINE
) {
456 } else if (segment_type
== svgtiny_PATH_CLOSE
) {
460 } else /* svgtiny_PATH_BEZIER */ {
469 x1_trans
= trans
[0]*x1
+ trans
[2]*y1
+ trans
[4];
470 y1_trans
= trans
[1]*x1
+ trans
[3]*y1
+ trans
[5];
471 r1
= ((x1_trans
- gradient_x0
) * gradient_dx
+
472 (y1_trans
- gradient_y0
) * gradient_dy
) /
473 gradient_norm_squared
;
475 /* determine steps from change in r */
477 if(isnan(r0
) || isnan(r1
)) {
480 steps
= ceilf(fabsf(r1
- r0
) / 0.05);
485 #ifdef GRADIENT_DEBUG
486 fprintf(stderr
, "r0 %g, r1 %g, steps %i\n",
490 /* loop through intermediate points */
491 for (z
= 1; z
!= steps
; z
++) {
492 float t
, x
, y
, x_trans
, y_trans
, r
;
493 struct grad_point
*point
;
494 t
= (float) z
/ (float) steps
;
495 if (segment_type
== svgtiny_PATH_BEZIER
) {
496 x
= (1-t
) * (1-t
) * (1-t
) * x0
+
497 3 * t
* (1-t
) * (1-t
) * c0x
+
498 3 * t
* t
* (1-t
) * c1x
+
500 y
= (1-t
) * (1-t
) * (1-t
) * y0
+
501 3 * t
* (1-t
) * (1-t
) * c0y
+
502 3 * t
* t
* (1-t
) * c1y
+
505 x
= (1-t
) * x0
+ t
* x1
;
506 y
= (1-t
) * y0
+ t
* y1
;
508 x_trans
= trans
[0]*x
+ trans
[2]*y
+ trans
[4];
509 y_trans
= trans
[1]*x
+ trans
[3]*y
+ trans
[5];
510 r
= ((x_trans
- gradient_x0
) * gradient_dx
+
511 (y_trans
- gradient_y0
) * gradient_dy
) /
512 gradient_norm_squared
;
513 #ifdef GRADIENT_DEBUG
514 fprintf(stderr
, "(%g %g [%g]) ", x
, y
, r
);
516 point
= svgtiny_list_push(pts
);
518 svgtiny_list_free(pts
);
519 return svgtiny_OUT_OF_MEMORY
;
526 min_pt
= svgtiny_list_size(pts
) - 1;
529 #ifdef GRADIENT_DEBUG
530 fprintf(stderr
, "\n");
533 /* next segment start point is this segment end point */
537 #ifdef GRADIENT_DEBUG
538 fprintf(stderr
, "pts size %i, min_pt %i, min_r %.3f\n",
539 svgtiny_list_size(pts
), min_pt
, min_r
);
542 /* There must be at least a single point for the gradient */
543 if (svgtiny_list_size(pts
) == 0) {
544 svgtiny_list_free(pts
);
549 /* render triangles */
550 stop_count
= state
->linear_gradient_stop_count
;
551 assert(2 <= stop_count
);
554 current_stop_r
= state
->gradient_stop
[0].offset
;
555 red0
= red1
= svgtiny_RED(state
->gradient_stop
[0].color
);
556 green0
= green1
= svgtiny_GREEN(state
->gradient_stop
[0].color
);
557 blue0
= blue1
= svgtiny_BLUE(state
->gradient_stop
[0].color
);
559 a
= (min_pt
+ 1) % svgtiny_list_size(pts
);
560 b
= min_pt
== 0 ? svgtiny_list_size(pts
) - 1 : min_pt
- 1;
562 struct grad_point
*point_t
= svgtiny_list_get(pts
, t
);
563 struct grad_point
*point_a
= svgtiny_list_get(pts
, a
);
564 struct grad_point
*point_b
= svgtiny_list_get(pts
, b
);
565 float mean_r
= (point_t
->r
+ point_a
->r
+ point_b
->r
) / 3;
567 struct svgtiny_shape
*shape
;
568 /*fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
570 t, pts[t].r, a, pts[a].r, b, pts[b].r,
572 while (current_stop
!= stop_count
&& current_stop_r
< mean_r
) {
574 if (current_stop
== stop_count
)
579 red1
= svgtiny_RED(state
->
580 gradient_stop
[current_stop
].color
);
581 green1
= svgtiny_GREEN(state
->
582 gradient_stop
[current_stop
].color
);
583 blue1
= svgtiny_BLUE(state
->
584 gradient_stop
[current_stop
].color
);
585 last_stop_r
= current_stop_r
;
586 current_stop_r
= state
->
587 gradient_stop
[current_stop
].offset
;
589 p
= malloc(10 * sizeof p
[0]);
591 return svgtiny_OUT_OF_MEMORY
;
592 p
[0] = svgtiny_PATH_MOVE
;
595 p
[3] = svgtiny_PATH_LINE
;
598 p
[6] = svgtiny_PATH_LINE
;
601 p
[9] = svgtiny_PATH_CLOSE
;
602 svgtiny_transform_path(p
, 10, state
);
603 shape
= svgtiny_add_shape(state
);
606 return svgtiny_OUT_OF_MEMORY
;
609 shape
->path_length
= 10;
610 /*shape->fill = svgtiny_TRANSPARENT;*/
611 if (current_stop
== 0)
612 shape
->fill
= state
->gradient_stop
[0].color
;
613 else if (current_stop
== stop_count
)
614 shape
->fill
= state
->
615 gradient_stop
[stop_count
- 1].color
;
617 float stop_r
= (mean_r
- last_stop_r
) /
618 (current_stop_r
- last_stop_r
);
619 shape
->fill
= svgtiny_RGB(
620 (int) ((1 - stop_r
) * red0
+ stop_r
* red1
),
621 (int) ((1 - stop_r
) * green0
+ stop_r
* green1
),
622 (int) ((1 - stop_r
) * blue0
+ stop_r
* blue1
));
624 shape
->stroke
= svgtiny_TRANSPARENT
;
625 #ifdef GRADIENT_DEBUG
626 shape
->stroke
= svgtiny_RGB(0, 0, 0xff);
628 state
->diagram
->shape_count
++;
629 if (point_a
->r
< point_b
->r
) {
631 a
= (a
+ 1) % svgtiny_list_size(pts
);
634 b
= b
== 0 ? svgtiny_list_size(pts
) - 1 : b
- 1;
638 /* render gradient vector for debugging */
639 #ifdef GRADIENT_DEBUG
641 float *p
= malloc(7 * sizeof p
[0]);
643 return svgtiny_OUT_OF_MEMORY
;
644 p
[0] = svgtiny_PATH_MOVE
;
647 p
[3] = svgtiny_PATH_LINE
;
650 p
[6] = svgtiny_PATH_CLOSE
;
651 svgtiny_transform_path(p
, 7, state
);
652 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
655 return svgtiny_OUT_OF_MEMORY
;
658 shape
->path_length
= 7;
659 shape
->fill
= svgtiny_TRANSPARENT
;
660 shape
->stroke
= svgtiny_RGB(0xff, 0, 0);
661 state
->diagram
->shape_count
++;
665 /* render triangle vertices with r values for debugging */
666 #ifdef GRADIENT_DEBUG
667 for (unsigned int i
= 0; i
!= svgtiny_list_size(pts
); i
++) {
668 struct grad_point
*point
= svgtiny_list_get(pts
, i
);
669 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
671 return svgtiny_OUT_OF_MEMORY
;
672 char *text
= malloc(20);
674 return svgtiny_OUT_OF_MEMORY
;
675 sprintf(text
, "%i=%.3f", i
, point
->r
);
677 shape
->text_x
= state
->ctm
.a
* point
->x
+
678 state
->ctm
.c
* point
->y
+ state
->ctm
.e
;
679 shape
->text_y
= state
->ctm
.b
* point
->x
+
680 state
->ctm
.d
* point
->y
+ state
->ctm
.f
;
681 shape
->fill
= svgtiny_RGB(0, 0, 0);
682 shape
->stroke
= svgtiny_TRANSPARENT
;
683 state
->diagram
->shape_count
++;
687 /* plot actual path outline */
688 if (state
->stroke
!= svgtiny_TRANSPARENT
) {
689 struct svgtiny_shape
*shape
;
690 svgtiny_transform_path(p
, n
, state
);
692 shape
= svgtiny_add_shape(state
);
695 return svgtiny_OUT_OF_MEMORY
;
698 shape
->path_length
= n
;
699 shape
->fill
= svgtiny_TRANSPARENT
;
700 state
->diagram
->shape_count
++;
705 svgtiny_list_free(pts
);
712 * Get the bounding box of path.
715 void svgtiny_path_bbox(float *p
, unsigned int n
,
716 float *x0
, float *y0
, float *x1
, float *y1
)
723 for (j
= 0; j
!= n
; ) {
724 unsigned int points
= 0;
726 switch ((int) p
[j
]) {
727 case svgtiny_PATH_MOVE
:
728 case svgtiny_PATH_LINE
:
731 case svgtiny_PATH_CLOSE
:
734 case svgtiny_PATH_BEZIER
:
741 for (k
= 0; k
!= points
; k
++) {
742 float x
= p
[j
], y
= p
[j
+ 1];
758 * Invert a transformation matrix.
760 void svgtiny_invert_matrix(float *m
, float *inv
)
762 float determinant
= m
[0]*m
[3] - m
[1]*m
[2];
763 inv
[0] = m
[3] / determinant
;
764 inv
[1] = -m
[1] / determinant
;
765 inv
[2] = -m
[2] / determinant
;
766 inv
[3] = m
[0] / determinant
;
767 inv
[4] = (m
[2]*m
[5] - m
[3]*m
[4]) / determinant
;
768 inv
[5] = (m
[1]*m
[4] - m
[0]*m
[5]) / determinant
;