source: mainline/uspace/lib/draw/source.c@ a35b458

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.0 KB
Line 
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_extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK;
48
49 source->alpha = PIXEL(255, 0, 0, 0);
50 source->mask = NULL;
51 source->mask_extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK;
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,
76 pixelmap_extend_t extend)
77{
78 source->texture = texture;
79 source->texture_extend = extend;
80}
81
82void source_set_alpha(source_t *source, pixel_t alpha)
83{
84 source->alpha = alpha;
85}
86
87void source_set_mask(source_t *source, surface_t *mask,
88 pixelmap_extend_t extend)
89{
90 source->mask = mask;
91 source->mask_extend = extend;
92}
93
94bool source_is_fast(source_t *source)
95{
96 return ((source->mask == NULL) &&
97 (source->alpha == (pixel_t) PIXEL(255, 0, 0, 0)) &&
98 (source->texture != NULL) &&
99 (transform_is_fast(&source->transform)));
100}
101
102pixel_t *source_direct_access(source_t *source, double x, double y)
103{
104 assert(source_is_fast(source));
105
106 long _x = (long) (x + source->transform.matrix[0][2]);
107 long _y = (long) (y + source->transform.matrix[1][2]);
108
109 return pixelmap_pixel_at(
110 surface_pixmap_access(source->texture), (sysarg_t) _x, (sysarg_t) _y);
111}
112
113pixel_t source_determine_pixel(source_t *source, double x, double y)
114{
115 if (source->mask || source->texture) {
116 transform_apply_affine(&source->transform, &x, &y);
117 }
118
119 pixel_t mask_pix;
120 if (source->mask) {
121 mask_pix = source->filter(
122 surface_pixmap_access(source->mask),
123 x, y, source->mask_extend);
124 } else {
125 mask_pix = source->alpha;
126 }
127
128 if (!ALPHA(mask_pix)) {
129 return 0;
130 }
131
132 pixel_t texture_pix;
133 if (source->texture) {
134 texture_pix = source->filter(
135 surface_pixmap_access(source->texture),
136 x, y, source->texture_extend);
137 } else {
138 texture_pix = source->color;
139 }
140
141 if (ALPHA(mask_pix) < 255) {
142 double ratio = ((double) ALPHA(mask_pix)) / 255.0;
143 double res_a = ratio * ((double) ALPHA(texture_pix));
144 return PIXEL((unsigned) res_a,
145 RED(texture_pix), GREEN(texture_pix), BLUE(texture_pix));
146 } else {
147 return texture_pix;
148 }
149}
150
151/** @}
152 */
Note: See TracBrowser for help on using the repository browser.