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
);
93 fprintf(stderr
, "linear_gradient_stop_count %i\n",
94 state
->linear_gradient_stop_count
);
100 * Parse a <linearGradient> element node.
102 * http://www.w3.org/TR/SVG11/pservers#LinearGradients
105 svgtiny_code
svgtiny_parse_linear_gradient(dom_element
*linear
,
106 struct svgtiny_parse_state
*state
)
113 exc
= dom_element_get_attribute(linear
, state
->interned_href
, &attr
);
114 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
115 if (dom_string_data(attr
)[0] == (uint8_t) '#') {
116 char *s
= strndup(dom_string_data(attr
) + 1,
117 dom_string_byte_length(attr
) - 1);
118 svgtiny_find_gradient(s
, state
);
121 dom_string_unref(attr
);
124 exc
= dom_element_get_attribute(linear
, state
->interned_x1
, &attr
);
125 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
126 dom_string_unref(state
->gradient_x1
);
127 state
->gradient_x1
= attr
;
131 exc
= dom_element_get_attribute(linear
, state
->interned_y1
, &attr
);
132 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
133 dom_string_unref(state
->gradient_y1
);
134 state
->gradient_y1
= attr
;
138 exc
= dom_element_get_attribute(linear
, state
->interned_x2
, &attr
);
139 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
140 dom_string_unref(state
->gradient_x2
);
141 state
->gradient_x2
= attr
;
145 exc
= dom_element_get_attribute(linear
, state
->interned_y2
, &attr
);
146 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
147 dom_string_unref(state
->gradient_y2
);
148 state
->gradient_y2
= attr
;
152 exc
= dom_element_get_attribute(linear
, state
->interned_gradientUnits
,
154 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
155 state
->gradient_user_space_on_use
=
156 dom_string_isequal(attr
,
157 state
->interned_userSpaceOnUse
);
158 dom_string_unref(attr
);
161 exc
= dom_element_get_attribute(linear
,
162 state
->interned_gradientTransform
,
164 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
165 float a
= 1, b
= 0, c
= 0, d
= 1, e
= 0, f
= 0;
166 char *s
= strndup(dom_string_data(attr
),
167 dom_string_byte_length(attr
));
169 dom_string_unref(attr
);
170 return svgtiny_OUT_OF_MEMORY
;
172 svgtiny_parse_transform(s
, &a
, &b
, &c
, &d
, &e
, &f
);
174 #ifdef GRADIENT_DEBUG
175 fprintf(stderr
, "transform %g %g %g %g %g %g\n",
178 state
->gradient_transform
.a
= a
;
179 state
->gradient_transform
.b
= b
;
180 state
->gradient_transform
.c
= c
;
181 state
->gradient_transform
.d
= d
;
182 state
->gradient_transform
.e
= e
;
183 state
->gradient_transform
.f
= f
;
184 dom_string_unref(attr
);
187 exc
= dom_element_get_elements_by_tag_name(linear
,
188 state
->interned_stop
,
190 if (exc
== DOM_NO_ERR
&& stops
!= NULL
) {
191 uint32_t listlen
, stopnr
;
192 exc
= dom_nodelist_get_length(stops
, &listlen
);
193 if (exc
!= DOM_NO_ERR
) {
194 dom_nodelist_unref(stops
);
198 for (stopnr
= 0; stopnr
< listlen
; ++stopnr
) {
201 svgtiny_colour color
= svgtiny_TRANSPARENT
;
202 exc
= dom_nodelist_item(stops
, stopnr
,
203 (dom_node
**) (void *) &stop
);
204 if (exc
!= DOM_NO_ERR
)
206 exc
= dom_element_get_attribute(stop
,
207 state
->interned_offset
,
209 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
210 char *s
= strndup(dom_string_data(attr
),
211 dom_string_byte_length(attr
));
212 offset
= svgtiny_parse_gradient_offset(s
);
214 dom_string_unref(attr
);
216 exc
= dom_element_get_attribute(stop
,
217 state
->interned_stop_color
,
219 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
220 svgtiny_parse_color(attr
, &color
, state
);
221 dom_string_unref(attr
);
223 exc
= dom_element_get_attribute(stop
,
224 state
->interned_style
,
226 if (exc
== DOM_NO_ERR
&& attr
!= NULL
) {
227 char *content
= strndup(dom_string_data(attr
),
228 dom_string_byte_length(attr
));
231 if ((s
= strstr(content
, "stop-color:"))) {
235 exc
= dom_string_create_interned(
239 if (exc
!= DOM_NO_ERR
&&
241 svgtiny_parse_color(value
,
244 dom_string_unref(value
);
248 dom_string_unref(attr
);
250 if (offset
!= -1 && color
!= svgtiny_TRANSPARENT
) {
251 #ifdef GRADIENT_DEBUG
252 fprintf(stderr
, "stop %g %x\n", offset
, color
);
254 state
->gradient_stop
[i
].offset
= offset
;
255 state
->gradient_stop
[i
].color
= color
;
258 dom_node_unref(stop
);
259 if (i
== svgtiny_MAX_STOPS
)
263 dom_nodelist_unref(stops
);
267 state
->linear_gradient_stop_count
= i
;
273 float svgtiny_parse_gradient_offset(const char *s
)
275 int num_length
= strspn(s
, "0123456789+-.");
276 const char *unit
= s
+ num_length
;
277 float n
= atof((const char *) s
);
281 else if (unit
[0] == '%')
295 * Add a path with a linear gradient fill to the svgtiny_diagram.
298 svgtiny_code
svgtiny_add_path_linear_gradient(float *p
, unsigned int n
,
299 struct svgtiny_parse_state
*state
)
304 float object_x0
, object_y0
, object_x1
, object_y1
;
305 float gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
,
306 gradient_dx
, gradient_dy
;
308 unsigned int steps
= 10;
309 float x0
= 0, y0
= 0, x0_trans
, y0_trans
, r0
; /* segment start point */
310 float x1
, y1
, x1_trans
, y1_trans
, r1
; /* segment end point */
311 /* segment control points (beziers only) */
312 float c0x
= 0, c0y
= 0, c1x
= 0, c1y
= 0;
313 float gradient_norm_squared
;
314 struct svgtiny_list
*pts
;
316 unsigned int min_pt
= 0;
318 unsigned int stop_count
;
319 unsigned int current_stop
;
321 float current_stop_r
;
322 int red0
, green0
, blue0
, red1
, green1
, blue1
;
323 unsigned int t
, a
, b
;
325 /* determine object bounding box */
326 svgtiny_path_bbox(p
, n
, &object_x0
, &object_y0
, &object_x1
, &object_y1
);
327 #ifdef GRADIENT_DEBUG
328 fprintf(stderr
, "object bbox: (%g %g) (%g %g)\n",
329 object_x0
, object_y0
, object_x1
, object_y1
);
332 if (!state
->gradient_user_space_on_use
) {
333 gradient_x0
= object_x0
+
334 svgtiny_parse_length(state
->gradient_x1
,
335 object_x1
- object_x0
, *state
);
336 gradient_y0
= object_y0
+
337 svgtiny_parse_length(state
->gradient_y1
,
338 object_y1
- object_y0
, *state
);
339 gradient_x1
= object_x0
+
340 svgtiny_parse_length(state
->gradient_x2
,
341 object_x1
- object_x0
, *state
);
342 gradient_y1
= object_y0
+
343 svgtiny_parse_length(state
->gradient_y2
,
344 object_y1
- object_y0
, *state
);
346 gradient_x0
= svgtiny_parse_length(state
->gradient_x1
,
347 state
->viewport_width
, *state
);
348 gradient_y0
= svgtiny_parse_length(state
->gradient_y1
,
349 state
->viewport_height
, *state
);
350 gradient_x1
= svgtiny_parse_length(state
->gradient_x2
,
351 state
->viewport_width
, *state
);
352 gradient_y1
= svgtiny_parse_length(state
->gradient_y2
,
353 state
->viewport_height
, *state
);
355 gradient_dx
= gradient_x1
- gradient_x0
;
356 gradient_dy
= gradient_y1
- gradient_y0
;
357 #ifdef GRADIENT_DEBUG
358 fprintf(stderr
, "gradient vector: (%g %g) => (%g %g)\n",
359 gradient_x0
, gradient_y0
, gradient_x1
, gradient_y1
);
362 /* show theoretical gradient strips for debugging */
363 /*unsigned int strips = 10;
364 for (unsigned int z = 0; z != strips; z++) {
365 float f0, fd, strip_x0, strip_y0, strip_dx, strip_dy;
366 f0 = (float) z / (float) strips;
367 fd = (float) 1 / (float) strips;
368 strip_x0 = gradient_x0 + f0 * gradient_dx;
369 strip_y0 = gradient_y0 + f0 * gradient_dy;
370 strip_dx = fd * gradient_dx;
371 strip_dy = fd * gradient_dy;
372 fprintf(stderr, "strip %i vector: (%g %g) + (%g %g)\n",
373 z, strip_x0, strip_y0, strip_dx, strip_dy);
375 float *p = malloc(13 * sizeof p[0]);
377 return svgtiny_OUT_OF_MEMORY;
378 p[0] = svgtiny_PATH_MOVE;
379 p[1] = strip_x0 + (strip_dy * 3);
380 p[2] = strip_y0 - (strip_dx * 3);
381 p[3] = svgtiny_PATH_LINE;
382 p[4] = p[1] + strip_dx;
383 p[5] = p[2] + strip_dy;
384 p[6] = svgtiny_PATH_LINE;
385 p[7] = p[4] - (strip_dy * 6);
386 p[8] = p[5] + (strip_dx * 6);
387 p[9] = svgtiny_PATH_LINE;
388 p[10] = p[7] - strip_dx;
389 p[11] = p[8] - strip_dy;
390 p[12] = svgtiny_PATH_CLOSE;
391 svgtiny_transform_path(p, 13, state);
392 struct svgtiny_shape *shape = svgtiny_add_shape(state);
395 return svgtiny_OUT_OF_MEMORY;
398 shape->path_length = 13;
399 shape->fill = svgtiny_TRANSPARENT;
400 shape->stroke = svgtiny_RGB(0, 0xff, 0);
401 state->diagram->shape_count++;
404 /* invert gradient transform for applying to vertices */
405 svgtiny_invert_matrix(&state
->gradient_transform
.a
, trans
);
406 #ifdef GRADIENT_DEBUG
407 fprintf(stderr
, "inverse transform %g %g %g %g %g %g\n",
408 trans
[0], trans
[1], trans
[2], trans
[3],
412 /* compute points on the path for triangle vertices */
413 /* r, r0, r1 are distance along gradient vector */
414 gradient_norm_squared
= gradient_dx
* gradient_dx
+
415 gradient_dy
* gradient_dy
;
416 pts
= svgtiny_list_create(
417 sizeof (struct grad_point
));
419 return svgtiny_OUT_OF_MEMORY
;
420 for (j
= 0; j
!= n
; ) {
421 int segment_type
= (int) p
[j
];
422 struct grad_point
*point
;
425 if (segment_type
== svgtiny_PATH_MOVE
) {
432 assert(segment_type
== svgtiny_PATH_CLOSE
||
433 segment_type
== svgtiny_PATH_LINE
||
434 segment_type
== svgtiny_PATH_BEZIER
);
436 /* start point (x0, y0) */
437 x0_trans
= trans
[0]*x0
+ trans
[2]*y0
+ trans
[4];
438 y0_trans
= trans
[1]*x0
+ trans
[3]*y0
+ trans
[5];
439 r0
= ((x0_trans
- gradient_x0
) * gradient_dx
+
440 (y0_trans
- gradient_y0
) * gradient_dy
) /
441 gradient_norm_squared
;
442 point
= svgtiny_list_push(pts
);
444 svgtiny_list_free(pts
);
445 return svgtiny_OUT_OF_MEMORY
;
452 min_pt
= svgtiny_list_size(pts
) - 1;
455 /* end point (x1, y1) */
456 if (segment_type
== svgtiny_PATH_LINE
) {
460 } else if (segment_type
== svgtiny_PATH_CLOSE
) {
464 } else /* svgtiny_PATH_BEZIER */ {
473 x1_trans
= trans
[0]*x1
+ trans
[2]*y1
+ trans
[4];
474 y1_trans
= trans
[1]*x1
+ trans
[3]*y1
+ trans
[5];
475 r1
= ((x1_trans
- gradient_x0
) * gradient_dx
+
476 (y1_trans
- gradient_y0
) * gradient_dy
) /
477 gradient_norm_squared
;
479 /* determine steps from change in r */
481 if(isnan(r0
) || isnan(r1
)) {
484 steps
= ceilf(fabsf(r1
- r0
) / 0.05);
489 #ifdef GRADIENT_DEBUG
490 fprintf(stderr
, "r0 %g, r1 %g, steps %i\n",
494 /* loop through intermediate points */
495 for (z
= 1; z
!= steps
; z
++) {
496 float t
, x
, y
, x_trans
, y_trans
, r
;
497 struct grad_point
*point
;
498 t
= (float) z
/ (float) steps
;
499 if (segment_type
== svgtiny_PATH_BEZIER
) {
500 x
= (1-t
) * (1-t
) * (1-t
) * x0
+
501 3 * t
* (1-t
) * (1-t
) * c0x
+
502 3 * t
* t
* (1-t
) * c1x
+
504 y
= (1-t
) * (1-t
) * (1-t
) * y0
+
505 3 * t
* (1-t
) * (1-t
) * c0y
+
506 3 * t
* t
* (1-t
) * c1y
+
509 x
= (1-t
) * x0
+ t
* x1
;
510 y
= (1-t
) * y0
+ t
* y1
;
512 x_trans
= trans
[0]*x
+ trans
[2]*y
+ trans
[4];
513 y_trans
= trans
[1]*x
+ trans
[3]*y
+ trans
[5];
514 r
= ((x_trans
- gradient_x0
) * gradient_dx
+
515 (y_trans
- gradient_y0
) * gradient_dy
) /
516 gradient_norm_squared
;
517 #ifdef GRADIENT_DEBUG
518 fprintf(stderr
, "(%g %g [%g]) ", x
, y
, r
);
520 point
= svgtiny_list_push(pts
);
522 svgtiny_list_free(pts
);
523 return svgtiny_OUT_OF_MEMORY
;
530 min_pt
= svgtiny_list_size(pts
) - 1;
533 #ifdef GRADIENT_DEBUG
534 fprintf(stderr
, "\n");
537 /* next segment start point is this segment end point */
541 #ifdef GRADIENT_DEBUG
542 fprintf(stderr
, "pts size %i, min_pt %i, min_r %.3f\n",
543 svgtiny_list_size(pts
), min_pt
, min_r
);
546 /* render triangles */
547 stop_count
= state
->linear_gradient_stop_count
;
548 assert(2 <= stop_count
);
551 current_stop_r
= state
->gradient_stop
[0].offset
;
552 red0
= red1
= svgtiny_RED(state
->gradient_stop
[0].color
);
553 green0
= green1
= svgtiny_GREEN(state
->gradient_stop
[0].color
);
554 blue0
= blue1
= svgtiny_BLUE(state
->gradient_stop
[0].color
);
556 a
= (min_pt
+ 1) % svgtiny_list_size(pts
);
557 b
= min_pt
== 0 ? svgtiny_list_size(pts
) - 1 : min_pt
- 1;
559 struct grad_point
*point_t
= svgtiny_list_get(pts
, t
);
560 struct grad_point
*point_a
= svgtiny_list_get(pts
, a
);
561 struct grad_point
*point_b
= svgtiny_list_get(pts
, b
);
562 float mean_r
= (point_t
->r
+ point_a
->r
+ point_b
->r
) / 3;
564 struct svgtiny_shape
*shape
;
565 /*fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
567 t, pts[t].r, a, pts[a].r, b, pts[b].r,
569 while (current_stop
!= stop_count
&& current_stop_r
< mean_r
) {
571 if (current_stop
== stop_count
)
576 red1
= svgtiny_RED(state
->
577 gradient_stop
[current_stop
].color
);
578 green1
= svgtiny_GREEN(state
->
579 gradient_stop
[current_stop
].color
);
580 blue1
= svgtiny_BLUE(state
->
581 gradient_stop
[current_stop
].color
);
582 last_stop_r
= current_stop_r
;
583 current_stop_r
= state
->
584 gradient_stop
[current_stop
].offset
;
586 p
= malloc(10 * sizeof p
[0]);
588 return svgtiny_OUT_OF_MEMORY
;
589 p
[0] = svgtiny_PATH_MOVE
;
592 p
[3] = svgtiny_PATH_LINE
;
595 p
[6] = svgtiny_PATH_LINE
;
598 p
[9] = svgtiny_PATH_CLOSE
;
599 svgtiny_transform_path(p
, 10, state
);
600 shape
= svgtiny_add_shape(state
);
603 return svgtiny_OUT_OF_MEMORY
;
606 shape
->path_length
= 10;
607 /*shape->fill = svgtiny_TRANSPARENT;*/
608 if (current_stop
== 0)
609 shape
->fill
= state
->gradient_stop
[0].color
;
610 else if (current_stop
== stop_count
)
611 shape
->fill
= state
->
612 gradient_stop
[stop_count
- 1].color
;
614 float stop_r
= (mean_r
- last_stop_r
) /
615 (current_stop_r
- last_stop_r
);
616 shape
->fill
= svgtiny_RGB(
617 (int) ((1 - stop_r
) * red0
+ stop_r
* red1
),
618 (int) ((1 - stop_r
) * green0
+ stop_r
* green1
),
619 (int) ((1 - stop_r
) * blue0
+ stop_r
* blue1
));
621 shape
->stroke
= svgtiny_TRANSPARENT
;
622 #ifdef GRADIENT_DEBUG
623 shape
->stroke
= svgtiny_RGB(0, 0, 0xff);
625 state
->diagram
->shape_count
++;
626 if (point_a
->r
< point_b
->r
) {
628 a
= (a
+ 1) % svgtiny_list_size(pts
);
631 b
= b
== 0 ? svgtiny_list_size(pts
) - 1 : b
- 1;
635 /* render gradient vector for debugging */
636 #ifdef GRADIENT_DEBUG
638 float *p
= malloc(7 * sizeof p
[0]);
640 return svgtiny_OUT_OF_MEMORY
;
641 p
[0] = svgtiny_PATH_MOVE
;
644 p
[3] = svgtiny_PATH_LINE
;
647 p
[6] = svgtiny_PATH_CLOSE
;
648 svgtiny_transform_path(p
, 7, state
);
649 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
652 return svgtiny_OUT_OF_MEMORY
;
655 shape
->path_length
= 7;
656 shape
->fill
= svgtiny_TRANSPARENT
;
657 shape
->stroke
= svgtiny_RGB(0xff, 0, 0);
658 state
->diagram
->shape_count
++;
662 /* render triangle vertices with r values for debugging */
663 #ifdef GRADIENT_DEBUG
664 for (unsigned int i
= 0; i
!= pts
->size
; i
++) {
665 struct grad_point
*point
= svgtiny_list_get(pts
, i
);
666 struct svgtiny_shape
*shape
= svgtiny_add_shape(state
);
668 return svgtiny_OUT_OF_MEMORY
;
669 char *text
= malloc(20);
671 return svgtiny_OUT_OF_MEMORY
;
672 sprintf(text
, "%i=%.3f", i
, point
->r
);
674 shape
->text_x
= state
->ctm
.a
* point
->x
+
675 state
->ctm
.c
* point
->y
+ state
->ctm
.e
;
676 shape
->text_y
= state
->ctm
.b
* point
->x
+
677 state
->ctm
.d
* point
->y
+ state
->ctm
.f
;
678 shape
->fill
= svgtiny_RGB(0, 0, 0);
679 shape
->stroke
= svgtiny_TRANSPARENT
;
680 state
->diagram
->shape_count
++;
684 /* plot actual path outline */
685 if (state
->stroke
!= svgtiny_TRANSPARENT
) {
686 struct svgtiny_shape
*shape
;
687 svgtiny_transform_path(p
, n
, state
);
689 shape
= svgtiny_add_shape(state
);
692 return svgtiny_OUT_OF_MEMORY
;
695 shape
->path_length
= n
;
696 shape
->fill
= svgtiny_TRANSPARENT
;
697 state
->diagram
->shape_count
++;
702 svgtiny_list_free(pts
);
709 * Get the bounding box of path.
712 void svgtiny_path_bbox(float *p
, unsigned int n
,
713 float *x0
, float *y0
, float *x1
, float *y1
)
720 for (j
= 0; j
!= n
; ) {
721 unsigned int points
= 0;
723 switch ((int) p
[j
]) {
724 case svgtiny_PATH_MOVE
:
725 case svgtiny_PATH_LINE
:
728 case svgtiny_PATH_CLOSE
:
731 case svgtiny_PATH_BEZIER
:
738 for (k
= 0; k
!= points
; k
++) {
739 float x
= p
[j
], y
= p
[j
+ 1];
755 * Invert a transformation matrix.
757 void svgtiny_invert_matrix(float *m
, float *inv
)
759 float determinant
= m
[0]*m
[3] - m
[1]*m
[2];
760 inv
[0] = m
[3] / determinant
;
761 inv
[1] = -m
[1] / determinant
;
762 inv
[2] = -m
[2] / determinant
;
763 inv
[3] = m
[0] / determinant
;
764 inv
[4] = (m
[2]*m
[5] - m
[3]*m
[4]) / determinant
;
765 inv
[5] = (m
[1]*m
[4] - m
[0]*m
[5]) / determinant
;