Debian Codegraph @

src/mixer2/uvmap/uvmap.c

raw symbols SCIP
1 /* uvmap.c
2 * Copyright (C) 2008 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 #include <math.h>
23
24 #include "frei0r.h"
25
26 typedef struct uvmap_instance
27 {
28 unsigned int width;
29 unsigned int height;
30 } uvmap_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* uvmapInfo)
41 {
42 uvmapInfo->name = "UV Map";
43 uvmapInfo->author = "Richard Spindler";
44 uvmapInfo->plugin_type = F0R_PLUGIN_TYPE_MIXER2;
45 uvmapInfo->color_model = F0R_COLOR_MODEL_RGBA8888;
46 uvmapInfo->frei0r_version = FREI0R_MAJOR_VERSION;
47 uvmapInfo->major_version = 0;
48 uvmapInfo->minor_version = 9;
49 uvmapInfo->num_params = 0;
50 uvmapInfo->explanation = "Uses Input 1 as UV Map to distort Input 2";
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 uvmap_instance_t* inst = (uvmap_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 void f0r_update2(f0r_instance_t instance,
79 double time,
80 const uint32_t* inframe1,
81 const uint32_t* inframe2,
82 const uint32_t* inframe3,
83 uint32_t* outframe)
84 {
85 assert(instance);
86 uvmap_instance_t* inst = (uvmap_instance_t*)instance;
87 unsigned int w = inst->width;
88 unsigned int h = inst->height;
89 unsigned int x,y;
90
91 uint32_t* dst = outframe;
92 const uint32_t* uvmap = inframe1;
93 const uint32_t* src = inframe2;
94 float fx, fy;
95 long px, py;
96 for( y = 0; y < h; ++y )
97 for( x = 0; x < w; ++x ) {
98 /* The coordinates start in the lower left corner:
99 *
100 * ^ +-------------+
101 * | | |
102 * G | |
103 * 0+-------------+
104 * 0 R ->
105 *
106 */
107 unsigned char* tmpc = (unsigned char*)uvmap;
108 fx = ((float)tmpc[0]) / 255.0;
109 fy = ((float)tmpc[1]) / 255.0;
110 fy = 1.0 - fy;
111
112 px = lrintf( (w - 1) * fx );
113 py = lrintf( (h - 1) * fy );
114 if ( tmpc[2] > 128 ) {
115 *dst++ = src[px+w*py];
116 } else {
117 *dst++ = 0x00000000;
118 }
119 uvmap++;
120 }
121 }
122
123