source: mainline/uspace/lib/draw/source.c@ 4f351432

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4f351432 was 6d5e378, checked in by Martin Decky <martin@…>, 13 years ago

cherrypick GUI implementation (originally by Petr Koupy), with several major changes

  • for character-oriented devices a new output server and output protocol was created based on the original fb server
  • DDF visualizer drivers are pixel-oriented only
  • console and compositor can coexist in the same build
  • terminal widget is self-sufficient, no strange console nesting is needed
  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[6d5e378]1/*
2 * Copyright (c) 2012 Petr Koupy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup draw
30 * @{
31 */
32/**
33 * @file
34 */
35
36#include <assert.h>
37
38#include "source.h"
39
40void source_init(source_t *source)
41{
42 transform_identity(&source->transform);
43 source->filter = filter_nearest;
44
45 source->color = PIXEL(0, 0, 0, 0);
46 source->texture = NULL;
47 source->texture_tile = false;
48
49 source->alpha = PIXEL(255, 0, 0, 0);
50 source->mask = NULL;
51 source->mask_tile = false;
52}
53
54void source_set_transform(source_t *source, transform_t transform)
55{
56 source->transform = transform;
57 transform_invert(&source->transform);
58}
59
60void source_reset_transform(source_t *source)
61{
62 transform_identity(&source->transform);
63}
64
65void source_set_filter(source_t *source, filter_t filter)
66{
67 source->filter = filter;
68}
69
70void source_set_color(source_t *source, pixel_t color)
71{
72 source->color = color;
73}
74
75void source_set_texture(source_t *source, surface_t *texture, bool tile)
76{
77 source->texture = texture;
78 source->texture_tile = tile;
79}
80
81void source_set_alpha(source_t *source, pixel_t alpha)
82{
83 source->alpha = alpha;
84}
85
86void source_set_mask(source_t *source, surface_t *mask, bool tile)
87{
88 source->mask = mask;
89 source->mask_tile = tile;
90}
91
92pixel_t source_determine_pixel(source_t *source, double x, double y)
93{
94 if (source->mask || source->texture) {
95 transform_apply_affine(&source->transform, &x, &y);
96 }
97
98 pixel_t mask_pix;
99 if (source->mask) {
100 mask_pix = source->filter(
101 surface_pixmap_access(source->mask),
102 x, y, source->mask_tile);
103 } else {
104 mask_pix = source->alpha;
105 }
106
107 if (!ALPHA(mask_pix)) {
108 return 0;
109 }
110
111 pixel_t texture_pix;
112 if (source->texture) {
113 texture_pix = source->filter(
114 surface_pixmap_access(source->texture),
115 x, y, source->texture_tile);
116 } else {
117 texture_pix = source->color;
118 }
119
120 if (ALPHA(mask_pix) < 255) {
121 double ratio = ((double) ALPHA(mask_pix)) / 255.0;
122 double res_a = ratio * ((double) ALPHA(texture_pix));
123 return PIXEL((unsigned) res_a,
124 RED(texture_pix), GREEN(texture_pix), BLUE(texture_pix));
125 } else {
126 return texture_pix;
127 }
128}
129
130/** @}
131 */
Note: See TracBrowser for help on using the repository browser.