1 #include "overlayframe.h"
2 #include "overlaynearest.h"
4 /* Nearest Neighbor scale / translate / blend ********************/
10 NNUnit::NNUnit(NNEngine *server)
13 this->engine = server;
20 void NNUnit::process_package(LoadPackage *package)
22 pkg = (NNPackage*)package;
23 output = engine->output;
24 input = engine->input;
26 fade = BC_CModels::has_alpha(input->get_color_model()) &&
27 mode == TRANSFER_REPLACE ? 1.f : engine->alpha;
30 ow = engine->out_x2i - ox;
31 ly = engine->in_lookup_y + pkg->out_row1;
33 switch(input->get_color_model()) {
34 case BC_RGB_FLOAT: rgb_float(); break;
35 case BC_RGBA_FLOAT: rgba_float(); break;
36 case BC_RGB888: rgb888(); break;
37 case BC_YUV888: yuv888(); break;
38 case BC_RGBA8888: rgba8888(); break;
39 case BC_YUVA8888: yuva8888(); break;
40 case BC_RGB161616: rgb161616(); break;
41 case BC_YUV161616: yuv161616(); break;
42 case BC_RGBA16161616: rgba16161616(); break;
43 case BC_YUVA16161616: yuva16161616(); break;
47 NNEngine::NNEngine(int cpus)
48 : LoadServer(cpus, cpus)
62 void NNEngine::init_packages()
64 int in_w = input->get_w();
65 int in_h = input->get_h();
66 int out_w = output->get_w();
67 int out_h = output->get_h();
69 float in_subw = in_x2 - in_x1;
70 float in_subh = in_y2 - in_y1;
71 float out_subw = out_x2 - out_x1;
72 float out_subh = out_y2 - out_y1;
73 int first, last, count, i;
76 out_x1i = rint(out_x1);
77 out_x2i = rint(out_x2);
78 if(out_x1i < 0) out_x1i = 0;
79 if(out_x1i > out_w) out_x1i = out_w;
80 if(out_x2i < 0) out_x2i = 0;
81 if(out_x2i > out_w) out_x2i = out_w;
82 int out_wi = out_x2i - out_x1i;
86 in_lookup_x = new int[out_wi];
88 in_lookup_y = new int[out_h];
90 switch(input->get_color_model()) {
101 for(i = out_x1i; i < out_x2i; i++) {
102 int in = (i - out_x1 + .5) * in_subw / out_subw + in_x1;
108 if(in >= 0 && in < in_w && in >= in_x1 && i >= 0 && i < out_w) {
111 in_lookup_x[0] = in * components;
114 in_lookup_x[count] = (in-last)*components;
123 out_x2i = first + count;
126 for(i = out_y1; i < out_y2; i++) {
127 int in = (i - out_y1+.5) * in_subh / out_subh + in_y1;
128 if(in < in_y1) in = in_y1;
129 if(in > in_y2) in = in_y2;
130 if(in >= 0 && in < in_h && i >= 0 && i < out_h) {
131 if(count == 0) first = i;
139 out_y2 = first + count;
142 int pkgs = get_total_packages();
143 int row1 = out_y1, row2 = row1;
144 for(int i = 0; i < pkgs; row1=row2 ) {
145 NNPackage *package = (NNPackage*)get_package(i);
146 row2 = ++i * rows / pkgs + out_y1;
147 package->out_row1 = row1;
148 package->out_row2 = row2;
152 LoadClient* NNEngine::new_client()
154 return new NNUnit(this);
157 LoadPackage* NNEngine::new_package()
159 return new NNPackage;