Debian Codegraph @

src/mixer2/composition/composition.c

raw symbols SCIP
1 /* composition.c
2 * Copyright (C) 2007 Richard Spindler ([email protected])
3 * This file is a Frei0r plugin.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <stdlib.h>
21 #include <assert.h>
22
23 #include "frei0r.h"
24 #include "frei0r/math.h"
25
26 typedef struct composition_instance
27 {
28 unsigned int width;
29 unsigned int height;
30 } composition_instance_t;
31
32 int f0r_init()
33 {
34 return 1;
35 }
36
37 void f0r_deinit()
38 { /* no initialization required */ }
39
40 void f0r_get_plugin_info(f0r_plugin_info_t* compositionInfo)
41 {
42 compositionInfo->name = "Composition";
43 compositionInfo->author = "Richard Spindler";
44 compositionInfo->plugin_type = F0R_PLUGIN_TYPE_MIXER2;
45 compositionInfo->color_model = F0R_COLOR_MODEL_RGBA8888;
46 compositionInfo->frei0r_version = FREI0R_MAJOR_VERSION;
47 compositionInfo->major_version = 0;
48 compositionInfo->minor_version = 9;
49 compositionInfo->num_params = 0;
50 compositionInfo->explanation = "Composites Image 2 onto Image 1 according to its Alpha Channel";
51 }
52
53 void f0r_get_param_info(f0r_param_info_t* info, int param_index)
54 {
55 /* no params */
56 }
57
58 f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
59 {
60 composition_instance_t* inst = (composition_instance_t*)calloc(1, sizeof(*inst));
61 inst->width = width; inst->height = height;
62 return (f0r_instance_t)inst;
63 }
64
65 void f0r_destruct(f0r_instance_t instance)
66 {
67 free(instance);
68 }
69
70 void f0r_set_param_value(f0r_instance_t instance,
71 f0r_param_t param, int param_index)
72 { /* no params */ }
73
74 void f0r_get_param_value(f0r_instance_t instance,
75 f0r_param_t param, int param_index)
76 { /* no params */ }
77
78
79 void f0r_update2(f0r_instance_t instance,
80 double time,
81 const uint32_t* inframe1,
82 const uint32_t* inframe2,
83 const uint32_t* inframe3,
84 uint32_t* outframe)
85 {
86 assert(instance);
87 composition_instance_t* inst = (composition_instance_t*)instance;
88 unsigned int w = inst->width;
89 unsigned int h = inst->height;
90
91 unsigned char *ps1, *ps2, *pd, *pd_end;
92 ps1 = (unsigned char *)inframe2;
93 ps2 = (unsigned char *)inframe1;
94 pd = (unsigned char *)outframe;
95 pd_end = pd + ( w * h * 4 );
96 while ( pd < pd_end ) {
97 pd[0] = ( ( ( ps1[0] - ps2[0] ) * 255 * ps1[3] ) >> 16 ) + ps2[0];
98 pd[1] = ( ( ( ps1[1] - ps2[1] ) * 255 * ps1[3] ) >> 16 ) + ps2[1];
99 pd[2] = ( ( ( ps1[2] - ps2[2] ) * 255 * ps1[3] ) >> 16 ) + ps2[2];
100 pd[3] = CLAMP0255( ps1[3] + ps2[3] );
101 ps1 += 4;
102 ps2 += 4;
103 pd += 4;
104 }
105 }
106
107