Use an iterator in pixman_image_get_solid()
[profile/ivi/pixman.git] / pixman / pixman-image.c
1 /*
2  * Copyright © 2000 SuSE, Inc.
3  * Copyright © 2007 Red Hat, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and its
6  * documentation for any purpose is hereby granted without fee, provided that
7  * the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of SuSE not be used in advertising or
10  * publicity pertaining to distribution of the software without specific,
11  * written prior permission.  SuSE makes no representations about the
12  * suitability of this software for any purpose.  It is provided "as is"
13  * without express or implied warranty.
14  *
15  * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
17  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <assert.h>
31
32 #include "pixman-private.h"
33 #include "pixman-combine32.h"
34
35 pixman_bool_t
36 _pixman_init_gradient (gradient_t *                  gradient,
37                        const pixman_gradient_stop_t *stops,
38                        int                           n_stops)
39 {
40     return_val_if_fail (n_stops > 0, FALSE);
41
42     gradient->stops = pixman_malloc_ab (n_stops, sizeof (pixman_gradient_stop_t));
43     if (!gradient->stops)
44         return FALSE;
45
46     memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t));
47
48     gradient->n_stops = n_stops;
49
50     return TRUE;
51 }
52
53 /*
54  * By default, just evaluate the image at 32bpp and expand.  Individual image
55  * types can plug in a better scanline getter if they want to. For example
56  * we  could produce smoother gradients by evaluating them at higher color
57  * depth, but that's a project for the future.
58  */
59 void
60 _pixman_image_get_scanline_generic_64 (pixman_image_t * image,
61                                        int              x,
62                                        int              y,
63                                        int              width,
64                                        uint32_t *       buffer,
65                                        const uint32_t * mask)
66 {
67     uint32_t *mask8 = NULL;
68
69     /* Contract the mask image, if one exists, so that the 32-bit fetch
70      * function can use it.
71      */
72     if (mask)
73     {
74         mask8 = pixman_malloc_ab (width, sizeof(uint32_t));
75         if (!mask8)
76             return;
77
78         pixman_contract (mask8, (uint64_t *)mask, width);
79     }
80
81     /* Fetch the source image into the first half of buffer. */
82     _pixman_image_get_scanline_32 (image, x, y, width, (uint32_t*)buffer, mask8);
83
84     /* Expand from 32bpp to 64bpp in place. */
85     pixman_expand ((uint64_t *)buffer, buffer, PIXMAN_a8r8g8b8, width);
86
87     free (mask8);
88 }
89
90 pixman_image_t *
91 _pixman_image_allocate (void)
92 {
93     pixman_image_t *image = malloc (sizeof (pixman_image_t));
94
95     if (image)
96     {
97         image_common_t *common = &image->common;
98
99         pixman_region32_init (&common->clip_region);
100
101         common->alpha_count = 0;
102         common->have_clip_region = FALSE;
103         common->clip_sources = FALSE;
104         common->transform = NULL;
105         common->repeat = PIXMAN_REPEAT_NONE;
106         common->filter = PIXMAN_FILTER_NEAREST;
107         common->filter_params = NULL;
108         common->n_filter_params = 0;
109         common->alpha_map = NULL;
110         common->component_alpha = FALSE;
111         common->ref_count = 1;
112         common->classify = NULL;
113         common->client_clip = FALSE;
114         common->destroy_func = NULL;
115         common->destroy_data = NULL;
116         common->dirty = TRUE;
117     }
118
119     return image;
120 }
121
122 source_image_class_t
123 _pixman_image_classify (pixman_image_t *image,
124                         int             x,
125                         int             y,
126                         int             width,
127                         int             height)
128 {
129     if (image->common.classify)
130         return image->common.classify (image, x, y, width, height);
131     else
132         return SOURCE_IMAGE_CLASS_UNKNOWN;
133 }
134
135 void
136 _pixman_image_get_scanline_32 (pixman_image_t *image,
137                                int             x,
138                                int             y,
139                                int             width,
140                                uint32_t *      buffer,
141                                const uint32_t *mask)
142 {
143     image->common.get_scanline_32 (image, x, y, width, buffer, mask);
144 }
145
146 /* Even thought the type of buffer is uint32_t *, the function actually expects
147  * a uint64_t *buffer.
148  */
149 void
150 _pixman_image_get_scanline_64 (pixman_image_t *image,
151                                int             x,
152                                int             y,
153                                int             width,
154                                uint32_t *      buffer,
155                                const uint32_t *unused)
156 {
157     image->common.get_scanline_64 (image, x, y, width, buffer, unused);
158 }
159
160 static void
161 image_property_changed (pixman_image_t *image)
162 {
163     image->common.dirty = TRUE;
164 }
165
166 /* Ref Counting */
167 PIXMAN_EXPORT pixman_image_t *
168 pixman_image_ref (pixman_image_t *image)
169 {
170     image->common.ref_count++;
171
172     return image;
173 }
174
175 /* returns TRUE when the image is freed */
176 PIXMAN_EXPORT pixman_bool_t
177 pixman_image_unref (pixman_image_t *image)
178 {
179     image_common_t *common = (image_common_t *)image;
180
181     common->ref_count--;
182
183     if (common->ref_count == 0)
184     {
185         if (image->common.destroy_func)
186             image->common.destroy_func (image, image->common.destroy_data);
187
188         pixman_region32_fini (&common->clip_region);
189
190         if (common->transform)
191             free (common->transform);
192
193         if (common->filter_params)
194             free (common->filter_params);
195
196         if (common->alpha_map)
197             pixman_image_unref ((pixman_image_t *)common->alpha_map);
198
199         if (image->type == LINEAR ||
200             image->type == RADIAL ||
201             image->type == CONICAL)
202         {
203             if (image->gradient.stops)
204                 free (image->gradient.stops);
205         }
206
207         if (image->type == BITS && image->bits.free_me)
208             free (image->bits.free_me);
209
210         free (image);
211
212         return TRUE;
213     }
214
215     return FALSE;
216 }
217
218 PIXMAN_EXPORT void
219 pixman_image_set_destroy_function (pixman_image_t *            image,
220                                    pixman_image_destroy_func_t func,
221                                    void *                      data)
222 {
223     image->common.destroy_func = func;
224     image->common.destroy_data = data;
225 }
226
227 PIXMAN_EXPORT void *
228 pixman_image_get_destroy_data (pixman_image_t *image)
229 {
230   return image->common.destroy_data;
231 }
232
233 void
234 _pixman_image_reset_clip_region (pixman_image_t *image)
235 {
236     image->common.have_clip_region = FALSE;
237 }
238
239 /* Executive Summary: This function is a no-op that only exists
240  * for historical reasons.
241  *
242  * There used to be a bug in the X server where it would rely on
243  * out-of-bounds accesses when it was asked to composite with a
244  * window as the source. It would create a pixman image pointing
245  * to some bogus position in memory, but then set a clip region
246  * to the position where the actual bits were.
247  *
248  * Due to a bug in old versions of pixman, where it would not clip
249  * against the image bounds when a clip region was set, this would
250  * actually work. So when the pixman bug was fixed, a workaround was
251  * added to allow certain out-of-bound accesses. This function disabled
252  * those workarounds.
253  *
254  * Since 0.21.2, pixman doesn't do these workarounds anymore, so now
255  * this function is a no-op.
256  */
257 PIXMAN_EXPORT void
258 pixman_disable_out_of_bounds_workaround (void)
259 {
260 }
261
262 static void
263 compute_image_info (pixman_image_t *image)
264 {
265     pixman_format_code_t code;
266     uint32_t flags = 0;
267
268     /* Transform */
269     if (!image->common.transform)
270     {
271         flags |= (FAST_PATH_ID_TRANSFORM        |
272                   FAST_PATH_X_UNIT_POSITIVE     |
273                   FAST_PATH_Y_UNIT_ZERO         |
274                   FAST_PATH_AFFINE_TRANSFORM);
275     }
276     else
277     {
278         flags |= FAST_PATH_HAS_TRANSFORM;
279
280         if (image->common.transform->matrix[2][0] == 0                  &&
281             image->common.transform->matrix[2][1] == 0                  &&
282             image->common.transform->matrix[2][2] == pixman_fixed_1)
283         {
284             flags |= FAST_PATH_AFFINE_TRANSFORM;
285
286             if (image->common.transform->matrix[0][1] == 0 &&
287                 image->common.transform->matrix[1][0] == 0)
288             {
289                 flags |= FAST_PATH_SCALE_TRANSFORM;
290             }
291         }
292
293         if (image->common.transform->matrix[0][0] > 0)
294             flags |= FAST_PATH_X_UNIT_POSITIVE;
295
296         if (image->common.transform->matrix[1][0] == 0)
297             flags |= FAST_PATH_Y_UNIT_ZERO;
298     }
299
300     /* Filter */
301     switch (image->common.filter)
302     {
303     case PIXMAN_FILTER_NEAREST:
304     case PIXMAN_FILTER_FAST:
305         flags |= (FAST_PATH_NEAREST_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
306         break;
307
308     case PIXMAN_FILTER_BILINEAR:
309     case PIXMAN_FILTER_GOOD:
310     case PIXMAN_FILTER_BEST:
311         flags |= (FAST_PATH_BILINEAR_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
312         break;
313
314     case PIXMAN_FILTER_CONVOLUTION:
315         break;
316
317     default:
318         flags |= FAST_PATH_NO_CONVOLUTION_FILTER;
319         break;
320     }
321
322     /* Repeat mode */
323     switch (image->common.repeat)
324     {
325     case PIXMAN_REPEAT_NONE:
326         flags |=
327             FAST_PATH_NO_REFLECT_REPEAT         |
328             FAST_PATH_NO_PAD_REPEAT             |
329             FAST_PATH_NO_NORMAL_REPEAT;
330         break;
331
332     case PIXMAN_REPEAT_REFLECT:
333         flags |=
334             FAST_PATH_NO_PAD_REPEAT             |
335             FAST_PATH_NO_NONE_REPEAT            |
336             FAST_PATH_NO_NORMAL_REPEAT;
337         break;
338
339     case PIXMAN_REPEAT_PAD:
340         flags |=
341             FAST_PATH_NO_REFLECT_REPEAT         |
342             FAST_PATH_NO_NONE_REPEAT            |
343             FAST_PATH_NO_NORMAL_REPEAT;
344         break;
345
346     default:
347         flags |=
348             FAST_PATH_NO_REFLECT_REPEAT         |
349             FAST_PATH_NO_PAD_REPEAT             |
350             FAST_PATH_NO_NONE_REPEAT;
351         break;
352     }
353
354     /* Component alpha */
355     if (image->common.component_alpha)
356         flags |= FAST_PATH_COMPONENT_ALPHA;
357     else
358         flags |= FAST_PATH_UNIFIED_ALPHA;
359
360     flags |= (FAST_PATH_NO_ACCESSORS | FAST_PATH_NARROW_FORMAT);
361
362     /* Type specific checks */
363     switch (image->type)
364     {
365     case SOLID:
366         code = PIXMAN_solid;
367
368         if (image->solid.color.alpha == 0xffff)
369             flags |= FAST_PATH_IS_OPAQUE;
370         break;
371
372     case BITS:
373         if (image->bits.width == 1      &&
374             image->bits.height == 1     &&
375             image->common.repeat != PIXMAN_REPEAT_NONE)
376         {
377             code = PIXMAN_solid;
378         }
379         else
380         {
381             code = image->bits.format;
382         }
383
384         if (!PIXMAN_FORMAT_A (image->bits.format)                               &&
385             PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_GRAY         &&
386             PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_COLOR)
387         {
388             flags |= FAST_PATH_SAMPLES_OPAQUE;
389
390             if (image->common.repeat != PIXMAN_REPEAT_NONE)
391                 flags |= FAST_PATH_IS_OPAQUE;
392         }
393
394         if (image->bits.read_func || image->bits.write_func)
395             flags &= ~FAST_PATH_NO_ACCESSORS;
396
397         if (PIXMAN_FORMAT_IS_WIDE (image->bits.format))
398             flags &= ~FAST_PATH_NARROW_FORMAT;
399         break;
400
401     case RADIAL:
402         code = PIXMAN_unknown;
403
404         /*
405          * As explained in pixman-radial-gradient.c, every point of
406          * the plane has a valid associated radius (and thus will be
407          * colored) if and only if a is negative (i.e. one of the two
408          * circles contains the other one).
409          */
410
411         if (image->radial.a >= 0)
412             break;
413
414         /* Fall through */
415
416     case CONICAL:
417     case LINEAR:
418         code = PIXMAN_unknown;
419
420         if (image->common.repeat != PIXMAN_REPEAT_NONE)
421         {
422             int i;
423
424             flags |= FAST_PATH_IS_OPAQUE;
425             for (i = 0; i < image->gradient.n_stops; ++i)
426             {
427                 if (image->gradient.stops[i].color.alpha != 0xffff)
428                 {
429                     flags &= ~FAST_PATH_IS_OPAQUE;
430                     break;
431                 }
432             }
433         }
434         break;
435
436     default:
437         code = PIXMAN_unknown;
438         break;
439     }
440
441     /* Alpha map */
442     if (!image->common.alpha_map)
443     {
444         flags |= FAST_PATH_NO_ALPHA_MAP;
445     }
446     else
447     {
448         if (PIXMAN_FORMAT_IS_WIDE (image->common.alpha_map->format))
449             flags &= ~FAST_PATH_NARROW_FORMAT;
450     }
451
452     /* Both alpha maps and convolution filters can introduce
453      * non-opaqueness in otherwise opaque images. Also
454      * an image with component alpha turned on is only opaque
455      * if all channels are opaque, so we simply turn it off
456      * unconditionally for those images.
457      */
458     if (image->common.alpha_map                                 ||
459         image->common.filter == PIXMAN_FILTER_CONVOLUTION       ||
460         image->common.component_alpha)
461     {
462         flags &= ~(FAST_PATH_IS_OPAQUE | FAST_PATH_SAMPLES_OPAQUE);
463     }
464
465     image->common.flags = flags;
466     image->common.extended_format_code = code;
467 }
468
469 void
470 _pixman_image_validate (pixman_image_t *image)
471 {
472     if (image->common.dirty)
473     {
474         compute_image_info (image);
475
476         /* It is important that property_changed is
477          * called *after* compute_image_info() because
478          * property_changed() can make use of the flags
479          * to set up accessors etc.
480          */
481         image->common.property_changed (image);
482
483         image->common.dirty = FALSE;
484     }
485
486     if (image->common.alpha_map)
487         _pixman_image_validate ((pixman_image_t *)image->common.alpha_map);
488 }
489
490 PIXMAN_EXPORT pixman_bool_t
491 pixman_image_set_clip_region32 (pixman_image_t *   image,
492                                 pixman_region32_t *region)
493 {
494     image_common_t *common = (image_common_t *)image;
495     pixman_bool_t result;
496
497     if (region)
498     {
499         if ((result = pixman_region32_copy (&common->clip_region, region)))
500             image->common.have_clip_region = TRUE;
501     }
502     else
503     {
504         _pixman_image_reset_clip_region (image);
505
506         result = TRUE;
507     }
508
509     image_property_changed (image);
510
511     return result;
512 }
513
514 PIXMAN_EXPORT pixman_bool_t
515 pixman_image_set_clip_region (pixman_image_t *   image,
516                               pixman_region16_t *region)
517 {
518     image_common_t *common = (image_common_t *)image;
519     pixman_bool_t result;
520
521     if (region)
522     {
523         if ((result = pixman_region32_copy_from_region16 (&common->clip_region, region)))
524             image->common.have_clip_region = TRUE;
525     }
526     else
527     {
528         _pixman_image_reset_clip_region (image);
529
530         result = TRUE;
531     }
532
533     image_property_changed (image);
534
535     return result;
536 }
537
538 PIXMAN_EXPORT void
539 pixman_image_set_has_client_clip (pixman_image_t *image,
540                                   pixman_bool_t   client_clip)
541 {
542     image->common.client_clip = client_clip;
543 }
544
545 PIXMAN_EXPORT pixman_bool_t
546 pixman_image_set_transform (pixman_image_t *          image,
547                             const pixman_transform_t *transform)
548 {
549     static const pixman_transform_t id =
550     {
551         { { pixman_fixed_1, 0, 0 },
552           { 0, pixman_fixed_1, 0 },
553           { 0, 0, pixman_fixed_1 } }
554     };
555
556     image_common_t *common = (image_common_t *)image;
557     pixman_bool_t result;
558
559     if (common->transform == transform)
560         return TRUE;
561
562     if (memcmp (&id, transform, sizeof (pixman_transform_t)) == 0)
563     {
564         free (common->transform);
565         common->transform = NULL;
566         result = TRUE;
567
568         goto out;
569     }
570
571     if (common->transform == NULL)
572         common->transform = malloc (sizeof (pixman_transform_t));
573
574     if (common->transform == NULL)
575     {
576         result = FALSE;
577
578         goto out;
579     }
580
581     memcpy (common->transform, transform, sizeof(pixman_transform_t));
582
583     result = TRUE;
584
585 out:
586     image_property_changed (image);
587
588     return result;
589 }
590
591 PIXMAN_EXPORT void
592 pixman_image_set_repeat (pixman_image_t *image,
593                          pixman_repeat_t repeat)
594 {
595     image->common.repeat = repeat;
596
597     image_property_changed (image);
598 }
599
600 PIXMAN_EXPORT pixman_bool_t
601 pixman_image_set_filter (pixman_image_t *      image,
602                          pixman_filter_t       filter,
603                          const pixman_fixed_t *params,
604                          int                   n_params)
605 {
606     image_common_t *common = (image_common_t *)image;
607     pixman_fixed_t *new_params;
608
609     if (params == common->filter_params && filter == common->filter)
610         return TRUE;
611
612     new_params = NULL;
613     if (params)
614     {
615         new_params = pixman_malloc_ab (n_params, sizeof (pixman_fixed_t));
616         if (!new_params)
617             return FALSE;
618
619         memcpy (new_params,
620                 params, n_params * sizeof (pixman_fixed_t));
621     }
622
623     common->filter = filter;
624
625     if (common->filter_params)
626         free (common->filter_params);
627
628     common->filter_params = new_params;
629     common->n_filter_params = n_params;
630
631     image_property_changed (image);
632     return TRUE;
633 }
634
635 PIXMAN_EXPORT void
636 pixman_image_set_source_clipping (pixman_image_t *image,
637                                   pixman_bool_t   clip_sources)
638 {
639     image->common.clip_sources = clip_sources;
640
641     image_property_changed (image);
642 }
643
644 /* Unlike all the other property setters, this function does not
645  * copy the content of indexed. Doing this copying is simply
646  * way, way too expensive.
647  */
648 PIXMAN_EXPORT void
649 pixman_image_set_indexed (pixman_image_t *        image,
650                           const pixman_indexed_t *indexed)
651 {
652     bits_image_t *bits = (bits_image_t *)image;
653
654     bits->indexed = indexed;
655
656     image_property_changed (image);
657 }
658
659 PIXMAN_EXPORT void
660 pixman_image_set_alpha_map (pixman_image_t *image,
661                             pixman_image_t *alpha_map,
662                             int16_t         x,
663                             int16_t         y)
664 {
665     image_common_t *common = (image_common_t *)image;
666
667     return_if_fail (!alpha_map || alpha_map->type == BITS);
668
669     if (alpha_map && common->alpha_count > 0)
670     {
671         /* If this image is being used as an alpha map itself,
672          * then you can't give it an alpha map of its own.
673          */
674         return;
675     }
676
677     if (alpha_map && alpha_map->common.alpha_map)
678     {
679         /* If the image has an alpha map of its own,
680          * then it can't be used as an alpha map itself
681          */
682         return;
683     }
684
685     if (common->alpha_map != (bits_image_t *)alpha_map)
686     {
687         if (common->alpha_map)
688         {
689             common->alpha_map->common.alpha_count--;
690
691             pixman_image_unref ((pixman_image_t *)common->alpha_map);
692         }
693
694         if (alpha_map)
695         {
696             common->alpha_map = (bits_image_t *)pixman_image_ref (alpha_map);
697
698             common->alpha_map->common.alpha_count++;
699         }
700         else
701         {
702             common->alpha_map = NULL;
703         }
704     }
705
706     common->alpha_origin_x = x;
707     common->alpha_origin_y = y;
708
709     image_property_changed (image);
710 }
711
712 PIXMAN_EXPORT void
713 pixman_image_set_component_alpha   (pixman_image_t *image,
714                                     pixman_bool_t   component_alpha)
715 {
716     image->common.component_alpha = component_alpha;
717
718     image_property_changed (image);
719 }
720
721 PIXMAN_EXPORT pixman_bool_t
722 pixman_image_get_component_alpha   (pixman_image_t       *image)
723 {
724     return image->common.component_alpha;
725 }
726
727 PIXMAN_EXPORT void
728 pixman_image_set_accessors (pixman_image_t *           image,
729                             pixman_read_memory_func_t  read_func,
730                             pixman_write_memory_func_t write_func)
731 {
732     return_if_fail (image != NULL);
733
734     if (image->type == BITS)
735     {
736         image->bits.read_func = read_func;
737         image->bits.write_func = write_func;
738
739         image_property_changed (image);
740     }
741 }
742
743 PIXMAN_EXPORT uint32_t *
744 pixman_image_get_data (pixman_image_t *image)
745 {
746     if (image->type == BITS)
747         return image->bits.bits;
748
749     return NULL;
750 }
751
752 PIXMAN_EXPORT int
753 pixman_image_get_width (pixman_image_t *image)
754 {
755     if (image->type == BITS)
756         return image->bits.width;
757
758     return 0;
759 }
760
761 PIXMAN_EXPORT int
762 pixman_image_get_height (pixman_image_t *image)
763 {
764     if (image->type == BITS)
765         return image->bits.height;
766
767     return 0;
768 }
769
770 PIXMAN_EXPORT int
771 pixman_image_get_stride (pixman_image_t *image)
772 {
773     if (image->type == BITS)
774         return image->bits.rowstride * (int) sizeof (uint32_t);
775
776     return 0;
777 }
778
779 PIXMAN_EXPORT int
780 pixman_image_get_depth (pixman_image_t *image)
781 {
782     if (image->type == BITS)
783         return PIXMAN_FORMAT_DEPTH (image->bits.format);
784
785     return 0;
786 }
787
788 PIXMAN_EXPORT pixman_format_code_t
789 pixman_image_get_format (pixman_image_t *image)
790 {
791     if (image->type == BITS)
792         return image->bits.format;
793
794     return 0;
795 }
796
797 uint32_t
798 _pixman_image_get_solid (pixman_implementation_t *imp,
799                          pixman_image_t *         image,
800                          pixman_format_code_t     format)
801 {
802     uint32_t result;
803     pixman_iter_t iter;
804
805     _pixman_implementation_src_iter_init (
806         imp, &iter, image, 0, 0, 1, 1,
807         (uint8_t *)&result, ITER_NARROW);
808
809     result = *iter.get_scanline (&iter, NULL);
810
811     /* If necessary, convert RGB <--> BGR. */
812     if (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_ARGB)
813     {
814         result = (((result & 0xff000000) >>  0) |
815                   ((result & 0x00ff0000) >> 16) |
816                   ((result & 0x0000ff00) >>  0) |
817                   ((result & 0x000000ff) << 16));
818     }
819
820     return result;
821 }