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
, &stop
);
192 if (exc
!= DOM_NO_ERR
)
194 exc
= dom_element_get_attribute(stop
,
195 state
->interned_offset
,
197 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
198 char *s
= strndup(dom_string_data(attr
),
199 dom_string_length(attr
));
200 offset
= svgtiny_parse_gradient_offset(s
);
202 dom_string_unref(attr
);
204 exc
= dom_element_get_attribute(stop
,
205 state
->interned_stop_color
,
207 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
208 svgtiny_parse_color(attr
, &color
, state
);
209 dom_string_unref(attr
);
211 exc
= dom_element_get_attribute(stop
,
212 state
->interned_style
,
214 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
215 char *content
= strndup(dom_string_data(attr
),
216 dom_string_length(attr
));
219 if ((s
= strstr(content
, "stop-color:"))) {
223 exc
= dom_string_create_interned(
227 if (exc
!= DOM_NO_ERR
&&
229 svgtiny_parse_color(value
,
232 dom_string_unref(value
);
236 dom_string_unref(attr
);
238 if (offset
!= -1 && color
!= svgtiny_TRANSPARENT
) {
239 fprintf(stderr
, "stop %g %x\n", offset
, color
);
240 state
->gradient_stop
[i
].offset
= offset
;
241 state
->gradient_stop
[i
].color
= color
;
244 dom_node_unref(stop
);
245 if (i
== svgtiny_MAX_STOPS
)
249 dom_nodelist_unref(stops
);
253 state
->linear_gradient_stop_count
= i
;
259 float svgtiny_parse_gradient_offset(const char *s
)
261 int num_length
= strspn(s
, "0123456789+-.");
262 const char *unit
= s
+ num_length
;
263 float n
= atof((const char *) s
);
267 else if (unit
[0] == '%')
281 * Add a path with a linear gradient fill to the svgtiny_diagram.
284 svgtiny_code
svgtiny_add_path_linear_gradient(float *p
, unsigned int n
,
285 struct svgtiny_parse_state
*state
)
290 float object_x0
, object_y0
, object_x1
, object_y1
;
291 float gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
,
292 gradient_dx
, gradient_dy
;
294 unsigned int steps
= 10;
295 float x0
= 0, y0
= 0, x0_trans
, y0_trans
, r0
; /* segment start point */
296 float x1
, y1
, x1_trans
, y1_trans
, r1
; /* segment end point */
297 /* segment control points (beziers only) */
298 float c0x
= 0, c0y
= 0, c1x
= 0, c1y
= 0;
299 float gradient_norm_squared
;
300 struct svgtiny_list
*pts
;
302 unsigned int min_pt
= 0;
304 unsigned int stop_count
;
305 unsigned int current_stop
;
307 float current_stop_r
;
308 int red0
, green0
, blue0
, red1
, green1
, blue1
;
309 unsigned int t
, a
, b
;
311 /* determine object bounding box */
312 svgtiny_path_bbox(p
, n
, &object_x0
, &object_y0
, &object_x1
, &object_y1
);
313 #ifdef GRADIENT_DEBUG
314 fprintf(stderr
, "object bbox: (%g %g) (%g %g)\n",
315 object_x0
, object_y0
, object_x1
, object_y1
);
318 /* compute gradient vector */
319 fprintf(stderr
, "x1 %*s, y1 %*s, x2 %*s, y2 %*s\n",
320 dom_string_length(state
->gradient_x1
),
321 dom_string_data(state
->gradient_x1
),
322 dom_string_length(state
->gradient_y1
),
323 dom_string_data(state
->gradient_y1
),
324 dom_string_length(state
->gradient_x2
),
325 dom_string_data(state
->gradient_x2
),
326 dom_string_length(state
->gradient_y2
),
327 dom_string_data(state
->gradient_y2
));
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 fprintf(stderr
, "inverse transform %g %g %g %g %g %g\n",
404 trans
[0], trans
[1], trans
[2], trans
[3],
407 /* compute points on the path for triangle vertices */
408 /* r, r0, r1 are distance along gradient vector */
409 gradient_norm_squared
= gradient_dx
* gradient_dx
+
410 gradient_dy
* gradient_dy
;
411 pts
= svgtiny_list_create(
412 sizeof (struct grad_point
));
414 return svgtiny_OUT_OF_MEMORY
;
415 for (j
= 0; j
!= n
; ) {
416 int segment_type
= (int) p
[j
];
417 struct grad_point
*point
;
420 if (segment_type
== svgtiny_PATH_MOVE
) {
427 assert(segment_type
== svgtiny_PATH_CLOSE
||
428 segment_type
== svgtiny_PATH_LINE
||
429 segment_type
== svgtiny_PATH_BEZIER
);
431 /* start point (x0, y0) */
432 x0_trans
= trans
[0]*x0
+ trans
[2]*y0
+ trans
[4];
433 y0_trans
= trans
[1]*x0
+ trans
[3]*y0
+ trans
[5];
434 r0
= ((x0_trans
- gradient_x0
) * gradient_dx
+
435 (y0_trans
- gradient_y0
) * gradient_dy
) /
436 gradient_norm_squared
;
437 point
= svgtiny_list_push(pts
);
439 svgtiny_list_free(pts
);
440 return svgtiny_OUT_OF_MEMORY
;
447 min_pt
= svgtiny_list_size(pts
) - 1;
450 /* end point (x1, y1) */
451 if (segment_type
== svgtiny_PATH_LINE
) {
455 } else if (segment_type
== svgtiny_PATH_CLOSE
) {
459 } else /* svgtiny_PATH_BEZIER */ {
468 x1_trans
= trans
[0]*x1
+ trans
[2]*y1
+ trans
[4];
469 y1_trans
= trans
[1]*x1
+ trans
[3]*y1
+ trans
[5];
470 r1
= ((x1_trans
- gradient_x0
) * gradient_dx
+
471 (y1_trans
- gradient_y0
) * gradient_dy
) /
472 gradient_norm_squared
;
474 /* determine steps from change in r */
475 steps
= ceilf(fabsf(r1
- r0
) / 0.05);
478 fprintf(stderr
, "r0 %g, r1 %g, steps %i\n",
481 /* loop through intermediate points */
482 for (z
= 1; z
!= steps
; z
++) {
483 float t
, x
, y
, x_trans
, y_trans
, r
;
484 struct grad_point
*point
;
485 t
= (float) z
/ (float) steps
;
486 if (segment_type
== svgtiny_PATH_BEZIER
) {
487 x
= (1-t
) * (1-t
) * (1-t
) * x0
+
488 3 * t
* (1-t
) * (1-t
) * c0x
+
489 3 * t
* t
* (1-t
) * c1x
+
491 y
= (1-t
) * (1-t
) * (1-t
) * y0
+
492 3 * t
* (1-t
) * (1-t
) * c0y
+
493 3 * t
* t
* (1-t
) * c1y
+
496 x
= (1-t
) * x0
+ t
* x1
;
497 y
= (1-t
) * y0
+ t
* y1
;
499 x_trans
= trans
[0]*x
+ trans
[2]*y
+ trans
[4];
500 y_trans
= trans
[1]*x
+ trans
[3]*y
+ trans
[5];
501 r
= ((x_trans
- gradient_x0
) * gradient_dx
+
502 (y_trans
- gradient_y0
) * gradient_dy
) /
503 gradient_norm_squared
;
504 fprintf(stderr
, "(%g %g [%g]) ", x
, y
, r
);
505 point
= svgtiny_list_push(pts
);
507 svgtiny_list_free(pts
);
508 return svgtiny_OUT_OF_MEMORY
;
515 min_pt
= svgtiny_list_size(pts
) - 1;
518 fprintf(stderr
, "\n");
520 /* next segment start point is this segment end point */
524 fprintf(stderr
, "pts size %i, min_pt %i, min_r %.3f\n",
525 svgtiny_list_size(pts
), min_pt
, min_r
);
527 /* render triangles */
528 stop_count
= state
->linear_gradient_stop_count
;
529 assert(2 <= stop_count
);
532 current_stop_r
= state
->gradient_stop
[0].offset
;
533 red0
= red1
= svgtiny_RED(state
->gradient_stop
[0].color
);
534 green0
= green1
= svgtiny_GREEN(state
->gradient_stop
[0].color
);
535 blue0
= blue1
= svgtiny_BLUE(state
->gradient_stop
[0].color
);
537 a
= (min_pt
+ 1) % svgtiny_list_size(pts
);
538 b
= min_pt
== 0 ? svgtiny_list_size(pts
) - 1 : min_pt
- 1;
540 struct grad_point
*point_t
= svgtiny_list_get(pts
, t
);
541 struct grad_point
*point_a
= svgtiny_list_get(pts
, a
);
542 struct grad_point
*point_b
= svgtiny_list_get(pts
, b
);
543 float mean_r
= (point_t
->r
+ point_a
->r
+ point_b
->r
) / 3;
545 struct svgtiny_shape
*shape
;
546 /*fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
548 t, pts[t].r, a, pts[a].r, b, pts[b].r,
550 while (current_stop
!= stop_count
&& current_stop_r
< mean_r
) {
552 if (current_stop
== stop_count
)
557 red1
= svgtiny_RED(state
->
558 gradient_stop
[current_stop
].color
);
559 green1
= svgtiny_GREEN(state
->
560 gradient_stop
[current_stop
].color
);
561 blue1
= svgtiny_BLUE(state
->
562 gradient_stop
[current_stop
].color
);
563 last_stop_r
= current_stop_r
;
564 current_stop_r
= state
->
565 gradient_stop
[current_stop
].offset
;
567 p
= malloc(10 * sizeof p
[0]);
569 return svgtiny_OUT_OF_MEMORY
;
570 p
[0] = svgtiny_PATH_MOVE
;
573 p
[3] = svgtiny_PATH_LINE
;
576 p
[6] = svgtiny_PATH_LINE
;
579 p
[9] = svgtiny_PATH_CLOSE
;
580 svgtiny_transform_path(p
, 10, state
);
581 shape
= svgtiny_add_shape(state
);
584 return svgtiny_OUT_OF_MEMORY
;
587 shape
->path_length
= 10;
588 /*shape->fill = svgtiny_TRANSPARENT;*/
589 if (current_stop
== 0)
590 shape
->fill
= state
->gradient_stop
[0].color
;
591 else if (current_stop
== stop_count
)
592 shape
->fill
= state
->
593 gradient_stop
[stop_count
- 1].color
;
595 float stop_r
= (mean_r
- last_stop_r
) /
596 (current_stop_r
- last_stop_r
);
597 shape
->fill
= svgtiny_RGB(
598 (int) ((1 - stop_r
) * red0
+ stop_r
* red1
),
599 (int) ((1 - stop_r
) * green0
+ stop_r
* green1
),
600 (int) ((1 - stop_r
) * blue0
+ stop_r
* blue1
));
602 shape
->stroke
= svgtiny_TRANSPARENT
;
603 #ifdef GRADIENT_DEBUG
604 shape
->stroke
= svgtiny_RGB(0, 0, 0xff);
606 state
->diagram
->shape_count
++;
607 if (point_a
->r
< point_b
->r
) {
609 a
= (a
+ 1) % svgtiny_list_size(pts
);
612 b
= b
== 0 ? svgtiny_list_size(pts
) - 1 : b
- 1;
616 /* render gradient vector for debugging */
617 #ifdef GRADIENT_DEBUG
619 float *p
= malloc(7 * sizeof p
[0]);
621 return svgtiny_OUT_OF_MEMORY
;
622 p
[0] = svgtiny_PATH_MOVE
;
625 p
[3] = svgtiny_PATH_LINE
;
628 p
[6] = svgtiny_PATH_CLOSE
;
629 svgtiny_transform_path(p
, 7, state
);
630 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
633 return svgtiny_OUT_OF_MEMORY
;
636 shape
->path_length
= 7;
637 shape
->fill
= svgtiny_TRANSPARENT
;
638 shape
->stroke
= svgtiny_RGB(0xff, 0, 0);
639 state
->diagram
->shape_count
++;
643 /* render triangle vertices with r values for debugging */
644 #ifdef GRADIENT_DEBUG
645 for (unsigned int i
= 0; i
!= pts
->size
; i
++) {
646 struct grad_point
*point
= svgtiny_list_get(pts
, i
);
647 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
649 return svgtiny_OUT_OF_MEMORY
;
650 char *text
= malloc(20);
652 return svgtiny_OUT_OF_MEMORY
;
653 sprintf(text
, "%i=%.3f", i
, point
->r
);
655 shape
->text_x
= state
->ctm
.a
* point
->x
+
656 state
->ctm
.c
* point
->y
+ state
->ctm
.e
;
657 shape
->text_y
= state
->ctm
.b
* point
->x
+
658 state
->ctm
.d
* point
->y
+ state
->ctm
.f
;
659 shape
->fill
= svgtiny_RGB(0, 0, 0);
660 shape
->stroke
= svgtiny_TRANSPARENT
;
661 state
->diagram
->shape_count
++;
665 /* plot actual path outline */
666 if (state
->stroke
!= svgtiny_TRANSPARENT
) {
667 struct svgtiny_shape
*shape
;
668 svgtiny_transform_path(p
, n
, state
);
670 shape
= svgtiny_add_shape(state
);
673 return svgtiny_OUT_OF_MEMORY
;
676 shape
->path_length
= n
;
677 shape
->fill
= svgtiny_TRANSPARENT
;
678 state
->diagram
->shape_count
++;
683 svgtiny_list_free(pts
);
690 * Get the bounding box of path.
693 void svgtiny_path_bbox(float *p
, unsigned int n
,
694 float *x0
, float *y0
, float *x1
, float *y1
)
701 for (j
= 0; j
!= n
; ) {
702 unsigned int points
= 0;
704 switch ((int) p
[j
]) {
705 case svgtiny_PATH_MOVE
:
706 case svgtiny_PATH_LINE
:
709 case svgtiny_PATH_CLOSE
:
712 case svgtiny_PATH_BEZIER
:
719 for (k
= 0; k
!= points
; k
++) {
720 float x
= p
[j
], y
= p
[j
+ 1];
736 * Invert a transformation matrix.
738 void svgtiny_invert_matrix(float *m
, float *inv
)
740 float determinant
= m
[0]*m
[3] - m
[1]*m
[2];
741 inv
[0] = m
[3] / determinant
;
742 inv
[1] = -m
[1] / determinant
;
743 inv
[2] = -m
[2] / determinant
;
744 inv
[3] = m
[0] / determinant
;
745 inv
[4] = (m
[2]*m
[5] - m
[3]*m
[4]) / determinant
;
746 inv
[5] = (m
[1]*m
[4] - m
[0]*m
[5]) / determinant
;