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
;
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
, strlen(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
)
73 if (gradient
== NULL
) {
75 fprintf(stderr
, "gradient \"%s\" not found\n", id
);
80 exc
= dom_node_get_node_name(gradient
, &id_str
);
81 if (exc
!= DOM_NO_ERR
) {
82 dom_node_unref(gradient
);
86 if (dom_string_isequal(id_str
, state
->interned_linearGradient
))
87 svgtiny_parse_linear_gradient(gradient
, state
);
89 dom_string_unref(id_str
);
90 dom_node_unref(gradient
);
95 * Parse a <linearGradient> element node.
97 * http://www.w3.org/TR/SVG11/pservers#LinearGradients
100 svgtiny_code
svgtiny_parse_linear_gradient(dom_element
*linear
,
101 struct svgtiny_parse_state
*state
)
108 exc
= dom_element_get_attribute(linear
, state
->interned_href
, &attr
);
109 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
110 if (dom_string_data(attr
)[0] == (uint8_t) '#') {
111 char *s
= strndup(dom_string_data(attr
) + 1,
112 dom_string_byte_length(attr
) - 1);
113 svgtiny_find_gradient(s
, state
);
116 dom_string_unref(attr
);
119 exc
= dom_element_get_attribute(linear
, state
->interned_x1
, &attr
);
120 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
121 dom_string_unref(state
->gradient_x1
);
122 state
->gradient_x1
= attr
;
126 exc
= dom_element_get_attribute(linear
, state
->interned_y1
, &attr
);
127 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
128 dom_string_unref(state
->gradient_y1
);
129 state
->gradient_y1
= attr
;
133 exc
= dom_element_get_attribute(linear
, state
->interned_x2
, &attr
);
134 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
135 dom_string_unref(state
->gradient_x2
);
136 state
->gradient_x2
= attr
;
140 exc
= dom_element_get_attribute(linear
, state
->interned_y2
, &attr
);
141 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
142 dom_string_unref(state
->gradient_y2
);
143 state
->gradient_y2
= attr
;
147 exc
= dom_element_get_attribute(linear
, state
->interned_gradientUnits
,
149 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
150 state
->gradient_user_space_on_use
=
151 dom_string_isequal(attr
,
152 state
->interned_userSpaceOnUse
);
153 dom_string_unref(attr
);
156 exc
= dom_element_get_attribute(linear
,
157 state
->interned_gradientTransform
,
159 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
160 float a
= 1, b
= 0, c
= 0, d
= 1, e
= 0, f
= 0;
161 char *s
= strndup(dom_string_data(attr
),
162 dom_string_byte_length(attr
));
164 dom_string_unref(attr
);
165 return svgtiny_OUT_OF_MEMORY
;
167 svgtiny_parse_transform(s
, &a
, &b
, &c
, &d
, &e
, &f
);
169 #ifdef GRADIENT_DEBUG
170 fprintf(stderr
, "transform %g %g %g %g %g %g\n",
173 state
->gradient_transform
.a
= a
;
174 state
->gradient_transform
.b
= b
;
175 state
->gradient_transform
.c
= c
;
176 state
->gradient_transform
.d
= d
;
177 state
->gradient_transform
.e
= e
;
178 state
->gradient_transform
.f
= f
;
179 dom_string_unref(attr
);
182 exc
= dom_element_get_elements_by_tag_name(linear
,
183 state
->interned_stop
,
185 if (exc
== DOM_NO_ERR
&& stops
!= NULL
) {
186 uint32_t listlen
, stopnr
;
187 exc
= dom_nodelist_get_length(stops
, &listlen
);
188 if (exc
!= DOM_NO_ERR
) {
189 dom_nodelist_unref(stops
);
193 for (stopnr
= 0; stopnr
< listlen
; ++stopnr
) {
196 svgtiny_colour color
= svgtiny_TRANSPARENT
;
197 exc
= dom_nodelist_item(stops
, stopnr
,
198 (dom_node
**) (void *) &stop
);
199 if (exc
!= DOM_NO_ERR
)
201 exc
= dom_element_get_attribute(stop
,
202 state
->interned_offset
,
204 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
205 char *s
= strndup(dom_string_data(attr
),
206 dom_string_byte_length(attr
));
207 offset
= svgtiny_parse_gradient_offset(s
);
209 dom_string_unref(attr
);
211 exc
= dom_element_get_attribute(stop
,
212 state
->interned_stop_color
,
214 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
215 svgtiny_parse_color(attr
, &color
, state
);
216 dom_string_unref(attr
);
218 exc
= dom_element_get_attribute(stop
,
219 state
->interned_style
,
221 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
222 char *content
= strndup(dom_string_data(attr
),
223 dom_string_byte_length(attr
));
226 if ((s
= strstr(content
, "stop-color:"))) {
230 exc
= dom_string_create_interned(
234 if (exc
!= DOM_NO_ERR
&&
236 svgtiny_parse_color(value
,
239 dom_string_unref(value
);
243 dom_string_unref(attr
);
245 if (offset
!= -1 && color
!= svgtiny_TRANSPARENT
) {
246 #ifdef GRADIENT_DEBUG
247 fprintf(stderr
, "stop %g %x\n", offset
, color
);
249 state
->gradient_stop
[i
].offset
= offset
;
250 state
->gradient_stop
[i
].color
= color
;
253 dom_node_unref(stop
);
254 if (i
== svgtiny_MAX_STOPS
)
258 dom_nodelist_unref(stops
);
262 state
->linear_gradient_stop_count
= i
;
268 float svgtiny_parse_gradient_offset(const char *s
)
270 int num_length
= strspn(s
, "0123456789+-.");
271 const char *unit
= s
+ num_length
;
272 float n
= atof((const char *) s
);
276 else if (unit
[0] == '%')
290 * Add a path with a linear gradient fill to the svgtiny_diagram.
293 svgtiny_code
svgtiny_add_path_linear_gradient(float *p
, unsigned int n
,
294 struct svgtiny_parse_state
*state
)
299 float object_x0
, object_y0
, object_x1
, object_y1
;
300 float gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
,
301 gradient_dx
, gradient_dy
;
303 unsigned int steps
= 10;
304 float x0
= 0, y0
= 0, x0_trans
, y0_trans
, r0
; /* segment start point */
305 float x1
, y1
, x1_trans
, y1_trans
, r1
; /* segment end point */
306 /* segment control points (beziers only) */
307 float c0x
= 0, c0y
= 0, c1x
= 0, c1y
= 0;
308 float gradient_norm_squared
;
309 struct svgtiny_list
*pts
;
311 unsigned int min_pt
= 0;
313 unsigned int stop_count
;
314 unsigned int current_stop
;
316 float current_stop_r
;
317 int red0
, green0
, blue0
, red1
, green1
, blue1
;
318 unsigned int t
, a
, b
;
320 /* determine object bounding box */
321 svgtiny_path_bbox(p
, n
, &object_x0
, &object_y0
, &object_x1
, &object_y1
);
322 #ifdef GRADIENT_DEBUG
323 fprintf(stderr
, "object bbox: (%g %g) (%g %g)\n",
324 object_x0
, object_y0
, object_x1
, object_y1
);
327 if (!state
->gradient_user_space_on_use
) {
328 gradient_x0
= object_x0
+
329 svgtiny_parse_length(state
->gradient_x1
,
330 object_x1
- object_x0
, *state
);
331 gradient_y0
= object_y0
+
332 svgtiny_parse_length(state
->gradient_y1
,
333 object_y1
- object_y0
, *state
);
334 gradient_x1
= object_x0
+
335 svgtiny_parse_length(state
->gradient_x2
,
336 object_x1
- object_x0
, *state
);
337 gradient_y1
= object_y0
+
338 svgtiny_parse_length(state
->gradient_y2
,
339 object_y1
- object_y0
, *state
);
341 gradient_x0
= svgtiny_parse_length(state
->gradient_x1
,
342 state
->viewport_width
, *state
);
343 gradient_y0
= svgtiny_parse_length(state
->gradient_y1
,
344 state
->viewport_height
, *state
);
345 gradient_x1
= svgtiny_parse_length(state
->gradient_x2
,
346 state
->viewport_width
, *state
);
347 gradient_y1
= svgtiny_parse_length(state
->gradient_y2
,
348 state
->viewport_height
, *state
);
350 gradient_dx
= gradient_x1
- gradient_x0
;
351 gradient_dy
= gradient_y1
- gradient_y0
;
352 #ifdef GRADIENT_DEBUG
353 fprintf(stderr
, "gradient vector: (%g %g) => (%g %g)\n",
354 gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
);
357 /* show theoretical gradient strips for debugging */
358 /*unsigned int strips = 10;
359 for (unsigned int z = 0; z != strips; z++) {
360 float f0, fd, strip_x0, strip_y0, strip_dx, strip_dy;
361 f0 = (float) z / (float) strips;
362 fd = (float) 1 / (float) strips;
363 strip_x0 = gradient_x0 + f0 * gradient_dx;
364 strip_y0 = gradient_y0 + f0 * gradient_dy;
365 strip_dx = fd * gradient_dx;
366 strip_dy = fd * gradient_dy;
367 fprintf(stderr, "strip %i vector: (%g %g) + (%g %g)\n",
368 z, strip_x0, strip_y0, strip_dx, strip_dy);
370 float *p = malloc(13 * sizeof p[0]);
372 return svgtiny_OUT_OF_MEMORY;
373 p[0] = svgtiny_PATH_MOVE;
374 p[1] = strip_x0 + (strip_dy * 3);
375 p[2] = strip_y0 - (strip_dx * 3);
376 p[3] = svgtiny_PATH_LINE;
377 p[4] = p[1] + strip_dx;
378 p[5] = p[2] + strip_dy;
379 p[6] = svgtiny_PATH_LINE;
380 p[7] = p[4] - (strip_dy * 6);
381 p[8] = p[5] + (strip_dx * 6);
382 p[9] = svgtiny_PATH_LINE;
383 p[10] = p[7] - strip_dx;
384 p[11] = p[8] - strip_dy;
385 p[12] = svgtiny_PATH_CLOSE;
386 svgtiny_transform_path(p, 13, state);
387 struct svgtiny_shape *shape = svgtiny_add_shape(state);
390 return svgtiny_OUT_OF_MEMORY;
393 shape->path_length = 13;
394 shape->fill = svgtiny_TRANSPARENT;
395 shape->stroke = svgtiny_RGB(0, 0xff, 0);
396 state->diagram->shape_count++;
399 /* invert gradient transform for applying to vertices */
400 svgtiny_invert_matrix(&state
->gradient_transform
.a
, trans
);
401 #ifdef GRADIENT_DEBUG
402 fprintf(stderr
, "inverse transform %g %g %g %g %g %g\n",
403 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 */
476 if(isnan(r0
) || isnan(r1
)) {
479 steps
= ceilf(fabsf(r1
- r0
) / 0.05);
484 #ifdef GRADIENT_DEBUG
485 fprintf(stderr
, "r0 %g, r1 %g, steps %i\n",
489 /* loop through intermediate points */
490 for (z
= 1; z
!= steps
; z
++) {
491 float t
, x
, y
, x_trans
, y_trans
, r
;
492 struct grad_point
*point
;
493 t
= (float) z
/ (float) steps
;
494 if (segment_type
== svgtiny_PATH_BEZIER
) {
495 x
= (1-t
) * (1-t
) * (1-t
) * x0
+
496 3 * t
* (1-t
) * (1-t
) * c0x
+
497 3 * t
* t
* (1-t
) * c1x
+
499 y
= (1-t
) * (1-t
) * (1-t
) * y0
+
500 3 * t
* (1-t
) * (1-t
) * c0y
+
501 3 * t
* t
* (1-t
) * c1y
+
504 x
= (1-t
) * x0
+ t
* x1
;
505 y
= (1-t
) * y0
+ t
* y1
;
507 x_trans
= trans
[0]*x
+ trans
[2]*y
+ trans
[4];
508 y_trans
= trans
[1]*x
+ trans
[3]*y
+ trans
[5];
509 r
= ((x_trans
- gradient_x0
) * gradient_dx
+
510 (y_trans
- gradient_y0
) * gradient_dy
) /
511 gradient_norm_squared
;
512 #ifdef GRADIENT_DEBUG
513 fprintf(stderr
, "(%g %g [%g]) ", x
, y
, r
);
515 point
= svgtiny_list_push(pts
);
517 svgtiny_list_free(pts
);
518 return svgtiny_OUT_OF_MEMORY
;
525 min_pt
= svgtiny_list_size(pts
) - 1;
528 #ifdef GRADIENT_DEBUG
529 fprintf(stderr
, "\n");
532 /* next segment start point is this segment end point */
536 #ifdef GRADIENT_DEBUG
537 fprintf(stderr
, "pts size %i, min_pt %i, min_r %.3f\n",
538 svgtiny_list_size(pts
), min_pt
, min_r
);
541 /* render triangles */
542 stop_count
= state
->linear_gradient_stop_count
;
543 assert(2 <= stop_count
);
546 current_stop_r
= state
->gradient_stop
[0].offset
;
547 red0
= red1
= svgtiny_RED(state
->gradient_stop
[0].color
);
548 green0
= green1
= svgtiny_GREEN(state
->gradient_stop
[0].color
);
549 blue0
= blue1
= svgtiny_BLUE(state
->gradient_stop
[0].color
);
551 a
= (min_pt
+ 1) % svgtiny_list_size(pts
);
552 b
= min_pt
== 0 ? svgtiny_list_size(pts
) - 1 : min_pt
- 1;
554 struct grad_point
*point_t
= svgtiny_list_get(pts
, t
);
555 struct grad_point
*point_a
= svgtiny_list_get(pts
, a
);
556 struct grad_point
*point_b
= svgtiny_list_get(pts
, b
);
557 float mean_r
= (point_t
->r
+ point_a
->r
+ point_b
->r
) / 3;
559 struct svgtiny_shape
*shape
;
560 /*fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
562 t, pts[t].r, a, pts[a].r, b, pts[b].r,
564 while (current_stop
!= stop_count
&& current_stop_r
< mean_r
) {
566 if (current_stop
== stop_count
)
571 red1
= svgtiny_RED(state
->
572 gradient_stop
[current_stop
].color
);
573 green1
= svgtiny_GREEN(state
->
574 gradient_stop
[current_stop
].color
);
575 blue1
= svgtiny_BLUE(state
->
576 gradient_stop
[current_stop
].color
);
577 last_stop_r
= current_stop_r
;
578 current_stop_r
= state
->
579 gradient_stop
[current_stop
].offset
;
581 p
= malloc(10 * sizeof p
[0]);
583 return svgtiny_OUT_OF_MEMORY
;
584 p
[0] = svgtiny_PATH_MOVE
;
587 p
[3] = svgtiny_PATH_LINE
;
590 p
[6] = svgtiny_PATH_LINE
;
593 p
[9] = svgtiny_PATH_CLOSE
;
594 svgtiny_transform_path(p
, 10, state
);
595 shape
= svgtiny_add_shape(state
);
598 return svgtiny_OUT_OF_MEMORY
;
601 shape
->path_length
= 10;
602 /*shape->fill = svgtiny_TRANSPARENT;*/
603 if (current_stop
== 0)
604 shape
->fill
= state
->gradient_stop
[0].color
;
605 else if (current_stop
== stop_count
)
606 shape
->fill
= state
->
607 gradient_stop
[stop_count
- 1].color
;
609 float stop_r
= (mean_r
- last_stop_r
) /
610 (current_stop_r
- last_stop_r
);
611 shape
->fill
= svgtiny_RGB(
612 (int) ((1 - stop_r
) * red0
+ stop_r
* red1
),
613 (int) ((1 - stop_r
) * green0
+ stop_r
* green1
),
614 (int) ((1 - stop_r
) * blue0
+ stop_r
* blue1
));
616 shape
->stroke
= svgtiny_TRANSPARENT
;
617 #ifdef GRADIENT_DEBUG
618 shape
->stroke
= svgtiny_RGB(0, 0, 0xff);
620 state
->diagram
->shape_count
++;
621 if (point_a
->r
< point_b
->r
) {
623 a
= (a
+ 1) % svgtiny_list_size(pts
);
626 b
= b
== 0 ? svgtiny_list_size(pts
) - 1 : b
- 1;
630 /* render gradient vector for debugging */
631 #ifdef GRADIENT_DEBUG
633 float *p
= malloc(7 * sizeof p
[0]);
635 return svgtiny_OUT_OF_MEMORY
;
636 p
[0] = svgtiny_PATH_MOVE
;
639 p
[3] = svgtiny_PATH_LINE
;
642 p
[6] = svgtiny_PATH_CLOSE
;
643 svgtiny_transform_path(p
, 7, state
);
644 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
647 return svgtiny_OUT_OF_MEMORY
;
650 shape
->path_length
= 7;
651 shape
->fill
= svgtiny_TRANSPARENT
;
652 shape
->stroke
= svgtiny_RGB(0xff, 0, 0);
653 state
->diagram
->shape_count
++;
657 /* render triangle vertices with r values for debugging */
658 #ifdef GRADIENT_DEBUG
659 for (unsigned int i
= 0; i
!= pts
->size
; i
++) {
660 struct grad_point
*point
= svgtiny_list_get(pts
, i
);
661 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
663 return svgtiny_OUT_OF_MEMORY
;
664 char *text
= malloc(20);
666 return svgtiny_OUT_OF_MEMORY
;
667 sprintf(text
, "%i=%.3f", i
, point
->r
);
669 shape
->text_x
= state
->ctm
.a
* point
->x
+
670 state
->ctm
.c
* point
->y
+ state
->ctm
.e
;
671 shape
->text_y
= state
->ctm
.b
* point
->x
+
672 state
->ctm
.d
* point
->y
+ state
->ctm
.f
;
673 shape
->fill
= svgtiny_RGB(0, 0, 0);
674 shape
->stroke
= svgtiny_TRANSPARENT
;
675 state
->diagram
->shape_count
++;
679 /* plot actual path outline */
680 if (state
->stroke
!= svgtiny_TRANSPARENT
) {
681 struct svgtiny_shape
*shape
;
682 svgtiny_transform_path(p
, n
, state
);
684 shape
= svgtiny_add_shape(state
);
687 return svgtiny_OUT_OF_MEMORY
;
690 shape
->path_length
= n
;
691 shape
->fill
= svgtiny_TRANSPARENT
;
692 state
->diagram
->shape_count
++;
697 svgtiny_list_free(pts
);
704 * Get the bounding box of path.
707 void svgtiny_path_bbox(float *p
, unsigned int n
,
708 float *x0
, float *y0
, float *x1
, float *y1
)
715 for (j
= 0; j
!= n
; ) {
716 unsigned int points
= 0;
718 switch ((int) p
[j
]) {
719 case svgtiny_PATH_MOVE
:
720 case svgtiny_PATH_LINE
:
723 case svgtiny_PATH_CLOSE
:
726 case svgtiny_PATH_BEZIER
:
733 for (k
= 0; k
!= points
; k
++) {
734 float x
= p
[j
], y
= p
[j
+ 1];
750 * Invert a transformation matrix.
752 void svgtiny_invert_matrix(float *m
, float *inv
)
754 float determinant
= m
[0]*m
[3] - m
[1]*m
[2];
755 inv
[0] = m
[3] / determinant
;
756 inv
[1] = -m
[1] / determinant
;
757 inv
[2] = -m
[2] / determinant
;
758 inv
[3] = m
[0] / determinant
;
759 inv
[4] = (m
[2]*m
[5] - m
[3]*m
[4]) / determinant
;
760 inv
[5] = (m
[1]*m
[4] - m
[0]*m
[5]) / determinant
;