@@ -76,6 +76,16 @@ static PF_Err ParamsSetup (PF_InData *in_data, PF_OutData *out_data, PF_ParamDef
76
76
KEEPLAYER_PARAM_ID
77
77
);
78
78
79
+ AEFX_CLR_STRUCT (def);
80
+
81
+ PF_ADD_CHECKBOX (
82
+ STR (StrID_Antialias_Param_Name),
83
+ STR (StrID_Antialias_Param_Desc),
84
+ TRUE ,
85
+ 0 ,
86
+ ANTIALIAS_PARAM_ID
87
+ );
88
+
79
89
out_data->num_params = INVEQUI_NUM_PARAMS;
80
90
81
91
return PF_Err_NONE;
@@ -87,10 +97,64 @@ struct RenderArgs {
87
97
PF_ParamDef *scanLayer;
88
98
};
89
99
90
- inline PF_Pixel *sampleIntegral8 (PF_EffectWorld &def, int x, int y) {
100
+ inline PF_Pixel8 *sampleIntegral8 (PF_EffectWorld &def, int x, int y) {
91
101
return (PF_Pixel8*)((char *)def.data + (y * def.rowbytes ) + (x * sizeof (PF_Pixel8)));
92
102
}
93
103
104
+ inline PF_Pixel8 boundedIntegral (PF_EffectWorld &def, int x, int y) {
105
+ if (x < 0 || y < 0 )
106
+ return {0 , 0 , 0 , 0 };
107
+ if (x > def.width || y > def.height )
108
+ return {0 , 0 , 0 , 0 };
109
+
110
+ PF_Pixel8 *ptr = sampleIntegral8 (def, x, y);
111
+ if (ptr == nullptr )
112
+ return {0 , 0 , 0 , 0 };
113
+
114
+ return *ptr;
115
+ }
116
+
117
+ inline PF_Pixel8 lanczosSample (PF_EffectWorld &def, float x, float y) {
118
+ int xi = static_cast <int >(x);
119
+ int yi = static_cast <int >(y);
120
+ float xo = x - static_cast <float >(xi);
121
+ float yo = y - static_cast <float >(yi);
122
+
123
+ float lx, ly;
124
+ float a, r, g, b;
125
+ float y_a, y_r, y_g, y_b;
126
+
127
+ a = r = g = b = 0 .0f ;
128
+
129
+ for (int iy = -3 ; iy <= 3 ; iy++) {
130
+ y_a = y_r = y_g = y_b = 0 .0f ;
131
+
132
+ for (int ix = -3 ; ix <= 3 ; ix++) {
133
+ lx = Math3D::lanczos (xo - ix);
134
+ PF_Pixel px = boundedIntegral (def, xi + ix, yi + iy);
135
+
136
+ y_a += lx * px.alpha ;
137
+ y_r += lx * px.red ;
138
+ y_g += lx * px.green ;
139
+ y_b += lx * px.blue ;
140
+ }
141
+
142
+ ly = Math3D::lanczos (yo - iy);
143
+
144
+ a += ly * y_a;
145
+ r += ly * y_r;
146
+ g += ly * y_g;
147
+ b += ly * y_b;
148
+ }
149
+
150
+ return {
151
+ static_cast <A_u_char>(fmaxf (fminf (255 .0f , a), 0 .0f )),
152
+ static_cast <A_u_char>(fmaxf (fminf (255 .0f , r), 0 .0f )),
153
+ static_cast <A_u_char>(fmaxf (fminf (255 .0f , g), 0 .0f )),
154
+ static_cast <A_u_char>(fmaxf (fminf (255 .0f , b), 0 .0f ))
155
+ };
156
+ }
157
+
94
158
static PF_Err SubSample_Pixel8 (void *refcon, A_long x, A_long y, PF_Pixel8 *inP, PF_Pixel8 *outP) {
95
159
PF_Err err = PF_Err_NONE;
96
160
RenderArgs* rArgs = reinterpret_cast <RenderArgs*>(refcon);
@@ -107,79 +171,67 @@ static PF_Err SubSample_Pixel8(void *refcon, A_long x, A_long y, PF_Pixel8 *inP,
107
171
fov = fminf (fmaxf (fov, 0 .1f ), 179 .9f );
108
172
109
173
bool keepLayer = static_cast <bool >(rArgs->params [INVEQUI_KEEPLAYER]->u .bd .value );
174
+ bool antialias = static_cast <bool >(rArgs->params [INVEQUI_ANTIALIAS]->u .bd .value );
110
175
111
- Math3D::Vector3D<float > model =
176
+ Math3D::Vector3D<> model =
112
177
Math3D::rotate (
113
178
Math3D::rotate (
114
- Math3D::Vector3D<float >(0 .0f , 0 .0f , -1 .0f ),
179
+ Math3D::Vector3D<>(0 .0f , 0 .0f , -1 .0f ),
115
180
Math3D::radians (pitchDeg),
116
- Math3D::Vector3D<float >(1 .0f , 0 .0f , 0 .0f )
181
+ Math3D::Vector3D<>(1 .0f , 0 .0f , 0 .0f )
117
182
),
118
183
Math3D::radians (yawDeg),
119
- Math3D::Vector3D<float >(0 .0f , 1 .0f , 0 .0f )
184
+ Math3D::Vector3D<>(0 .0f , 1 .0f , 0 .0f )
120
185
);
121
186
122
- Math3D::Vector3D<float > view =
187
+ Math3D::Vector3D<> view =
123
188
Math3D::rotate (
124
189
Math3D::rotate (
125
190
model,
126
191
Math3D::radians (-yaw),
127
- Math3D::Vector3D<float >(0 .0f , 1 .0f , 0 .0f )
192
+ Math3D::Vector3D<>(0 .0f , 1 .0f , 0 .0f )
128
193
),
129
194
Math3D::radians (-pitch),
130
- Math3D::Vector3D<float >(1 .0f , 0 .0f , 0 .0f )
195
+ Math3D::Vector3D<>(1 .0f , 0 .0f , 0 .0f )
131
196
);
132
197
133
- Math3D::Vector3D<float > screen =
198
+ Math3D::Vector3D<> screen =
134
199
Math3D::perspective (
135
200
view,
136
201
Math3D::radians (fov),
137
202
static_cast <float >(sample.width ) / static_cast <float >(sample.height )
138
203
);
139
204
140
- if (screen.z < -1 .0f || screen.z > 1 .0f || screen.x < -1 .0f || screen.x > 1 .0f || screen.y < -1 .0f || screen.y > 1 .0f ) {
141
- if (keepLayer) {
142
- outP->red = inP->red ;
143
- outP->green = inP->green ;
144
- outP->blue = inP->blue ;
145
- outP->alpha = inP->alpha ;
146
- }
147
- else {
148
- outP->red = 0 ;
149
- outP->green = 0 ;
150
- outP->blue = 0 ;
151
- outP->alpha = 0 ;
152
- }
153
- }
154
- else {
155
- float samplePosX = (screen.x + 1 .0f ) * 0 .5f * static_cast <float >(sample.width );
156
- float samplePosY = (1 .0f - ((screen.y + 1 .0f ) * 0 .5f )) * static_cast <float >(sample.height );
157
-
158
- int sX = static_cast <int >(samplePosX);
159
- int sY = static_cast <int >(samplePosY);
205
+ float width = static_cast <float >(sample.width );
206
+ float height = static_cast <float >(sample.height );
160
207
161
- PF_Pixel* sampleP = sampleIntegral8 (sample, sX , sY );
208
+ float samplePosX = (screen.x + 1 .0f ) * 0 .5f * width;
209
+ float samplePosY = (1 .0f - ((screen.y + 1 .0f ) * 0 .5f )) * height;
162
210
163
- if (sampleP != nullptr ) {
164
- outP->red = sampleP->red ;
165
- outP->green = sampleP->green ;
166
- outP->blue = sampleP->blue ;
167
- outP->alpha = sampleP->alpha ;
211
+ if (screen.z < -1 .0f || screen.z > 1 .0f || samplePosX < -2 .0f || samplePosY < -2 .0f || samplePosX + 1 .0f > width || samplePosY + 1 .0f > height) {
212
+ if (keepLayer)
213
+ *outP = *inP;
214
+ else
215
+ *outP = { 0 , 0 , 0 , 0 };
216
+ } else {
217
+ if (antialias) {
218
+ *outP = lanczosSample (sample, samplePosX, samplePosY);
168
219
}
169
220
else {
170
- outP-> red = 255 ;
171
- outP-> green = 255 ;
172
- outP-> blue = 0 ;
173
- outP-> alpha = 255 ;
221
+ int sX = static_cast < int >(samplePosX) ;
222
+ int sY = static_cast < int >(samplePosY) ;
223
+
224
+ * outP = boundedIntegral (sample, sX , sY ) ;
174
225
}
175
226
}
176
227
177
228
return err;
178
229
}
179
230
180
231
static PF_Err Render (PF_InData *in_data, PF_OutData *out_data, PF_ParamDef *params[], PF_LayerDef *output) {
181
- PF_Err err = PF_Err_NONE;
182
- AEGP_SuiteHandler suites (in_data->pica_basicP );
232
+ PF_Err err = PF_Err_NONE,
233
+ err2 = PF_Err_NONE;
234
+ AEGP_SuiteHandler suites (in_data->pica_basicP );
183
235
184
236
PF_ParamDef scanLayer;
185
237
@@ -189,7 +241,7 @@ static PF_Err Render (PF_InData *in_data, PF_OutData *out_data, PF_ParamDef *par
189
241
&scanLayer
190
242
};
191
243
192
- A_long progress_baseL = 0 , progress_finalL = 1 ;
244
+ A_long progress_baseL = 0 , progress_finalL = 3 ;
193
245
194
246
ERR (PF_CHECKOUT_PARAM (
195
247
in_data,
@@ -200,6 +252,8 @@ static PF_Err Render (PF_InData *in_data, PF_OutData *out_data, PF_ParamDef *par
200
252
&scanLayer
201
253
));
202
254
255
+ progress_baseL++;
256
+
203
257
ERR (suites.Iterate8Suite1 ()->iterate(
204
258
in_data,
205
259
progress_baseL,
@@ -213,6 +267,10 @@ static PF_Err Render (PF_InData *in_data, PF_OutData *out_data, PF_ParamDef *par
213
267
214
268
progress_baseL++;
215
269
270
+ ERR2 (PF_CHECKIN_PARAM (in_data, &scanLayer));
271
+
272
+ progress_baseL++;
273
+
216
274
return err;
217
275
}
218
276
0 commit comments