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(
414 sizeof (struct grad_point
));
416 return svgtiny_OUT_OF_MEMORY
;
417 for (j
= 0; j
!= n
; ) {
418 int segment_type
= (int) p
[j
];
419 struct grad_point
*point
;
422 if (segment_type
== svgtiny_PATH_MOVE
) {
429 assert(segment_type
== svgtiny_PATH_CLOSE
||
430 segment_type
== svgtiny_PATH_LINE
||
431 segment_type
== svgtiny_PATH_BEZIER
);
433 /* start point (x0, y0) */
434 x0_trans
= trans
[0]*x0
+ trans
[2]*y0
+ trans
[4];
435 y0_trans
= trans
[1]*x0
+ trans
[3]*y0
+ trans
[5];
436 r0
= ((x0_trans
- gradient_x0
) * gradient_dx
+
437 (y0_trans
- gradient_y0
) * gradient_dy
) /
438 gradient_norm_squared
;
439 point
= svgtiny_list_push(pts
);
441 svgtiny_list_free(pts
);
442 return svgtiny_OUT_OF_MEMORY
;
449 min_pt
= svgtiny_list_size(pts
) - 1;
452 /* end point (x1, y1) */
453 if (segment_type
== svgtiny_PATH_LINE
) {
457 } else if (segment_type
== svgtiny_PATH_CLOSE
) {
461 } else /* svgtiny_PATH_BEZIER */ {
470 x1_trans
= trans
[0]*x1
+ trans
[2]*y1
+ trans
[4];
471 y1_trans
= trans
[1]*x1
+ trans
[3]*y1
+ trans
[5];
472 r1
= ((x1_trans
- gradient_x0
) * gradient_dx
+
473 (y1_trans
- gradient_y0
) * gradient_dy
) /
474 gradient_norm_squared
;
476 /* determine steps from change in r */
478 if(isnan(r0
) || isnan(r1
)) {
481 steps
= ceilf(fabsf(r1
- r0
) / 0.05);
486 #ifdef GRADIENT_DEBUG
487 fprintf(stderr
, "r0 %g, r1 %g, steps %i\n",
491 /* loop through intermediate points */
492 for (z
= 1; z
!= steps
; z
++) {
493 float t
, x
, y
, x_trans
, y_trans
, r
;
494 struct grad_point
*point
;
495 t
= (float) z
/ (float) steps
;
496 if (segment_type
== svgtiny_PATH_BEZIER
) {
497 x
= (1-t
) * (1-t
) * (1-t
) * x0
+
498 3 * t
* (1-t
) * (1-t
) * c0x
+
499 3 * t
* t
* (1-t
) * c1x
+
501 y
= (1-t
) * (1-t
) * (1-t
) * y0
+
502 3 * t
* (1-t
) * (1-t
) * c0y
+
503 3 * t
* t
* (1-t
) * c1y
+
506 x
= (1-t
) * x0
+ t
* x1
;
507 y
= (1-t
) * y0
+ t
* y1
;
509 x_trans
= trans
[0]*x
+ trans
[2]*y
+ trans
[4];
510 y_trans
= trans
[1]*x
+ trans
[3]*y
+ trans
[5];
511 r
= ((x_trans
- gradient_x0
) * gradient_dx
+
512 (y_trans
- gradient_y0
) * gradient_dy
) /
513 gradient_norm_squared
;
514 #ifdef GRADIENT_DEBUG
515 fprintf(stderr
, "(%g %g [%g]) ", x
, y
, r
);
517 point
= svgtiny_list_push(pts
);
519 svgtiny_list_free(pts
);
520 return svgtiny_OUT_OF_MEMORY
;
527 min_pt
= svgtiny_list_size(pts
) - 1;
530 #ifdef GRADIENT_DEBUG
531 fprintf(stderr
, "\n");
534 /* next segment start point is this segment end point */
538 #ifdef GRADIENT_DEBUG
539 fprintf(stderr
, "pts size %i, min_pt %i, min_r %.3f\n",
540 svgtiny_list_size(pts
), min_pt
, min_r
);
543 /* render triangles */
544 stop_count
= state
->linear_gradient_stop_count
;
545 assert(2 <= stop_count
);
548 current_stop_r
= state
->gradient_stop
[0].offset
;
549 red0
= red1
= svgtiny_RED(state
->gradient_stop
[0].color
);
550 green0
= green1
= svgtiny_GREEN(state
->gradient_stop
[0].color
);
551 blue0
= blue1
= svgtiny_BLUE(state
->gradient_stop
[0].color
);
553 a
= (min_pt
+ 1) % svgtiny_list_size(pts
);
554 b
= min_pt
== 0 ? svgtiny_list_size(pts
) - 1 : min_pt
- 1;
556 struct grad_point
*point_t
= svgtiny_list_get(pts
, t
);
557 struct grad_point
*point_a
= svgtiny_list_get(pts
, a
);
558 struct grad_point
*point_b
= svgtiny_list_get(pts
, b
);
559 float mean_r
= (point_t
->r
+ point_a
->r
+ point_b
->r
) / 3;
561 struct svgtiny_shape
*shape
;
562 /*fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
564 t, pts[t].r, a, pts[a].r, b, pts[b].r,
566 while (current_stop
!= stop_count
&& current_stop_r
< mean_r
) {
568 if (current_stop
== stop_count
)
573 red1
= svgtiny_RED(state
->
574 gradient_stop
[current_stop
].color
);
575 green1
= svgtiny_GREEN(state
->
576 gradient_stop
[current_stop
].color
);
577 blue1
= svgtiny_BLUE(state
->
578 gradient_stop
[current_stop
].color
);
579 last_stop_r
= current_stop_r
;
580 current_stop_r
= state
->
581 gradient_stop
[current_stop
].offset
;
583 p
= malloc(10 * sizeof p
[0]);
585 return svgtiny_OUT_OF_MEMORY
;
586 p
[0] = svgtiny_PATH_MOVE
;
589 p
[3] = svgtiny_PATH_LINE
;
592 p
[6] = svgtiny_PATH_LINE
;
595 p
[9] = svgtiny_PATH_CLOSE
;
596 svgtiny_transform_path(p
, 10, state
);
597 shape
= svgtiny_add_shape(state
);
600 return svgtiny_OUT_OF_MEMORY
;
603 shape
->path_length
= 10;
604 /*shape->fill = svgtiny_TRANSPARENT;*/
605 if (current_stop
== 0)
606 shape
->fill
= state
->gradient_stop
[0].color
;
607 else if (current_stop
== stop_count
)
608 shape
->fill
= state
->
609 gradient_stop
[stop_count
- 1].color
;
611 float stop_r
= (mean_r
- last_stop_r
) /
612 (current_stop_r
- last_stop_r
);
613 shape
->fill
= svgtiny_RGB(
614 (int) ((1 - stop_r
) * red0
+ stop_r
* red1
),
615 (int) ((1 - stop_r
) * green0
+ stop_r
* green1
),
616 (int) ((1 - stop_r
) * blue0
+ stop_r
* blue1
));
618 shape
->stroke
= svgtiny_TRANSPARENT
;
619 #ifdef GRADIENT_DEBUG
620 shape
->stroke
= svgtiny_RGB(0, 0, 0xff);
622 state
->diagram
->shape_count
++;
623 if (point_a
->r
< point_b
->r
) {
625 a
= (a
+ 1) % svgtiny_list_size(pts
);
628 b
= b
== 0 ? svgtiny_list_size(pts
) - 1 : b
- 1;
632 /* render gradient vector for debugging */
633 #ifdef GRADIENT_DEBUG
635 float *p
= malloc(7 * sizeof p
[0]);
637 return svgtiny_OUT_OF_MEMORY
;
638 p
[0] = svgtiny_PATH_MOVE
;
641 p
[3] = svgtiny_PATH_LINE
;
644 p
[6] = svgtiny_PATH_CLOSE
;
645 svgtiny_transform_path(p
, 7, state
);
646 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
649 return svgtiny_OUT_OF_MEMORY
;
652 shape
->path_length
= 7;
653 shape
->fill
= svgtiny_TRANSPARENT
;
654 shape
->stroke
= svgtiny_RGB(0xff, 0, 0);
655 state
->diagram
->shape_count
++;
659 /* render triangle vertices with r values for debugging */
660 #ifdef GRADIENT_DEBUG
661 for (unsigned int i
= 0; i
!= svgtiny_list_size(pts
); i
++) {
662 struct grad_point
*point
= svgtiny_list_get(pts
, i
);
663 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
665 return svgtiny_OUT_OF_MEMORY
;
666 char *text
= malloc(20);
668 return svgtiny_OUT_OF_MEMORY
;
669 sprintf(text
, "%i=%.3f", i
, point
->r
);
671 shape
->text_x
= state
->ctm
.a
* point
->x
+
672 state
->ctm
.c
* point
->y
+ state
->ctm
.e
;
673 shape
->text_y
= state
->ctm
.b
* point
->x
+
674 state
->ctm
.d
* point
->y
+ state
->ctm
.f
;
675 shape
->fill
= svgtiny_RGB(0, 0, 0);
676 shape
->stroke
= svgtiny_TRANSPARENT
;
677 state
->diagram
->shape_count
++;
681 /* plot actual path outline */
682 if (state
->stroke
!= svgtiny_TRANSPARENT
) {
683 struct svgtiny_shape
*shape
;
684 svgtiny_transform_path(p
, n
, state
);
686 shape
= svgtiny_add_shape(state
);
689 return svgtiny_OUT_OF_MEMORY
;
692 shape
->path_length
= n
;
693 shape
->fill
= svgtiny_TRANSPARENT
;
694 state
->diagram
->shape_count
++;
699 svgtiny_list_free(pts
);
706 * Get the bounding box of path.
709 void svgtiny_path_bbox(float *p
, unsigned int n
,
710 float *x0
, float *y0
, float *x1
, float *y1
)
717 for (j
= 0; j
!= n
; ) {
718 unsigned int points
= 0;
720 switch ((int) p
[j
]) {
721 case svgtiny_PATH_MOVE
:
722 case svgtiny_PATH_LINE
:
725 case svgtiny_PATH_CLOSE
:
728 case svgtiny_PATH_BEZIER
:
735 for (k
= 0; k
!= points
; k
++) {
736 float x
= p
[j
], y
= p
[j
+ 1];
752 * Invert a transformation matrix.
754 void svgtiny_invert_matrix(float *m
, float *inv
)
756 float determinant
= m
[0]*m
[3] - m
[1]*m
[2];
757 inv
[0] = m
[3] / determinant
;
758 inv
[1] = -m
[1] / determinant
;
759 inv
[2] = -m
[2] / determinant
;
760 inv
[3] = m
[0] / determinant
;
761 inv
[4] = (m
[2]*m
[5] - m
[3]*m
[4]) / determinant
;
762 inv
[5] = (m
[1]*m
[4] - m
[0]*m
[5]) / determinant
;