+namespace movit {
+
+class Input;
+
+namespace {
+
+// Not thread-safe, but this isn't a big problem for testing.
+ResourcePool *get_static_pool()
+{
+ static ResourcePool *resource_pool = NULL;
+ if (!resource_pool) {
+ resource_pool = new ResourcePool();
+ }
+ return resource_pool;
+}
+
+// Flip upside-down to compensate for different origin.
+template<class T>
+void vertical_flip(T *data, unsigned width, unsigned height)
+{
+ for (unsigned y = 0; y < height / 2; ++y) {
+ unsigned flip_y = height - y - 1;
+ for (unsigned x = 0; x < width; ++x) {
+ swap(data[y * width + x], data[flip_y * width + x]);
+ }
+ }
+}
+
+} // namespace
+
+EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height,
+ MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve,
+ GLenum framebuffer_format)
+ : chain(width, height, get_static_pool()), width(width), height(height), framebuffer_format(framebuffer_format), output_added(false), finalized(false)
+{
+ CHECK(init_movit(".", MOVIT_DEBUG_OFF));
+
+ if (data != NULL) {
+ add_input(data, pixel_format, color_space, gamma_curve);
+ }
+}
+
+EffectChainTester::~EffectChainTester()
+{
+}
+
+Input *EffectChainTester::add_input(const float *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve, int input_width, int input_height)
+{
+ ImageFormat format;
+ format.color_space = color_space;
+ format.gamma_curve = gamma_curve;
+
+ if (input_width == -1) {
+ input_width = width;
+ }
+ if (input_height == -1) {
+ input_height = height;
+ }
+
+ FlatInput *input = new FlatInput(format, pixel_format, GL_FLOAT, input_width, input_height);
+ input->set_pixel_data(data);
+ chain.add_input(input);
+ return input;
+}
+
+Input *EffectChainTester::add_input(const unsigned char *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve, int input_width, int input_height)
+{
+ ImageFormat format;
+ format.color_space = color_space;
+ format.gamma_curve = gamma_curve;
+
+ if (input_width == -1) {
+ input_width = width;
+ }
+ if (input_height == -1) {
+ input_height = height;
+ }
+
+ FlatInput *input = new FlatInput(format, pixel_format, GL_UNSIGNED_BYTE, input_width, input_height);
+ input->set_pixel_data(data);
+ chain.add_input(input);
+ return input;
+}
+
+void EffectChainTester::run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run(out_data, GL_FLOAT, format, color_space, gamma_curve, alpha_format);
+}
+
+void EffectChainTester::run(unsigned char *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run(out_data, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format);
+}