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
;
37 fprintf(stderr
, "svgtiny_find_gradient: id \"%s\"\n", id
);
39 state
->linear_gradient_stop_count
= 0;
40 if (state
->gradient_x1
!= NULL
)
41 dom_string_unref(state
->gradient_x1
);
42 if (state
->gradient_y1
!= NULL
)
43 dom_string_unref(state
->gradient_y1
);
44 if (state
->gradient_x2
!= NULL
)
45 dom_string_unref(state
->gradient_x2
);
46 if (state
->gradient_y2
!= NULL
)
47 dom_string_unref(state
->gradient_y2
);
48 state
->gradient_x1
= dom_string_ref(state
->interned_zero_percent
);
49 state
->gradient_y1
= dom_string_ref(state
->interned_zero_percent
);
50 state
->gradient_x2
= dom_string_ref(state
->interned_hundred_percent
);
51 state
->gradient_y2
= dom_string_ref(state
->interned_zero_percent
);
52 state
->gradient_user_space_on_use
= false;
53 state
->gradient_transform
.a
= 1;
54 state
->gradient_transform
.b
= 0;
55 state
->gradient_transform
.c
= 0;
56 state
->gradient_transform
.d
= 1;
57 state
->gradient_transform
.e
= 0;
58 state
->gradient_transform
.f
= 0;
60 exc
= dom_string_create_interned((const uint8_t *) id
, strlen(id
),
62 if (exc
!= DOM_NO_ERR
)
65 exc
= dom_document_get_element_by_id(state
->document
, id_str
,
67 dom_string_unref(id_str
);
68 if (exc
!= DOM_NO_ERR
)
71 if (gradient
== NULL
) {
72 fprintf(stderr
, "gradient \"%s\" not found\n", id
);
76 exc
= dom_node_get_node_name(gradient
, &id_str
);
77 if (exc
!= DOM_NO_ERR
) {
78 dom_node_unref(gradient
);
82 if (dom_string_isequal(id_str
, state
->interned_linearGradient
))
83 svgtiny_parse_linear_gradient(gradient
, state
);
85 dom_string_unref(id_str
);
86 dom_node_unref(gradient
);
91 * Parse a <linearGradient> element node.
93 * http://www.w3.org/TR/SVG11/pservers#LinearGradients
96 svgtiny_code
svgtiny_parse_linear_gradient(dom_element
*linear
,
97 struct svgtiny_parse_state
*state
)
104 exc
= dom_element_get_attribute(linear
, state
->interned_href
, &attr
);
105 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
106 if (dom_string_data(attr
)[0] == (uint8_t) '#') {
107 char *s
= strndup(dom_string_data(attr
) + 1,
108 dom_string_length(attr
) - 1);
109 svgtiny_find_gradient(s
, state
);
112 dom_string_unref(attr
);
115 exc
= dom_element_get_attribute(linear
, state
->interned_x1
, &attr
);
116 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
117 dom_string_unref(state
->gradient_x1
);
118 state
->gradient_x1
= attr
;
122 exc
= dom_element_get_attribute(linear
, state
->interned_y1
, &attr
);
123 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
124 dom_string_unref(state
->gradient_y1
);
125 state
->gradient_y1
= attr
;
129 exc
= dom_element_get_attribute(linear
, state
->interned_x2
, &attr
);
130 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
131 dom_string_unref(state
->gradient_x2
);
132 state
->gradient_x2
= attr
;
136 exc
= dom_element_get_attribute(linear
, state
->interned_y2
, &attr
);
137 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
138 dom_string_unref(state
->gradient_y2
);
139 state
->gradient_y2
= attr
;
143 exc
= dom_element_get_attribute(linear
, state
->interned_gradientUnits
,
145 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
146 state
->gradient_user_space_on_use
=
147 dom_string_isequal(attr
,
148 state
->interned_userSpaceOnUse
);
149 dom_string_unref(attr
);
152 exc
= dom_element_get_attribute(linear
,
153 state
->interned_gradientTransform
,
155 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
156 float a
= 1, b
= 0, c
= 0, d
= 1, e
= 0, f
= 0;
157 char *s
= strndup(dom_string_data(attr
),
158 dom_string_length(attr
));
160 dom_string_unref(attr
);
161 return svgtiny_OUT_OF_MEMORY
;
163 svgtiny_parse_transform(s
, &a
, &b
, &c
, &d
, &e
, &f
);
165 fprintf(stderr
, "transform %g %g %g %g %g %g\n",
167 state
->gradient_transform
.a
= a
;
168 state
->gradient_transform
.b
= b
;
169 state
->gradient_transform
.c
= c
;
170 state
->gradient_transform
.d
= d
;
171 state
->gradient_transform
.e
= e
;
172 state
->gradient_transform
.f
= f
;
173 dom_string_unref(attr
);
176 exc
= dom_element_get_elements_by_tag_name(linear
,
177 state
->interned_stop
,
179 if (exc
== DOM_NO_ERR
&& stops
!= NULL
) {
180 uint32_t listlen
, stopnr
;
181 exc
= dom_nodelist_get_length(stops
, &listlen
);
182 if (exc
!= DOM_NO_ERR
) {
183 dom_nodelist_unref(stops
);
187 for (stopnr
= 0; stopnr
< listlen
; ++stopnr
) {
190 svgtiny_colour color
= svgtiny_TRANSPARENT
;
191 exc
= dom_nodelist_item(stops
, stopnr
,
192 (dom_node
**) (void *) &stop
);
193 if (exc
!= DOM_NO_ERR
)
195 exc
= dom_element_get_attribute(stop
,
196 state
->interned_offset
,
198 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
199 char *s
= strndup(dom_string_data(attr
),
200 dom_string_length(attr
));
201 offset
= svgtiny_parse_gradient_offset(s
);
203 dom_string_unref(attr
);
205 exc
= dom_element_get_attribute(stop
,
206 state
->interned_stop_color
,
208 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
209 svgtiny_parse_color(attr
, &color
, state
);
210 dom_string_unref(attr
);
212 exc
= dom_element_get_attribute(stop
,
213 state
->interned_style
,
215 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
216 char *content
= strndup(dom_string_data(attr
),
217 dom_string_length(attr
));
220 if ((s
= strstr(content
, "stop-color:"))) {
224 exc
= dom_string_create_interned(
228 if (exc
!= DOM_NO_ERR
&&
230 svgtiny_parse_color(value
,
233 dom_string_unref(value
);
237 dom_string_unref(attr
);
239 if (offset
!= -1 && color
!= svgtiny_TRANSPARENT
) {
240 fprintf(stderr
, "stop %g %x\n", offset
, color
);
241 state
->gradient_stop
[i
].offset
= offset
;
242 state
->gradient_stop
[i
].color
= color
;
245 dom_node_unref(stop
);
246 if (i
== svgtiny_MAX_STOPS
)
250 dom_nodelist_unref(stops
);
254 state
->linear_gradient_stop_count
= i
;
260 float svgtiny_parse_gradient_offset(const char *s
)
262 int num_length
= strspn(s
, "0123456789+-.");
263 const char *unit
= s
+ num_length
;
264 float n
= atof((const char *) s
);
268 else if (unit
[0] == '%')
282 * Add a path with a linear gradient fill to the svgtiny_diagram.
285 svgtiny_code
svgtiny_add_path_linear_gradient(float *p
, unsigned int n
,
286 struct svgtiny_parse_state
*state
)
291 float object_x0
, object_y0
, object_x1
, object_y1
;
292 float gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
,
293 gradient_dx
, gradient_dy
;
295 unsigned int steps
= 10;
296 float x0
= 0, y0
= 0, x0_trans
, y0_trans
, r0
; /* segment start point */
297 float x1
, y1
, x1_trans
, y1_trans
, r1
; /* segment end point */
298 /* segment control points (beziers only) */
299 float c0x
= 0, c0y
= 0, c1x
= 0, c1y
= 0;
300 float gradient_norm_squared
;
301 struct svgtiny_list
*pts
;
303 unsigned int min_pt
= 0;
305 unsigned int stop_count
;
306 unsigned int current_stop
;
308 float current_stop_r
;
309 int red0
, green0
, blue0
, red1
, green1
, blue1
;
310 unsigned int t
, a
, b
;
312 /* determine object bounding box */
313 svgtiny_path_bbox(p
, n
, &object_x0
, &object_y0
, &object_x1
, &object_y1
);
314 #ifdef GRADIENT_DEBUG
315 fprintf(stderr
, "object bbox: (%g %g) (%g %g)\n",
316 object_x0
, object_y0
, object_x1
, object_y1
);
319 /* compute gradient vector */
320 fprintf(stderr
, "x1 %*s, y1 %*s, x2 %*s, y2 %*s\n",
321 dom_string_length(state
->gradient_x1
),
322 dom_string_data(state
->gradient_x1
),
323 dom_string_length(state
->gradient_y1
),
324 dom_string_data(state
->gradient_y1
),
325 dom_string_length(state
->gradient_x2
),
326 dom_string_data(state
->gradient_x2
),
327 dom_string_length(state
->gradient_y2
),
328 dom_string_data(state
->gradient_y2
));
330 if (!state
->gradient_user_space_on_use
) {
331 gradient_x0
= object_x0
+
332 svgtiny_parse_length(state
->gradient_x1
,
333 object_x1
- object_x0
, *state
);
334 gradient_y0
= object_y0
+
335 svgtiny_parse_length(state
->gradient_y1
,
336 object_y1
- object_y0
, *state
);
337 gradient_x1
= object_x0
+
338 svgtiny_parse_length(state
->gradient_x2
,
339 object_x1
- object_x0
, *state
);
340 gradient_y1
= object_y0
+
341 svgtiny_parse_length(state
->gradient_y2
,
342 object_y1
- object_y0
, *state
);
344 gradient_x0
= svgtiny_parse_length(state
->gradient_x1
,
345 state
->viewport_width
, *state
);
346 gradient_y0
= svgtiny_parse_length(state
->gradient_y1
,
347 state
->viewport_height
, *state
);
348 gradient_x1
= svgtiny_parse_length(state
->gradient_x2
,
349 state
->viewport_width
, *state
);
350 gradient_y1
= svgtiny_parse_length(state
->gradient_y2
,
351 state
->viewport_height
, *state
);
353 gradient_dx
= gradient_x1
- gradient_x0
;
354 gradient_dy
= gradient_y1
- gradient_y0
;
355 #ifdef GRADIENT_DEBUG
356 fprintf(stderr
, "gradient vector: (%g %g) => (%g %g)\n",
357 gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
);
360 /* show theoretical gradient strips for debugging */
361 /*unsigned int strips = 10;
362 for (unsigned int z = 0; z != strips; z++) {
363 float f0, fd, strip_x0, strip_y0, strip_dx, strip_dy;
364 f0 = (float) z / (float) strips;
365 fd = (float) 1 / (float) strips;
366 strip_x0 = gradient_x0 + f0 * gradient_dx;
367 strip_y0 = gradient_y0 + f0 * gradient_dy;
368 strip_dx = fd * gradient_dx;
369 strip_dy = fd * gradient_dy;
370 fprintf(stderr, "strip %i vector: (%g %g) + (%g %g)\n",
371 z, strip_x0, strip_y0, strip_dx, strip_dy);
373 float *p = malloc(13 * sizeof p[0]);
375 return svgtiny_OUT_OF_MEMORY;
376 p[0] = svgtiny_PATH_MOVE;
377 p[1] = strip_x0 + (strip_dy * 3);
378 p[2] = strip_y0 - (strip_dx * 3);
379 p[3] = svgtiny_PATH_LINE;
380 p[4] = p[1] + strip_dx;
381 p[5] = p[2] + strip_dy;
382 p[6] = svgtiny_PATH_LINE;
383 p[7] = p[4] - (strip_dy * 6);
384 p[8] = p[5] + (strip_dx * 6);
385 p[9] = svgtiny_PATH_LINE;
386 p[10] = p[7] - strip_dx;
387 p[11] = p[8] - strip_dy;
388 p[12] = svgtiny_PATH_CLOSE;
389 svgtiny_transform_path(p, 13, state);
390 struct svgtiny_shape *shape = svgtiny_add_shape(state);
393 return svgtiny_OUT_OF_MEMORY;
396 shape->path_length = 13;
397 shape->fill = svgtiny_TRANSPARENT;
398 shape->stroke = svgtiny_RGB(0, 0xff, 0);
399 state->diagram->shape_count++;
402 /* invert gradient transform for applying to vertices */
403 svgtiny_invert_matrix(&state
->gradient_transform
.a
, trans
);
404 fprintf(stderr
, "inverse transform %g %g %g %g %g %g\n",
405 trans
[0], trans
[1], trans
[2], trans
[3],
408 /* compute points on the path for triangle vertices */
409 /* r, r0, r1 are distance along gradient vector */
410 gradient_norm_squared
= gradient_dx
* gradient_dx
+
411 gradient_dy
* gradient_dy
;
412 pts
= svgtiny_list_create(
413 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 */
476 steps
= ceilf(fabsf(r1
- r0
) / 0.05);
479 fprintf(stderr
, "r0 %g, r1 %g, steps %i\n",
482 /* loop through intermediate points */
483 for (z
= 1; z
!= steps
; z
++) {
484 float t
, x
, y
, x_trans
, y_trans
, r
;
485 struct grad_point
*point
;
486 t
= (float) z
/ (float) steps
;
487 if (segment_type
== svgtiny_PATH_BEZIER
) {
488 x
= (1-t
) * (1-t
) * (1-t
) * x0
+
489 3 * t
* (1-t
) * (1-t
) * c0x
+
490 3 * t
* t
* (1-t
) * c1x
+
492 y
= (1-t
) * (1-t
) * (1-t
) * y0
+
493 3 * t
* (1-t
) * (1-t
) * c0y
+
494 3 * t
* t
* (1-t
) * c1y
+
497 x
= (1-t
) * x0
+ t
* x1
;
498 y
= (1-t
) * y0
+ t
* y1
;
500 x_trans
= trans
[0]*x
+ trans
[2]*y
+ trans
[4];
501 y_trans
= trans
[1]*x
+ trans
[3]*y
+ trans
[5];
502 r
= ((x_trans
- gradient_x0
) * gradient_dx
+
503 (y_trans
- gradient_y0
) * gradient_dy
) /
504 gradient_norm_squared
;
505 fprintf(stderr
, "(%g %g [%g]) ", x
, y
, r
);
506 point
= svgtiny_list_push(pts
);
508 svgtiny_list_free(pts
);
509 return svgtiny_OUT_OF_MEMORY
;
516 min_pt
= svgtiny_list_size(pts
) - 1;
519 fprintf(stderr
, "\n");
521 /* next segment start point is this segment end point */
525 fprintf(stderr
, "pts size %i, min_pt %i, min_r %.3f\n",
526 svgtiny_list_size(pts
), min_pt
, min_r
);
528 /* render triangles */
529 stop_count
= state
->linear_gradient_stop_count
;
530 assert(2 <= stop_count
);
533 current_stop_r
= state
->gradient_stop
[0].offset
;
534 red0
= red1
= svgtiny_RED(state
->gradient_stop
[0].color
);
535 green0
= green1
= svgtiny_GREEN(state
->gradient_stop
[0].color
);
536 blue0
= blue1
= svgtiny_BLUE(state
->gradient_stop
[0].color
);
538 a
= (min_pt
+ 1) % svgtiny_list_size(pts
);
539 b
= min_pt
== 0 ? svgtiny_list_size(pts
) - 1 : min_pt
- 1;
541 struct grad_point
*point_t
= svgtiny_list_get(pts
, t
);
542 struct grad_point
*point_a
= svgtiny_list_get(pts
, a
);
543 struct grad_point
*point_b
= svgtiny_list_get(pts
, b
);
544 float mean_r
= (point_t
->r
+ point_a
->r
+ point_b
->r
) / 3;
546 struct svgtiny_shape
*shape
;
547 /*fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
549 t, pts[t].r, a, pts[a].r, b, pts[b].r,
551 while (current_stop
!= stop_count
&& current_stop_r
< mean_r
) {
553 if (current_stop
== stop_count
)
558 red1
= svgtiny_RED(state
->
559 gradient_stop
[current_stop
].color
);
560 green1
= svgtiny_GREEN(state
->
561 gradient_stop
[current_stop
].color
);
562 blue1
= svgtiny_BLUE(state
->
563 gradient_stop
[current_stop
].color
);
564 last_stop_r
= current_stop_r
;
565 current_stop_r
= state
->
566 gradient_stop
[current_stop
].offset
;
568 p
= malloc(10 * sizeof p
[0]);
570 return svgtiny_OUT_OF_MEMORY
;
571 p
[0] = svgtiny_PATH_MOVE
;
574 p
[3] = svgtiny_PATH_LINE
;
577 p
[6] = svgtiny_PATH_LINE
;
580 p
[9] = svgtiny_PATH_CLOSE
;
581 svgtiny_transform_path(p
, 10, state
);
582 shape
= svgtiny_add_shape(state
);
585 return svgtiny_OUT_OF_MEMORY
;
588 shape
->path_length
= 10;
589 /*shape->fill = svgtiny_TRANSPARENT;*/
590 if (current_stop
== 0)
591 shape
->fill
= state
->gradient_stop
[0].color
;
592 else if (current_stop
== stop_count
)
593 shape
->fill
= state
->
594 gradient_stop
[stop_count
- 1].color
;
596 float stop_r
= (mean_r
- last_stop_r
) /
597 (current_stop_r
- last_stop_r
);
598 shape
->fill
= svgtiny_RGB(
599 (int) ((1 - stop_r
) * red0
+ stop_r
* red1
),
600 (int) ((1 - stop_r
) * green0
+ stop_r
* green1
),
601 (int) ((1 - stop_r
) * blue0
+ stop_r
* blue1
));
603 shape
->stroke
= svgtiny_TRANSPARENT
;
604 #ifdef GRADIENT_DEBUG
605 shape
->stroke
= svgtiny_RGB(0, 0, 0xff);
607 state
->diagram
->shape_count
++;
608 if (point_a
->r
< point_b
->r
) {
610 a
= (a
+ 1) % svgtiny_list_size(pts
);
613 b
= b
== 0 ? svgtiny_list_size(pts
) - 1 : b
- 1;
617 /* render gradient vector for debugging */
618 #ifdef GRADIENT_DEBUG
620 float *p
= malloc(7 * sizeof p
[0]);
622 return svgtiny_OUT_OF_MEMORY
;
623 p
[0] = svgtiny_PATH_MOVE
;
626 p
[3] = svgtiny_PATH_LINE
;
629 p
[6] = svgtiny_PATH_CLOSE
;
630 svgtiny_transform_path(p
, 7, state
);
631 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
634 return svgtiny_OUT_OF_MEMORY
;
637 shape
->path_length
= 7;
638 shape
->fill
= svgtiny_TRANSPARENT
;
639 shape
->stroke
= svgtiny_RGB(0xff, 0, 0);
640 state
->diagram
->shape_count
++;
644 /* render triangle vertices with r values for debugging */
645 #ifdef GRADIENT_DEBUG
646 for (unsigned int i
= 0; i
!= pts
->size
; i
++) {
647 struct grad_point
*point
= svgtiny_list_get(pts
, i
);
648 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
650 return svgtiny_OUT_OF_MEMORY
;
651 char *text
= malloc(20);
653 return svgtiny_OUT_OF_MEMORY
;
654 sprintf(text
, "%i=%.3f", i
, point
->r
);
656 shape
->text_x
= state
->ctm
.a
* point
->x
+
657 state
->ctm
.c
* point
->y
+ state
->ctm
.e
;
658 shape
->text_y
= state
->ctm
.b
* point
->x
+
659 state
->ctm
.d
* point
->y
+ state
->ctm
.f
;
660 shape
->fill
= svgtiny_RGB(0, 0, 0);
661 shape
->stroke
= svgtiny_TRANSPARENT
;
662 state
->diagram
->shape_count
++;
666 /* plot actual path outline */
667 if (state
->stroke
!= svgtiny_TRANSPARENT
) {
668 struct svgtiny_shape
*shape
;
669 svgtiny_transform_path(p
, n
, state
);
671 shape
= svgtiny_add_shape(state
);
674 return svgtiny_OUT_OF_MEMORY
;
677 shape
->path_length
= n
;
678 shape
->fill
= svgtiny_TRANSPARENT
;
679 state
->diagram
->shape_count
++;
684 svgtiny_list_free(pts
);
691 * Get the bounding box of path.
694 void svgtiny_path_bbox(float *p
, unsigned int n
,
695 float *x0
, float *y0
, float *x1
, float *y1
)
702 for (j
= 0; j
!= n
; ) {
703 unsigned int points
= 0;
705 switch ((int) p
[j
]) {
706 case svgtiny_PATH_MOVE
:
707 case svgtiny_PATH_LINE
:
710 case svgtiny_PATH_CLOSE
:
713 case svgtiny_PATH_BEZIER
:
720 for (k
= 0; k
!= points
; k
++) {
721 float x
= p
[j
], y
= p
[j
+ 1];
737 * Invert a transformation matrix.
739 void svgtiny_invert_matrix(float *m
, float *inv
)
741 float determinant
= m
[0]*m
[3] - m
[1]*m
[2];
742 inv
[0] = m
[3] / determinant
;
743 inv
[1] = -m
[1] / determinant
;
744 inv
[2] = -m
[2] / determinant
;
745 inv
[3] = m
[0] / determinant
;
746 inv
[4] = (m
[2]*m
[5] - m
[3]*m
[4]) / determinant
;
747 inv
[5] = (m
[1]*m
[4] - m
[0]*m
[5]) / determinant
;