@@ -128,42 +128,62 @@ namespace SmartObject
128
128
// We then bilinearly sample the source image to avoid artifacts from nearest
129
129
// neighbour sampling.
130
130
131
- bool sampled = false ;
132
- float accumulated_color = 0 ;
133
-
134
- for (size_t sy = 0 ; sy < supersample_resolution; ++sy)
131
+ // Simplify the code at compile time already if not supersampling
132
+ if constexpr (supersample_resolution == 1 )
135
133
{
136
- double subpixel_y = y + static_cast <double >(sy) / supersample_resolution;
134
+ auto position = Geometry::Point2D<double >(static_cast <double >(x), static_cast <double >(y));
135
+ auto uv = warp_mesh.uv_coordinate (position);
137
136
138
- for (size_t sx = 0 ; sx < supersample_resolution; ++sx)
137
+ // If the uv coordinate is outside of the image we dont bother with it.
138
+ // We can check against the exact -1.0f here as that is what we return
139
+ if (uv != failure_condition)
139
140
{
140
- double subpixel_x = x + static_cast <double >(sx) / supersample_resolution;
141
+ size_t idx = y * buffer.width + x;
142
+ buffer.buffer [idx] = image.template sample_bilinear_uv <double >(uv);
143
+ }
144
+ }
145
+ else
146
+ {
147
+ bool sampled = false ;
148
+ float accumulated_color = 0 ;
141
149
142
- auto position = Geometry::Point2D<double >(subpixel_x, subpixel_y);
143
- auto uv = warp_mesh.uv_coordinate (position);
150
+ // Perform the supersampling steps
151
+ for (size_t sy = 0 ; sy < supersample_resolution; ++sy)
152
+ {
153
+ double subpixel_y = y + static_cast <double >(sy) / supersample_resolution;
144
154
145
- // If the uv coordinate is outside of the image we dont bother with it.
146
- // We can check against the exact -1.0f here as that is what we return
147
- if (uv != failure_condition)
155
+ for (size_t sx = 0 ; sx < supersample_resolution; ++sx)
148
156
{
149
- sampled = true ;
150
- accumulated_color += image.template sample_bilinear_uv <double >(uv);
157
+ double subpixel_x = x + static_cast <double >(sx) / supersample_resolution;
158
+
159
+ auto position = Geometry::Point2D<double >(subpixel_x, subpixel_y);
160
+ auto uv = warp_mesh.uv_coordinate (position);
161
+
162
+ // If the uv coordinate is outside of the image we dont bother with it.
163
+ // We can check against the exact -1.0f here as that is what we return
164
+ if (uv != failure_condition)
165
+ {
166
+ sampled = true ;
167
+ accumulated_color += image.template sample_bilinear_uv <double >(uv);
168
+ }
151
169
}
152
170
}
153
- }
154
171
155
- if (sampled)
156
- {
157
- T final_value = static_cast <T>(std::clamp<double >(accumulated_color / total_supersamples, 0.0 , static_cast <double >(max_t )));
172
+ if (sampled)
173
+ {
174
+ T final_value = static_cast <T>(std::clamp<double >(accumulated_color / total_supersamples, 0.0 , static_cast <double >(max_t )));
158
175
159
- size_t idx = y * buffer.width + x;
160
- buffer.buffer [idx] = final_value;
176
+ size_t idx = y * buffer.width + x;
177
+ buffer.buffer [idx] = final_value;
178
+ }
161
179
}
162
180
}
163
181
});
164
182
}
165
183
166
184
185
+
186
+
167
187
// / Apply the warp by warping the `image` into the `buffer` using the locally stored warp description.
168
188
// / The `buffer` passed should match the general resolution of the warp points. So if e.g. the warp points
169
189
// / are from { 0 - 4000, 0 - 2000 } the `buffer` parameter should cover these.
0 commit comments