graphic art overlay modes, pref window resize, submenu fixes
authorGood Guy <good1.2guy@gmail.com>
Sat, 1 Oct 2016 19:29:11 +0000 (13:29 -0600)
committerGood Guy <good1.2guy@gmail.com>
Sat, 1 Oct 2016 19:29:11 +0000 (13:29 -0600)
107 files changed:
cinelerra-5.1/cinelerra/Makefile
cinelerra-5.1/cinelerra/overlaydirect.C [new file with mode: 0644]
cinelerra-5.1/cinelerra/overlayframe.C
cinelerra-5.1/cinelerra/overlayframe.C.clamp [deleted file]
cinelerra-5.1/cinelerra/overlayframe.C.float [deleted file]
cinelerra-5.1/cinelerra/overlayframe.C.floattable [deleted file]
cinelerra-5.1/cinelerra/overlayframe.C.int [deleted file]
cinelerra-5.1/cinelerra/overlayframe.h
cinelerra-5.1/cinelerra/overlayframe.h.clamp [deleted file]
cinelerra-5.1/cinelerra/overlayframe.h.float [deleted file]
cinelerra-5.1/cinelerra/overlayframe.h.floattable [deleted file]
cinelerra-5.1/cinelerra/overlayframe.h.int [deleted file]
cinelerra-5.1/cinelerra/overlayframe.inc
cinelerra-5.1/cinelerra/overlaynearest.C [new file with mode: 0644]
cinelerra-5.1/cinelerra/overlaysample.C [new file with mode: 0644]
cinelerra-5.1/cinelerra/patchbay.C
cinelerra-5.1/cinelerra/playback3d.C
cinelerra-5.1/cinelerra/preferencesthread.C
cinelerra-5.1/cinelerra/theme.C
cinelerra-5.1/cinelerra/vpatchgui.C
cinelerra-5.1/cinelerra/vpatchgui.h
cinelerra-5.1/guicast/bcmenuitem.C
cinelerra-5.1/guicast/bcmenuitem.h
cinelerra-5.1/guicast/bcmenupopup.C
cinelerra-5.1/guicast/bcwindowbase.C
cinelerra-5.1/plugins/overlay/overlay.C
cinelerra-5.1/plugins/theme_blond/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_blond/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blond_cv/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_blue/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_blue_dot/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_bright/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_bright/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_hulk/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_hulk/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_pinklady/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_pinklady/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_suv/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_suv/data/mode_softlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_and.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_average.png [deleted file]
cinelerra-5.1/plugins/theme_unflat/data/mode_burn.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_difference.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_dodge.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_hardlight.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_overlay.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_screen.png [new file with mode: 0644]
cinelerra-5.1/plugins/theme_unflat/data/mode_softlight.png [new file with mode: 0644]

index f2c3debd708657cd14edef17a55a9c5e67709d0d..853ab8f1a500bacbc66f76863367b08b079df572 100644 (file)
@@ -191,7 +191,10 @@ OBJS = \
        $(OBJDIR)/nestededls.o \
        $(OBJDIR)/newfolder.o \
        $(OBJDIR)/new.o \
+       $(OBJDIR)/overlaydirect.o \
        $(OBJDIR)/overlayframe.o \
+       $(OBJDIR)/overlaynearest.o \
+       $(OBJDIR)/overlaysample.o \
        $(OBJDIR)/packagedispatcher.o \
        $(OBJDIR)/packagerenderer.o \
        $(OBJDIR)/packagingengine.o \
diff --git a/cinelerra-5.1/cinelerra/overlaydirect.C b/cinelerra-5.1/cinelerra/overlaydirect.C
new file mode 100644 (file)
index 0000000..3297fda
--- /dev/null
@@ -0,0 +1,122 @@
+#include "overlayframe.h"
+
+/* Direct translate / blend **********************************************/
+
+#define XBLEND(FN, temp_type, type, max, components, ofs, round) { \
+       temp_type opcty = fade * max + round, trnsp = max - opcty; \
+       type** output_rows = (type**)output->get_rows(); \
+       type** input_rows = (type**)input->get_rows(); \
+       ix *= components;  ox *= components; \
+ \
+       for(int i = pkg->out_row1; i < pkg->out_row2; i++) { \
+               type* in_row = input_rows[i + iy] + ix; \
+               type* output = output_rows[i] + ox; \
+               for(int j = 0; j < ow; j++) { \
+                       if( components == 4 ) { \
+                               temp_type r, g, b, a; \
+                               ALPHA4_BLEND(FN, temp_type, in_row, output, max, ofs, ofs, round); \
+                               ALPHA4_STORE(output, ofs, max); \
+                       } \
+                       else { \
+                               temp_type r, g, b; \
+                               ALPHA3_BLEND(FN, temp_type, in_row, output, max, ofs, ofs, round); \
+                               ALPHA3_STORE(output, ofs, max); \
+                       } \
+                       in_row += components;  output += components; \
+               } \
+       } \
+       break; \
+}
+
+#define XBLEND_ONLY(FN) { \
+       switch(input->get_color_model()) { \
+       case BC_RGB_FLOAT:      XBLEND(FN, z_float,   z_float,    1.f,    3, 0,      0.f); \
+       case BC_RGBA_FLOAT:     XBLEND(FN, z_float,   z_float,    1.f,    4, 0,      0.f); \
+       case BC_RGB888:         XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   3, 0,      .5f); \
+       case BC_YUV888:         XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   3, 0x80,   .5f); \
+       case BC_RGBA8888:       XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   4, 0,      .5f); \
+       case BC_YUVA8888:       XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   4, 0x80,   .5f); \
+       case BC_RGB161616:      XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0,      .5f); \
+       case BC_YUV161616:      XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0x8000, .5f); \
+       case BC_RGBA16161616:   XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0,      .5f); \
+       case BC_YUVA16161616:   XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0x8000, .5f); \
+       } \
+       break; \
+}
+
+DirectPackage::DirectPackage()
+{
+}
+
+DirectUnit::DirectUnit(DirectEngine *server)
+ : LoadClient(server)
+{
+       this->engine = server;
+}
+
+DirectUnit::~DirectUnit()
+{
+}
+
+void DirectUnit::process_package(LoadPackage *package)
+{
+       DirectPackage *pkg = (DirectPackage*)package;
+
+       VFrame *output = engine->output;
+       VFrame *input = engine->input;
+       int mode = engine->mode;
+       float fade =
+               BC_CModels::has_alpha(input->get_color_model()) &&
+               mode == TRANSFER_REPLACE ? 1.f : engine->alpha;
+
+       int ix = engine->in_x1;
+       int ox = engine->out_x1;
+       int ow = engine->out_x2 - ox;
+       int iy = engine->in_y1 - engine->out_y1;
+
+       BLEND_SWITCH(XBLEND_ONLY);
+}
+
+DirectEngine::DirectEngine(int cpus)
+ : LoadServer(cpus, cpus)
+{
+}
+
+DirectEngine::~DirectEngine()
+{
+}
+
+void DirectEngine::init_packages()
+{
+       if(in_x1 < 0) { out_x1 -= in_x1; in_x1 = 0; }
+       if(in_y1 < 0) { out_y1 -= in_y1; in_y1 = 0; }
+       if(out_x1 < 0) { in_x1 -= out_x1; out_x1 = 0; }
+       if(out_y1 < 0) { in_y1 -= out_y1; out_y1 = 0; }
+       if(out_x2 > output->get_w()) out_x2 = output->get_w();
+       if(out_y2 > output->get_h()) out_y2 = output->get_h();
+       int out_w = out_x2 - out_x1;
+       int out_h = out_y2 - out_y1;
+       if( !out_w || !out_h ) return;
+
+       int rows = out_h;
+       int pkgs = get_total_packages();
+       int row1 = out_y1, row2 = row1;
+       for(int i = 0; i < pkgs; row1=row2 ) {
+               DirectPackage *package = (DirectPackage*)get_package(i);
+               row2 = ++i * rows / pkgs + out_y1;
+               package->out_row1 = row1;
+               package->out_row2 = row2;
+       }
+}
+
+LoadClient* DirectEngine::new_client()
+{
+       return new DirectUnit(this);
+}
+
+LoadPackage* DirectEngine::new_package()
+{
+       return new DirectPackage;
+}
+
+
index 642a936749df91cb57ab23b5f6b584a5cdd2ec57..849912fd4c93bee7c1bf40cdc342d3bfcfa032d0 100644 (file)
  * 
  */
 
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <unistd.h>
-
 #include "clip.h"
 #include "edl.inc"
 #include "mutex.h"
 #include "overlayframe.h"
 #include "units.h"
-#include "vframe.h"
-
-static inline int   mabs(int32_t v) { return abs(v); }
-static inline int   mabs(int64_t v) { return llabs(v); }
-static inline float mabs(float v)   { return fabsf(v); }
-
-static inline int32_t aclip(int32_t v, int mx) {
-       return v < 0 ? 0 : v > mx ? mx : v;
-}
-static inline int64_t aclip(int64_t v, int mx) {
-       return v < 0 ? 0 : v > mx ? mx : v;
-}
-static inline float   aclip(float v, float mx) {
-       return v < 0 ? 0 : v > mx ? mx : v;
-}
-static inline float   aclip(float v, int mx) {
-       return v < 0 ? 0 : v > mx ? mx : v;
-}
-static inline int   aclip(int v, float mx) {
-       return v < 0 ? 0 : v > mx ? mx : v;
-}
-static inline int32_t cclip(int32_t v, int mx) {
-       return v > (mx/=2) ? mx : v < (mx=(-mx-1)) ? mx : v;
-}
-static inline int64_t cclip(int64_t v, int mx) {
-       return v > (mx/=2) ? mx : v < (mx=(-mx-1)) ? mx : v;
-}
-static inline float   cclip(float v, float mx) {
-       return v > (mx/=2) ? mx : v < (mx=(-mx)) ? mx : v;
-}
-static inline float   cclip(float v, int mx) {
-       return v > (mx/=2) ? mx : v < (mx=(-mx-1)) ? mx : v;
-}
-static inline int   cclip(int v, float mx) {
-       return v > (mx/=2) ? mx : v < (mx=(-mx-1)) ? mx : v;
-}
 
 /*
  * New resampler code; replace the original somehwat blurry engine
@@ -107,19 +64,11 @@ static inline int   cclip(int v, float mx) {
  *    output_alpha = output_alpha + ((max - output_alpha) * input_alpha) / max;
  */
 
-#define TRANSFORM_SPP    (4096)    /* number of data pts per unit x in lookup table */
-#define INDEX_FRACTION   (8)       /* bits of fraction past TRANSFORM_SPP on kernel
-                                      index accumulation */
-#define TRANSFORM_MIN    (.5 / TRANSFORM_SPP)
-
 /* Sinc needed for Lanczos kernel */
 static float sinc(const float x)
 {
+       if(fabsf(x) < TRANSFORM_MIN) return 1.0f;
        float y = x * M_PI;
-
-       if(fabsf(x) < TRANSFORM_MIN)
-               return 1.0f;
-
        return sinf(y) / y;
 }
 
@@ -405,852 +354,4 @@ int OverlayFrame::overlay(VFrame *output, VFrame *input,
        return 0;
 }
 
-// NORMAL      [Sa + Da * (1 - Sa), Sc * Sa + Dc * (1 - Sa)])
-#define ALPHA_NORMAL(mx, Sa, Da) (Sa + (Da * (mx - Sa)) / mx)
-#define COLOR_NORMAL(mx, Sc, Sa, Dc, Da) ((Sc * Sa + Dc * (mx - Sa)) / mx)
-#define CHROMA_NORMAL COLOR_NORMAL
-
-// ADDITION    [(Sa + Da), (Sc + Dc)]
-#define ALPHA_ADDITION(mx, Sa, Da) (Sa + Da)
-#define COLOR_ADDITION(mx, Sc, Sa, Dc, Da) (Sc + Dc)
-#define CHROMA_ADDITION(mx, Sc, Sa, Dc, Da) (Sc + Dc)
-
-// SUBTRACT    [(Sa - Da), (Sc - Dc)]
-#define ALPHA_SUBTRACT(mx, Sa, Da) (Sa - Da)
-#define COLOR_SUBTRACT(mx, Sc, Sa, Dc, Da) (Sc - Dc)
-#define CHROMA_SUBTRACT(mx, Sc, Sa, Dc, Da) (Sc - Dc)
-
-// MULTIPLY    [(Sa * Da), Sc * Dc]
-#define ALPHA_MULTIPLY(mx, Sa, Da) ((Sa * Da) / mx)
-#define COLOR_MULTIPLY(mx, Sc, Sa, Dc, Da) ((Sc * Dc) / mx)
-#define CHROMA_MULTIPLY(mx, Sc, Sa, Dc, Da) ((Sc * Dc) / mx)
-
-// DIVIDE      [(Sa / Da), (Sc / Dc)]
-#define ALPHA_DIVIDE(mx, Sa, Da) (Da ? ((Sa * mx) / Da) : mx)
-#define COLOR_DIVIDE(mx, Sc, Sa, Dc, Da) (Dc ? ((Sc * mx) / Dc) : mx)
-#define CHROMA_DIVIDE(mx, Sc, Sa, Dc, Da) (Dc ? ((Sc * mx) / Dc) : mx)
-
-// REPLACE     [Sa, Sc] (fade = 1)
-#define ALPHA_REPLACE(mx, Sa, Da) Sa
-#define COLOR_REPLACE(mx, Sc, Sa, Dc, Da) Sc
-#define CHROMA_REPLACE COLOR_REPLACE
-
-// MAX         [max(Sa, Da), MAX(Sc, Dc)]
-#define ALPHA_MAX(mx, Sa, Da) (Sa > Da ? Sa : Da)
-#define COLOR_MAX(mx, Sc, Sa, Dc, Da) (Sc > Dc ? Sc : Dc)
-#define CHROMA_MAX(mx, Sc, Sa, Dc, Da) (mabs(Sc) > mabs(Dc) ? Sc : Dc)
-
-// MIN         [min(Sa, Da), MIN(Sc, Dc)]
-#define ALPHA_MIN(mx, Sa, Da) (Sa < Da ? Sa : Da)
-#define COLOR_MIN(mx, Sc, Sa, Dc, Da) (Sc < Dc ? Sc : Dc)
-#define CHROMA_MIN(mx, Sc, Sa, Dc, Da) (mabs(Sc) < mabs(Dc) ? Sc : Dc)
-
-// AVERAGE     [(Sa + Da) * 0.5, (Sc + Dc) * 0.5]
-#define ALPHA_AVERAGE(mx, Sa, Da) ((Sa + Da) / 2)
-#define COLOR_AVERAGE(mx, Sc, Sa, Dc, Da) ((Sc + Dc) / 2)
-#define CHROMA_AVERAGE COLOR_AVERAGE
-
-// DARKEN      [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)]  
-#define ALPHA_DARKEN(mx, Sa, Da) (Sa + Da - (Sa * Da) / mx)
-#define COLOR_DARKEN(mx, Sc, Sa, Dc, Da) ((Sc * (mx - Da) + Dc * (mx - Sa)) / mx + (Sc < Dc ? Sc : Dc))
-#define CHROMA_DARKEN(mx, Sc, Sa, Dc, Da) ((Sc * (mx - Da) + Dc * (mx - Sa)) / mx + (mabs(Sc) < mabs(Dc) ? Sc : Dc))
-
-// LIGHTEN     [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)]  
-#define ALPHA_LIGHTEN(mx, Sa, Da) (Sa + Da - Sa * Da / mx)
-#define COLOR_LIGHTEN(mx, Sc, Sa, Dc, Da) ((Sc * (mx - Da) + Dc * (mx - Sa)) / mx + (Sc > Dc ? Sc : Dc))
-#define CHROMA_LIGHTEN(mx, Sc, Sa, Dc, Da) ((Sc * (mx - Da) + Dc * (mx - Sa)) / mx + (mabs(Sc) > mabs(Dc) ? Sc : Dc))
-
-// DST         [Da, Dc]  
-#define ALPHA_DST(mx, Sa, Da) Da
-#define COLOR_DST(mx, Sc, Sa, Dc, Da) Dc
-#define CHROMA_DST COLOR_DST
-
-// DST_ATOP    [Sa, Sc * (1 - Da) + Dc * Sa]
-#define ALPHA_DST_ATOP(mx, Sa, Da) Sa
-#define COLOR_DST_ATOP(mx, Sc, Sa, Dc, Da) ((Sc * (mx - Da) + Dc * Sa) / mx)
-#define CHROMA_DST_ATOP COLOR_DST_ATOP
-
-// DST_IN      [Da * Sa, Dc * Sa]  
-#define ALPHA_DST_IN(mx, Sa, Da) ((Da * Sa) / mx)
-#define COLOR_DST_IN(mx, Sc, Sa, Dc, Da) ((Dc * Sa) / mx)
-#define CHROMA_DST_IN COLOR_DST_IN
-
-// DST_OUT     [Da * (1 - Sa), Dc * (1 - Sa)]  
-#define ALPHA_DST_OUT(mx, Sa, Da) (Da * (mx - Sa) / mx)
-#define COLOR_DST_OUT(mx, Sc, Sa, Dc, Da) (Dc * (mx - Sa) / mx)
-#define CHROMA_DST_OUT COLOR_DST_OUT
-
-// DST_OVER    [Sa * (1 - Da) + Da, Sc * (1 - Da) + Dc]  
-#define ALPHA_DST_OVER(mx, Sa, Da) ((Sa * (mx - Da)) / mx + Da)
-#define COLOR_DST_OVER(mx, Sc, Sa, Dc, Da) (Sc * (mx - Da)/ mx + Dc)
-#define CHROMA_DST_OVER COLOR_DST_OVER
-
-// SRC                 [Sa, Sc]  
-#define ALPHA_SRC(mx, Sa, Da) Sa
-#define COLOR_SRC(mx, Sc, Sa, Dc, Da) Sc
-#define CHROMA_SRC COLOR_SRC
-
-// SRC_ATOP    [Da, Sc * Da + Dc * (1 - Sa)]  
-#define ALPHA_SRC_ATOP(mx, Sa, Da) Da
-#define COLOR_SRC_ATOP(mx, Sc, Sa, Dc, Da) ((Sc * Da + Dc * (mx - Sa)) / mx)
-#define CHROMA_SRC_ATOP COLOR_SRC_ATOP
-
-// SRC_IN      [Sa * Da, Sc * Da]  
-#define ALPHA_SRC_IN(mx, Sa, Da) ((Sa * Da) / mx)
-#define COLOR_SRC_IN(mx, Sc, Sa, Dc, Da) (Sc * Da / mx)
-#define CHROMA_SRC_IN COLOR_SRC_IN
-
-// SRC_OUT     [Sa * (1 - Da), Sc * (1 - Da)]  
-#define ALPHA_SRC_OUT(mx, Sa, Da) (Sa * (mx - Da) / mx)
-#define COLOR_SRC_OUT(mx, Sc, Sa, Dc, Da) (Sc * (mx - Da) / mx)
-#define CHROMA_SRC_OUT COLOR_SRC_OUT
-
-// SRC_OVER    [Sa + Da * (1 - Sa), Sc + (1 - Sa) * Dc]  
-#define ALPHA_SRC_OVER(mx, Sa, Da) (Sa + Da * (mx - Sa) / mx)
-#define COLOR_SRC_OVER(mx, Sc, Sa, Dc, Da) (Sc + Dc * (mx - Sa) / mx)
-#define CHROMA_SRC_OVER COLOR_SRC_OVER
-
-// OR          [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]   
-#define ALPHA_OR(mx, Sa, Da) (Sa + Da - (Sa * Da) / mx)
-#define COLOR_OR(mx, Sc, Sa, Dc, Da) (Sc + Dc - (Sc * Dc) / mx)
-#define CHROMA_OR COLOR_OR
-
-// XOR         [Sa * (1 - Da) + Da * (1 - Sa), Sc * (1 - Da) + Dc * (1 - Sa)]   
-#define ALPHA_XOR(mx, Sa, Da) ((Sa * (mx - Da) + Da * (mx - Sa)) / mx)
-#define COLOR_XOR(mx, Sc, Sa, Dc, Da) ((Sc * (mx - Da) + Dc * (mx - Sa)) / mx)
-#define CHROMA_XOR COLOR_XOR
-
-#define ZTYP(ty) typedef ty z_##ty __attribute__ ((__unused__))
-ZTYP(int8_t);  ZTYP(uint8_t);
-ZTYP(int16_t); ZTYP(uint16_t);
-ZTYP(int32_t); ZTYP(uint32_t);
-ZTYP(int64_t); ZTYP(uint64_t);
-ZTYP(float);   ZTYP(double);
-
-#define ALPHA3_BLEND(FN, typ, inp, out, mx, iofs, oofs, rnd) \
-  typ inp0 = (typ)inp[0], inp1 = (typ)inp[1] - iofs; \
-  typ inp2 = (typ)inp[2] - iofs, inp3 = mx; \
-  typ out0 = (typ)out[0], out1 = (typ)out[1] - oofs; \
-  typ out2 = (typ)out[2] - oofs, out3 = mx; \
-  r = COLOR_##FN(mx, inp0, inp3, out0, out3); \
-  if( oofs ) { \
-    g = CHROMA_##FN(mx, inp1, inp3, out1, out3); \
-    b = CHROMA_##FN(mx, inp2, inp3, out2, out3); \
-  } \
-  else { \
-    g = COLOR_##FN(mx, inp1, inp3, out1, out3); \
-    b = COLOR_##FN(mx, inp2, inp3, out2, out3); \
-  }
-
-#define ALPHA4_BLEND(FN, typ, inp, out, mx, iofs, oofs, rnd) \
-  typ inp0 = (typ)inp[0], inp1 = (typ)inp[1] - iofs; \
-  typ inp2 = (typ)inp[2] - iofs, inp3 = inp[3]; \
-  typ out0 = (typ)out[0], out1 = (typ)out[1] - oofs; \
-  typ out2 = (typ)out[2] - oofs, out3 = out[3]; \
-  r = COLOR_##FN(mx, inp0, inp3, out0, out3); \
-  if( oofs ) { \
-    g = CHROMA_##FN(mx, inp1, inp3, out1, out3); \
-    b = CHROMA_##FN(mx, inp2, inp3, out2, out3); \
-  } \
-  else { \
-    g = COLOR_##FN(mx, inp1, inp3, out1, out3); \
-    b = COLOR_##FN(mx, inp2, inp3, out2, out3); \
-  } \
-  a = ALPHA_##FN(mx, inp3, out3)
-
-#define ALPHA_STORE(out, ofs, mx) \
-  out[0] = r; \
-  out[1] = g + ofs; \
-  out[2] = b + ofs
-
-#define ALPHA3_STORE(out, ofs, mx) \
-  r = aclip(r, mx); \
-  g = ofs ? cclip(g, mx) : aclip(g, mx); \
-  b = ofs ? cclip(b, mx) : aclip(b, mx); \
-  if( trnsp ) { \
-    r = (r * opcty + out0 * trnsp) / mx; \
-    g = (g * opcty + out1 * trnsp) / mx; \
-    b = (b * opcty + out2 * trnsp) / mx; \
-  } \
-  ALPHA_STORE(out, ofs, mx)
-
-#define ALPHA4_STORE(out, ofs, mx) \
-  r = aclip(r, mx); \
-  g = ofs ? cclip(g, mx) : aclip(g, mx); \
-  b = ofs ? cclip(b, mx) : aclip(b, mx); \
-  if( trnsp ) { \
-    r = (r * opcty + out0 * trnsp) / mx; \
-    g = (g * opcty + out1 * trnsp) / mx; \
-    b = (b * opcty + out2 * trnsp) / mx; \
-    a = (a * opcty + out3 * trnsp) / mx; \
-  } \
-  ALPHA_STORE(out, ofs, mx); \
-  out[3] = aclip(a, mx)
-
-#define XBLEND(FN, temp_type, type, max, components, ofs, round) { \
-       temp_type opcty = fade * max + round, trnsp = max - opcty; \
-       type** output_rows = (type**)output->get_rows(); \
-       type** input_rows = (type**)input->get_rows(); \
-       ix *= components;  ox *= components; \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) { \
-               type* in_row = input_rows[i + iy] + ix; \
-               type* output = output_rows[i] + ox; \
-               for(int j = 0; j < ow; j++) { \
-                       if( components == 4 ) { \
-                               temp_type r, g, b, a; \
-                               ALPHA4_BLEND(FN, temp_type, in_row, output, max, ofs, ofs, round); \
-                               ALPHA4_STORE(output, ofs, max); \
-                       } \
-                       else { \
-                               temp_type r, g, b; \
-                               ALPHA3_BLEND(FN, temp_type, in_row, output, max, ofs, ofs, round); \
-                               ALPHA3_STORE(output, ofs, max); \
-                       } \
-                       in_row += components;  output += components; \
-               } \
-       } \
-       break; \
-}
-
-#define XBLEND_ONLY(FN) { \
-       switch(input->get_color_model()) { \
-       case BC_RGB_FLOAT:      XBLEND(FN, z_float,   z_float,    1.f,    3, 0,      0.f); \
-       case BC_RGBA_FLOAT:     XBLEND(FN, z_float,   z_float,    1.f,    4, 0,      0.f); \
-       case BC_RGB888:         XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   3, 0,      .5f); \
-       case BC_YUV888:         XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   3, 0x80,   .5f); \
-       case BC_RGBA8888:       XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   4, 0,      .5f); \
-       case BC_YUVA8888:       XBLEND(FN, z_int32_t, z_uint8_t,  0xff,   4, 0x80,   .5f); \
-       case BC_RGB161616:      XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0,      .5f); \
-       case BC_YUV161616:      XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0x8000, .5f); \
-       case BC_RGBA16161616:   XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0,      .5f); \
-       case BC_YUVA16161616:   XBLEND(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0x8000, .5f); \
-       } \
-       break; \
-}
-
-/* Direct translate / blend **********************************************/
-
-DirectPackage::DirectPackage()
-{
-}
-
-DirectUnit::DirectUnit(DirectEngine *server)
- : LoadClient(server)
-{
-       this->engine = server;
-}
-
-DirectUnit::~DirectUnit()
-{
-}
-
-void DirectUnit::process_package(LoadPackage *package)
-{
-       DirectPackage *pkg = (DirectPackage*)package;
-
-       VFrame *output = engine->output;
-       VFrame *input = engine->input;
-       int mode = engine->mode;
-       float fade =
-               BC_CModels::has_alpha(input->get_color_model()) &&
-               mode == TRANSFER_REPLACE ? 1.f : engine->alpha;
-
-       int ix = engine->in_x1;
-       int ox = engine->out_x1;
-       int ow = engine->out_x2 - ox;
-       int iy = engine->in_y1 - engine->out_y1;
-
-       switch( mode ) {
-        case TRANSFER_NORMAL:          XBLEND_ONLY(NORMAL);
-        case TRANSFER_ADDITION:                XBLEND_ONLY(ADDITION);
-        case TRANSFER_SUBTRACT:                XBLEND_ONLY(SUBTRACT);
-        case TRANSFER_MULTIPLY:                XBLEND_ONLY(MULTIPLY);
-        case TRANSFER_DIVIDE:          XBLEND_ONLY(DIVIDE);
-        case TRANSFER_REPLACE:                 XBLEND_ONLY(REPLACE);
-        case TRANSFER_MAX:             XBLEND_ONLY(MAX);
-        case TRANSFER_MIN:             XBLEND_ONLY(MIN);
-       case TRANSFER_AVERAGE:          XBLEND_ONLY(AVERAGE);
-       case TRANSFER_DARKEN:           XBLEND_ONLY(DARKEN);
-       case TRANSFER_LIGHTEN:          XBLEND_ONLY(LIGHTEN);
-       case TRANSFER_DST:              XBLEND_ONLY(DST);
-       case TRANSFER_DST_ATOP:         XBLEND_ONLY(DST_ATOP);
-       case TRANSFER_DST_IN:           XBLEND_ONLY(DST_IN);
-       case TRANSFER_DST_OUT:          XBLEND_ONLY(DST_OUT);
-       case TRANSFER_DST_OVER:         XBLEND_ONLY(DST_OVER);
-       case TRANSFER_SRC:              XBLEND_ONLY(SRC);
-       case TRANSFER_SRC_ATOP:         XBLEND_ONLY(SRC_ATOP);
-       case TRANSFER_SRC_IN:           XBLEND_ONLY(SRC_IN);
-       case TRANSFER_SRC_OUT:          XBLEND_ONLY(SRC_OUT);
-       case TRANSFER_SRC_OVER:         XBLEND_ONLY(SRC_OVER);
-       case TRANSFER_OR:               XBLEND_ONLY(OR);
-       case TRANSFER_XOR:              XBLEND_ONLY(XOR);
-       }
-}
-
-DirectEngine::DirectEngine(int cpus)
- : LoadServer(cpus, cpus)
-{
-}
-
-DirectEngine::~DirectEngine()
-{
-}
-
-void DirectEngine::init_packages()
-{
-       if(in_x1 < 0) { out_x1 -= in_x1; in_x1 = 0; }
-       if(in_y1 < 0) { out_y1 -= in_y1; in_y1 = 0; }
-       if(out_x1 < 0) { in_x1 -= out_x1; out_x1 = 0; }
-       if(out_y1 < 0) { in_y1 -= out_y1; out_y1 = 0; }
-       if(out_x2 > output->get_w()) out_x2 = output->get_w();
-       if(out_y2 > output->get_h()) out_y2 = output->get_h();
-       int out_w = out_x2 - out_x1;
-       int out_h = out_y2 - out_y1;
-       if( !out_w || !out_h ) return;
-
-       int rows = out_h;
-       int pkgs = get_total_packages();
-       int row1 = out_y1, row2 = row1;
-       for(int i = 0; i < pkgs; row1=row2 ) {
-               DirectPackage *package = (DirectPackage*)get_package(i);
-               row2 = ++i * rows / pkgs + out_y1;
-               package->out_row1 = row1;
-               package->out_row2 = row2;
-       }
-}
-
-LoadClient* DirectEngine::new_client()
-{
-       return new DirectUnit(this);
-}
-
-LoadPackage* DirectEngine::new_package()
-{
-       return new DirectPackage;
-}
-
-/* Nearest Neighbor scale / translate / blend ********************/
-
-#define XBLEND_3NN(FN, temp_type, type, max, components, ofs, round) { \
-       temp_type opcty = fade * max + round, trnsp = max - opcty; \
-       type** output_rows = (type**)output->get_rows(); \
-       type** input_rows = (type**)input->get_rows(); \
-       ox *= components; \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) { \
-               int *lx = engine->in_lookup_x; \
-               type* in_row = input_rows[*ly++]; \
-               type* output = output_rows[i] + ox; \
-               for(int j = 0; j < ow; j++) { \
-                       in_row += *lx++; \
-                       if( components == 4 ) { \
-                               temp_type r, g, b, a; \
-                               ALPHA4_BLEND(FN, temp_type, in_row, output, max, ofs, ofs, round); \
-                               ALPHA4_STORE(output, ofs, max); \
-                       } \
-                       else { \
-                               temp_type r, g, b; \
-                               ALPHA3_BLEND(FN, temp_type, in_row, output, max, ofs, ofs, round); \
-                               ALPHA3_STORE(output, ofs, max); \
-                       } \
-                       output += components; \
-               } \
-       } \
-       break; \
-}
-
-#define XBLEND_NN(FN) { \
-       switch(input->get_color_model()) { \
-       case BC_RGB_FLOAT:      XBLEND_3NN(FN, z_float,   z_float,    1.f,    3, 0,       0.f); \
-       case BC_RGBA_FLOAT:     XBLEND_3NN(FN, z_float,   z_float,    1.f,    4, 0,       0.f); \
-       case BC_RGB888:         XBLEND_3NN(FN, z_int32_t, z_uint8_t,  0xff,   3, 0,      .5f); \
-       case BC_YUV888:         XBLEND_3NN(FN, z_int32_t, z_uint8_t,  0xff,   3, 0x80,   .5f); \
-       case BC_RGBA8888:       XBLEND_3NN(FN, z_int32_t, z_uint8_t,  0xff,   4, 0,      .5f); \
-       case BC_YUVA8888:       XBLEND_3NN(FN, z_int32_t, z_uint8_t,  0xff,   4, 0x80,   .5f); \
-       case BC_RGB161616:      XBLEND_3NN(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0,      .5f); \
-       case BC_YUV161616:      XBLEND_3NN(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0x8000, .5f); \
-       case BC_RGBA16161616:   XBLEND_3NN(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0,      .5f); \
-       case BC_YUVA16161616:   XBLEND_3NN(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0x8000, .5f); \
-       } \
-       break; \
-}
-
-NNPackage::NNPackage()
-{
-}
-
-NNUnit::NNUnit(NNEngine *server)
- : LoadClient(server)
-{
-       this->engine = server;
-}
-
-NNUnit::~NNUnit()
-{
-}
-
-void NNUnit::process_package(LoadPackage *package)
-{
-       NNPackage *pkg = (NNPackage*)package;
-       VFrame *output = engine->output;
-       VFrame *input = engine->input;
-       int mode = engine->mode;
-       float fade =
-               BC_CModels::has_alpha(input->get_color_model()) &&
-               mode == TRANSFER_REPLACE ? 1.f : engine->alpha;
 
-       int ox = engine->out_x1i;
-       int ow = engine->out_x2i - ox;
-       int *ly = engine->in_lookup_y + pkg->out_row1;
-
-       switch( mode ) {
-        case TRANSFER_NORMAL:          XBLEND_NN(NORMAL);
-        case TRANSFER_ADDITION:                XBLEND_NN(ADDITION);
-        case TRANSFER_SUBTRACT:                XBLEND_NN(SUBTRACT);
-        case TRANSFER_MULTIPLY:                XBLEND_NN(MULTIPLY);
-        case TRANSFER_DIVIDE:          XBLEND_NN(DIVIDE);
-        case TRANSFER_REPLACE:                 XBLEND_NN(REPLACE);
-        case TRANSFER_MAX:             XBLEND_NN(MAX);
-        case TRANSFER_MIN:             XBLEND_NN(MIN);
-       case TRANSFER_AVERAGE:          XBLEND_NN(AVERAGE);
-       case TRANSFER_DARKEN:           XBLEND_NN(DARKEN);
-       case TRANSFER_LIGHTEN:          XBLEND_NN(LIGHTEN);
-       case TRANSFER_DST:              XBLEND_NN(DST);
-       case TRANSFER_DST_ATOP:         XBLEND_NN(DST_ATOP);
-       case TRANSFER_DST_IN:           XBLEND_NN(DST_IN);
-       case TRANSFER_DST_OUT:          XBLEND_NN(DST_OUT);
-       case TRANSFER_DST_OVER:         XBLEND_NN(DST_OVER);
-       case TRANSFER_SRC:              XBLEND_NN(SRC);
-       case TRANSFER_SRC_ATOP:         XBLEND_NN(SRC_ATOP);
-       case TRANSFER_SRC_IN:           XBLEND_NN(SRC_IN);
-       case TRANSFER_SRC_OUT:          XBLEND_NN(SRC_OUT);
-       case TRANSFER_SRC_OVER:         XBLEND_NN(SRC_OVER);
-       case TRANSFER_OR:               XBLEND_NN(OR);
-       case TRANSFER_XOR:              XBLEND_NN(XOR);
-       }
-}
-
-NNEngine::NNEngine(int cpus)
- : LoadServer(cpus, cpus)
-{
-       in_lookup_x = 0;
-       in_lookup_y = 0;
-}
-
-NNEngine::~NNEngine()
-{
-       if(in_lookup_x)
-               delete[] in_lookup_x;
-       if(in_lookup_y)
-               delete[] in_lookup_y;
-}
-
-void NNEngine::init_packages()
-{
-       int in_w = input->get_w();
-       int in_h = input->get_h();
-       int out_w = output->get_w();
-       int out_h = output->get_h();
-
-       float in_subw = in_x2 - in_x1;
-       float in_subh = in_y2 - in_y1;
-       float out_subw = out_x2 - out_x1;
-       float out_subh = out_y2 - out_y1;
-       int first, last, count, i;
-       int components = 3;
-
-       out_x1i = rint(out_x1);
-       out_x2i = rint(out_x2);
-       if(out_x1i < 0) out_x1i = 0;
-       if(out_x1i > out_w) out_x1i = out_w;
-       if(out_x2i < 0) out_x2i = 0;
-       if(out_x2i > out_w) out_x2i = out_w;
-       int out_wi = out_x2i - out_x1i;
-       if( !out_wi ) return;
-
-       delete[] in_lookup_x;
-       in_lookup_x = new int[out_wi];
-       delete[] in_lookup_y;
-       in_lookup_y = new int[out_h];
-
-       switch(input->get_color_model()) {
-       case BC_RGBA_FLOAT:
-       case BC_RGBA8888:
-       case BC_YUVA8888:
-       case BC_RGBA16161616:
-               components = 4;
-               break;
-       }
-
-       first = count = 0;
-
-       for(i = out_x1i; i < out_x2i; i++) {
-               int in = (i - out_x1 + .5) * in_subw / out_subw + in_x1;
-               if(in < in_x1)
-                       in = in_x1;
-               if(in > in_x2)
-                       in = in_x2;
-
-               if(in >= 0 && in < in_w && in >= in_x1 && i >= 0 && i < out_w) {
-                       if(count == 0) {
-                               first = i;
-                               in_lookup_x[0] = in * components;
-                       }
-                       else {
-                               in_lookup_x[count] = (in-last)*components;
-                       }
-                       last = in;
-                       count++;
-               }
-               else if(count)
-                       break;
-       }
-       out_x1i = first;
-       out_x2i = first + count;
-       first = count = 0;
-
-       for(i = out_y1; i < out_y2; i++) {
-               int in = (i - out_y1+.5) * in_subh / out_subh + in_y1;
-               if(in < in_y1) in = in_y1;
-               if(in > in_y2) in = in_y2;
-               if(in >= 0 && in < in_h && i >= 0 && i < out_h) {
-                       if(count == 0) first = i;
-                       in_lookup_y[i] = in;
-                       count++;
-               }
-               else if(count)
-                       break;
-       }
-       out_y1 = first;
-       out_y2 = first + count;
-
-       int rows = count;
-       int pkgs = get_total_packages();
-       int row1 = out_y1, row2 = row1;
-       for(int i = 0; i < pkgs; row1=row2 ) {
-               NNPackage *package = (NNPackage*)get_package(i);
-               row2 = ++i * rows / pkgs + out_y1;
-               package->out_row1 = row1;
-               package->out_row2 = row2;
-       }
-}
-
-LoadClient* NNEngine::new_client()
-{
-       return new NNUnit(this);
-}
-
-LoadPackage* NNEngine::new_package()
-{
-       return new NNPackage;
-}
-
-/* Fully resampled scale / translate / blend ******************************/
-/* resample into a temporary row vector, then blend */
-
-#define XSAMPLE(FN, temp_type, type, max, components, ofs, round) { \
-       float temp[oh*components]; \
-       temp_type opcty = fade * max + round, trnsp = max - opcty; \
-       type **output_rows = (type**)voutput->get_rows() + o1i; \
-       type **input_rows = (type**)vinput->get_rows(); \
- \
-       for(int i = pkg->out_col1; i < pkg->out_col2; i++) { \
-               type *input = input_rows[i - engine->col_out1 + engine->row_in]; \
-               float *tempp = temp; \
-               if( !k ) { /* direct copy case */ \
-                       type *ip = input + i1i * components; \
-                       for(int j = 0; j < oh; j++) { \
-                               *tempp++ = *ip++; \
-                               *tempp++ = *ip++ - ofs; \
-                               *tempp++ = *ip++ - ofs; \
-                               if( components == 4 ) *tempp++ = *ip++; \
-                       } \
-               } \
-               else { /* resample */ \
-                       for(int j = 0; j < oh; j++) { \
-                               float racc=0.f, gacc=0.f, bacc=0.f, aacc=0.f; \
-                               int ki = lookup_sk[j], x = lookup_sx0[j]; \
-                               type *ip = input + x * components; \
-                               float wacc = 0, awacc = 0; \
-                               while(x++ < lookup_sx1[j]) { \
-                                       float kv = k[abs(ki >> INDEX_FRACTION)]; \
-                                       /* handle fractional pixels on edges of input */ \
-                                       if(x == i1i) kv *= i1f; \
-                                       if(x + 1 == i2i) kv *= i2f; \
-                                       if( components == 4 ) { awacc += kv;  kv *= ip[3]; } \
-                                       wacc += kv; \
-                                       racc += kv * *ip++; \
-                                       gacc += kv * (*ip++ - ofs); \
-                                       bacc += kv * (*ip++ - ofs); \
-                                       if( components == 4 ) { aacc += kv;  ++ip; } \
-                                       ki += kd; \
-                               } \
-                               if(wacc > 0.) wacc = 1. / wacc; \
-                               *tempp++ = racc * wacc; \
-                               *tempp++ = gacc * wacc; \
-                               *tempp++ = bacc * wacc; \
-                               if( components == 4 ) { \
-                                       if(awacc > 0.) awacc = 1. / awacc; \
-                                       *tempp++ = aacc * awacc; \
-                               } \
-                       } \
-               } \
- \
-               /* handle fractional pixels on edges of output */ \
-               temp[0] *= o1f;   temp[1] *= o1f;   temp[2] *= o1f; \
-               if( components == 4 ) temp[3] *= o1f; \
-               tempp = temp + (oh-1)*components; \
-               tempp[0] *= o2f;  tempp[1] *= o2f;  tempp[2] *= o2f; \
-               if( components == 4 ) tempp[3] *= o2f; \
-               tempp = temp; \
-               /* blend output */ \
-               for(int j = 0; j < oh; j++) { \
-                       type *output = output_rows[j] + i * components; \
-                       if( components == 4 ) { \
-                               temp_type r, g, b, a; \
-                               ALPHA4_BLEND(FN, temp_type, tempp, output, max, 0, ofs, round); \
-                               ALPHA4_STORE(output, ofs, max); \
-                       } \
-                       else { \
-                               temp_type r, g, b; \
-                               ALPHA3_BLEND(FN, temp_type, tempp, output, max, 0, ofs, round); \
-                               ALPHA3_STORE(output, ofs, max); \
-                       } \
-                       tempp += components; \
-               } \
-       } \
-       break; \
-}
-
-#define XBLEND_SAMPLE(FN) { \
-        switch(vinput->get_color_model()) { \
-        case BC_RGB_FLOAT:      XSAMPLE(FN, z_float,   z_float,    1.f,    3, 0.f,    0.f); \
-        case BC_RGBA_FLOAT:     XSAMPLE(FN, z_float,   z_float,    1.f,    4, 0.f,    0.f); \
-        case BC_RGB888:         XSAMPLE(FN, z_int32_t, z_uint8_t,  0xff,   3, 0,      .5f); \
-        case BC_YUV888:         XSAMPLE(FN, z_int32_t, z_uint8_t,  0xff,   3, 0x80,   .5f); \
-        case BC_RGBA8888:       XSAMPLE(FN, z_int32_t, z_uint8_t,  0xff,   4, 0,      .5f); \
-        case BC_YUVA8888:       XSAMPLE(FN, z_int32_t, z_uint8_t,  0xff,   4, 0x80,   .5f); \
-        case BC_RGB161616:      XSAMPLE(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0,      .5f); \
-        case BC_YUV161616:      XSAMPLE(FN, z_int64_t, z_uint16_t, 0xffff, 3, 0x8000, .5f); \
-        case BC_RGBA16161616:   XSAMPLE(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0,      .5f); \
-        case BC_YUVA16161616:   XSAMPLE(FN, z_int64_t, z_uint16_t, 0xffff, 4, 0x8000, .5f); \
-        } \
-        break; \
-}
-
-
-SamplePackage::SamplePackage()
-{
-}
-
-SampleUnit::SampleUnit(SampleEngine *server)
- : LoadClient(server)
-{
-       this->engine = server;
-}
-
-SampleUnit::~SampleUnit()
-{
-}
-
-void SampleUnit::process_package(LoadPackage *package)
-{
-       SamplePackage *pkg = (SamplePackage*)package;
-
-       float i1  = engine->in1;
-       float i2  = engine->in2;
-       float o1  = engine->out1;
-       float o2  = engine->out2;
-
-       if(i2 - i1 <= 0 || o2 - o1 <= 0)
-               return;
-
-       VFrame *voutput = engine->output;
-       VFrame *vinput = engine->input;
-       int mode = engine->mode;
-       float fade =
-               BC_CModels::has_alpha(vinput->get_color_model()) &&
-               mode == TRANSFER_REPLACE ? 1.f : engine->alpha;
-
-       //int   iw  = vinput->get_w();
-       int   i1i = floor(i1);
-       int   i2i = ceil(i2);
-       float i1f = 1.f - i1 + i1i;
-       float i2f = 1.f - i2i + i2;
-
-       int   o1i = floor(o1);
-       int   o2i = ceil(o2);
-       float o1f = 1.f - o1 + o1i;
-       float o2f = 1.f - o2i + o2;
-       int   oh  = o2i - o1i;
-
-       float *k  = engine->kernel->lookup;
-       //float kw  = engine->kernel->width;
-       //int   kn  = engine->kernel->n;
-       int   kd = engine->kd;
-
-       int *lookup_sx0 = engine->lookup_sx0;
-       int *lookup_sx1 = engine->lookup_sx1;
-       int *lookup_sk = engine->lookup_sk;
-       //float *lookup_wacc = engine->lookup_wacc;
-
-       switch( mode ) {
-        case TRANSFER_NORMAL:          XBLEND_SAMPLE(NORMAL);
-        case TRANSFER_ADDITION:                XBLEND_SAMPLE(ADDITION);
-        case TRANSFER_SUBTRACT:                XBLEND_SAMPLE(SUBTRACT);
-        case TRANSFER_MULTIPLY:                XBLEND_SAMPLE(MULTIPLY);
-        case TRANSFER_DIVIDE:          XBLEND_SAMPLE(DIVIDE);
-        case TRANSFER_REPLACE:                 XBLEND_SAMPLE(REPLACE);
-        case TRANSFER_MAX:             XBLEND_SAMPLE(MAX);
-        case TRANSFER_MIN:             XBLEND_SAMPLE(MIN);
-       case TRANSFER_AVERAGE:          XBLEND_SAMPLE(AVERAGE);
-       case TRANSFER_DARKEN:           XBLEND_SAMPLE(DARKEN);
-       case TRANSFER_LIGHTEN:          XBLEND_SAMPLE(LIGHTEN);
-       case TRANSFER_DST:              XBLEND_SAMPLE(DST);
-       case TRANSFER_DST_ATOP:         XBLEND_SAMPLE(DST_ATOP);
-       case TRANSFER_DST_IN:           XBLEND_SAMPLE(DST_IN);
-       case TRANSFER_DST_OUT:          XBLEND_SAMPLE(DST_OUT);
-       case TRANSFER_DST_OVER:         XBLEND_SAMPLE(DST_OVER);
-       case TRANSFER_SRC:              XBLEND_SAMPLE(SRC);
-       case TRANSFER_SRC_ATOP:         XBLEND_SAMPLE(SRC_ATOP);
-       case TRANSFER_SRC_IN:           XBLEND_SAMPLE(SRC_IN);
-       case TRANSFER_SRC_OUT:          XBLEND_SAMPLE(SRC_OUT);
-       case TRANSFER_SRC_OVER:         XBLEND_SAMPLE(SRC_OVER);
-       case TRANSFER_OR:               XBLEND_SAMPLE(OR);
-       case TRANSFER_XOR:              XBLEND_SAMPLE(XOR);
-       }
-}
-
-
-SampleEngine::SampleEngine(int cpus)
- : LoadServer(cpus, cpus)
-{
-       lookup_sx0 = 0;
-       lookup_sx1 = 0;
-       lookup_sk = 0;
-       lookup_wacc = 0;
-       kd = 0;
-}
-
-SampleEngine::~SampleEngine()
-{
-       if(lookup_sx0) delete [] lookup_sx0;
-       if(lookup_sx1) delete [] lookup_sx1;
-       if(lookup_sk) delete [] lookup_sk;
-       if(lookup_wacc) delete [] lookup_wacc;
-}
-
-/*
- * unlike the Direct and NN engines, the Sample engine works across
- * output columns (it makes for more economical memory addressing
- * during convolution)
- */
-void SampleEngine::init_packages()
-{
-       int   iw  = input->get_w();
-       int   i1i = floor(in1);
-       int   i2i = ceil(in2);
-       float i1f = 1.f - in1 + i1i;
-       float i2f = 1.f - i2i + in2;
-
-       int   oy  = floor(out1);
-       float oyf = out1 - oy;
-       int   oh  = ceil(out2) - oy;
-
-       float *k  = kernel->lookup;
-       float kw  = kernel->width;
-       int   kn  = kernel->n;
-
-       if(in2 - in1 <= 0 || out2 - out1 <= 0)
-               return;
-
-       /* determine kernel spatial coverage */
-       float scale = (out2 - out1) / (in2 - in1);
-       float iscale = (in2 - in1) / (out2 - out1);
-       float coverage = fabs(1.f / scale);
-       float bound = (coverage < 1.f ? kw : kw * coverage) - (.5f / TRANSFORM_SPP);
-       float coeff = (coverage < 1.f ? 1.f : scale) * TRANSFORM_SPP;
-
-       delete [] lookup_sx0;
-       delete [] lookup_sx1;
-       delete [] lookup_sk;
-       delete [] lookup_wacc;
-
-       lookup_sx0 = new int[oh];
-       lookup_sx1 = new int[oh];
-       lookup_sk = new int[oh];
-       lookup_wacc = new float[oh];
-
-       kd = (double)coeff * (1 << INDEX_FRACTION) + .5;
-
-       /* precompute kernel values and weight sums */
-       for(int i = 0; i < oh; i++) {
-               /* map destination back to source */
-               double sx = (i - oyf + .5) * iscale + in1 - .5;
-
-               /*
-                * clip iteration to source area but not source plane. Points
-                * outside the source plane count as transparent. Points outside
-                * the source area don't count at all.  The actual convolution
-                * later will be clipped to both, but we need to compute
-                * weights.
-                */
-               int sx0 = MAX((int)floor(sx - bound) + 1, i1i);
-               int sx1 = MIN((int)ceil(sx + bound), i2i);
-               int ki = (double)(sx0 - sx) * coeff * (1 << INDEX_FRACTION)
-                               + (1 << (INDEX_FRACTION - 1)) + .5;
-               float wacc=0.;
-
-               lookup_sx0[i] = -1;
-               lookup_sx1[i] = -1;
-
-               for(int j= sx0; j < sx1; j++) {
-                       int kv = (ki >> INDEX_FRACTION);
-                       if(kv > kn) break;
-                       if(kv >= -kn) {
-                               /*
-                                * the contribution of the first and last input pixel (if
-                                * fractional) are linearly weighted by the fraction
-                                */
-                               if(j == i1i)
-                                       wacc += k[abs(kv)] * i1f;
-                               else if(j + 1 == i2i)
-                                       wacc += k[abs(kv)] * i2f;
-                               else
-                                       wacc += k[abs(kv)];
-
-                               /* this is where we clip the kernel convolution to the source plane */
-                               if(j >= 0 && j < iw) {
-                                       if(lookup_sx0[i] == -1) {
-                                               lookup_sx0[i] = j;
-                                               lookup_sk[i] = ki;
-                                       }
-                                       lookup_sx1[i] = j + 1;
-                               }
-                       }
-                       ki += kd;
-               }
-               lookup_wacc[i] = wacc > 0. ? 1. / wacc : 0.;
-       }
-
-       int cols = col_out2 - col_out1;
-       int pkgs = get_total_packages();
-       int col1 = col_out1, col2 = col1;
-       for(int i = 0; i < pkgs; col1=col2 ) {
-               SamplePackage *package = (SamplePackage*)get_package(i);
-               col2 = ++i * cols / pkgs + col_out1;
-               package->out_col1 = col1;
-               package->out_col2 = col2;
-       }
-}
-
-LoadClient* SampleEngine::new_client()
-{
-       return new SampleUnit(this);
-}
-
-LoadPackage* SampleEngine::new_package()
-{
-       return new SamplePackage;
-}
diff --git a/cinelerra-5.1/cinelerra/overlayframe.C.clamp b/cinelerra-5.1/cinelerra/overlayframe.C.clamp
deleted file mode 100644 (file)
index c3ce4f1..0000000
+++ /dev/null
@@ -1,1796 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-
-#include "clip.h"
-#include "edl.inc"
-#include "mutex.h"
-#include "overlayframe.h"
-#include "vframe.h"
-
-OverlayFrame::OverlayFrame(int cpus)
-{
-       temp_frame = 0;
-       blend_engine = 0;
-       scale_engine = 0;
-       scaletranslate_engine = 0;
-       translate_engine = 0;
-       this->cpus = cpus;
-}
-
-OverlayFrame::~OverlayFrame()
-{
-//printf("OverlayFrame::~OverlayFrame 1\n");
-       if(temp_frame) delete temp_frame;
-       if(scale_engine) delete scale_engine;
-       if(translate_engine) delete translate_engine;
-       if(blend_engine) delete blend_engine;
-       if(scaletranslate_engine) delete scaletranslate_engine;
-//printf("OverlayFrame::~OverlayFrame 2\n");
-}
-
-
-
-
-
-
-
-
-// Verification: 
-
-// (255 * 255 + 0 * 0) / 255 = 255
-// (255 * 127 + 255 * (255 - 127)) / 255 = 255
-
-// (65535 * 65535 + 0 * 0) / 65535 = 65535
-// (65535 * 32767 + 65535 * (65535 - 32767)) / 65535 = 65535
-
-
-// Branch prediction 4 U
-
-#define BLEND_3(max, type) \
-{ \
-       int64_t r, g, b; \
- \
-/* if(mode != TRANSFER_NORMAL) printf("BLEND mode = %d\n", mode); */ \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * opacity + output[0] * transparency) / max; \
-                       g = ((int64_t)input2 * opacity + output[1] * transparency) / max; \
-                       b = ((int64_t)input3 * opacity + output[2] * transparency) / max; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-}
-
-
-
-
-
-// Blending equations are drastically different for 3 and 4 components
-#define BLEND_4(max, type) \
-{ \
-       int64_t r, g, b, a; \
-       int64_t pixel_opacity, pixel_transparency; \
- \
-       pixel_opacity = opacity * input4 / max; \
-       pixel_transparency = (max - pixel_opacity) * output[3] / max; \
- \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       a = input4; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = ((int64_t)input2 * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = ((int64_t)input3 * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-       output[3] = (type)a; \
-}
-
-
-
-
-
-
-
-
-// Bicubic algorithm using multiprocessors
-// input -> scale nearest integer boundaries -> temp -> translation -> blend -> output
-
-// Nearest neighbor algorithm using multiprocessors for blending
-// input -> scale + translate -> blend -> output
-
-
-int OverlayFrame::overlay(VFrame *output, 
-       VFrame *input, 
-       float in_x1, 
-       float in_y1, 
-       float in_x2, 
-       float in_y2, 
-       float out_x1, 
-       float out_y1, 
-       float out_x2, 
-       float out_y2, 
-       float alpha,       // 0 - 1
-       int mode,
-       int interpolation_type)
-{
-       float w_scale = (out_x2 - out_x1) / (in_x2 - in_x1);
-       float h_scale = (out_y2 - out_y1) / (in_y2 - in_y1);
-
-//printf("OverlayFrame::overlay 1 %d %f\n", mode, alpha);
-// Limit values
-       if(in_x1 < 0)
-       {
-               out_x1 += -in_x1 * w_scale;
-               in_x1 = 0;
-       }
-       else
-       if(in_x1 >= input->get_w())
-       {
-               out_x1 -= (in_x1 - input->get_w()) * w_scale;
-               in_x1 = input->get_w();
-       }
-
-       if(in_y1 < 0)
-       {
-               out_y1 += -in_y1 * h_scale;
-               in_y1 = 0;
-       }
-       else
-       if(in_y1 >= input->get_h())
-       {
-               out_y1 -= (in_y1 - input->get_h()) * h_scale;
-               in_y1 = input->get_h();
-       }
-
-       if(in_x2 < 0)
-       {
-               out_x2 += -in_x2 * w_scale;
-               in_x2 = 0;
-       }
-       else
-       if(in_x2 >= input->get_w())
-       {
-               out_x2 -= (in_x2 - input->get_w()) * w_scale;
-               in_x2 = input->get_w();
-       }
-
-       if(in_y2 < 0)
-       {
-               out_y2 += -in_y2 * h_scale;
-               in_y2 = 0;
-       }
-       else
-       if(in_y2 >= input->get_h())
-       {
-               out_y2 -= (in_y2 - input->get_h()) * h_scale;
-               in_y2 = input->get_h();
-       }
-
-       if(out_x1 < 0)
-       {
-               in_x1 += -out_x1 / w_scale;
-               out_x1 = 0;
-       }
-       else
-       if(out_x1 >= output->get_w())
-       {
-               in_x1 -= (out_x1 - output->get_w()) / w_scale;
-               out_x1 = output->get_w();
-       }
-
-       if(out_y1 < 0)
-       {
-               in_y1 += -out_y1 / h_scale;
-               out_y1 = 0;
-       }
-       else
-       if(out_y1 >= output->get_h())
-       {
-               in_y1 -= (out_y1 - output->get_h()) / h_scale;
-               out_y1 = output->get_h();
-       }
-
-       if(out_x2 < 0)
-       {
-               in_x2 += -out_x2 / w_scale;
-               out_x2 = 0;
-       }
-       else
-       if(out_x2 >= output->get_w())
-       {
-               in_x2 -= (out_x2 - output->get_w()) / w_scale;
-               out_x2 = output->get_w();
-       }
-
-       if(out_y2 < 0)
-       {
-               in_y2 += -out_y2 / h_scale;
-               out_y2 = 0;
-       }
-       else
-       if(out_y2 >= output->get_h())
-       {
-               in_y2 -= (out_y2 - output->get_h()) / h_scale;
-               out_y2 = output->get_h();
-       }
-
-
-
-
-
-       float in_w = in_x2 - in_x1;
-       float in_h = in_y2 - in_y1;
-       float out_w = out_x2 - out_x1;
-       float out_h = out_y2 - out_y1;
-// Input for translation operation
-       VFrame *translation_input = input;
-
-
-
-// printf("OverlayFrame::overlay %f %f %f %f -> %f %f %f %f\n", in_x1,
-//                     in_y1,
-//                     in_x2,
-//                     in_y2,
-//                     out_x1,
-//                     out_y1,
-//                     out_x2,
-//                     out_y2);
-
-
-
-
-
-// ****************************************************************************
-// Transfer to temp buffer by scaling nearest integer boundaries
-// ****************************************************************************
-       if(interpolation_type != NEAREST_NEIGHBOR &&
-               (!EQUIV(w_scale, 1) || !EQUIV(h_scale, 1)))
-       {
-// Create integer boundaries for interpolation
-               int in_x1_int = (int)in_x1;
-               int in_y1_int = (int)in_y1;
-               int in_x2_int = MIN((int)ceil(in_x2), input->get_w());
-               int in_y2_int = MIN((int)ceil(in_y2), input->get_h());
-
-// Dimensions of temp frame.  Integer boundaries scaled.
-               int temp_w = (int)ceil(w_scale * (in_x2_int - in_x1_int));
-               int temp_h = (int)ceil(h_scale * (in_y2_int - in_y1_int));
-               VFrame *scale_output;
-
-
-
-#define NO_TRANSLATION1 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(in_x2, in_x2_int) && \
-       EQUIV(in_y2, in_y2_int) && \
-       EQUIV(out_x2, temp_w) && \
-       EQUIV(out_y2, temp_h))
-
-
-#define NO_BLEND \
-       (EQUIV(alpha, 1) && \
-       (mode == TRANSFER_REPLACE || \
-       (mode == TRANSFER_NORMAL && cmodel_components(input->get_color_model()) == 3)))
-
-
-
-
-
-// Prepare destination for operation
-
-// No translation and no blending.  The blending operation is built into the
-// translation unit but not the scaling unit.
-// input -> output
-               if(NO_TRANSLATION1 &&
-                       NO_BLEND)
-               {
-// printf("OverlayFrame::overlay input -> output\n");
-
-                       scale_output = output;
-                       translation_input = 0;
-               }
-               else
-// If translation or blending
-// input -> nearest integer boundary temp
-               {
-                       if(temp_frame && 
-                               (temp_frame->get_w() != temp_w ||
-                                       temp_frame->get_h() != temp_h))
-                       {
-                               delete temp_frame;
-                               temp_frame = 0;
-                       }
-
-                       if(!temp_frame)
-                       {
-                               temp_frame = new VFrame(0,
-                                       temp_w,
-                                       temp_h,
-                                       input->get_color_model(),
-                                       -1);
-                       }
-//printf("OverlayFrame::overlay input -> temp\n");
-
-
-                       temp_frame->clear_frame();
-
-// printf("OverlayFrame::overlay 4 temp_w=%d temp_h=%d\n",
-//     temp_w, temp_h);
-                       scale_output = temp_frame;
-                       translation_input = scale_output;
-
-// Adjust input coordinates to reflect new scaled coordinates.
-                       in_x1 = (in_x1 - in_x1_int) * w_scale;
-                       in_y1 = (in_y1 - in_y1_int) * h_scale;
-                       in_x2 = (in_x2 - in_x1_int) * w_scale;
-                       in_y2 = (in_y2 - in_y1_int) * h_scale;
-               }
-
-
-
-//printf("Overlay 1\n");
-
-// Scale input -> scale_output
-               if(!scale_engine) scale_engine = new ScaleEngine(this, cpus);
-               scale_engine->scale_output = scale_output;
-               scale_engine->scale_input = input;
-               scale_engine->w_scale = w_scale;
-               scale_engine->h_scale = h_scale;
-               scale_engine->in_x1_int = in_x1_int;
-               scale_engine->in_y1_int = in_y1_int;
-               scale_engine->out_w_int = temp_w;
-               scale_engine->out_h_int = temp_h;
-               scale_engine->interpolation_type = interpolation_type;
-//printf("Overlay 2\n");
-
-//printf("OverlayFrame::overlay ScaleEngine 1 %d\n", out_h_int);
-               scale_engine->process_packages();
-//printf("OverlayFrame::overlay ScaleEngine 2\n");
-
-
-
-       }
-
-// printf("OverlayFrame::overlay 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-
-
-
-
-
-#define NO_TRANSLATION2 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(in_x2, translation_input->get_w()) && \
-       EQUIV(in_y2, translation_input->get_h()) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(out_x2, output->get_w()) && \
-       EQUIV(out_y2, output->get_h())) \
-
-#define NO_SCALE \
-       (EQUIV(out_x2 - out_x1, in_x2 - in_x1) && \
-       EQUIV(out_y2 - out_y1, in_y2 - in_y1))
-
-       
-
-
-//printf("OverlayFrame::overlay 4 %d\n", mode);
-
-
-
-
-       if(translation_input)
-       {
-// Direct copy
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE &&
-                       NO_BLEND)
-               {
-//printf("OverlayFrame::overlay direct copy\n");
-                       output->copy_from(translation_input);
-               }
-               else
-// Blend only
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE)
-               {
-                       if(!blend_engine) blend_engine = new BlendEngine(this, cpus);
-
-
-                       blend_engine->output = output;
-                       blend_engine->input = translation_input;
-                       blend_engine->alpha = alpha;
-                       blend_engine->mode = mode;
-
-                       blend_engine->process_packages();
-               }
-               else
-// Scale and translate using nearest neighbor
-// Translation is exactly on integer boundaries
-               if(interpolation_type == NEAREST_NEIGHBOR ||
-                       EQUIV(in_x1, (int)in_x1) &&
-                       EQUIV(in_y1, (int)in_y1) &&
-                       EQUIV(in_x2, (int)in_x2) &&
-                       EQUIV(in_y2, (int)in_y2) &&
-
-                       EQUIV(out_x1, (int)out_x1) &&
-                       EQUIV(out_y1, (int)out_y1) &&
-                       EQUIV(out_x2, (int)out_x2) &&
-                       EQUIV(out_y2, (int)out_y2))
-               {
-//printf("OverlayFrame::overlay NEAREST_NEIGHBOR 1\n");
-                       if(!scaletranslate_engine) scaletranslate_engine = new ScaleTranslateEngine(this, cpus);
-
-
-                       scaletranslate_engine->output = output;
-                       scaletranslate_engine->input = translation_input;
-                       scaletranslate_engine->in_x1 = (int)in_x1;
-                       scaletranslate_engine->in_y1 = (int)in_y1;
-                       scaletranslate_engine->in_x2 = (int)in_x2;
-                       scaletranslate_engine->in_y2 = (int)in_y2;
-                       scaletranslate_engine->out_x1 = (int)out_x1;
-                       scaletranslate_engine->out_y1 = (int)out_y1;
-                       scaletranslate_engine->out_x2 = (int)out_x2;
-                       scaletranslate_engine->out_y2 = (int)out_y2;
-                       scaletranslate_engine->alpha = alpha;
-                       scaletranslate_engine->mode = mode;
-
-                       scaletranslate_engine->process_packages();
-               }
-               else
-// Fractional translation
-               {
-// Use fractional translation
-// printf("OverlayFrame::overlay temp -> output  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-
-//printf("Overlay 3\n");
-                       if(!translate_engine) translate_engine = new TranslateEngine(this, cpus);
-                       translate_engine->translate_output = output;
-                       translate_engine->translate_input = translation_input;
-                       translate_engine->translate_in_x1 = in_x1;
-                       translate_engine->translate_in_y1 = in_y1;
-                       translate_engine->translate_in_x2 = in_x2;
-                       translate_engine->translate_in_y2 = in_y2;
-                       translate_engine->translate_out_x1 = out_x1;
-                       translate_engine->translate_out_y1 = out_y1;
-                       translate_engine->translate_out_x2 = out_x2;
-                       translate_engine->translate_out_y2 = out_y2;
-                       translate_engine->translate_alpha = alpha;
-                       translate_engine->translate_mode = mode;
-//printf("Overlay 4\n");
-
-//printf("OverlayFrame::overlay 5 %d\n", mode);
-                       translate_engine->process_packages();
-
-               }
-       }
-//printf("OverlayFrame::overlay 2\n");
-
-       return 0;
-}
-
-
-
-
-
-
-
-ScalePackage::ScalePackage()
-{
-}
-
-
-
-
-ScaleUnit::ScaleUnit(ScaleEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->engine = server;
-}
-
-ScaleUnit::~ScaleUnit()
-{
-}
-
-
-
-#define BILINEAR(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       int out_h = pkg->out_row2 - pkg->out_row1; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
-       int *table_int_x1, *table_int_y1; \
-       int *table_int_x2, *table_int_y2; \
-       float *table_frac_x, *table_antifrac_x, *table_frac_y, *table_antifrac_y; \
- \
-       tabulate_blinear(table_int_x1,  \
-               table_int_x2,  \
-               table_frac_x,  \
-               table_antifrac_x,  \
-               k_x,  \
-               0,  \
-               out_w_int, \
-               in_x1_int,  \
-               in_w_int); \
-       tabulate_blinear(table_int_y1,  \
-               table_int_y2,  \
-               table_frac_y,  \
-               table_antifrac_y,  \
-               k_y,  \
-               pkg->out_row1,  \
-               pkg->out_row2,  \
-               in_y1_int, \
-               in_h_int); \
- \
-       for(int i = 0; i < out_h; i++) \
-       { \
-               int i_y1 = table_int_y1[i]; \
-               int i_y2 = table_int_y2[i]; \
-               float a = table_frac_y[i]; \
-        float anti_a = table_antifrac_y[i]; \
-               type *in_row1 = in_rows[i_y1]; \
-               type *in_row2 = in_rows[i_y2]; \
-               type *out_row = out_rows[i + pkg->out_row1]; \
- \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       int i_x1 = table_int_x1[j]; \
-                       int i_x2 = table_int_x2[j]; \
-                       float b = table_frac_x[j]; \
-                       float anti_b = table_antifrac_x[j]; \
-                       float output1r, output1g, output1b, output1a; \
-                       float output2r, output2g, output2b, output2a; \
-                       float output3r, output3g, output3b, output3a; \
-                       float output4r, output4g, output4b, output4a; \
- \
-                       output1r = in_row1[i_x1 * components]; \
-                       output1g = in_row1[i_x1 * components + 1]; \
-                       output1b = in_row1[i_x1 * components + 2]; \
-                       if(components == 4) output1a = in_row1[i_x1 * components + 3]; \
- \
-                       output2r = in_row1[i_x2 * components]; \
-                       output2g = in_row1[i_x2 * components + 1]; \
-                       output2b = in_row1[i_x2 * components + 2]; \
-                       if(components == 4) output2a = in_row1[i_x2 * components + 3]; \
- \
-                       output3r = in_row2[i_x1 * components]; \
-                       output3g = in_row2[i_x1 * components + 1]; \
-                       output3b = in_row2[i_x1 * components + 2]; \
-                       if(components == 4) output3a = in_row2[i_x1 * components + 3]; \
-\
-                       output4r = in_row2[i_x2 * components]; \
-                       output4g = in_row2[i_x2 * components + 1]; \
-                       output4b = in_row2[i_x2 * components + 2]; \
-                       if(components == 4) output4a = in_row2[i_x2 * components + 3]; \
- \
-                       out_row[j * components] =  \
-                               (type)((anti_a) * (((anti_b) * output1r) +  \
-                               (b * output2r)) +  \
-                a * (((anti_b) * output3r) +  \
-                               (b * output4r))); \
-                       out_row[j * components + 1] =   \
-                               (type)((anti_a) * (((anti_b) * output1g) +  \
-                               (b * output2g)) +  \
-                a * (((anti_b) * output3g) +  \
-                               (b * output4g))); \
-                       out_row[j * components + 2] =   \
-                               (type)((anti_a) * (((anti_b) * output1b) +  \
-                               (b * output2b)) +  \
-                a * (((anti_b) * output3b) +  \
-                               (b * output4b))); \
-                       if(components == 4) \
-                               out_row[j * components + 3] =   \
-                                       (type)((anti_a) * (((anti_b) * output1a) +  \
-                                       (b * output2a)) +  \
-                       a * (((anti_b) * output3a) +  \
-                                       (b * output4a))); \
-               } \
-       } \
- \
- \
-       delete [] table_int_x1; \
-       delete [] table_int_x2; \
-       delete [] table_frac_x; \
-       delete [] table_antifrac_x; \
-       delete [] table_int_y1; \
-       delete [] table_int_y2; \
-       delete [] table_frac_y; \
-       delete [] table_antifrac_y; \
- \
-}
-
-
-#define BICUBIC(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       float *bspline_x, *bspline_y; \
-       int *in_x_table, *in_y_table; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
- \
-       tabulate_bicubic(bspline_x,  \
-               in_x_table, \
-               k_x, \
-               in_x1_int, \
-               out_w_int, \
-               in_w_int, \
-               -1); \
- \
-       tabulate_bicubic(bspline_y,  \
-               in_y_table, \
-               k_y, \
-               in_y1_int, \
-               out_h_int, \
-               in_h_int, \
-               1); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       int i_x = (int)(k_x * j); \
-                       float output1, output2, output3, output4; \
-                       output1 = 0; \
-                       output2 = 0; \
-                       output3 = 0; \
-                       if(components == 4) \
-                               output4 = 0; \
-                       int table_y = i * 4; \
- \
-/* Kernel */ \
-                       for(int m = -1; m < 3; m++) \
-                       { \
-                               float r1 = bspline_y[table_y]; \
-                               int y = in_y_table[table_y]; \
-                               int table_x = j * 4; \
- \
-                               for(int n = -1; n < 3; n++) \
-                               { \
-                                       float r2 = bspline_x[table_x]; \
-                                       int x = in_x_table[table_x]; \
-                                       float r_square = r1 * r2; \
- \
-                                       output1 += r_square * in_rows[y][x * components]; \
-                                       output2 += r_square * in_rows[y][x * components + 1]; \
-                                       output3 += r_square * in_rows[y][x * components + 2]; \
-                                       if(components == 4) \
-                                               output4 += r_square * in_rows[y][x * components + 3]; \
- \
-                                       table_x++; \
-                               } \
-                               table_y++; \
-                       } \
- \
- \
-                       out_rows[i][j * components] = (type)output1; \
-                       out_rows[i][j * components + 1] = (type)output2; \
-                       out_rows[i][j * components + 2] = (type)output3; \
-                       if(components == 4) \
-                               out_rows[i][j * components + 3] = (type)output4; \
- \
-               } \
-       } \
- \
-       delete [] bspline_x; \
-       delete [] bspline_y; \
-       delete [] in_x_table; \
-       delete [] in_y_table; \
-}
-
-
-
-
-// Pow function is not thread safe in Compaqt C
-#define CUBE(x) ((x) * (x) * (x))
-
-float ScaleUnit::cubic_bspline(float x)
-{
-       float a, b, c, d;
-
-       if((x + 2.0F) <= 0.0F) 
-       {
-       a = 0.0F;
-       }
-       else 
-       {
-       a = CUBE(x + 2.0F);
-       }
-
-
-       if((x + 1.0F) <= 0.0F) 
-       {
-       b = 0.0F;
-       }
-       else 
-       {
-       b = CUBE(x + 1.0F);
-       }    
-
-       if(x <= 0) 
-       {
-       c = 0.0F;
-       }
-       else 
-       {
-       c = CUBE(x);
-       }  
-
-       if((x - 1.0F) <= 0.0F) 
-       {
-       d = 0.0F;
-       }
-       else 
-       {
-       d = CUBE(x - 1.0F);
-       }
-
-
-       return (a - (4.0F * b) + (6.0F * c) - (4.0F * d)) / 6.0;
-}
-
-
-void ScaleUnit::tabulate_bicubic(float* &coef_table, 
-       int* &coord_table,
-       float scale,
-       int start, 
-       int pixels,
-       int total_pixels,
-       float coefficient)
-{
-       coef_table = new float[pixels * 4];
-       coord_table = new int[pixels * 4];
-       for(int i = 0, j = 0; i < pixels; i++)
-       {
-               float f_x = (float)i * scale;
-               float a = f_x - floor(f_x);
-               
-               for(float m = -1; m < 3; m++)
-               {
-                       coef_table[j] = cubic_bspline(coefficient * (m - a));
-                       coord_table[j] = start + (int)f_x + m;
-                       CLAMP(coord_table[j], 0, total_pixels - 1);
-                       j++;
-               }
-               
-       }
-}
-
-void ScaleUnit::tabulate_blinear(int* &table_int1,
-               int* &table_int2,
-               float* &table_frac,
-               float* &table_antifrac,
-               float scale,
-               int pixel1,
-               int pixel2,
-               int start,
-               int total_pixels)
-{
-       table_int1 = new int[pixel2 - pixel1];
-       table_int2 = new int[pixel2 - pixel1];
-       table_frac = new float[pixel2 - pixel1];
-       table_antifrac = new float[pixel2 - pixel1];
-
-       for(int i = pixel1, j = 0; i < pixel2; i++, j++)
-       {
-               float f_x = (float)i * scale;
-               int i_x = (int)floor(f_x);
-               float a = (f_x - floor(f_x));
-
-               table_int1[j] = i_x + start;
-               table_int2[j] = i_x + start + 1;
-               CLAMP(table_int1[j], 0, total_pixels - 1);
-               CLAMP(table_int2[j], 0, total_pixels - 1);
-               table_frac[j] = a;
-               table_antifrac[j] = 1.0F - a;
-//printf("ScaleUnit::tabulate_blinear %d %d %d\n", j, table_int1[j], table_int2[j]);
-       }
-}
-
-void ScaleUnit::process_package(LoadPackage *package)
-{
-       ScalePackage *pkg = (ScalePackage*)package;
-
-//printf("ScaleUnit::process_package 1\n");
-// Arguments for macros
-       VFrame *output = engine->scale_output;
-       VFrame *input = engine->scale_input;
-       float scale_w = engine->w_scale;
-       float scale_h = engine->h_scale;
-       int in_x1_int = engine->in_x1_int;
-       int in_y1_int = engine->in_y1_int;
-       int out_h_int = engine->out_h_int;
-       int out_w_int = engine->out_w_int;
-       int do_yuv = 
-               (input->get_color_model() == BC_YUV888 ||
-               input->get_color_model() == BC_YUVA8888 ||
-               input->get_color_model() == BC_YUV161616 ||
-               input->get_color_model() == BC_YUVA16161616);
-
-//printf("ScaleUnit::process_package 2\n");
-       if(engine->interpolation_type == CUBIC_CUBIC || 
-               (engine->interpolation_type == CUBIC_LINEAR 
-                       && engine->w_scale > 1 && 
-                       engine->h_scale > 1))
-       {
-       
-               switch(engine->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BICUBIC(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BICUBIC(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BICUBIC(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BICUBIC(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-       else
-// Perform bilinear scaling input -> scale_output
-       {
-               switch(engine->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BILINEAR(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BILINEAR(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BILINEAR(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BILINEAR(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-//printf("ScaleUnit::process_package 3\n");
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-ScaleEngine::ScaleEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-ScaleEngine::~ScaleEngine()
-{
-}
-
-void ScaleEngine::init_packages()
-{
-       for(int i = 0; i < total_packages; i++)
-       {
-               ScalePackage *package = (ScalePackage*)packages[i];
-               package->out_row1 = out_h_int / total_packages * i;
-               package->out_row2 = package->out_row1 + out_h_int / total_packages;
-
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_h_int;
-       }
-}
-
-LoadClient* ScaleEngine::new_client()
-{
-       return new ScaleUnit(this, overlay);
-}
-
-LoadPackage* ScaleEngine::new_package()
-{
-       return new ScalePackage;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-TranslatePackage::TranslatePackage()
-{
-}
-
-
-
-TranslateUnit::TranslateUnit(TranslateEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->engine = server;
-}
-
-TranslateUnit::~TranslateUnit()
-{
-}
-
-
-
-void TranslateUnit::translation_array(transfer_table* &table, 
-       float out_x1, 
-       float out_x2,
-       float in_x1,
-       float in_x2,
-       int in_total, 
-       int out_total, 
-       int &out_x1_int,
-       int &out_x2_int)
-{
-       int out_w_int;
-       float offset = out_x1 - in_x1;
-
-       out_x1_int = (int)out_x1;
-       out_x2_int = MIN((int)ceil(out_x2), out_total);
-       out_w_int = out_x2_int - out_x1_int;
-
-       table = new transfer_table[out_w_int];
-       bzero(table, sizeof(transfer_table) * out_w_int);
-
-
-//printf("OverlayFrame::translation_array 1 %f %f -> %f %f\n", in_x1, in_x2, out_x1, out_x2);
-
-       float in_x = in_x1;
-       for(int out_x = out_x1_int; out_x < out_x2_int; out_x++)
-       {
-               transfer_table *entry = &table[out_x - out_x1_int];
-
-               entry->in_x1 = (int)in_x;
-               entry->in_x2 = (int)in_x + 1;
-
-// Get fraction of output pixel to fill
-               entry->output_fraction = 1;
-
-               if(out_x1 > out_x)
-               {
-                       entry->output_fraction -= out_x1 - out_x;
-               }
-
-               if(out_x2 < out_x + 1)
-               {
-                       entry->output_fraction = (out_x2 - out_x);
-               }
-
-// Advance in_x until out_x_fraction is filled
-               float out_x_fraction = entry->output_fraction;
-               float in_x_fraction = floor(in_x + 1) - in_x;
-
-               if(out_x_fraction <= in_x_fraction)
-               {
-                       entry->in_fraction1 = out_x_fraction;
-                       entry->in_fraction2 = 0.0;
-                       in_x += out_x_fraction;
-               }
-               else
-               {
-                       entry->in_fraction1 = in_x_fraction;
-                       in_x += out_x_fraction;
-                       entry->in_fraction2 = in_x - floor(in_x);
-               }
-
-// Clip in_x and zero out fraction.  This doesn't work for YUV.
-               if(entry->in_x2 >= in_total)
-               {
-                       entry->in_x2 = in_total - 1;
-                       entry->in_fraction2 = 0.0;
-               }
-               
-               if(entry->in_x1 >= in_total)
-               {
-                       entry->in_x1 = in_total - 1;
-                       entry->in_fraction1 = 0.0;
-               }
-// printf("OverlayFrame::translation_array 2 %d %d %d %f %f %f\n", 
-//     out_x, 
-//     entry->in_x1, 
-//     entry->in_x2, 
-//     entry->in_fraction1, 
-//     entry->in_fraction2, 
-//     entry->output_fraction);
-       }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#define TRANSLATE(max, type, components, do_yuv) \
-{ \
- \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
- \
-/* printf("OverlayFrame::translate 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",  */ \
-/*     (in_x1),  in_y1,  in_x2,  in_y2,  out_x1,  out_y1, out_x2,  out_y2); */ \
- \
-       unsigned int master_opacity = (int)(alpha * max + 0.5); \
-       unsigned int master_transparency = max - master_opacity; \
-       float zero_r, zero_g, zero_b; \
-       zero_r = 0; \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
- \
-/* printf("TRANSLATE %d\n", mode); */ \
- \
-       for(int i = row1; i < row2; i++) \
-       { \
-               int in_y1 = y_table[i - out_y1_int].in_x1; \
-               int in_y2 = y_table[i - out_y1_int].in_x2; \
-               float y_fraction1 = y_table[i - out_y1_int].in_fraction1; \
-               float y_fraction2 = y_table[i - out_y1_int].in_fraction2; \
-               float y_output_fraction = y_table[i - out_y1_int].output_fraction; \
-               type *in_row1 = in_rows[(in_y1)]; \
-               type *in_row2 = in_rows[(in_y2)]; \
-               type *out_row = out_rows[i]; \
- \
-               for(int j = out_x1_int; j < out_x2_int; j++) \
-               { \
-                       int in_x1 = x_table[j - out_x1_int].in_x1; \
-                       int in_x2 = x_table[j - out_x1_int].in_x2; \
-                       float x_fraction1 = x_table[j - out_x1_int].in_fraction1; \
-                       float x_fraction2 = x_table[j - out_x1_int].in_fraction2; \
-                       float x_output_fraction = x_table[j - out_x1_int].output_fraction; \
-                       type *output = &out_row[j * components]; \
-                       int input1, input2, input3, input4; \
-                       float fraction1 = x_fraction1 * y_fraction1; \
-                       float fraction2 = x_fraction2 * y_fraction1; \
-                       float fraction3 = x_fraction1 * y_fraction2; \
-                       float fraction4 = x_fraction2 * y_fraction2; \
- \
-                       input1 = (int)(in_row1[in_x1 * components] * fraction1 +  \
-                               in_row1[in_x2 * components] * fraction2 +  \
-                               in_row2[in_x1 * components] * fraction3 +  \
-                               in_row2[in_x2 * components] * fraction4 + 0.5); \
- \
-/* Add chroma to fractional pixels */ \
-                       if(do_yuv) \
-                       { \
-                               float extra_chroma = (1.0F - \
-                                       fraction1 - \
-                                       fraction2 - \
-                                       fraction3 - \
-                                       fraction4) * zero_b; \
-                               input2 = (int)(in_row1[in_x1 * components + 1] * fraction1 +  \
-                                       in_row1[in_x2 * components + 1] * fraction2 +  \
-                                       in_row2[in_x1 * components + 1] * fraction3 +  \
-                                       in_row2[in_x2 * components + 1] * fraction4 + \
-                                       extra_chroma + 0.5); \
-                               input3 = (int)(in_row1[in_x1 * components + 2] * fraction1 +  \
-                                       in_row1[in_x2 * components + 2] * fraction2 +  \
-                                       in_row2[in_x1 * components + 2] * fraction3 +  \
-                                       in_row2[in_x2 * components + 2] * fraction4 +  \
-                                       extra_chroma + 0.5); \
-                       } \
-                       else \
-                       { \
-                               input2 = (int)(in_row1[in_x1 * components + 1] * fraction1 +  \
-                                       in_row1[in_x2 * components + 1] * fraction2 +  \
-                                       in_row2[in_x1 * components + 1] * fraction3 +  \
-                                       in_row2[in_x2 * components + 1] * fraction4 + 0.5); \
-                               input3 = (int)(in_row1[in_x1 * components + 2] * fraction1 +  \
-                                       in_row1[in_x2 * components + 2] * fraction2 +  \
-                                       in_row2[in_x1 * components + 2] * fraction3 +  \
-                                       in_row2[in_x2 * components + 2] * fraction4 + 0.5); \
-                       } \
- \
-                       if(components == 4) \
-                               input4 = (int)(in_row1[in_x1 * components + 3] * fraction1 +  \
-                                       in_row1[in_x2 * components + 3] * fraction2 +  \
-                                       in_row2[in_x1 * components + 3] * fraction3 +  \
-                                       in_row2[in_x2 * components + 3] * fraction4 + 0.5); \
- \
-                       unsigned int opacity = (int)(master_opacity *  \
-                               y_output_fraction *  \
-                               x_output_fraction + 0.5); \
-                       unsigned int transparency = max - opacity; \
- \
-/* if(opacity != max) printf("TRANSLATE %x %d %d\n", opacity, j, i); */ \
- \
-                       if(components == 3) \
-                       { \
-                               BLEND_3(max, type); \
-                       } \
-                       else \
-                       { \
-                               BLEND_4(max, type); \
-                       } \
-               } \
-       } \
-}
-
-void TranslateUnit::process_package(LoadPackage *package)
-{
-       TranslatePackage *pkg = (TranslatePackage*)package;
-       int out_y1_int; 
-       int out_y2_int; 
-       int out_x1_int; 
-       int out_x2_int; 
-
-
-// Variables for TRANSLATE
-       VFrame *input = engine->translate_input;
-       VFrame *output = engine->translate_output;
-       float in_x1 = engine->translate_in_x1;
-       float in_y1 = engine->translate_in_y1;
-       float in_x2 = engine->translate_in_x2;
-       float in_y2 = engine->translate_in_y2;
-       float out_x1 = engine->translate_out_x1;
-       float out_y1 = engine->translate_out_y1;
-       float out_x2 = engine->translate_out_x2;
-       float out_y2 = engine->translate_out_y2;
-       float alpha = engine->translate_alpha;
-       int row1 = pkg->out_row1;
-       int row2 = pkg->out_row2;
-       int mode = engine->translate_mode;
-       int in_total_x = input->get_w();
-       int in_total_y = input->get_h();
-       int do_yuv = 
-               (engine->translate_input->get_color_model() == BC_YUV888 ||
-               engine->translate_input->get_color_model() == BC_YUVA8888 ||
-               engine->translate_input->get_color_model() == BC_YUV161616 ||
-               engine->translate_input->get_color_model() == BC_YUVA16161616);
-
-       transfer_table *x_table; 
-       transfer_table *y_table; 
-       translation_array(x_table,  
-               out_x1,  
-               out_x2, 
-               in_x1, 
-               in_x2, 
-               in_total_x,  
-               output->get_w(),  
-               out_x1_int, 
-               out_x2_int); 
-       translation_array(y_table,  
-               out_y1,  
-               out_y2, 
-               in_y1, 
-               in_y2, 
-               in_total_y,  
-               output->get_h(),  
-               out_y1_int, 
-               out_y2_int); 
-       switch(engine->translate_input->get_color_model())
-       {
-               case BC_RGB888:
-                       TRANSLATE(0xff, unsigned char, 3, 0);
-                       break;
-
-               case BC_RGBA8888:
-                       TRANSLATE(0xff, unsigned char, 4, 0);
-                       break;
-
-               case BC_RGB161616:
-                       TRANSLATE(0xffff, uint16_t, 3, 0);
-                       break;
-
-               case BC_RGBA16161616:
-                       TRANSLATE(0xffff, uint16_t, 4, 0);
-                       break;
-
-               case BC_YUV888:
-                       TRANSLATE(0xff, unsigned char, 3, 1);
-                       break;
-
-               case BC_YUVA8888:
-                       TRANSLATE(0xff, unsigned char, 4, 1);
-                       break;
-
-               case BC_YUV161616:
-                       TRANSLATE(0xffff, uint16_t, 3, 1);
-                       break;
-
-               case BC_YUVA16161616:
-                       TRANSLATE(0xffff, uint16_t, 4, 1);
-                       break;
-       }
-       delete [] x_table; 
-       delete [] y_table; 
-}
-
-
-
-
-
-
-
-
-
-
-TranslateEngine::TranslateEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-TranslateEngine::~TranslateEngine()
-{
-}
-
-void TranslateEngine::init_packages()
-{
-       int out_y1_int = (int)translate_out_y1;
-       int out_y2_int = MIN((int)ceil(translate_out_y2), translate_output->get_h());
-       int out_h = out_y2_int - out_y1_int;
-
-       for(int i = 0; i < total_packages; i++)
-       {
-               TranslatePackage *package = (TranslatePackage*)packages[i];
-               package->out_row1 = (int)(out_y1_int + out_h / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 + 
-                       out_h / 
-                       total_packages);
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_y2_int;
-       }
-}
-
-LoadClient* TranslateEngine::new_client()
-{
-       return new TranslateUnit(this, overlay);
-}
-
-LoadPackage* TranslateEngine::new_package()
-{
-       return new TranslatePackage;
-}
-
-
-
-
-
-
-
-
-#define SCALE_TRANSLATE(max, type, components) \
-{ \
-       int64_t opacity = (int)(alpha * max + 0.5); \
-       int64_t transparency = max - opacity; \
-       int out_w = out_x2 - out_x1; \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               int in_y = y_table[i - out_y1]; \
-               type *in_row = (type*)in_rows[in_y] + in_x1 * components; \
-               type *out_row = (type*)out_rows[i] + out_x1 * components; \
- \
-/* X direction is scaled and requires a table lookup */ \
-               if(out_w != in_x2 - in_x1) \
-               { \
-                       for(int j = 0; j < out_w; j++) \
-                       { \
-                               int in_x = x_table[j]; \
-                               int input1, input2, input3, input4; \
-                               type *output = out_row + j * components; \
-        \
-                               input1 = in_row[in_x * components]; \
-                               input2 = in_row[in_x * components + 1]; \
-                               input3 = in_row[in_x * components + 2]; \
-                               if(components == 4) \
-                                       input4 = in_row[in_x * components + 3]; \
-        \
-                               if(components == 3) \
-                               { \
-                                       BLEND_3(max, type); \
-                               } \
-                               else \
-                               { \
-                                       BLEND_4(max, type); \
-                               } \
-                       } \
-               } \
-               else \
-/* X direction is not scaled */ \
-               { \
-                       for(int j = 0; j < out_w; j++) \
-                       { \
-                               int input1, input2, input3, input4; \
-                               type *output = out_row + j * components; \
-        \
-                               input1 = in_row[j * components]; \
-                               input2 = in_row[j * components + 1]; \
-                               input3 = in_row[j * components + 2]; \
-                               if(components == 4) \
-                                       input4 = in_row[j * components + 3]; \
-        \
-                               if(components == 3) \
-                               { \
-                                       BLEND_3(max, type); \
-                               } \
-                               else \
-                               { \
-                                       BLEND_4(max, type); \
-                               } \
-                       } \
-               } \
-       } \
-}
-
-
-
-ScaleTranslateUnit::ScaleTranslateUnit(ScaleTranslateEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->scale_translate = server;
-}
-
-ScaleTranslateUnit::~ScaleTranslateUnit()
-{
-}
-
-void ScaleTranslateUnit::scale_array(int* &table, 
-       int out_x1, 
-       int out_x2,
-       int in_x1,
-       int in_x2,
-       int is_x)
-{
-       float scale = (float)(out_x2 - out_x1) / (in_x2 - in_x1);
-
-       table = new int[out_x2 - out_x1];
-       
-       if(!is_x)
-       {
-               for(int i = 0; i < out_x2 - out_x1; i++)
-               {
-                       table[i] = (int)((float)i / scale + in_x1);
-               }
-       }
-       else
-       {       
-               for(int i = 0; i < out_x2 - out_x1; i++)
-               {
-                       table[i] = (int)((float)i / scale);
-               }
-       }
-}
-
-
-void ScaleTranslateUnit::process_package(LoadPackage *package)
-{
-       ScaleTranslatePackage *pkg = (ScaleTranslatePackage*)package;
-
-// Args for NEAREST_NEIGHBOR_MACRO
-       VFrame *output = scale_translate->output;
-       VFrame *input = scale_translate->input;
-       int in_x1 = scale_translate->in_x1;
-       int in_y1 = scale_translate->in_y1;
-       int in_x2 = scale_translate->in_x2;
-       int in_y2 = scale_translate->in_y2;
-       int out_x1 = scale_translate->out_x1;
-       int out_y1 = scale_translate->out_y1;
-       int out_x2 = scale_translate->out_x2;
-       int out_y2 = scale_translate->out_y2;
-       float alpha = scale_translate->alpha;
-       int mode = scale_translate->mode;
-
-       int *x_table;
-       int *y_table;
-       unsigned char **in_rows = input->get_rows();
-       unsigned char **out_rows = output->get_rows();
-
-       scale_array(x_table, 
-               out_x1, 
-               out_x2,
-               in_x1,
-               in_x2,
-               1);
-       scale_array(y_table, 
-               out_y1, 
-               out_y2,
-               in_y1,
-               in_y2,
-               0);
-
-
-       switch(input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       SCALE_TRANSLATE(0xff, uint8_t, 3);
-                       break;
-
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       SCALE_TRANSLATE(0xff, uint8_t, 4);
-                       break;
-
-
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       SCALE_TRANSLATE(0xffff, uint16_t, 3);
-                       break;
-
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       SCALE_TRANSLATE(0xffff, uint16_t, 4);
-                       break;
-       }
-       
-       delete [] x_table;
-       delete [] y_table;
-
-};
-
-
-
-
-
-
-
-
-
-ScaleTranslateEngine::ScaleTranslateEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-ScaleTranslateEngine::~ScaleTranslateEngine()
-{
-}
-
-void ScaleTranslateEngine::init_packages()
-{
-       int out_h = out_y2 - out_y1;
-
-       for(int i = 0; i < total_packages; i++)
-       {
-               ScaleTranslatePackage *package = (ScaleTranslatePackage*)packages[i];
-               package->out_row1 = (int)(out_y1 + out_h / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 + 
-                       out_h / 
-                       total_packages);
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_y2;
-       }
-}
-
-LoadClient* ScaleTranslateEngine::new_client()
-{
-       return new ScaleTranslateUnit(this, overlay);
-}
-
-LoadPackage* ScaleTranslateEngine::new_package()
-{
-       return new ScaleTranslatePackage;
-}
-
-
-ScaleTranslatePackage::ScaleTranslatePackage()
-{
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#define BLEND_ONLY(type, max, components) \
-{ \
-       int64_t opacity = (int)(alpha * max + 0.5); \
-       int64_t transparency = max - opacity; \
- \
-       type** output_rows = (type**)output->get_rows(); \
-       type** input_rows = (type**)input->get_rows(); \
-       int w = input->get_w(); \
-       int h = input->get_h(); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               type* in_row = input_rows[i]; \
-               type* output = output_rows[i]; \
- \
-               for(int j = 0; j < w; j++) \
-               { \
-                       int input1, input2, input3, input4; \
-                       input1 = in_row[j * components]; \
-                       input2 = in_row[j * components + 1]; \
-                       input3 = in_row[j * components + 2]; \
-                       if(components == 4) input4 = in_row[j * components + 3]; \
- \
- \
-                       if(components == 3) \
-                       { \
-                               BLEND_3(max, type); \
-                       } \
-                       else \
-                       { \
-                               BLEND_4(max, type); \
-                       } \
- \
-                       input += components; \
-                       output += components; \
-               } \
-       } \
-}
-
-
-
-
-BlendUnit::BlendUnit(BlendEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->blend_engine = server;
-}
-
-BlendUnit::~BlendUnit()
-{
-}
-
-void BlendUnit::process_package(LoadPackage *package)
-{
-       BlendPackage *pkg = (BlendPackage*)package;
-
-
-       VFrame *output = blend_engine->output;
-       VFrame *input = blend_engine->input;
-       float alpha = blend_engine->alpha;
-       int mode = blend_engine->mode;
-
-       switch(input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       BLEND_ONLY(unsigned char, 0xff, 3);
-                       break;
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       BLEND_ONLY(unsigned char, 0xff, 4);
-                       break;
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       BLEND_ONLY(uint16_t, 0xffff, 3);
-                       break;
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       BLEND_ONLY(uint16_t, 0xffff, 4);
-                       break;
-       }
-}
-
-
-
-BlendEngine::BlendEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-BlendEngine::~BlendEngine()
-{
-}
-
-void BlendEngine::init_packages()
-{
-       for(int i = 0; i < total_packages; i++)
-       {
-               BlendPackage *package = (BlendPackage*)packages[i];
-               package->out_row1 = (int)(input->get_h() / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 +
-                       input->get_h() / 
-                       total_packages);
-
-               if(i >= total_packages - 1)
-                       package->out_row2 = input->get_h();
-       }
-}
-
-LoadClient* BlendEngine::new_client()
-{
-       return new BlendUnit(this, overlay);
-}
-
-LoadPackage* BlendEngine::new_package()
-{
-       return new BlendPackage;
-}
-
-
-BlendPackage::BlendPackage()
-{
-}
-
-
diff --git a/cinelerra-5.1/cinelerra/overlayframe.C.float b/cinelerra-5.1/cinelerra/overlayframe.C.float
deleted file mode 100644 (file)
index 24c7781..0000000
+++ /dev/null
@@ -1,1723 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-
-#include "clip.h"
-#include "edl.inc"
-#include "overlayframe.h"
-#include "vframe.h"
-
-OverlayFrame::OverlayFrame(int cpus)
-{
-       temp_frame = 0;
-       blend_engine = 0;
-       scale_engine = 0;
-       scaletranslate_engine = 0;
-       translate_engine = 0;
-       this->cpus = cpus;
-}
-
-OverlayFrame::~OverlayFrame()
-{
-//printf("OverlayFrame::~OverlayFrame 1\n");
-       if(temp_frame) delete temp_frame;
-       if(scale_engine) delete scale_engine;
-       if(translate_engine) delete translate_engine;
-       if(blend_engine) delete blend_engine;
-       if(scaletranslate_engine) delete scaletranslate_engine;
-//printf("OverlayFrame::~OverlayFrame 2\n");
-}
-
-
-
-
-
-
-
-
-// Verification: 
-
-// (255 * 255 + 0 * 0) / 255 = 255
-// (255 * 127 + 255 * (255 - 127)) / 255 = 255
-
-// (65535 * 65535 + 0 * 0) / 65535 = 65535
-// (65535 * 32767 + 65535 * (65535 - 32767)) / 65535 = 65535
-
-
-// Branch prediction 4 U
-
-#define BLEND_3(max, type) \
-{ \
-       int64_t r, g, b; \
- \
-/* if(mode != TRANSFER_NORMAL) printf("BLEND mode = %d\n", mode); */ \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * opacity + output[0] * transparency) / max; \
-                       g = ((int64_t)input2 * opacity + output[1] * transparency) / max; \
-                       b = ((int64_t)input3 * opacity + output[2] * transparency) / max; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-}
-
-
-
-
-
-// Blending equations are drastically different for 3 and 4 components
-#define BLEND_4(max, type) \
-{ \
-       int64_t r, g, b, a; \
-       int64_t pixel_opacity, pixel_transparency; \
- \
-       pixel_opacity = opacity * input4 / max; \
-       pixel_transparency = (max - pixel_opacity) * output[3] / max; \
- \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       a = input4; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = ((int64_t)input2 * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = ((int64_t)input3 * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-       output[3] = (type)a; \
-}
-
-
-
-
-
-
-
-
-// Bicubic algorithm using multiprocessors
-// input -> scale nearest integer boundaries -> temp -> translation -> blend -> output
-
-// Nearest neighbor algorithm using multiprocessors for blending
-// input -> scale + translate -> blend -> output
-
-
-int OverlayFrame::overlay(VFrame *output, 
-       VFrame *input, 
-       float in_x1, 
-       float in_y1, 
-       float in_x2, 
-       float in_y2, 
-       float out_x1, 
-       float out_y1, 
-       float out_x2, 
-       float out_y2, 
-       float alpha,       // 0 - 1
-       int mode,
-       int interpolation_type)
-{
-       float w_scale = (out_x2 - out_x1) / (in_x2 - in_x1);
-       float h_scale = (out_y2 - out_y1) / (in_y2 - in_y1);
-
-//printf("OverlayFrame::overlay 1 %d %f\n", mode, alpha);
-// Limit values
-       if(in_x1 < 0)
-       {
-               out_x1 += -in_x1 * w_scale;
-               in_x1 = 0;
-       }
-       else
-       if(in_x1 >= input->get_w())
-       {
-               out_x1 -= (in_x1 - input->get_w()) * w_scale;
-               in_x1 = input->get_w();
-       }
-
-       if(in_y1 < 0)
-       {
-               out_y1 += -in_y1 * h_scale;
-               in_y1 = 0;
-       }
-       else
-       if(in_y1 >= input->get_h())
-       {
-               out_y1 -= (in_y1 - input->get_h()) * h_scale;
-               in_y1 = input->get_h();
-       }
-
-       if(in_x2 < 0)
-       {
-               out_x2 += -in_x2 * w_scale;
-               in_x2 = 0;
-       }
-       else
-       if(in_x2 >= input->get_w())
-       {
-               out_x2 -= (in_x2 - input->get_w()) * w_scale;
-               in_x2 = input->get_w();
-       }
-
-       if(in_y2 < 0)
-       {
-               out_y2 += -in_y2 * h_scale;
-               in_y2 = 0;
-       }
-       else
-       if(in_y2 >= input->get_h())
-       {
-               out_y2 -= (in_y2 - input->get_h()) * h_scale;
-               in_y2 = input->get_h();
-       }
-
-       if(out_x1 < 0)
-       {
-               in_x1 += -out_x1 / w_scale;
-               out_x1 = 0;
-       }
-       else
-       if(out_x1 >= output->get_w())
-       {
-               in_x1 -= (out_x1 - output->get_w()) / w_scale;
-               out_x1 = output->get_w();
-       }
-
-       if(out_y1 < 0)
-       {
-               in_y1 += -out_y1 / h_scale;
-               out_y1 = 0;
-       }
-       else
-       if(out_y1 >= output->get_h())
-       {
-               in_y1 -= (out_y1 - output->get_h()) / h_scale;
-               out_y1 = output->get_h();
-       }
-
-       if(out_x2 < 0)
-       {
-               in_x2 += -out_x2 / w_scale;
-               out_x2 = 0;
-       }
-       else
-       if(out_x2 >= output->get_w())
-       {
-               in_x2 -= (out_x2 - output->get_w()) / w_scale;
-               out_x2 = output->get_w();
-       }
-
-       if(out_y2 < 0)
-       {
-               in_y2 += -out_y2 / h_scale;
-               out_y2 = 0;
-       }
-       else
-       if(out_y2 >= output->get_h())
-       {
-               in_y2 -= (out_y2 - output->get_h()) / h_scale;
-               out_y2 = output->get_h();
-       }
-
-
-
-
-
-       float in_w = in_x2 - in_x1;
-       float in_h = in_y2 - in_y1;
-       float out_w = out_x2 - out_x1;
-       float out_h = out_y2 - out_y1;
-// Input for translation operation
-       VFrame *translation_input = input;
-
-
-
-// printf("OverlayFrame::overlay %f %f %f %f -> %f %f %f %f\n", in_x1,
-//                     in_y1,
-//                     in_x2,
-//                     in_y2,
-//                     out_x1,
-//                     out_y1,
-//                     out_x2,
-//                     out_y2);
-
-
-
-
-
-// ****************************************************************************
-// Transfer to temp buffer by scaling nearest integer boundaries
-// ****************************************************************************
-       if(interpolation_type != NEAREST_NEIGHBOR &&
-               (!EQUIV(w_scale, 1) || !EQUIV(h_scale, 1)))
-       {
-// Create integer boundaries for interpolation
-               int in_x1_int = (int)in_x1;
-               int in_y1_int = (int)in_y1;
-               int in_x2_int = MIN((int)ceil(in_x2), input->get_w());
-               int in_y2_int = MIN((int)ceil(in_y2), input->get_h());
-
-// Dimensions of temp frame.  Integer boundaries scaled.
-               int temp_w = (int)ceil(w_scale * (in_x2_int - in_x1_int));
-               int temp_h = (int)ceil(h_scale * (in_y2_int - in_y1_int));
-               VFrame *scale_output;
-
-
-
-#define NO_TRANSLATION1 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(in_x2, in_x2_int) && \
-       EQUIV(in_y2, in_y2_int) && \
-       EQUIV(out_x2, temp_w) && \
-       EQUIV(out_y2, temp_h))
-
-
-#define NO_BLEND \
-       (EQUIV(alpha, 1) && \
-       (mode == TRANSFER_REPLACE || \
-       (mode == TRANSFER_NORMAL && cmodel_components(input->get_color_model()) == 3)))
-
-
-
-
-
-// Prepare destination for operation
-
-// No translation and no blending.  The blending operation is built into the
-// translation unit but not the scaling unit.
-// input -> output
-               if(NO_TRANSLATION1 &&
-                       NO_BLEND)
-               {
-// printf("OverlayFrame::overlay input -> output\n");
-
-                       scale_output = output;
-                       translation_input = 0;
-               }
-               else
-// If translation or blending
-// input -> nearest integer boundary temp
-               {
-                       if(temp_frame && 
-                               (temp_frame->get_w() != temp_w ||
-                                       temp_frame->get_h() != temp_h))
-                       {
-                               delete temp_frame;
-                               temp_frame = 0;
-                       }
-
-                       if(!temp_frame)
-                       {
-                               temp_frame = new VFrame(0,
-                                       temp_w,
-                                       temp_h,
-                                       input->get_color_model(),
-                                       -1);
-                       }
-//printf("OverlayFrame::overlay input -> temp\n");
-
-
-                       temp_frame->clear_frame();
-
-// printf("OverlayFrame::overlay 4 temp_w=%d temp_h=%d\n",
-//     temp_w, temp_h);
-                       scale_output = temp_frame;
-                       translation_input = scale_output;
-
-// Adjust input coordinates to reflect new scaled coordinates.
-                       in_x1 = (in_x1 - in_x1_int) * w_scale;
-                       in_y1 = (in_y1 - in_y1_int) * h_scale;
-                       in_x2 = (in_x2 - in_x1_int) * w_scale;
-                       in_y2 = (in_y2 - in_y1_int) * h_scale;
-               }
-
-
-
-
-// Scale input -> scale_output
-               this->scale_output = scale_output;
-               this->scale_input = input;
-               this->w_scale = w_scale;
-               this->h_scale = h_scale;
-               this->in_x1_int = in_x1_int;
-               this->in_y1_int = in_y1_int;
-               this->out_w_int = temp_w;
-               this->out_h_int = temp_h;
-               this->interpolation_type = interpolation_type;
-
-//printf("OverlayFrame::overlay ScaleEngine 1 %d\n", out_h_int);
-               if(!scale_engine) scale_engine = new ScaleEngine(this, cpus);
-               scale_engine->process_packages();
-//printf("OverlayFrame::overlay ScaleEngine 2\n");
-
-
-
-       }
-
-// printf("OverlayFrame::overlay 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-
-
-
-
-
-#define NO_TRANSLATION2 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(in_x2, translation_input->get_w()) && \
-       EQUIV(in_y2, translation_input->get_h()) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(out_x2, output->get_w()) && \
-       EQUIV(out_y2, output->get_h())) \
-
-#define NO_SCALE \
-       (EQUIV(out_x2 - out_x1, in_x2 - in_x1) && \
-       EQUIV(out_y2 - out_y1, in_y2 - in_y1))
-
-       
-
-
-//printf("OverlayFrame::overlay 4 %d\n", mode);
-
-
-
-
-       if(translation_input)
-       {
-// Direct copy
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE &&
-                       NO_BLEND)
-               {
-//printf("OverlayFrame::overlay direct copy\n");
-                       output->copy_from(translation_input);
-               }
-               else
-// Blend only
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE)
-               {
-                       if(!blend_engine) blend_engine = new BlendEngine(this, cpus);
-
-
-                       blend_engine->output = output;
-                       blend_engine->input = translation_input;
-                       blend_engine->alpha = alpha;
-                       blend_engine->mode = mode;
-
-                       blend_engine->process_packages();
-               }
-               else
-// Scale and translate using nearest neighbor
-// Translation is exactly on integer boundaries
-               if(interpolation_type == NEAREST_NEIGHBOR ||
-                       EQUIV(in_x1, (int)in_x1) &&
-                       EQUIV(in_y1, (int)in_y1) &&
-                       EQUIV(in_x2, (int)in_x2) &&
-                       EQUIV(in_y2, (int)in_y2) &&
-
-                       EQUIV(out_x1, (int)out_x1) &&
-                       EQUIV(out_y1, (int)out_y1) &&
-                       EQUIV(out_x2, (int)out_x2) &&
-                       EQUIV(out_y2, (int)out_y2))
-               {
-//printf("OverlayFrame::overlay NEAREST_NEIGHBOR 1\n");
-                       if(!scaletranslate_engine) scaletranslate_engine = new ScaleTranslateEngine(this, cpus);
-
-
-                       scaletranslate_engine->output = output;
-                       scaletranslate_engine->input = translation_input;
-                       scaletranslate_engine->in_x1 = (int)in_x1;
-                       scaletranslate_engine->in_y1 = (int)in_y1;
-                       scaletranslate_engine->in_x2 = (int)in_x2;
-                       scaletranslate_engine->in_y2 = (int)in_y2;
-                       scaletranslate_engine->out_x1 = (int)out_x1;
-                       scaletranslate_engine->out_y1 = (int)out_y1;
-                       scaletranslate_engine->out_x2 = (int)out_x2;
-                       scaletranslate_engine->out_y2 = (int)out_y2;
-                       scaletranslate_engine->alpha = alpha;
-                       scaletranslate_engine->mode = mode;
-
-                       scaletranslate_engine->process_packages();
-               }
-               else
-// Fractional translation
-               {
-// Use fractional translation
-// printf("OverlayFrame::overlay temp -> output  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-                       this->translate_output = output;
-                       this->translate_input = translation_input;
-                       this->translate_in_x1 = in_x1;
-                       this->translate_in_y1 = in_y1;
-                       this->translate_in_x2 = in_x2;
-                       this->translate_in_y2 = in_y2;
-                       this->translate_out_x1 = out_x1;
-                       this->translate_out_y1 = out_y1;
-                       this->translate_out_x2 = out_x2;
-                       this->translate_out_y2 = out_y2;
-                       this->translate_alpha = alpha;
-                       this->translate_mode = mode;
-
-//printf("OverlayFrame::overlay 5 %d\n", mode);
-                       if(!translate_engine) translate_engine = new TranslateEngine(this, cpus);
-                       translate_engine->process_packages();
-
-               }
-       }
-//printf("OverlayFrame::overlay 2\n");
-
-       return 0;
-}
-
-
-
-
-
-
-
-ScalePackage::ScalePackage()
-{
-}
-
-
-
-
-ScaleUnit::ScaleUnit(ScaleEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-}
-
-ScaleUnit::~ScaleUnit()
-{
-}
-
-
-
-#define BILINEAR(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       type zero_r, zero_g, zero_b, zero_a; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
- \
-       zero_r = 0; \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       if(components == 4) zero_a = 0; \
- \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               float f_y = (float)i * k_y; \
-               int i_y = (int)floor(f_y); \
-               float a = f_y - floor(f_y); \
-               type *in_row1 = in_rows[i_y + in_y1_int]; \
-               type *in_row2 = (i_y + in_y1_int < in_h_int - 1) ?  \
-                       in_rows[i_y + in_y1_int + 1] : \
-                       0; \
-               type *out_row = out_rows[i]; \
- \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       float f_x = (float)j * k_x; \
-                       int i_x = (int)floor(f_x); \
-                       float b = f_x - floor(f_x); \
-                       int x = i_x + in_x1_int; \
-                       float output1r, output1g, output1b, output1a; \
-                       float output2r, output2g, output2b, output2a; \
-                       float output3r, output3g, output3b, output3a; \
-                       float output4r, output4g, output4b, output4a; \
- \
-                       output1r = in_row1[x * components]; \
-                       output1g = in_row1[x * components + 1]; \
-                       output1b = in_row1[x * components + 2]; \
-                       if(components == 4) output1a = in_row1[x * components + 3]; \
- \
-                       if(x < in_w_int - 1) \
-                       { \
-                               output2r = in_row1[x * components + components]; \
-                               output2g = in_row1[x * components + components + 1]; \
-                               output2b = in_row1[x * components + components + 2]; \
-                               if(components == 4) output2a = in_row1[x * components + components + 3]; \
- \
-                               if(in_row2) \
-                               { \
-                                       output4r = in_row2[x * components + components]; \
-                                       output4g = in_row2[x * components + components + 1]; \
-                                       output4b = in_row2[x * components + components + 2]; \
-                                       if(components == 4) output4a = in_row2[x * components + components + 3]; \
-                               } \
-                               else \
-                               { \
-                                       output4r = zero_r; \
-                                       output4g = zero_g; \
-                                       output4b = zero_b; \
-                                       if(components == 4) output4a = zero_a; \
-                               } \
-                       } \
-                       else \
-                       { \
-                               output2r = zero_r; \
-                               output2g = zero_g; \
-                               output2b = zero_b; \
-                               if(components == 4) output2a = zero_a; \
-                               output4r = zero_r; \
-                               output4g = zero_g; \
-                               output4b = zero_b; \
-                               if(components == 4) output4a = zero_a; \
-                       } \
- \
-                       if(in_row2) \
-                       { \
-                               output3r = in_row2[x * components]; \
-                               output3g = in_row2[x * components + 1]; \
-                               output3b = in_row2[x * components + 2]; \
-                               if(components == 4) output3a = in_row2[x * components + 3]; \
-                       } \
-                       else \
-                       { \
-                               output3r = zero_r; \
-                               output3g = zero_g; \
-                               output3b = zero_b; \
-                               if(components == 4) output3a = zero_a; \
-                       } \
- \
-            float anti_a = 1.0F - a; \
-                       float anti_b = 1.0F - b; \
-                       out_row[j * components] =  \
-                               (type)((anti_a) * (((anti_b) * output1r) +  \
-                               (b * output2r)) +  \
-                a * (((anti_b) * output3r) +  \
-                               (b * output4r))); \
-                       out_row[j * components + 1] =   \
-                               (type)((anti_a) * (((anti_b) * output1g) +  \
-                               (b * output2g)) +  \
-                a * (((anti_b) * output3g) +  \
-                               (b * output4g))); \
-                       out_row[j * components + 2] =   \
-                               (type)((anti_a) * (((anti_b) * output1b) +  \
-                               (b * output2b)) +  \
-                a * (((anti_b) * output3b) +  \
-                               (b * output4b))); \
-                       if(components == 4) \
-                               out_row[j * components + 3] =   \
-                                       (type)((anti_a) * (((anti_b) * output1a) +  \
-                                       (b * output2a)) +  \
-                       a * (((anti_b) * output3a) +  \
-                                       (b * output4a))); \
-               } \
-       } \
- \
- \
-}
-
-
-#define BICUBIC(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       float *bspline_x, *bspline_y; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
-       type zero_r, zero_g, zero_b, zero_a; \
- \
-       zero_r = 0; \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
-       if(components == 4) \
-               zero_a = 0; \
- \
-       tabulate_bspline(bspline_x,  \
-               k_x, \
-               out_w_int, \
-               -1); \
- \
-       tabulate_bspline(bspline_y,  \
-               k_y, \
-               out_h_int, \
-               1); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               float f_y = (float)i * k_y; \
-               int i_y = (int)floor(f_y); \
-               float a = f_y - floor(f_y); \
- \
- \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       float f_x = (float)j * k_x; \
-                       int i_x = (int)floor(f_x); \
-                       float b = f_x - floor(f_x); \
-                       float output1, output2, output3, output4; \
-                       output1 = 0; \
-                       output2 = 0; \
-                       output3 = 0; \
-                       if(components == 4) \
-                               output4 = 0; \
-                       int table_y = i * 4; \
- \
-/* Kernel */ \
-                       for(int m = -1; m < 3; m++) \
-                       { \
-                               float r1 = bspline_y[table_y++]; \
-                               int y = in_y1_int + i_y + m; \
-                               int table_x = j * 4; \
- \
-                               for(int n = -1; n < 3; n++) \
-                               { \
-                                       float r2 = bspline_x[table_x++]; \
-                                       int x = in_x1_int + i_x + n; \
-                                       float r_square = r1 * r2; \
- \
-/* Inside boundary. */ \
-                                       if(x >= 0 && \
-                                               x < in_w_int && \
-                                               y >= 0 && \
-                                               y < in_h_int) \
-                                       { \
-                                               output1 += r_square * in_rows[y][x * components]; \
-                                               output2 += r_square * in_rows[y][x * components + 1]; \
-                                               output3 += r_square * in_rows[y][x * components + 2]; \
-                                               if(components == 4) \
-                                                       output4 += r_square * in_rows[y][x * components + 3]; \
-                                       } \
-                                       else \
-                                       { \
-                                               output1 += r_square * zero_r; \
-                                               output2 += r_square * zero_g; \
-                                               output3 += r_square * zero_b; \
-                                               if(components == 4) \
-                                                       output4 += r_square * zero_a; \
-                                       } \
-                               } \
-                       } \
- \
- \
-                       out_rows[i][j * components] = (type)output1; \
-                       out_rows[i][j * components + 1] = (type)output2; \
-                       out_rows[i][j * components + 2] = (type)output3; \
-                       if(components == 4) \
-                               out_rows[i][j * components + 3] = (type)output4; \
- \
-               } \
-       } \
- \
-       delete [] bspline_x; \
-       delete [] bspline_y; \
-}
-
-
-
-// Pow function is not thread safe in Compaqt C
-#define CUBE(x) ((x) * (x) * (x))
-
-float ScaleUnit::cubic_bspline(float x)
-{
-       float a, b, c, d;
-
-       if((x + 2.0F) <= 0.0F) 
-       {
-       a = 0.0F;
-       }
-       else 
-       {
-       a = CUBE(x + 2.0F);
-       }
-
-
-       if((x + 1.0F) <= 0.0F) 
-       {
-       b = 0.0F;
-       }
-       else 
-       {
-       b = CUBE(x + 1.0F);
-       }    
-
-       if(x <= 0) 
-       {
-       c = 0.0F;
-       }
-       else 
-       {
-       c = CUBE(x);
-       }  
-
-       if((x - 1.0F) <= 0.0F) 
-       {
-       d = 0.0F;
-       }
-       else 
-       {
-       d = CUBE(x - 1.0F);
-       }
-
-       return (a - (4.0F * b) + (6.0F * c) - (4.0F * d)) / 6.0;
-}
-
-
-void ScaleUnit::tabulate_bspline(float* &table, 
-       float scale,
-       int pixels,
-       float coefficient)
-{
-       table = new float[pixels * 4];
-
-       for(int i = 0, j = 0; i < pixels; i++)
-       {
-               float f_x = (float)i * scale;
-               float a = f_x - floor(f_x);
-               
-               for(float m = -1; m < 3; m++)
-               {
-                       table[j++] = cubic_bspline(coefficient * (m - a));
-               }
-       }
-}
-
-void ScaleUnit::process_package(LoadPackage *package)
-{
-       ScalePackage *pkg = (ScalePackage*)package;
-
-// Arguments for macros
-       VFrame *output = overlay->scale_output;
-       VFrame *input = overlay->scale_input;
-       float scale_w = overlay->w_scale;
-       float scale_h = overlay->h_scale;
-       int in_x1_int = overlay->in_x1_int;
-       int in_y1_int = overlay->in_y1_int;
-       int out_h_int = overlay->out_h_int;
-       int out_w_int = overlay->out_w_int;
-       int do_yuv = 
-               (overlay->scale_input->get_color_model() == BC_YUV888 ||
-               overlay->scale_input->get_color_model() == BC_YUVA8888 ||
-               overlay->scale_input->get_color_model() == BC_YUV161616 ||
-               overlay->scale_input->get_color_model() == BC_YUVA16161616);
-
-       if(overlay->interpolation_type == CUBIC_CUBIC || 
-               (overlay->interpolation_type == CUBIC_LINEAR 
-                       && overlay->w_scale > 1 && 
-                       overlay->h_scale > 1))
-       {
-       
-               switch(overlay->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BICUBIC(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BICUBIC(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BICUBIC(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BICUBIC(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-       else
-// Perform bilinear scaling input -> scale_output
-       {
-               switch(overlay->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BILINEAR(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BILINEAR(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BILINEAR(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BILINEAR(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-ScaleEngine::ScaleEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-ScaleEngine::~ScaleEngine()
-{
-}
-
-void ScaleEngine::init_packages()
-{
-       for(int i = 0; i < total_packages; i++)
-       {
-               ScalePackage *package = (ScalePackage*)packages[i];
-               package->out_row1 = overlay->out_h_int / total_packages * i;
-               package->out_row2 = package->out_row1 + overlay->out_h_int / total_packages;
-
-               if(i >= total_packages - 1)
-                       package->out_row2 = overlay->out_h_int;
-       }
-}
-
-LoadClient* ScaleEngine::new_client()
-{
-       return new ScaleUnit(this, overlay);
-}
-
-LoadPackage* ScaleEngine::new_package()
-{
-       return new ScalePackage;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-TranslatePackage::TranslatePackage()
-{
-}
-
-
-
-TranslateUnit::TranslateUnit(TranslateEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-}
-
-TranslateUnit::~TranslateUnit()
-{
-}
-
-
-
-void TranslateUnit::translation_array(transfer_table* &table, 
-       float out_x1, 
-       float out_x2,
-       float in_x1,
-       float in_x2,
-       int in_total, 
-       int out_total, 
-       int &out_x1_int,
-       int &out_x2_int)
-{
-       int out_w_int;
-       float offset = out_x1 - in_x1;
-
-       out_x1_int = (int)out_x1;
-       out_x2_int = MIN((int)ceil(out_x2), out_total);
-       out_w_int = out_x2_int - out_x1_int;
-
-       table = new transfer_table[out_w_int];
-       bzero(table, sizeof(transfer_table) * out_w_int);
-
-
-//printf("OverlayFrame::translation_array 1 %f %f -> %f %f\n", in_x1, in_x2, out_x1, out_x2);
-
-       float in_x = in_x1;
-       for(int out_x = out_x1_int; out_x < out_x2_int; out_x++)
-       {
-               transfer_table *entry = &table[out_x - out_x1_int];
-
-               entry->in_x1 = (int)in_x;
-               entry->in_x2 = (int)in_x + 1;
-
-// Get fraction of output pixel to fill
-               entry->output_fraction = 1;
-
-               if(out_x1 > out_x)
-               {
-                       entry->output_fraction -= out_x1 - out_x;
-               }
-
-               if(out_x2 < out_x + 1)
-               {
-                       entry->output_fraction = (out_x2 - out_x);
-               }
-
-// Advance in_x until out_x_fraction is filled
-               float out_x_fraction = entry->output_fraction;
-               float in_x_fraction = floor(in_x + 1) - in_x;
-
-               if(out_x_fraction <= in_x_fraction)
-               {
-                       entry->in_fraction1 = out_x_fraction;
-                       entry->in_fraction2 = 0.0;
-                       in_x += out_x_fraction;
-               }
-               else
-               {
-                       entry->in_fraction1 = in_x_fraction;
-                       in_x += out_x_fraction;
-                       entry->in_fraction2 = in_x - floor(in_x);
-               }
-
-// Clip in_x
-               if(entry->in_x2 >= in_total)
-               {
-                       entry->in_x2 = in_total - 1;
-                       entry->in_fraction2 = 0.0;
-               }
-               
-               if(entry->in_x1 >= in_total)
-               {
-                       entry->in_x1 = in_total - 1;
-                       entry->in_fraction1 = 0.0;
-               }
-// printf("OverlayFrame::translation_array 2 %d %d %d %f %f %f\n", 
-//     out_x, 
-//     entry->in_x1, 
-//     entry->in_x2, 
-//     entry->in_fraction1, 
-//     entry->in_fraction2, 
-//     entry->output_fraction);
-       }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#define TRANSLATE(max, type, components) \
-{ \
- \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
- \
-/* printf("OverlayFrame::translate 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",  */ \
-/*     (in_x1),  in_y1,  in_x2,  in_y2,  out_x1,  out_y1, out_x2,  out_y2); */ \
- \
-       unsigned int master_opacity = (int)(alpha * max + 0.5); \
-       unsigned int master_transparency = max - master_opacity; \
- \
-/* printf("TRANSLATE %d\n", mode); */ \
- \
-       for(int i = row1; i < row2; i++) \
-       { \
-               int in_y1 = y_table[i - out_y1_int].in_x1; \
-               int in_y2 = y_table[i - out_y1_int].in_x2; \
-               float y_fraction1 = y_table[i - out_y1_int].in_fraction1; \
-               float y_fraction2 = y_table[i - out_y1_int].in_fraction2; \
-               float y_output_fraction = y_table[i - out_y1_int].output_fraction; \
-               type *in_row1 = in_rows[(in_y1)]; \
-               type *in_row2 = in_rows[(in_y2)]; \
-               type *out_row = out_rows[i]; \
- \
-               for(int j = out_x1_int; j < out_x2_int; j++) \
-               { \
-                       int in_x1 = x_table[j - out_x1_int].in_x1; \
-                       int in_x2 = x_table[j - out_x1_int].in_x2; \
-                       float x_fraction1 = x_table[j - out_x1_int].in_fraction1; \
-                       float x_fraction2 = x_table[j - out_x1_int].in_fraction2; \
-                       float x_output_fraction = x_table[j - out_x1_int].output_fraction; \
-                       type *output = &out_row[j * components]; \
-                       int input1, input2, input3, input4; \
- \
-                       input1 = (int)(in_row1[in_x1 * components] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_x1 * components] * x_fraction1 * y_fraction2 +  \
-                               in_row2[in_x2 * components] * x_fraction2 * y_fraction2 + 0.5); \
-                       input2 = (int)(in_row1[in_x1 * components + 1] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components + 1] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_x1 * components + 1] * x_fraction1 * y_fraction2 +  \
-                               in_row2[in_x2 * components + 1] * x_fraction2 * y_fraction2 + 0.5); \
-                       input3 = (int)(in_row1[in_x1 * components + 2] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components + 2] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_x1 * components + 2] * x_fraction1 * y_fraction2 +  \
-                               in_row2[in_x2 * components + 2] * x_fraction2 * y_fraction2 + 0.5); \
-                       if(components == 4) \
-                               input4 = (int)(in_row1[in_x1 * components + 3] * x_fraction1 * y_fraction1 +  \
-                                       in_row1[in_x2 * components + 3] * x_fraction2 * y_fraction1 +  \
-                                       in_row2[in_x1 * components + 3] * x_fraction1 * y_fraction2 +  \
-                                       in_row2[in_x2 * components + 3] * x_fraction2 * y_fraction2 + 0.5); \
- \
-                       unsigned int opacity = (int)(master_opacity *  \
-                               y_output_fraction *  \
-                               x_output_fraction + 0.5); \
-                       unsigned int transparency = max - opacity; \
- \
-/* if(opacity != max) printf("TRANSLATE %x %d %d\n", opacity, j, i); */ \
- \
-                       if(components == 3) \
-                       { \
-                               BLEND_3(max, type); \
-                       } \
-                       else \
-                       { \
-                               BLEND_4(max, type); \
-                       } \
-               } \
-       } \
-}
-
-void TranslateUnit::process_package(LoadPackage *package)
-{
-       TranslatePackage *pkg = (TranslatePackage*)package;
-       int out_y1_int; 
-       int out_y2_int; 
-       int out_x1_int; 
-       int out_x2_int; 
-
-
-// Variables for TRANSLATE
-       VFrame *input = overlay->translate_input;
-       VFrame *output = overlay->translate_output;
-       float in_x1 = overlay->translate_in_x1;
-       float in_y1 = overlay->translate_in_y1;
-       float in_x2 = overlay->translate_in_x2;
-       float in_y2 = overlay->translate_in_y2;
-       float out_x1 = overlay->translate_out_x1;
-       float out_y1 = overlay->translate_out_y1;
-       float out_x2 = overlay->translate_out_x2;
-       float out_y2 = overlay->translate_out_y2;
-       float alpha = overlay->translate_alpha;
-       int row1 = pkg->out_row1;
-       int row2 = pkg->out_row2;
-       int mode = overlay->translate_mode;
-
-       transfer_table *x_table; 
-       transfer_table *y_table; 
-       translation_array(x_table,  
-               out_x1,  
-               out_x2, 
-               in_x1, 
-               in_x2, 
-               input->get_w(),  
-               output->get_w(),  
-               out_x1_int, 
-               out_x2_int); 
-       translation_array(y_table,  
-               out_y1,  
-               out_y2, 
-               in_y1, 
-               in_y2, 
-               input->get_h(),  
-               output->get_h(),  
-               out_y1_int, 
-               out_y2_int); 
-       switch(overlay->translate_input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       TRANSLATE(0xff, unsigned char, 3);
-                       break;
-
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       TRANSLATE(0xff, unsigned char, 4);
-                       break;
-
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       TRANSLATE(0xffff, uint16_t, 3);
-                       break;
-
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       TRANSLATE(0xffff, uint16_t, 4);
-                       break;
-       }
-       delete [] x_table; 
-       delete [] y_table; 
-}
-
-
-
-
-
-
-
-
-
-
-TranslateEngine::TranslateEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-TranslateEngine::~TranslateEngine()
-{
-}
-
-void TranslateEngine::init_packages()
-{
-       int out_y1_int = (int)overlay->translate_out_y1;
-       int out_y2_int = MIN((int)ceil(overlay->translate_out_y2), overlay->translate_output->get_h());
-       int out_h = out_y2_int - out_y1_int;
-
-       for(int i = 0; i < total_packages; i++)
-       {
-               TranslatePackage *package = (TranslatePackage*)packages[i];
-               package->out_row1 = (int)(out_y1_int + out_h / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 + 
-                       out_h / 
-                       total_packages);
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_y2_int;
-       }
-}
-
-LoadClient* TranslateEngine::new_client()
-{
-       return new TranslateUnit(this, overlay);
-}
-
-LoadPackage* TranslateEngine::new_package()
-{
-       return new TranslatePackage;
-}
-
-
-
-
-
-
-
-
-#define SCALE_TRANSLATE(max, type, components) \
-{ \
-       int64_t opacity = (int)(alpha * max + 0.5); \
-       int64_t transparency = max - opacity; \
-       int out_w = out_x2 - out_x1; \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               int in_y = y_table[i - out_y1]; \
-               type *in_row = (type*)in_rows[in_y] + in_x1 * components; \
-               type *out_row = (type*)out_rows[i] + out_x1 * components; \
- \
-/* X direction is scaled and requires a table lookup */ \
-               if(out_w != in_x2 - in_x1) \
-               { \
-                       for(int j = 0; j < out_w; j++) \
-                       { \
-                               int in_x = x_table[j]; \
-                               int input1, input2, input3, input4; \
-                               type *output = out_row + j * components; \
-        \
-                               input1 = in_row[in_x * components]; \
-                               input2 = in_row[in_x * components + 1]; \
-                               input3 = in_row[in_x * components + 2]; \
-                               if(components == 4) \
-                                       input4 = in_row[in_x * components + 3]; \
-        \
-                               if(components == 3) \
-                               { \
-                                       BLEND_3(max, type); \
-                               } \
-                               else \
-                               { \
-                                       BLEND_4(max, type); \
-                               } \
-                       } \
-               } \
-               else \
-/* X direction is not scaled */ \
-               { \
-                       for(int j = 0; j < out_w; j++) \
-                       { \
-                               int input1, input2, input3, input4; \
-                               type *output = out_row + j * components; \
-        \
-                               input1 = in_row[j * components]; \
-                               input2 = in_row[j * components + 1]; \
-                               input3 = in_row[j * components + 2]; \
-                               if(components == 4) \
-                                       input4 = in_row[j * components + 3]; \
-        \
-                               if(components == 3) \
-                               { \
-                                       BLEND_3(max, type); \
-                               } \
-                               else \
-                               { \
-                                       BLEND_4(max, type); \
-                               } \
-                       } \
-               } \
-       } \
-}
-
-
-
-ScaleTranslateUnit::ScaleTranslateUnit(ScaleTranslateEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->scale_translate = server;
-}
-
-ScaleTranslateUnit::~ScaleTranslateUnit()
-{
-}
-
-void ScaleTranslateUnit::scale_array(int* &table, 
-       int out_x1, 
-       int out_x2,
-       int in_x1,
-       int in_x2,
-       int is_x)
-{
-       float scale = (float)(out_x2 - out_x1) / (in_x2 - in_x1);
-
-       table = new int[out_x2 - out_x1];
-       
-       if(!is_x)
-       {
-               for(int i = 0; i < out_x2 - out_x1; i++)
-               {
-                       table[i] = (int)((float)i / scale + in_x1);
-               }
-       }
-       else
-       {       
-               for(int i = 0; i < out_x2 - out_x1; i++)
-               {
-                       table[i] = (int)((float)i / scale);
-               }
-       }
-}
-
-
-void ScaleTranslateUnit::process_package(LoadPackage *package)
-{
-       ScaleTranslatePackage *pkg = (ScaleTranslatePackage*)package;
-
-// Args for NEAREST_NEIGHBOR_MACRO
-       VFrame *output = scale_translate->output;
-       VFrame *input = scale_translate->input;
-       int in_x1 = scale_translate->in_x1;
-       int in_y1 = scale_translate->in_y1;
-       int in_x2 = scale_translate->in_x2;
-       int in_y2 = scale_translate->in_y2;
-       int out_x1 = scale_translate->out_x1;
-       int out_y1 = scale_translate->out_y1;
-       int out_x2 = scale_translate->out_x2;
-       int out_y2 = scale_translate->out_y2;
-       float alpha = scale_translate->alpha;
-       int mode = scale_translate->mode;
-
-       int *x_table;
-       int *y_table;
-       unsigned char **in_rows = input->get_rows();
-       unsigned char **out_rows = output->get_rows();
-
-       scale_array(x_table, 
-               out_x1, 
-               out_x2,
-               in_x1,
-               in_x2,
-               1);
-       scale_array(y_table, 
-               out_y1, 
-               out_y2,
-               in_y1,
-               in_y2,
-               0);
-
-
-       switch(input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       SCALE_TRANSLATE(0xff, uint8_t, 3);
-                       break;
-
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       SCALE_TRANSLATE(0xff, uint8_t, 4);
-                       break;
-
-
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       SCALE_TRANSLATE(0xffff, uint16_t, 3);
-                       break;
-
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       SCALE_TRANSLATE(0xffff, uint16_t, 4);
-                       break;
-       }
-       
-       delete [] x_table;
-       delete [] y_table;
-
-};
-
-
-
-
-
-
-
-
-
-ScaleTranslateEngine::ScaleTranslateEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-ScaleTranslateEngine::~ScaleTranslateEngine()
-{
-}
-
-void ScaleTranslateEngine::init_packages()
-{
-       int out_h = out_y2 - out_y1;
-
-       for(int i = 0; i < total_packages; i++)
-       {
-               ScaleTranslatePackage *package = (ScaleTranslatePackage*)packages[i];
-               package->out_row1 = (int)(out_y1 + out_h / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 + 
-                       out_h / 
-                       total_packages);
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_y2;
-       }
-}
-
-LoadClient* ScaleTranslateEngine::new_client()
-{
-       return new ScaleTranslateUnit(this, overlay);
-}
-
-LoadPackage* ScaleTranslateEngine::new_package()
-{
-       return new ScaleTranslatePackage;
-}
-
-
-ScaleTranslatePackage::ScaleTranslatePackage()
-{
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#define BLEND_ONLY(type, max, components) \
-{ \
-       int64_t opacity = (int)(alpha * max + 0.5); \
-       int64_t transparency = max - opacity; \
- \
-       type** output_rows = (type**)output->get_rows(); \
-       type** input_rows = (type**)input->get_rows(); \
-       int w = input->get_w(); \
-       int h = input->get_h(); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               type* in_row = input_rows[i]; \
-               type* output = output_rows[i]; \
- \
-               for(int j = 0; j < w; j++) \
-               { \
-                       int input1, input2, input3, input4; \
-                       input1 = in_row[j * components]; \
-                       input2 = in_row[j * components + 1]; \
-                       input3 = in_row[j * components + 2]; \
-                       if(components == 4) input4 = in_row[j * components + 3]; \
- \
- \
-                       if(components == 3) \
-                       { \
-                               BLEND_3(max, type); \
-                       } \
-                       else \
-                       { \
-                               BLEND_4(max, type); \
-                       } \
- \
-                       input += components; \
-                       output += components; \
-               } \
-       } \
-}
-
-
-
-
-BlendUnit::BlendUnit(BlendEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->blend_engine = server;
-}
-
-BlendUnit::~BlendUnit()
-{
-}
-
-void BlendUnit::process_package(LoadPackage *package)
-{
-       BlendPackage *pkg = (BlendPackage*)package;
-
-
-       VFrame *output = blend_engine->output;
-       VFrame *input = blend_engine->input;
-       float alpha = blend_engine->alpha;
-       int mode = blend_engine->mode;
-
-       switch(input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       BLEND_ONLY(unsigned char, 0xff, 3);
-                       break;
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       BLEND_ONLY(unsigned char, 0xff, 4);
-                       break;
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       BLEND_ONLY(uint16_t, 0xffff, 3);
-                       break;
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       BLEND_ONLY(uint16_t, 0xffff, 4);
-                       break;
-       }
-}
-
-
-
-BlendEngine::BlendEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-BlendEngine::~BlendEngine()
-{
-}
-
-void BlendEngine::init_packages()
-{
-       for(int i = 0; i < total_packages; i++)
-       {
-               BlendPackage *package = (BlendPackage*)packages[i];
-               package->out_row1 = (int)(input->get_h() / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 +
-                       input->get_h() / 
-                       total_packages);
-
-               if(i >= total_packages - 1)
-                       package->out_row2 = input->get_h();
-       }
-}
-
-LoadClient* BlendEngine::new_client()
-{
-       return new BlendUnit(this, overlay);
-}
-
-LoadPackage* BlendEngine::new_package()
-{
-       return new BlendPackage;
-}
-
-
-BlendPackage::BlendPackage()
-{
-}
-
-
diff --git a/cinelerra-5.1/cinelerra/overlayframe.C.floattable b/cinelerra-5.1/cinelerra/overlayframe.C.floattable
deleted file mode 100644 (file)
index 6b01219..0000000
+++ /dev/null
@@ -1,1769 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-
-#include "clip.h"
-#include "edl.inc"
-#include "mutex.h"
-#include "overlayframe.h"
-#include "vframe.h"
-
-OverlayFrame::OverlayFrame(int cpus)
-{
-       temp_frame = 0;
-       blend_engine = 0;
-       scale_engine = 0;
-       scaletranslate_engine = 0;
-       translate_engine = 0;
-       this->cpus = cpus;
-}
-
-OverlayFrame::~OverlayFrame()
-{
-//printf("OverlayFrame::~OverlayFrame 1\n");
-       if(temp_frame) delete temp_frame;
-       if(scale_engine) delete scale_engine;
-       if(translate_engine) delete translate_engine;
-       if(blend_engine) delete blend_engine;
-       if(scaletranslate_engine) delete scaletranslate_engine;
-//printf("OverlayFrame::~OverlayFrame 2\n");
-}
-
-
-
-
-
-
-
-
-// Verification: 
-
-// (255 * 255 + 0 * 0) / 255 = 255
-// (255 * 127 + 255 * (255 - 127)) / 255 = 255
-
-// (65535 * 65535 + 0 * 0) / 65535 = 65535
-// (65535 * 32767 + 65535 * (65535 - 32767)) / 65535 = 65535
-
-
-// Branch prediction 4 U
-
-#define BLEND_3(max, type) \
-{ \
-       int64_t r, g, b; \
- \
-/* if(mode != TRANSFER_NORMAL) printf("BLEND mode = %d\n", mode); */ \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * opacity + output[0] * transparency) / max; \
-                       g = ((int64_t)input2 * opacity + output[1] * transparency) / max; \
-                       b = ((int64_t)input3 * opacity + output[2] * transparency) / max; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-}
-
-
-
-
-
-// Blending equations are drastically different for 3 and 4 components
-#define BLEND_4(max, type) \
-{ \
-       int64_t r, g, b, a; \
-       int64_t pixel_opacity, pixel_transparency; \
- \
-       pixel_opacity = opacity * input4 / max; \
-       pixel_transparency = (max - pixel_opacity) * output[3] / max; \
- \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       a = input4; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = ((int64_t)input2 * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = ((int64_t)input3 * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-       output[3] = (type)a; \
-}
-
-
-
-
-
-
-
-
-// Bicubic algorithm using multiprocessors
-// input -> scale nearest integer boundaries -> temp -> translation -> blend -> output
-
-// Nearest neighbor algorithm using multiprocessors for blending
-// input -> scale + translate -> blend -> output
-
-
-int OverlayFrame::overlay(VFrame *output, 
-       VFrame *input, 
-       float in_x1, 
-       float in_y1, 
-       float in_x2, 
-       float in_y2, 
-       float out_x1, 
-       float out_y1, 
-       float out_x2, 
-       float out_y2, 
-       float alpha,       // 0 - 1
-       int mode,
-       int interpolation_type)
-{
-       float w_scale = (out_x2 - out_x1) / (in_x2 - in_x1);
-       float h_scale = (out_y2 - out_y1) / (in_y2 - in_y1);
-
-//printf("OverlayFrame::overlay 1 %d %f\n", mode, alpha);
-// Limit values
-       if(in_x1 < 0)
-       {
-               out_x1 += -in_x1 * w_scale;
-               in_x1 = 0;
-       }
-       else
-       if(in_x1 >= input->get_w())
-       {
-               out_x1 -= (in_x1 - input->get_w()) * w_scale;
-               in_x1 = input->get_w();
-       }
-
-       if(in_y1 < 0)
-       {
-               out_y1 += -in_y1 * h_scale;
-               in_y1 = 0;
-       }
-       else
-       if(in_y1 >= input->get_h())
-       {
-               out_y1 -= (in_y1 - input->get_h()) * h_scale;
-               in_y1 = input->get_h();
-       }
-
-       if(in_x2 < 0)
-       {
-               out_x2 += -in_x2 * w_scale;
-               in_x2 = 0;
-       }
-       else
-       if(in_x2 >= input->get_w())
-       {
-               out_x2 -= (in_x2 - input->get_w()) * w_scale;
-               in_x2 = input->get_w();
-       }
-
-       if(in_y2 < 0)
-       {
-               out_y2 += -in_y2 * h_scale;
-               in_y2 = 0;
-       }
-       else
-       if(in_y2 >= input->get_h())
-       {
-               out_y2 -= (in_y2 - input->get_h()) * h_scale;
-               in_y2 = input->get_h();
-       }
-
-       if(out_x1 < 0)
-       {
-               in_x1 += -out_x1 / w_scale;
-               out_x1 = 0;
-       }
-       else
-       if(out_x1 >= output->get_w())
-       {
-               in_x1 -= (out_x1 - output->get_w()) / w_scale;
-               out_x1 = output->get_w();
-       }
-
-       if(out_y1 < 0)
-       {
-               in_y1 += -out_y1 / h_scale;
-               out_y1 = 0;
-       }
-       else
-       if(out_y1 >= output->get_h())
-       {
-               in_y1 -= (out_y1 - output->get_h()) / h_scale;
-               out_y1 = output->get_h();
-       }
-
-       if(out_x2 < 0)
-       {
-               in_x2 += -out_x2 / w_scale;
-               out_x2 = 0;
-       }
-       else
-       if(out_x2 >= output->get_w())
-       {
-               in_x2 -= (out_x2 - output->get_w()) / w_scale;
-               out_x2 = output->get_w();
-       }
-
-       if(out_y2 < 0)
-       {
-               in_y2 += -out_y2 / h_scale;
-               out_y2 = 0;
-       }
-       else
-       if(out_y2 >= output->get_h())
-       {
-               in_y2 -= (out_y2 - output->get_h()) / h_scale;
-               out_y2 = output->get_h();
-       }
-
-
-
-
-
-       float in_w = in_x2 - in_x1;
-       float in_h = in_y2 - in_y1;
-       float out_w = out_x2 - out_x1;
-       float out_h = out_y2 - out_y1;
-// Input for translation operation
-       VFrame *translation_input = input;
-
-
-
-// printf("OverlayFrame::overlay %f %f %f %f -> %f %f %f %f\n", in_x1,
-//                     in_y1,
-//                     in_x2,
-//                     in_y2,
-//                     out_x1,
-//                     out_y1,
-//                     out_x2,
-//                     out_y2);
-
-
-
-
-
-// ****************************************************************************
-// Transfer to temp buffer by scaling nearest integer boundaries
-// ****************************************************************************
-       if(interpolation_type != NEAREST_NEIGHBOR &&
-               interpolation_type != LINEAR_LINEAR &&
-               (!EQUIV(w_scale, 1) || !EQUIV(h_scale, 1)))
-       {
-// Create integer boundaries for interpolation
-               int in_x1_int = (int)in_x1;
-               int in_y1_int = (int)in_y1;
-               int in_x2_int = MIN((int)ceil(in_x2), input->get_w());
-               int in_y2_int = MIN((int)ceil(in_y2), input->get_h());
-
-// Dimensions of temp frame.  Integer boundaries scaled.
-               int temp_w = (int)ceil(w_scale * (in_x2_int - in_x1_int));
-               int temp_h = (int)ceil(h_scale * (in_y2_int - in_y1_int));
-               VFrame *scale_output;
-
-
-
-#define NO_TRANSLATION1 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(in_x2, in_x2_int) && \
-       EQUIV(in_y2, in_y2_int) && \
-       EQUIV(out_x2, temp_w) && \
-       EQUIV(out_y2, temp_h))
-
-
-#define NO_BLEND \
-       (EQUIV(alpha, 1) && \
-       (mode == TRANSFER_REPLACE || \
-       (mode == TRANSFER_NORMAL && cmodel_components(input->get_color_model()) == 3)))
-
-
-
-
-
-// Prepare destination for operation
-
-// No translation and no blending.  The blending operation is built into the
-// translation unit but not the scaling unit.
-// input -> output
-               if(NO_TRANSLATION1 &&
-                       NO_BLEND)
-               {
-// printf("OverlayFrame::overlay input -> output\n");
-
-                       scale_output = output;
-                       translation_input = 0;
-               }
-               else
-// If translation or blending
-// input -> nearest integer boundary temp
-               {
-                       if(temp_frame && 
-                               (temp_frame->get_w() != temp_w ||
-                                       temp_frame->get_h() != temp_h))
-                       {
-                               delete temp_frame;
-                               temp_frame = 0;
-                       }
-
-                       if(!temp_frame)
-                       {
-                               temp_frame = new VFrame(0,
-                                       temp_w,
-                                       temp_h,
-                                       input->get_color_model(),
-                                       -1);
-                       }
-//printf("OverlayFrame::overlay input -> temp\n");
-
-
-                       temp_frame->clear_frame();
-
-// printf("OverlayFrame::overlay 4 temp_w=%d temp_h=%d\n",
-//     temp_w, temp_h);
-                       scale_output = temp_frame;
-                       translation_input = scale_output;
-
-// Adjust input coordinates to reflect new scaled coordinates.
-                       in_x1 = (in_x1 - in_x1_int) * w_scale;
-                       in_y1 = (in_y1 - in_y1_int) * h_scale;
-                       in_x2 = (in_x2 - in_x1_int) * w_scale;
-                       in_y2 = (in_y2 - in_y1_int) * h_scale;
-               }
-
-
-
-//printf("Overlay 1\n");
-
-// Scale input -> scale_output
-               if(!scale_engine) scale_engine = new ScaleEngine(this, cpus);
-               scale_engine->scale_output = scale_output;
-               scale_engine->scale_input = input;
-               scale_engine->w_scale = w_scale;
-               scale_engine->h_scale = h_scale;
-               scale_engine->in_x1_int = in_x1_int;
-               scale_engine->in_y1_int = in_y1_int;
-               scale_engine->out_w_int = temp_w;
-               scale_engine->out_h_int = temp_h;
-               scale_engine->interpolation_type = interpolation_type;
-//printf("Overlay 2\n");
-
-//printf("OverlayFrame::overlay ScaleEngine 1 %d\n", out_h_int);
-               scale_engine->process_packages();
-//printf("OverlayFrame::overlay ScaleEngine 2\n");
-
-
-
-       }
-
-// printf("OverlayFrame::overlay 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-
-
-
-
-
-#define NO_TRANSLATION2 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(in_x2, translation_input->get_w()) && \
-       EQUIV(in_y2, translation_input->get_h()) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(out_x2, output->get_w()) && \
-       EQUIV(out_y2, output->get_h())) \
-
-#define NO_SCALE \
-       (EQUIV(out_x2 - out_x1, in_x2 - in_x1) && \
-       EQUIV(out_y2 - out_y1, in_y2 - in_y1))
-
-       
-
-
-//printf("OverlayFrame::overlay 4 %d\n", mode);
-
-
-
-
-       if(translation_input)
-       {
-// Direct copy
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE &&
-                       NO_BLEND)
-               {
-//printf("OverlayFrame::overlay direct copy\n");
-                       output->copy_from(translation_input);
-               }
-               else
-// Blend only
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE)
-               {
-                       if(!blend_engine) blend_engine = new BlendEngine(this, cpus);
-
-
-                       blend_engine->output = output;
-                       blend_engine->input = translation_input;
-                       blend_engine->alpha = alpha;
-                       blend_engine->mode = mode;
-
-                       blend_engine->process_packages();
-               }
-               else
-// Scale and translate using nearest neighbor
-// Translation is exactly on integer boundaries
-               if(interpolation_type == NEAREST_NEIGHBOR ||
-                       EQUIV(in_x1, (int)in_x1) &&
-                       EQUIV(in_y1, (int)in_y1) &&
-                       EQUIV(in_x2, (int)in_x2) &&
-                       EQUIV(in_y2, (int)in_y2) &&
-
-                       EQUIV(out_x1, (int)out_x1) &&
-                       EQUIV(out_y1, (int)out_y1) &&
-                       EQUIV(out_x2, (int)out_x2) &&
-                       EQUIV(out_y2, (int)out_y2))
-               {
-//printf("OverlayFrame::overlay NEAREST_NEIGHBOR 1\n");
-                       if(!scaletranslate_engine) scaletranslate_engine = new ScaleTranslateEngine(this, cpus);
-
-
-                       scaletranslate_engine->output = output;
-                       scaletranslate_engine->input = translation_input;
-                       scaletranslate_engine->in_x1 = (int)in_x1;
-                       scaletranslate_engine->in_y1 = (int)in_y1;
-                       scaletranslate_engine->in_x2 = (int)in_x2;
-                       scaletranslate_engine->in_y2 = (int)in_y2;
-                       scaletranslate_engine->out_x1 = (int)out_x1;
-                       scaletranslate_engine->out_y1 = (int)out_y1;
-                       scaletranslate_engine->out_x2 = (int)out_x2;
-                       scaletranslate_engine->out_y2 = (int)out_y2;
-                       scaletranslate_engine->alpha = alpha;
-                       scaletranslate_engine->mode = mode;
-
-                       scaletranslate_engine->process_packages();
-               }
-               else
-// Fractional translation
-               {
-// Use fractional translation
-// printf("OverlayFrame::overlay temp -> output  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-
-//printf("Overlay 3\n");
-                       if(!translate_engine) translate_engine = new TranslateEngine(this, cpus);
-                       translate_engine->translate_output = output;
-                       translate_engine->translate_input = translation_input;
-                       translate_engine->translate_in_x1 = in_x1;
-                       translate_engine->translate_in_y1 = in_y1;
-                       translate_engine->translate_in_x2 = in_x2;
-                       translate_engine->translate_in_y2 = in_y2;
-                       translate_engine->translate_out_x1 = out_x1;
-                       translate_engine->translate_out_y1 = out_y1;
-                       translate_engine->translate_out_x2 = out_x2;
-                       translate_engine->translate_out_y2 = out_y2;
-                       translate_engine->translate_alpha = alpha;
-                       translate_engine->translate_mode = mode;
-//printf("Overlay 4\n");
-
-//printf("OverlayFrame::overlay 5 %d\n", mode);
-                       translate_engine->process_packages();
-
-               }
-       }
-//printf("OverlayFrame::overlay 2\n");
-
-       return 0;
-}
-
-
-
-
-
-
-
-ScalePackage::ScalePackage()
-{
-}
-
-
-
-
-ScaleUnit::ScaleUnit(ScaleEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->engine = server;
-}
-
-ScaleUnit::~ScaleUnit()
-{
-}
-
-
-
-#define BILINEAR(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       type zero_r, zero_g, zero_b, zero_a; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
-       int *table_int_x, *table_int_y; \
-       float *table_frac_x, *table_antifrac_x, *table_frac_y, *table_antifrac_y; \
- \
-       zero_r = 0; \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       if(components == 4) zero_a = 0; \
- \
-       tabulate_blinear(table_int_x, table_frac_x, table_antifrac_x, k_x, 0, out_w_int, in_w_int); \
-       tabulate_blinear(table_int_y, table_frac_y, table_antifrac_y, k_y, pkg->out_row1, pkg->out_row2, in_h_int); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               int i_y = table_int_y[i - pkg->out_row1]; \
-               float a = table_frac_y[i - pkg->out_row1]; \
-        float anti_a = table_antifrac_y[i - pkg->out_row1]; \
-               type *in_row1 = in_rows[i_y + in_y1_int]; \
-               type *in_row2 = (i_y + in_y1_int < in_h_int - 1) ?  \
-                       in_rows[i_y + in_y1_int + 1] : \
-                       0; \
-               type *out_row = out_rows[i]; \
- \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       int i_x = table_int_x[j]; \
-                       float b = table_frac_x[j]; \
-                       float anti_b = table_antifrac_x[j]; \
-                       int x = i_x + in_x1_int; \
-                       float output1r, output1g, output1b, output1a; \
-                       float output2r, output2g, output2b, output2a; \
-                       float output3r, output3g, output3b, output3a; \
-                       float output4r, output4g, output4b, output4a; \
- \
-                       output1r = in_row1[x * components]; \
-                       output1g = in_row1[x * components + 1]; \
-                       output1b = in_row1[x * components + 2]; \
-                       if(components == 4) output1a = in_row1[x * components + 3]; \
- \
-                       if(x < in_w_int - 1) \
-                       { \
-                               output2r = in_row1[x * components + components]; \
-                               output2g = in_row1[x * components + components + 1]; \
-                               output2b = in_row1[x * components + components + 2]; \
-                               if(components == 4) output2a = in_row1[x * components + components + 3]; \
- \
-                               if(in_row2) \
-                               { \
-                                       output4r = in_row2[x * components + components]; \
-                                       output4g = in_row2[x * components + components + 1]; \
-                                       output4b = in_row2[x * components + components + 2]; \
-                                       if(components == 4) output4a = in_row2[x * components + components + 3]; \
-                               } \
-                               else \
-                               { \
-                                       output4r = zero_r; \
-                                       output4g = zero_g; \
-                                       output4b = zero_b; \
-                                       if(components == 4) output4a = zero_a; \
-                               } \
-                       } \
-                       else \
-                       { \
-                               output2r = zero_r; \
-                               output2g = zero_g; \
-                               output2b = zero_b; \
-                               if(components == 4) output2a = zero_a; \
-                               output4r = zero_r; \
-                               output4g = zero_g; \
-                               output4b = zero_b; \
-                               if(components == 4) output4a = zero_a; \
-                       } \
- \
-                       if(in_row2) \
-                       { \
-                               output3r = in_row2[x * components]; \
-                               output3g = in_row2[x * components + 1]; \
-                               output3b = in_row2[x * components + 2]; \
-                               if(components == 4) output3a = in_row2[x * components + 3]; \
-                       } \
-                       else \
-                       { \
-                               output3r = zero_r; \
-                               output3g = zero_g; \
-                               output3b = zero_b; \
-                               if(components == 4) output3a = zero_a; \
-                       } \
- \
-                       out_row[j * components] =  \
-                               (type)((anti_a) * (((anti_b) * output1r) +  \
-                               (b * output2r)) +  \
-                a * (((anti_b) * output3r) +  \
-                               (b * output4r))); \
-                       out_row[j * components + 1] =   \
-                               (type)((anti_a) * (((anti_b) * output1g) +  \
-                               (b * output2g)) +  \
-                a * (((anti_b) * output3g) +  \
-                               (b * output4g))); \
-                       out_row[j * components + 2] =   \
-                               (type)((anti_a) * (((anti_b) * output1b) +  \
-                               (b * output2b)) +  \
-                a * (((anti_b) * output3b) +  \
-                               (b * output4b))); \
-                       if(components == 4) \
-                               out_row[j * components + 3] =   \
-                                       (type)((anti_a) * (((anti_b) * output1a) +  \
-                                       (b * output2a)) +  \
-                       a * (((anti_b) * output3a) +  \
-                                       (b * output4a))); \
-               } \
-       } \
- \
- \
-       delete [] table_int_x; \
-       delete [] table_frac_x; \
-       delete [] table_antifrac_x; \
-       delete [] table_int_y; \
-       delete [] table_frac_y; \
-       delete [] table_antifrac_y; \
- \
-}
-
-
-#define BICUBIC(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       float *bspline_x, *bspline_y; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
-       type zero_r, zero_g, zero_b, zero_a; \
-/* printf("BICUBIC\n"); */ \
- \
-       zero_r = 0; \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
-       if(components == 4) \
-               zero_a = 0; \
- \
-       tabulate_bspline(bspline_x,  \
-               k_x, \
-               out_w_int, \
-               -1); \
- \
-       tabulate_bspline(bspline_y,  \
-               k_y, \
-               out_h_int, \
-               1); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               int i_y = (int)(k_y * i); \
- \
- \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       int i_x = (int)(k_x * j); \
-                       float output1, output2, output3, output4; \
-                       output1 = 0; \
-                       output2 = 0; \
-                       output3 = 0; \
-                       if(components == 4) \
-                               output4 = 0; \
-                       int table_y = i * 4; \
- \
-/* Kernel */ \
-                       for(int m = -1; m < 3; m++) \
-                       { \
-                               float r1 = bspline_y[table_y++]; \
-                               int y = in_y1_int + i_y + m; \
-                               int table_x = j * 4; \
- \
-                               CLAMP(y, 0, in_h_int - 1); \
- \
-                               for(int n = -1; n < 3; n++) \
-                               { \
-                                       float r2 = bspline_x[table_x++]; \
-                                       int x = in_x1_int + i_x + n; \
-                                       float r_square = r1 * r2; \
- \
-                                       CLAMP(x, 0, in_w_int - 1); \
- \
-                                       output1 += r_square * in_rows[y][x * components]; \
-                                       output2 += r_square * in_rows[y][x * components + 1]; \
-                                       output3 += r_square * in_rows[y][x * components + 2]; \
-                                       if(components == 4) \
-                                               output4 += r_square * in_rows[y][x * components + 3]; \
-                               } \
-                       } \
- \
- \
-                       out_rows[i][j * components] = (type)output1; \
-                       out_rows[i][j * components + 1] = (type)output2; \
-                       out_rows[i][j * components + 2] = (type)output3; \
-                       if(components == 4) \
-                               out_rows[i][j * components + 3] = (type)output4; \
- \
-               } \
-       } \
- \
-       delete [] bspline_x; \
-       delete [] bspline_y; \
-}
-
-
-
-
-// Pow function is not thread safe in Compaqt C
-#define CUBE(x) ((x) * (x) * (x))
-
-float ScaleUnit::cubic_bspline(float x)
-{
-       float a, b, c, d;
-
-       if((x + 2.0F) <= 0.0F) 
-       {
-       a = 0.0F;
-       }
-       else 
-       {
-       a = CUBE(x + 2.0F);
-       }
-
-
-       if((x + 1.0F) <= 0.0F) 
-       {
-       b = 0.0F;
-       }
-       else 
-       {
-       b = CUBE(x + 1.0F);
-       }    
-
-       if(x <= 0) 
-       {
-       c = 0.0F;
-       }
-       else 
-       {
-       c = CUBE(x);
-       }  
-
-       if((x - 1.0F) <= 0.0F) 
-       {
-       d = 0.0F;
-       }
-       else 
-       {
-       d = CUBE(x - 1.0F);
-       }
-
-
-       return (a - (4.0F * b) + (6.0F * c) - (4.0F * d)) / 6.0;
-}
-
-
-void ScaleUnit::tabulate_bspline(float* &table, 
-       float scale,
-       int pixels,
-       float coefficient)
-{
-       table = new float[pixels * 4];
-       for(int i = 0, j = 0; i < pixels; i++)
-       {
-               float f_x = (float)i * scale;
-               float a = f_x - floor(f_x);
-               
-               for(float m = -1; m < 3; m++)
-               {
-                       table[j++] = cubic_bspline(coefficient * (m - a));
-               }
-               
-       }
-}
-
-void ScaleUnit::tabulate_blinear(int* &table_int,
-               float* &table_frac,
-               float* &table_antifrac,
-               float scale,
-               int pixel1,
-               int pixel2,
-               total_pixels)
-{
-       table_int = new int[pixel2 - pixel1];
-       table_frac = new float[pixel2 - pixel1];
-       table_antifrac = new float[pixel2 - pixel1];
-
-       for(int i = pixel1, j = 0; i < pixel2; i++, j++)
-       {
-               float f_x = (float)i * scale;
-               int i_x = (int)floor(f_x);
-               float a = (f_x - floor(f_x));
-
-               table_int[j] = CLAMP(i_x, 0, total_pixels - 1);
-               table_frac[j] = a;
-               table_antifrac[j] = 1.0F - a;
-       }
-}
-
-void ScaleUnit::process_package(LoadPackage *package)
-{
-       ScalePackage *pkg = (ScalePackage*)package;
-
-//printf("ScaleUnit::process_package 1\n");
-// Arguments for macros
-       VFrame *output = engine->scale_output;
-       VFrame *input = engine->scale_input;
-       float scale_w = engine->w_scale;
-       float scale_h = engine->h_scale;
-       int in_x1_int = engine->in_x1_int;
-       int in_y1_int = engine->in_y1_int;
-       int out_h_int = engine->out_h_int;
-       int out_w_int = engine->out_w_int;
-       int do_yuv = 
-               (input->get_color_model() == BC_YUV888 ||
-               input->get_color_model() == BC_YUVA8888 ||
-               input->get_color_model() == BC_YUV161616 ||
-               input->get_color_model() == BC_YUVA16161616);
-
-//printf("ScaleUnit::process_package 2\n");
-       if(engine->interpolation_type == CUBIC_CUBIC || 
-               (engine->interpolation_type == CUBIC_LINEAR 
-                       && engine->w_scale > 1 && 
-                       engine->h_scale > 1))
-       {
-       
-               switch(engine->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BICUBIC(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BICUBIC(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BICUBIC(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BICUBIC(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-       else
-// Perform bilinear scaling input -> scale_output
-       {
-               switch(engine->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BILINEAR(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BILINEAR(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BILINEAR(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BILINEAR(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-//printf("ScaleUnit::process_package 3\n");
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-ScaleEngine::ScaleEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-ScaleEngine::~ScaleEngine()
-{
-}
-
-void ScaleEngine::init_packages()
-{
-       for(int i = 0; i < total_packages; i++)
-       {
-               ScalePackage *package = (ScalePackage*)packages[i];
-               package->out_row1 = out_h_int / total_packages * i;
-               package->out_row2 = package->out_row1 + out_h_int / total_packages;
-
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_h_int;
-       }
-}
-
-LoadClient* ScaleEngine::new_client()
-{
-       return new ScaleUnit(this, overlay);
-}
-
-LoadPackage* ScaleEngine::new_package()
-{
-       return new ScalePackage;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-TranslatePackage::TranslatePackage()
-{
-}
-
-
-
-TranslateUnit::TranslateUnit(TranslateEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->engine = server;
-}
-
-TranslateUnit::~TranslateUnit()
-{
-}
-
-
-
-void TranslateUnit::translation_array(transfer_table* &table, 
-       float out_x1, 
-       float out_x2,
-       float in_x1,
-       float in_x2,
-       int in_total, 
-       int out_total, 
-       int &out_x1_int,
-       int &out_x2_int)
-{
-       int out_w_int;
-       float offset = out_x1 - in_x1;
-
-       out_x1_int = (int)out_x1;
-       out_x2_int = MIN((int)ceil(out_x2), out_total);
-       out_w_int = out_x2_int - out_x1_int;
-
-       table = new transfer_table[out_w_int];
-       bzero(table, sizeof(transfer_table) * out_w_int);
-
-
-//printf("OverlayFrame::translation_array 1 %f %f -> %f %f\n", in_x1, in_x2, out_x1, out_x2);
-
-       float in_x = in_x1;
-       for(int out_x = out_x1_int; out_x < out_x2_int; out_x++)
-       {
-               transfer_table *entry = &table[out_x - out_x1_int];
-
-               entry->in_x1 = (int)in_x;
-               entry->in_x2 = (int)in_x + 1;
-
-// Get fraction of output pixel to fill
-               entry->output_fraction = 1;
-
-               if(out_x1 > out_x)
-               {
-                       entry->output_fraction -= out_x1 - out_x;
-               }
-
-               if(out_x2 < out_x + 1)
-               {
-                       entry->output_fraction = (out_x2 - out_x);
-               }
-
-// Advance in_x until out_x_fraction is filled
-               float out_x_fraction = entry->output_fraction;
-               float in_x_fraction = floor(in_x + 1) - in_x;
-
-               if(out_x_fraction <= in_x_fraction)
-               {
-                       entry->in_fraction1 = out_x_fraction;
-                       entry->in_fraction2 = 0.0;
-                       in_x += out_x_fraction;
-               }
-               else
-               {
-                       entry->in_fraction1 = in_x_fraction;
-                       in_x += out_x_fraction;
-                       entry->in_fraction2 = in_x - floor(in_x);
-               }
-
-// Clip in_x and zero out fraction.  This doesn't work for YUV.
-               if(entry->in_x2 >= in_total)
-               {
-                       entry->in_x2 = in_total - 1;
-                       entry->in_fraction2 = 0.0;
-               }
-               
-               if(entry->in_x1 >= in_total)
-               {
-                       entry->in_x1 = in_total - 1;
-                       entry->in_fraction1 = 0.0;
-               }
-// printf("OverlayFrame::translation_array 2 %d %d %d %f %f %f\n", 
-//     out_x, 
-//     entry->in_x1, 
-//     entry->in_x2, 
-//     entry->in_fraction1, 
-//     entry->in_fraction2, 
-//     entry->output_fraction);
-       }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#define TRANSLATE(max, type, components) \
-{ \
- \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
- \
-/* printf("OverlayFrame::translate 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",  */ \
-/*     (in_x1),  in_y1,  in_x2,  in_y2,  out_x1,  out_y1, out_x2,  out_y2); */ \
- \
-       unsigned int master_opacity = (int)(alpha * max + 0.5); \
-       unsigned int master_transparency = max - master_opacity; \
-       type zero_r, zero_g, zero_b, zero_a; \
-       zero_r = 0; \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
-       if(components == 4) \
-               zero_a = 0; \
- \
-/* printf("TRANSLATE %d\n", mode); */ \
- \
-       for(int i = row1; i < row2; i++) \
-       { \
-               int in_y1 = y_table[i - out_y1_int].in_x1; \
-               int in_y2 = y_table[i - out_y1_int].in_x2; \
-               float y_fraction1 = y_table[i - out_y1_int].in_fraction1; \
-               float y_fraction2 = y_table[i - out_y1_int].in_fraction2; \
-               float y_output_fraction = y_table[i - out_y1_int].output_fraction; \
-               type *in_row1 = in_rows[(in_y1)]; \
-               type *in_row2 = in_rows[(in_y2)]; \
-               type *out_row = out_rows[i]; \
- \
-               for(int j = out_x1_int; j < out_x2_int; j++) \
-               { \
-                       int in_x1 = x_table[j - out_x1_int].in_x1; \
-                       int in_x2 = x_table[j - out_x1_int].in_x2; \
-                       float x_fraction1 = x_table[j - out_x1_int].in_fraction1; \
-                       float x_fraction2 = x_table[j - out_x1_int].in_fraction2; \
-                       float x_output_fraction = x_table[j - out_x1_int].output_fraction; \
-                       type *output = &out_row[j * components]; \
-                       int input1, input2, input3, input4; \
- \
-                       input1 = (int)(in_row1[in_x1 * components] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_x1 * components] * x_fraction1 * y_fraction2 +  \
-                               in_row2[in_x2 * components] * x_fraction2 * y_fraction2 + 0.5); \
-                       input2 = (int)(in_row1[in_x1 * components + 1] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components + 1] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_x1 * components + 1] * x_fraction1 * y_fraction2 +  \
-                               in_row2[in_x2 * components + 1] * x_fraction2 * y_fraction2 + 0.5); \
-                       input3 = (int)(in_row1[in_x1 * components + 2] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components + 2] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_x1 * components + 2] * x_fraction1 * y_fraction2 +  \
-                               in_row2[in_x2 * components + 2] * x_fraction2 * y_fraction2 + 0.5); \
-                       if(components == 4) \
-                               input4 = (int)(in_row1[in_x1 * components + 3] * x_fraction1 * y_fraction1 +  \
-                                       in_row1[in_x2 * components + 3] * x_fraction2 * y_fraction1 +  \
-                                       in_row2[in_x1 * components + 3] * x_fraction1 * y_fraction2 +  \
-                                       in_row2[in_x2 * components + 3] * x_fraction2 * y_fraction2 + 0.5); \
- \
-                       unsigned int opacity = (int)(master_opacity *  \
-                               y_output_fraction *  \
-                               x_output_fraction + 0.5); \
-                       unsigned int transparency = max - opacity; \
- \
-/* if(opacity != max) printf("TRANSLATE %x %d %d\n", opacity, j, i); */ \
- \
-                       if(components == 3) \
-                       { \
-                               BLEND_3(max, type); \
-                       } \
-                       else \
-                       { \
-                               BLEND_4(max, type); \
-                       } \
-               } \
-       } \
-}
-
-void TranslateUnit::process_package(LoadPackage *package)
-{
-       TranslatePackage *pkg = (TranslatePackage*)package;
-       int out_y1_int; 
-       int out_y2_int; 
-       int out_x1_int; 
-       int out_x2_int; 
-
-
-// Variables for TRANSLATE
-       VFrame *input = engine->translate_input;
-       VFrame *output = engine->translate_output;
-       float in_x1 = engine->translate_in_x1;
-       float in_y1 = engine->translate_in_y1;
-       float in_x2 = engine->translate_in_x2;
-       float in_y2 = engine->translate_in_y2;
-       float out_x1 = engine->translate_out_x1;
-       float out_y1 = engine->translate_out_y1;
-       float out_x2 = engine->translate_out_x2;
-       float out_y2 = engine->translate_out_y2;
-       float alpha = engine->translate_alpha;
-       int row1 = pkg->out_row1;
-       int row2 = pkg->out_row2;
-       int mode = engine->translate_mode;
-       int in_total_x = input->get_w();
-       int in_total_y = input->get_h();
-       int do_yuv = 
-               (engine->translate_input->get_color_model() == BC_YUV888 ||
-               engine->translate_input->get_color_model() == BC_YUVA8888 ||
-               engine->translate_input->get_color_model() == BC_YUV161616 ||
-               engine->translate_input->get_color_model() == BC_YUVA16161616);
-
-       transfer_table *x_table; 
-       transfer_table *y_table; 
-       translation_array(x_table,  
-               out_x1,  
-               out_x2, 
-               in_x1, 
-               in_x2, 
-               in_total_x,  
-               output->get_w(),  
-               out_x1_int, 
-               out_x2_int); 
-       translation_array(y_table,  
-               out_y1,  
-               out_y2, 
-               in_y1, 
-               in_y2, 
-               in_total_y,  
-               output->get_h(),  
-               out_y1_int, 
-               out_y2_int); 
-       switch(engine->translate_input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       TRANSLATE(0xff, unsigned char, 3);
-                       break;
-
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       TRANSLATE(0xff, unsigned char, 4);
-                       break;
-
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       TRANSLATE(0xffff, uint16_t, 3);
-                       break;
-
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       TRANSLATE(0xffff, uint16_t, 4);
-                       break;
-       }
-       delete [] x_table; 
-       delete [] y_table; 
-}
-
-
-
-
-
-
-
-
-
-
-TranslateEngine::TranslateEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-TranslateEngine::~TranslateEngine()
-{
-}
-
-void TranslateEngine::init_packages()
-{
-       int out_y1_int = (int)translate_out_y1;
-       int out_y2_int = MIN((int)ceil(translate_out_y2), translate_output->get_h());
-       int out_h = out_y2_int - out_y1_int;
-
-       for(int i = 0; i < total_packages; i++)
-       {
-               TranslatePackage *package = (TranslatePackage*)packages[i];
-               package->out_row1 = (int)(out_y1_int + out_h / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 + 
-                       out_h / 
-                       total_packages);
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_y2_int;
-       }
-}
-
-LoadClient* TranslateEngine::new_client()
-{
-       return new TranslateUnit(this, overlay);
-}
-
-LoadPackage* TranslateEngine::new_package()
-{
-       return new TranslatePackage;
-}
-
-
-
-
-
-
-
-
-#define SCALE_TRANSLATE(max, type, components) \
-{ \
-       int64_t opacity = (int)(alpha * max + 0.5); \
-       int64_t transparency = max - opacity; \
-       int out_w = out_x2 - out_x1; \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               int in_y = y_table[i - out_y1]; \
-               type *in_row = (type*)in_rows[in_y] + in_x1 * components; \
-               type *out_row = (type*)out_rows[i] + out_x1 * components; \
- \
-/* X direction is scaled and requires a table lookup */ \
-               if(out_w != in_x2 - in_x1) \
-               { \
-                       for(int j = 0; j < out_w; j++) \
-                       { \
-                               int in_x = x_table[j]; \
-                               int input1, input2, input3, input4; \
-                               type *output = out_row + j * components; \
-        \
-                               input1 = in_row[in_x * components]; \
-                               input2 = in_row[in_x * components + 1]; \
-                               input3 = in_row[in_x * components + 2]; \
-                               if(components == 4) \
-                                       input4 = in_row[in_x * components + 3]; \
-        \
-                               if(components == 3) \
-                               { \
-                                       BLEND_3(max, type); \
-                               } \
-                               else \
-                               { \
-                                       BLEND_4(max, type); \
-                               } \
-                       } \
-               } \
-               else \
-/* X direction is not scaled */ \
-               { \
-                       for(int j = 0; j < out_w; j++) \
-                       { \
-                               int input1, input2, input3, input4; \
-                               type *output = out_row + j * components; \
-        \
-                               input1 = in_row[j * components]; \
-                               input2 = in_row[j * components + 1]; \
-                               input3 = in_row[j * components + 2]; \
-                               if(components == 4) \
-                                       input4 = in_row[j * components + 3]; \
-        \
-                               if(components == 3) \
-                               { \
-                                       BLEND_3(max, type); \
-                               } \
-                               else \
-                               { \
-                                       BLEND_4(max, type); \
-                               } \
-                       } \
-               } \
-       } \
-}
-
-
-
-ScaleTranslateUnit::ScaleTranslateUnit(ScaleTranslateEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->scale_translate = server;
-}
-
-ScaleTranslateUnit::~ScaleTranslateUnit()
-{
-}
-
-void ScaleTranslateUnit::scale_array(int* &table, 
-       int out_x1, 
-       int out_x2,
-       int in_x1,
-       int in_x2,
-       int is_x)
-{
-       float scale = (float)(out_x2 - out_x1) / (in_x2 - in_x1);
-
-       table = new int[out_x2 - out_x1];
-       
-       if(!is_x)
-       {
-               for(int i = 0; i < out_x2 - out_x1; i++)
-               {
-                       table[i] = (int)((float)i / scale + in_x1);
-               }
-       }
-       else
-       {       
-               for(int i = 0; i < out_x2 - out_x1; i++)
-               {
-                       table[i] = (int)((float)i / scale);
-               }
-       }
-}
-
-
-void ScaleTranslateUnit::process_package(LoadPackage *package)
-{
-       ScaleTranslatePackage *pkg = (ScaleTranslatePackage*)package;
-
-// Args for NEAREST_NEIGHBOR_MACRO
-       VFrame *output = scale_translate->output;
-       VFrame *input = scale_translate->input;
-       int in_x1 = scale_translate->in_x1;
-       int in_y1 = scale_translate->in_y1;
-       int in_x2 = scale_translate->in_x2;
-       int in_y2 = scale_translate->in_y2;
-       int out_x1 = scale_translate->out_x1;
-       int out_y1 = scale_translate->out_y1;
-       int out_x2 = scale_translate->out_x2;
-       int out_y2 = scale_translate->out_y2;
-       float alpha = scale_translate->alpha;
-       int mode = scale_translate->mode;
-
-       int *x_table;
-       int *y_table;
-       unsigned char **in_rows = input->get_rows();
-       unsigned char **out_rows = output->get_rows();
-
-       scale_array(x_table, 
-               out_x1, 
-               out_x2,
-               in_x1,
-               in_x2,
-               1);
-       scale_array(y_table, 
-               out_y1, 
-               out_y2,
-               in_y1,
-               in_y2,
-               0);
-
-
-       switch(input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       SCALE_TRANSLATE(0xff, uint8_t, 3);
-                       break;
-
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       SCALE_TRANSLATE(0xff, uint8_t, 4);
-                       break;
-
-
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       SCALE_TRANSLATE(0xffff, uint16_t, 3);
-                       break;
-
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       SCALE_TRANSLATE(0xffff, uint16_t, 4);
-                       break;
-       }
-       
-       delete [] x_table;
-       delete [] y_table;
-
-};
-
-
-
-
-
-
-
-
-
-ScaleTranslateEngine::ScaleTranslateEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-ScaleTranslateEngine::~ScaleTranslateEngine()
-{
-}
-
-void ScaleTranslateEngine::init_packages()
-{
-       int out_h = out_y2 - out_y1;
-
-       for(int i = 0; i < total_packages; i++)
-       {
-               ScaleTranslatePackage *package = (ScaleTranslatePackage*)packages[i];
-               package->out_row1 = (int)(out_y1 + out_h / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 + 
-                       out_h / 
-                       total_packages);
-               if(i >= total_packages - 1)
-                       package->out_row2 = out_y2;
-       }
-}
-
-LoadClient* ScaleTranslateEngine::new_client()
-{
-       return new ScaleTranslateUnit(this, overlay);
-}
-
-LoadPackage* ScaleTranslateEngine::new_package()
-{
-       return new ScaleTranslatePackage;
-}
-
-
-ScaleTranslatePackage::ScaleTranslatePackage()
-{
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#define BLEND_ONLY(type, max, components) \
-{ \
-       int64_t opacity = (int)(alpha * max + 0.5); \
-       int64_t transparency = max - opacity; \
- \
-       type** output_rows = (type**)output->get_rows(); \
-       type** input_rows = (type**)input->get_rows(); \
-       int w = input->get_w(); \
-       int h = input->get_h(); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               type* in_row = input_rows[i]; \
-               type* output = output_rows[i]; \
- \
-               for(int j = 0; j < w; j++) \
-               { \
-                       int input1, input2, input3, input4; \
-                       input1 = in_row[j * components]; \
-                       input2 = in_row[j * components + 1]; \
-                       input3 = in_row[j * components + 2]; \
-                       if(components == 4) input4 = in_row[j * components + 3]; \
- \
- \
-                       if(components == 3) \
-                       { \
-                               BLEND_3(max, type); \
-                       } \
-                       else \
-                       { \
-                               BLEND_4(max, type); \
-                       } \
- \
-                       input += components; \
-                       output += components; \
-               } \
-       } \
-}
-
-
-
-
-BlendUnit::BlendUnit(BlendEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-       this->blend_engine = server;
-}
-
-BlendUnit::~BlendUnit()
-{
-}
-
-void BlendUnit::process_package(LoadPackage *package)
-{
-       BlendPackage *pkg = (BlendPackage*)package;
-
-
-       VFrame *output = blend_engine->output;
-       VFrame *input = blend_engine->input;
-       float alpha = blend_engine->alpha;
-       int mode = blend_engine->mode;
-
-       switch(input->get_color_model())
-       {
-               case BC_RGB888:
-               case BC_YUV888:
-                       BLEND_ONLY(unsigned char, 0xff, 3);
-                       break;
-               case BC_RGBA8888:
-               case BC_YUVA8888:
-                       BLEND_ONLY(unsigned char, 0xff, 4);
-                       break;
-               case BC_RGB161616:
-               case BC_YUV161616:
-                       BLEND_ONLY(uint16_t, 0xffff, 3);
-                       break;
-               case BC_RGBA16161616:
-               case BC_YUVA16161616:
-                       BLEND_ONLY(uint16_t, 0xffff, 4);
-                       break;
-       }
-}
-
-
-
-BlendEngine::BlendEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-BlendEngine::~BlendEngine()
-{
-}
-
-void BlendEngine::init_packages()
-{
-       for(int i = 0; i < total_packages; i++)
-       {
-               BlendPackage *package = (BlendPackage*)packages[i];
-               package->out_row1 = (int)(input->get_h() / 
-                       total_packages * 
-                       i);
-               package->out_row2 = (int)((float)package->out_row1 +
-                       input->get_h() / 
-                       total_packages);
-
-               if(i >= total_packages - 1)
-                       package->out_row2 = input->get_h();
-       }
-}
-
-LoadClient* BlendEngine::new_client()
-{
-       return new BlendUnit(this, overlay);
-}
-
-LoadPackage* BlendEngine::new_package()
-{
-       return new BlendPackage;
-}
-
-
-BlendPackage::BlendPackage()
-{
-}
-
-
diff --git a/cinelerra-5.1/cinelerra/overlayframe.C.int b/cinelerra-5.1/cinelerra/overlayframe.C.int
deleted file mode 100644 (file)
index f241c1f..0000000
+++ /dev/null
@@ -1,1749 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-
-#include "clip.h"
-#include "edl.inc"
-#include "mutex.h"
-#include "overlayframe.h"
-#include "vframe.h"
-
-OverlayFrame::OverlayFrame(int cpus)
-{
-       temp_frame = 0;
-       blend_engine = 0;
-       scale_engine = 0;
-       scaletranslate_engine = 0;
-       translate_engine = 0;
-       this->cpus = cpus;
-}
-
-OverlayFrame::~OverlayFrame()
-{
-//printf("OverlayFrame::~OverlayFrame 1\n");
-       if(temp_frame) delete temp_frame;
-       if(scale_engine) delete scale_engine;
-       if(translate_engine) delete translate_engine;
-       if(blend_engine) delete blend_engine;
-       if(scaletranslate_engine) delete scaletranslate_engine;
-//printf("OverlayFrame::~OverlayFrame 2\n");
-}
-
-
-
-
-
-
-
-
-// Verification: 
-
-// (255 * 255 + 0 * 0) / 255 = 255
-// (255 * 127 + 255 * (255 - 127)) / 255 = 255
-
-// (65535 * 65535 + 0 * 0) / 65535 = 65535
-// (65535 * 32767 + 65535 * (65535 - 32767)) / 65535 = 65535
-
-
-// Branch prediction 4 U
-
-#define BLEND_3(max, type) \
-{ \
-       int64_t r, g, b; \
- \
-/* if(mode != TRANSFER_NORMAL) printf("BLEND mode = %d\n", mode); */ \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * opacity + output[0] * transparency) / max; \
-                       g = (g * opacity + output[1] * transparency) / max; \
-                       b = (b * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * opacity + output[0] * transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * opacity + output[1] * transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * opacity + output[2] * transparency) / max; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * opacity + output[0] * transparency) / max; \
-                       g = ((int64_t)input2 * opacity + output[1] * transparency) / max; \
-                       b = ((int64_t)input3 * opacity + output[2] * transparency) / max; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-}
-
-
-
-
-
-// Blending equations are drastically different for 3 and 4 components
-#define BLEND_4(max, type) \
-{ \
-       int64_t r, g, b, a; \
-       int64_t pixel_opacity, pixel_transparency; \
- \
-       pixel_opacity = opacity * input4 / max; \
-       pixel_transparency = (max - pixel_opacity) * output[3] / max; \
- \
-       switch(mode) \
-       { \
-               case TRANSFER_DIVIDE: \
-                       r = output[0] ? (((int64_t)input1 * max) / output[0]) : max; \
-                       g = output[1] ? (((int64_t)input2 * max) / output[1]) : max; \
-                       b = output[2] ? (((int64_t)input3 * max) / output[2]) : max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_MULTIPLY: \
-                       r = ((int64_t)input1 * output[0]) / max; \
-                       g = ((int64_t)input2 * output[1]) / max; \
-                       b = ((int64_t)input3 * output[2]) / max; \
-                       r = (r * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (g * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (b * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_SUBTRACT: \
-                       r = (((int64_t)input1 - output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 - output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 - output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_ADDITION: \
-                       r = (((int64_t)input1 + output[0]) * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = (((int64_t)input2 + output[1]) * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = (((int64_t)input3 + output[2]) * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-               case TRANSFER_REPLACE: \
-                       r = input1; \
-                       g = input2; \
-                       b = input3; \
-                       a = input4; \
-                       break; \
-               case TRANSFER_NORMAL: \
-                       r = ((int64_t)input1 * pixel_opacity + output[0] * pixel_transparency) / max; \
-                       g = ((int64_t)input2 * pixel_opacity + output[1] * pixel_transparency) / max; \
-                       b = ((int64_t)input3 * pixel_opacity + output[2] * pixel_transparency) / max; \
-                       a = input4 > output[3] ? input4 : output[3]; \
-                       break; \
-       } \
- \
-       output[0] = (type)CLIP(r, 0, max); \
-       output[1] = (type)CLIP(g, 0, max); \
-       output[2] = (type)CLIP(b, 0, max); \
-       output[3] = (type)a; \
-}
-
-
-
-
-
-
-
-
-// Bicubic algorithm using multiprocessors
-// input -> scale nearest integer boundaries -> temp -> translation -> blend -> output
-
-// Nearest neighbor algorithm using multiprocessors for blending
-// input -> scale + translate -> blend -> output
-
-
-int OverlayFrame::overlay(VFrame *output, 
-       VFrame *input, 
-       float in_x1, 
-       float in_y1, 
-       float in_x2, 
-       float in_y2, 
-       float out_x1, 
-       float out_y1, 
-       float out_x2, 
-       float out_y2, 
-       float alpha,       // 0 - 1
-       int mode,
-       int interpolation_type)
-{
-       float w_scale = (out_x2 - out_x1) / (in_x2 - in_x1);
-       float h_scale = (out_y2 - out_y1) / (in_y2 - in_y1);
-
-//printf("OverlayFrame::overlay 1 %d %f\n", mode, alpha);
-// Limit values
-       if(in_x1 < 0)
-       {
-               out_x1 += -in_x1 * w_scale;
-               in_x1 = 0;
-       }
-       else
-       if(in_x1 >= input->get_w())
-       {
-               out_x1 -= (in_x1 - input->get_w()) * w_scale;
-               in_x1 = input->get_w();
-       }
-
-       if(in_y1 < 0)
-       {
-               out_y1 += -in_y1 * h_scale;
-               in_y1 = 0;
-       }
-       else
-       if(in_y1 >= input->get_h())
-       {
-               out_y1 -= (in_y1 - input->get_h()) * h_scale;
-               in_y1 = input->get_h();
-       }
-
-       if(in_x2 < 0)
-       {
-               out_x2 += -in_x2 * w_scale;
-               in_x2 = 0;
-       }
-       else
-       if(in_x2 >= input->get_w())
-       {
-               out_x2 -= (in_x2 - input->get_w()) * w_scale;
-               in_x2 = input->get_w();
-       }
-
-       if(in_y2 < 0)
-       {
-               out_y2 += -in_y2 * h_scale;
-               in_y2 = 0;
-       }
-       else
-       if(in_y2 >= input->get_h())
-       {
-               out_y2 -= (in_y2 - input->get_h()) * h_scale;
-               in_y2 = input->get_h();
-       }
-
-       if(out_x1 < 0)
-       {
-               in_x1 += -out_x1 / w_scale;
-               out_x1 = 0;
-       }
-       else
-       if(out_x1 >= output->get_w())
-       {
-               in_x1 -= (out_x1 - output->get_w()) / w_scale;
-               out_x1 = output->get_w();
-       }
-
-       if(out_y1 < 0)
-       {
-               in_y1 += -out_y1 / h_scale;
-               out_y1 = 0;
-       }
-       else
-       if(out_y1 >= output->get_h())
-       {
-               in_y1 -= (out_y1 - output->get_h()) / h_scale;
-               out_y1 = output->get_h();
-       }
-
-       if(out_x2 < 0)
-       {
-               in_x2 += -out_x2 / w_scale;
-               out_x2 = 0;
-       }
-       else
-       if(out_x2 >= output->get_w())
-       {
-               in_x2 -= (out_x2 - output->get_w()) / w_scale;
-               out_x2 = output->get_w();
-       }
-
-       if(out_y2 < 0)
-       {
-               in_y2 += -out_y2 / h_scale;
-               out_y2 = 0;
-       }
-       else
-       if(out_y2 >= output->get_h())
-       {
-               in_y2 -= (out_y2 - output->get_h()) / h_scale;
-               out_y2 = output->get_h();
-       }
-
-
-
-
-
-       float in_w = in_x2 - in_x1;
-       float in_h = in_y2 - in_y1;
-       float out_w = out_x2 - out_x1;
-       float out_h = out_y2 - out_y1;
-// Input for translation operation
-       VFrame *translation_input = input;
-
-
-
-// printf("OverlayFrame::overlay %f %f %f %f -> %f %f %f %f\n", in_x1,
-//                     in_y1,
-//                     in_x2,
-//                     in_y2,
-//                     out_x1,
-//                     out_y1,
-//                     out_x2,
-//                     out_y2);
-
-
-
-
-
-// ****************************************************************************
-// Transfer to temp buffer by scaling nearest integer boundaries
-// ****************************************************************************
-       if(interpolation_type != NEAREST_NEIGHBOR &&
-               (!EQUIV(w_scale, 1) || !EQUIV(h_scale, 1)))
-       {
-// Create integer boundaries for interpolation
-               int in_x1_int = (int)in_x1;
-               int in_y1_int = (int)in_y1;
-               int in_x2_int = MIN((int)ceil(in_x2), input->get_w());
-               int in_y2_int = MIN((int)ceil(in_y2), input->get_h());
-
-// Dimensions of temp frame.  Integer boundaries scaled.
-               int temp_w = (int)ceil(w_scale * (in_x2_int - in_x1_int));
-               int temp_h = (int)ceil(h_scale * (in_y2_int - in_y1_int));
-               VFrame *scale_output;
-
-
-
-#define NO_TRANSLATION1 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(in_x2, in_x2_int) && \
-       EQUIV(in_y2, in_y2_int) && \
-       EQUIV(out_x2, temp_w) && \
-       EQUIV(out_y2, temp_h))
-
-
-#define NO_BLEND \
-       (EQUIV(alpha, 1) && \
-       (mode == TRANSFER_REPLACE || \
-       (mode == TRANSFER_NORMAL && cmodel_components(input->get_color_model()) == 3)))
-
-
-
-
-
-// Prepare destination for operation
-
-// No translation and no blending.  The blending operation is built into the
-// translation unit but not the scaling unit.
-// input -> output
-               if(NO_TRANSLATION1 &&
-                       NO_BLEND)
-               {
-// printf("OverlayFrame::overlay input -> output\n");
-
-                       scale_output = output;
-                       translation_input = 0;
-               }
-               else
-// If translation or blending
-// input -> nearest integer boundary temp
-               {
-                       if(temp_frame && 
-                               (temp_frame->get_w() != temp_w ||
-                                       temp_frame->get_h() != temp_h))
-                       {
-                               delete temp_frame;
-                               temp_frame = 0;
-                       }
-
-                       if(!temp_frame)
-                       {
-                               temp_frame = new VFrame(0,
-                                       temp_w,
-                                       temp_h,
-                                       input->get_color_model(),
-                                       -1);
-                       }
-//printf("OverlayFrame::overlay input -> temp\n");
-
-
-                       temp_frame->clear_frame();
-
-// printf("OverlayFrame::overlay 4 temp_w=%d temp_h=%d\n",
-//     temp_w, temp_h);
-                       scale_output = temp_frame;
-                       translation_input = scale_output;
-
-// Adjust input coordinates to reflect new scaled coordinates.
-                       in_x1 = (in_x1 - in_x1_int) * w_scale;
-                       in_y1 = (in_y1 - in_y1_int) * h_scale;
-                       in_x2 = (in_x2 - in_x1_int) * w_scale;
-                       in_y2 = (in_y2 - in_y1_int) * h_scale;
-               }
-
-
-
-
-// Scale input -> scale_output
-               this->scale_output = scale_output;
-               this->scale_input = input;
-               this->w_scale = w_scale;
-               this->h_scale = h_scale;
-               this->in_x1_int = in_x1_int;
-               this->in_y1_int = in_y1_int;
-               this->out_w_int = temp_w;
-               this->out_h_int = temp_h;
-               this->interpolation_type = interpolation_type;
-
-//printf("OverlayFrame::overlay ScaleEngine 1 %d\n", out_h_int);
-               if(!scale_engine) scale_engine = new ScaleEngine(this, cpus);
-               scale_engine->process_packages();
-//printf("OverlayFrame::overlay ScaleEngine 2\n");
-
-
-
-       }
-
-// printf("OverlayFrame::overlay 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-
-
-
-
-
-#define NO_TRANSLATION2 \
-       (EQUIV(in_x1, 0) && \
-       EQUIV(in_y1, 0) && \
-       EQUIV(in_x2, translation_input->get_w()) && \
-       EQUIV(in_y2, translation_input->get_h()) && \
-       EQUIV(out_x1, 0) && \
-       EQUIV(out_y1, 0) && \
-       EQUIV(out_x2, output->get_w()) && \
-       EQUIV(out_y2, output->get_h())) \
-
-#define NO_SCALE \
-       (EQUIV(out_x2 - out_x1, in_x2 - in_x1) && \
-       EQUIV(out_y2 - out_y1, in_y2 - in_y1))
-
-       
-
-
-//printf("OverlayFrame::overlay 4 %d\n", mode);
-
-
-
-
-       if(translation_input)
-       {
-// Direct copy
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE &&
-                       NO_BLEND)
-               {
-//printf("OverlayFrame::overlay direct copy\n");
-                       output->copy_from(translation_input);
-               }
-               else
-// Blend only
-               if( NO_TRANSLATION2 &&
-                       NO_SCALE)
-               {
-                       if(!blend_engine) blend_engine = new BlendEngine(this, cpus);
-
-
-                       blend_engine->output = output;
-                       blend_engine->input = translation_input;
-                       blend_engine->alpha = alpha;
-                       blend_engine->mode = mode;
-
-                       blend_engine->process_packages();
-               }
-               else
-// Scale and translate using nearest neighbor
-// Translation is exactly on integer boundaries
-               if(interpolation_type == NEAREST_NEIGHBOR ||
-                       EQUIV(in_x1, (int)in_x1) &&
-                       EQUIV(in_y1, (int)in_y1) &&
-                       EQUIV(in_x2, (int)in_x2) &&
-                       EQUIV(in_y2, (int)in_y2) &&
-
-                       EQUIV(out_x1, (int)out_x1) &&
-                       EQUIV(out_y1, (int)out_y1) &&
-                       EQUIV(out_x2, (int)out_x2) &&
-                       EQUIV(out_y2, (int)out_y2))
-               {
-//printf("OverlayFrame::overlay NEAREST_NEIGHBOR 1\n");
-                       if(!scaletranslate_engine) scaletranslate_engine = new ScaleTranslateEngine(this, cpus);
-
-
-                       scaletranslate_engine->output = output;
-                       scaletranslate_engine->input = translation_input;
-                       scaletranslate_engine->in_x1 = (int)in_x1;
-                       scaletranslate_engine->in_y1 = (int)in_y1;
-                       scaletranslate_engine->in_x2 = (int)in_x2;
-                       scaletranslate_engine->in_y2 = (int)in_y2;
-                       scaletranslate_engine->out_x1 = (int)out_x1;
-                       scaletranslate_engine->out_y1 = (int)out_y1;
-                       scaletranslate_engine->out_x2 = (int)out_x2;
-                       scaletranslate_engine->out_y2 = (int)out_y2;
-                       scaletranslate_engine->alpha = alpha;
-                       scaletranslate_engine->mode = mode;
-
-                       scaletranslate_engine->process_packages();
-               }
-               else
-// Fractional translation
-               {
-// Use fractional translation
-// printf("OverlayFrame::overlay temp -> output  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n", 
-//     in_x1, 
-//     in_y1, 
-//     in_x2, 
-//     in_y2, 
-//     out_x1, 
-//     out_y1, 
-//     out_x2, 
-//     out_y2);
-                       this->translate_output = output;
-                       this->translate_input = translation_input;
-                       this->translate_in_x1 = in_x1;
-                       this->translate_in_y1 = in_y1;
-                       this->translate_in_x2 = in_x2;
-                       this->translate_in_y2 = in_y2;
-                       this->translate_out_x1 = out_x1;
-                       this->translate_out_y1 = out_y1;
-                       this->translate_out_x2 = out_x2;
-                       this->translate_out_y2 = out_y2;
-                       this->translate_alpha = alpha;
-                       this->translate_mode = mode;
-
-//printf("OverlayFrame::overlay 5 %d\n", mode);
-                       if(!translate_engine) translate_engine = new TranslateEngine(this, cpus);
-                       translate_engine->process_packages();
-
-               }
-       }
-//printf("OverlayFrame::overlay 2\n");
-
-       return 0;
-}
-
-
-
-
-
-
-
-ScalePackage::ScalePackage()
-{
-}
-
-
-
-
-ScaleUnit::ScaleUnit(ScaleEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-}
-
-ScaleUnit::~ScaleUnit()
-{
-}
-
-
-
-#define BILINEAR(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       type zero_r, zero_g, zero_b, zero_a; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
-       int *table_int_x, *table_int_y; \
-       int *table_frac_x, *table_frac_y; \
- \
-       zero_r = 0; \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       if(components == 4) zero_a = 0; \
- \
-       tabulate_blinear(table_int_x, table_frac_x, k_x, 0, out_w_int); \
-       tabulate_blinear(table_int_y, table_frac_y, k_y, pkg->out_row1, pkg->out_row2); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               int i_y = table_int_y[i - pkg->out_row1]; \
-               uint64_t a = table_frac_y[i - pkg->out_row1]; \
-        uint64_t anti_a = 0xffff - a; \
-               type *in_row1 = in_rows[i_y + in_y1_int]; \
-               type *in_row2 = (i_y + in_y1_int < in_h_int - 1) ?  \
-                       in_rows[i_y + in_y1_int + 1] : \
-                       0; \
-               type *out_row = out_rows[i]; \
- \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       int i_x = table_int_x[j]; \
-                       uint64_t b = table_frac_x[j]; \
-                       uint64_t anti_b = 0xffff - b; \
-                       int x = i_x + in_x1_int; \
-                       uint64_t output1r, output1g, output1b, output1a; \
-                       uint64_t output2r, output2g, output2b, output2a; \
-                       uint64_t output3r, output3g, output3b, output3a; \
-                       uint64_t output4r, output4g, output4b, output4a; \
- \
-                       output1r = in_row1[x * components]; \
-                       output1g = in_row1[x * components + 1]; \
-                       output1b = in_row1[x * components + 2]; \
-                       if(components == 4) output1a = in_row1[x * components + 3]; \
- \
-                       if(x < in_w_int - 1) \
-                       { \
-                               output2r = in_row1[x * components + components]; \
-                               output2g = in_row1[x * components + components + 1]; \
-                               output2b = in_row1[x * components + components + 2]; \
-                               if(components == 4) output2a = in_row1[x * components + components + 3]; \
- \
-                               if(in_row2) \
-                               { \
-                                       output4r = in_row2[x * components + components]; \
-                                       output4g = in_row2[x * components + components + 1]; \
-                                       output4b = in_row2[x * components + components + 2]; \
-                                       if(components == 4) output4a = in_row2[x * components + components + 3]; \
-                               } \
-                               else \
-                               { \
-                                       output4r = zero_r; \
-                                       output4g = zero_g; \
-                                       output4b = zero_b; \
-                                       if(components == 4) output4a = zero_a; \
-                               } \
-                       } \
-                       else \
-                       { \
-                               output2r = zero_r; \
-                               output2g = zero_g; \
-                               output2b = zero_b; \
-                               if(components == 4) output2a = zero_a; \
-                               output4r = zero_r; \
-                               output4g = zero_g; \
-                               output4b = zero_b; \
-                               if(components == 4) output4a = zero_a; \
-                       } \
- \
-                       if(in_row2) \
-                       { \
-                               output3r = in_row2[x * components]; \
-                               output3g = in_row2[x * components + 1]; \
-                               output3b = in_row2[x * components + 2]; \
-                               if(components == 4) output3a = in_row2[x * components + 3]; \
-                       } \
-                       else \
-                       { \
-                               output3r = zero_r; \
-                               output3g = zero_g; \
-                               output3b = zero_b; \
-                               if(components == 4) output3a = zero_a; \
-                       } \
- \
-                       out_row[j * components] =  \
-                               (type)(((anti_a) * (((anti_b) * output1r) +  \
-                               (b * output2r)) +  \
-                a * (((anti_b) * output3r) +  \
-                               (b * output4r))) / 0xffffffff); \
-                       out_row[j * components + 1] =   \
-                               (type)(((anti_a) * (((anti_b) * output1g) +  \
-                               (b * output2g)) +  \
-                a * (((anti_b) * output3g) +  \
-                               (b * output4g))) / 0xffffffff); \
-                       out_row[j * components + 2] =   \
-                               (type)(((anti_a) * (((anti_b) * output1b) +  \
-                               (b * output2b)) +  \
-                a * (((anti_b) * output3b) +  \
-                               (b * output4b))) / 0xffffffff); \
-                       if(components == 4) \
-                               out_row[j * components + 3] =   \
-                                       (type)(((anti_a) * (((anti_b) * output1a) +  \
-                                       (b * output2a)) +  \
-                       a * (((anti_b) * output3a) +  \
-                                       (b * output4a))) / 0xffffffff); \
-               } \
-       } \
- \
- \
-       delete [] table_int_x; \
-       delete [] table_frac_x; \
-       delete [] table_int_y; \
-       delete [] table_frac_y; \
- \
-}
-
-
-#define BICUBIC(max, type, components) \
-{ \
-       float k_y = 1.0 / scale_h; \
-       float k_x = 1.0 / scale_w; \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
-       int *bspline_x, *bspline_y; \
-       int in_h_int = input->get_h(); \
-       int in_w_int = input->get_w(); \
-       type zero_r, zero_g, zero_b, zero_a; \
- \
-       zero_r = 0; \
-       zero_b = ((max + 1) >> 1) * (do_yuv); \
-       zero_g = ((max + 1) >> 1) * (do_yuv); \
-       if(components == 4) \
-               zero_a = 0; \
- \
-       tabulate_bspline(bspline_x,  \
-               k_x, \
-               out_w_int, \
-               -1); \
- \
-       tabulate_bspline(bspline_y,  \
-               k_y, \
-               out_h_int, \
-               1); \
- \
-       for(int i = pkg->out_row1; i < pkg->out_row2; i++) \
-       { \
-               int i_y = (int)(k_y * i); \
- \
- \
-               for(int j = 0; j < out_w_int; j++) \
-               { \
-                       int i_x = (int)(k_x * j); \
-                       uint64_t output1, output2, output3, output4; \
-                       output1 = 0; \
-                       output2 = 0; \
-                       output3 = 0; \
-                       if(components == 4) \
-                               output4 = 0; \
-                       int table_y = i * 4; \
- \
-/* Kernel */ \
-                       for(int m = -1; m < 3; m++) \
-                       { \
-                               uint64_t r1 = bspline_y[table_y++]; \
-                               int y = in_y1_int + i_y + m; \
-                               int table_x = j * 4; \
- \
-                               for(int n = -1; n < 3; n++) \
-                               { \
-                                       uint64_t r2 = bspline_x[table_x++]; \
-                                       int x = in_x1_int + i_x + n; \
-                                       uint64_t r_square = r1 * r2; \
- \
-/* Inside boundary. */ \
-                                       if(x >= 0 && \
-                                               x < in_w_int && \
-                                               y >= 0 && \
-                                               y < in_h_int) \
-                                       { \
-                                               output1 += r_square * in_rows[y][x * components]; \
-                                               output2 += r_square * in_rows[y][x * components + 1]; \
-                                               output3 += r_square * in_rows[y][x * components + 2]; \
-                                               if(components == 4) \
-                                                       output4 += r_square * in_rows[y][x * components + 3]; \
-                                       } \
-                                       else \
-                                       { \
-                                               output1 += r_square * zero_r; \
-                                               output2 += r_square * zero_g; \
-                                               output3 += r_square * zero_b; \
-                                               if(components == 4) \
-                                                       output4 += r_square * zero_a; \
-                                       } \
-                               } \
-                       } \
- \
- \
-                       out_rows[i][j * components] = (type)(output1 / 0xffffffff); \
-                       out_rows[i][j * components + 1] = (type)(output2 / 0xffffffff); \
-                       out_rows[i][j * components + 2] = (type)(output3 / 0xffffffff); \
-                       if(components == 4) \
-                               out_rows[i][j * components + 3] = (type)(output4 / 0xffffffff); \
- \
-               } \
-       } \
- \
-       delete [] bspline_x; \
-       delete [] bspline_y; \
-}
-
-
-
-
-// Pow function is not thread safe in Compaqt C
-#define CUBE(x) ((x) * (x) * (x))
-
-int ScaleUnit::cubic_bspline(float x)
-{
-       float a, b, c, d;
-
-       if((x + 2.0F) <= 0.0F) 
-       {
-       a = 0.0F;
-       }
-       else 
-       {
-       a = CUBE(x + 2.0F);
-       }
-
-
-       if((x + 1.0F) <= 0.0F) 
-       {
-       b = 0.0F;
-       }
-       else 
-       {
-       b = CUBE(x + 1.0F);
-       }    
-
-       if(x <= 0) 
-       {
-       c = 0.0F;
-       }
-       else 
-       {
-       c = CUBE(x);
-       }  
-
-       if((x - 1.0F) <= 0.0F) 
-       {
-       d = 0.0F;
-       }
-       else 
-       {
-       d = CUBE(x - 1.0F);
-       }
-
-
-       return (int)((a - (4.0F * b) + (6.0F * c) - (4.0F * d)) / 6.0 * 0x10000);
-}
-
-
-void ScaleUnit::tabulate_bspline(int* &table, 
-       float scale,
-       int pixels,
-       float coefficient)
-{
-       table = new int[pixels * 4];
-       for(int i = 0, j = 0; i < pixels; i++)
-       {
-               float f_x = (float)i * scale;
-               float a = f_x - floor(f_x);
-               
-               for(float m = -1; m < 3; m++)
-               {
-                       table[j++] = cubic_bspline(coefficient * (m - a));
-               }
-               
-       }
-}
-
-void ScaleUnit::tabulate_blinear(int* &table_int,
-               int* &table_frac,
-               float scale,
-               int pixel1,
-               int pixel2)
-{
-       table_int = new int[pixel2 - pixel1];
-       table_frac = new int[pixel2 - pixel1];
-
-       for(int i = pixel1, j = 0; i < pixel2; i++, j++)
-       {
-               float f_x = (float)i * scale;
-               int i_x = (int)floor(f_x);
-               int a = (int)((f_x - floor(f_x)) * 0xffff);
-
-               table_int[j] = i_x;
-               table_frac[j] = a;
-       }
-}
-
-void ScaleUnit::process_package(LoadPackage *package)
-{
-       ScalePackage *pkg = (ScalePackage*)package;
-
-// Arguments for macros
-       VFrame *output = overlay->scale_output;
-       VFrame *input = overlay->scale_input;
-       float scale_w = overlay->w_scale;
-       float scale_h = overlay->h_scale;
-       int in_x1_int = overlay->in_x1_int;
-       int in_y1_int = overlay->in_y1_int;
-       int out_h_int = overlay->out_h_int;
-       int out_w_int = overlay->out_w_int;
-       int do_yuv = 
-               (overlay->scale_input->get_color_model() == BC_YUV888 ||
-               overlay->scale_input->get_color_model() == BC_YUVA8888 ||
-               overlay->scale_input->get_color_model() == BC_YUV161616 ||
-               overlay->scale_input->get_color_model() == BC_YUVA16161616);
-
-       if(overlay->interpolation_type == CUBIC_CUBIC || 
-               (overlay->interpolation_type == CUBIC_LINEAR 
-                       && overlay->w_scale > 1 && 
-                       overlay->h_scale > 1))
-       {
-       
-               switch(overlay->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BICUBIC(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BICUBIC(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BICUBIC(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BICUBIC(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-       else
-// Perform bilinear scaling input -> scale_output
-       {
-               switch(overlay->scale_input->get_color_model())
-               {
-                       case BC_RGB888:
-                       case BC_YUV888:
-                               BILINEAR(0xff, unsigned char, 3);
-                               break;
-
-                       case BC_RGBA8888:
-                       case BC_YUVA8888:
-                               BILINEAR(0xff, unsigned char, 4);
-                               break;
-
-                       case BC_RGB161616:
-                       case BC_YUV161616:
-                               BILINEAR(0xffff, uint16_t, 3);
-                               break;
-
-                       case BC_RGBA16161616:
-                       case BC_YUVA16161616:
-                               BILINEAR(0xffff, uint16_t, 4);
-                               break;
-               }
-       }
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-ScaleEngine::ScaleEngine(OverlayFrame *overlay, int cpus)
- : LoadServer(cpus, cpus)
-{
-       this->overlay = overlay;
-}
-
-ScaleEngine::~ScaleEngine()
-{
-}
-
-void ScaleEngine::init_packages()
-{
-       for(int i = 0; i < total_packages; i++)
-       {
-               ScalePackage *package = (ScalePackage*)packages[i];
-               package->out_row1 = overlay->out_h_int / total_packages * i;
-               package->out_row2 = package->out_row1 + overlay->out_h_int / total_packages;
-
-               if(i >= total_packages - 1)
-                       package->out_row2 = overlay->out_h_int;
-       }
-}
-
-LoadClient* ScaleEngine::new_client()
-{
-       return new ScaleUnit(this, overlay);
-}
-
-LoadPackage* ScaleEngine::new_package()
-{
-       return new ScalePackage;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-TranslatePackage::TranslatePackage()
-{
-}
-
-
-
-TranslateUnit::TranslateUnit(TranslateEngine *server, OverlayFrame *overlay)
- : LoadClient(server)
-{
-       this->overlay = overlay;
-}
-
-TranslateUnit::~TranslateUnit()
-{
-}
-
-
-
-void TranslateUnit::translation_array(transfer_table* &table, 
-       float out_x1, 
-       float out_x2,
-       float in_x1,
-       float in_x2,
-       int in_total, 
-       int out_total, 
-       int &out_x1_int,
-       int &out_x2_int)
-{
-       int out_w_int;
-       float offset = out_x1 - in_x1;
-
-       out_x1_int = (int)out_x1;
-       out_x2_int = MIN((int)ceil(out_x2), out_total);
-       out_w_int = out_x2_int - out_x1_int;
-
-       table = new transfer_table[out_w_int];
-       bzero(table, sizeof(transfer_table) * out_w_int);
-
-
-//printf("OverlayFrame::translation_array 1 %f %f -> %f %f\n", in_x1, in_x2, out_x1, out_x2);
-
-       float in_x = in_x1;
-       for(int out_x = out_x1_int; out_x < out_x2_int; out_x++)
-       {
-               transfer_table *entry = &table[out_x - out_x1_int];
-
-               entry->in_x1 = (int)in_x;
-               entry->in_x2 = (int)in_x + 1;
-
-// Get fraction of output pixel to fill
-               entry->output_fraction = 1;
-
-               if(out_x1 > out_x)
-               {
-                       entry->output_fraction -= out_x1 - out_x;
-               }
-
-               if(out_x2 < out_x + 1)
-               {
-                       entry->output_fraction = (out_x2 - out_x);
-               }
-
-// Advance in_x until out_x_fraction is filled
-               float out_x_fraction = entry->output_fraction;
-               float in_x_fraction = floor(in_x + 1) - in_x;
-
-               if(out_x_fraction <= in_x_fraction)
-               {
-                       entry->in_fraction1 = out_x_fraction;
-                       entry->in_fraction2 = 0.0;
-                       in_x += out_x_fraction;
-               }
-               else
-               {
-                       entry->in_fraction1 = in_x_fraction;
-                       in_x += out_x_fraction;
-                       entry->in_fraction2 = in_x - floor(in_x);
-               }
-
-// Clip in_x
-               if(entry->in_x2 >= in_total)
-               {
-                       entry->in_x2 = in_total - 1;
-                       entry->in_fraction2 = 0.0;
-               }
-               
-               if(entry->in_x1 >= in_total)
-               {
-                       entry->in_x1 = in_total - 1;
-                       entry->in_fraction1 = 0.0;
-               }
-// printf("OverlayFrame::translation_array 2 %d %d %d %f %f %f\n", 
-//     out_x, 
-//     entry->in_x1, 
-//     entry->in_x2, 
-//     entry->in_fraction1, 
-//     entry->in_fraction2, 
-//     entry->output_fraction);
-       }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#define TRANSLATE(max, type, components) \
-{ \
- \
-       type **in_rows = (type**)input->get_rows(); \
-       type **out_rows = (type**)output->get_rows(); \
- \
-/* printf("OverlayFrame::translate 1  %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",  */ \
-/*     (in_x1),  in_y1,  in_x2,  in_y2,  out_x1,  out_y1, out_x2,  out_y2); */ \
- \
-       unsigned int master_opacity = (int)(alpha * max + 0.5); \
-       unsigned int master_transparency = max - master_opacity; \
- \
-/* printf("TRANSLATE %d\n", mode); */ \
- \
-       for(int i = row1; i < row2; i++) \
-       { \
-               int in_y1 = y_table[i - out_y1_int].in_x1; \
-               int in_y2 = y_table[i - out_y1_int].in_x2; \
-               float y_fraction1 = y_table[i - out_y1_int].in_fraction1; \
-               float y_fraction2 = y_table[i - out_y1_int].in_fraction2; \
-               float y_output_fraction = y_table[i - out_y1_int].output_fraction; \
-               type *in_row1 = in_rows[(in_y1)]; \
-               type *in_row2 = in_rows[(in_y2)]; \
-               type *out_row = out_rows[i]; \
- \
-               for(int j = out_x1_int; j < out_x2_int; j++) \
-               { \
-                       int in_x1 = x_table[j - out_x1_int].in_x1; \
-                       int in_x2 = x_table[j - out_x1_int].in_x2; \
-                       float x_fraction1 = x_table[j - out_x1_int].in_fraction1; \
-                       float x_fraction2 = x_table[j - out_x1_int].in_fraction2; \
-                       float x_output_fraction = x_table[j - out_x1_int].output_fraction; \
-                       type *output = &out_row[j * components]; \
-                       int input1, input2, input3, input4; \
- \
-                       input1 = (int)(in_row1[in_x1 * components] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_x1 * components] * x_fraction1 * y_fraction2 +  \
-                               in_row2[in_x2 * components] * x_fraction2 * y_fraction2 + 0.5); \
-                       input2 = (int)(in_row1[in_x1 * components + 1] * x_fraction1 * y_fraction1 +  \
-                               in_row1[in_x2 * components + 1] * x_fraction2 * y_fraction1 +  \
-                               in_row2[in_