Skip to content

Instantly share code, notes, and snippets.

/sharp.cpp Secret

Created May 26, 2016
Embed
What would you like to do?
void do_compute(toonz::node_handle_t node, const toonz::rendering_setting_t *rs, double frame, toonz::tile_handle_t tile)
{
printf("do_compute(): node:%p tile:%p frame:%g\n", node, tile, frame);
toonz::port_handle_t port = nullptr;
{
auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);
if (nodeif) {
int ret = nodeif->get_input_port(node, "IPort", &port);
if (ret)
printf("do_compute(): get_input_port: ret:%d\n", ret);
}
}
int extend = 1;
// エフェクトパラメータ
double strength = 9;
auto pif = grab_interf<toonz::param_interface_t>(TOONZ_UUID_PARAM);
auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);
if (pif) {
toonz_param_handle_t p1;
int t, l;
int cnt = 0;
typename toonz_param_traits_double_t::iovaluetype v;
nodeif->get_param(node, "strength", &p1);
pif->get_value(p1, frame, &cnt, &v);
strength = v;
}
auto tileif = grab_interf<toonz::tile_interface_t>(TOONZ_UUID_TILE);
auto portif = grab_interf<toonz::port_interface_t>(TOONZ_UUID_PORT);
if (port && tileif && portif) {
toonz::fxnode_handle_t fx;
portif->get_fx(port, &fx);
auto fxif = grab_interf<toonz::fxnode_interface_t>(TOONZ_UUID_FXNODE);
if (fxif) {
/* evaluate upstream's flow */
toonz::rect_t rect;
tileif->get_rectangle(tile, &rect);
toonz::rect_t inRect = conv2rect(conv2rect(rect).enlarge(extend, extend));
toonz::tile_handle_t result = nullptr;
tileif->create(&result);
fxif->compute_to_tile(fx, rs, frame, &inRect, tile, result);
/* evaluate the fx */
int x = rect.x0;
int y = rect.y0;
int lx = rect.x1 - rect.x0;
int ly = rect.y1 - rect.y0;
int sstride, dstride;
tileif->get_raw_stride(result, &sstride);
tileif->get_raw_stride(tile, &dstride);
int selement_type, delement_type;
tileif->get_element_type(result, &delement_type);
tileif->get_element_type(tile, &selement_type);
uint8_t *saddr, *daddr;
tileif->get_raw_address_unsafe(result, reinterpret_cast<void **>(&saddr));
tileif->get_raw_address_unsafe(tile, reinterpret_cast<void **>(&daddr));
printf("%f %f %f %f\n", rect.x0, rect.y0, rect.x1, rect.y1);
printf("-+ x:%d y:%d lx:%d ly:%d\n", x, y, lx, ly);
printf(" + src tile: addr:%p stride:%d type:%d\n", saddr, sstride, selement_type);
printf(" + dst tile: addr:%p stride:%d type:%d\n", daddr, dstride, delement_type);
// need compatibility check for formats
hv_kernel<uint8_t, 4>(daddr, saddr + sstride + 4, lx, ly, dstride, sstride, [strength](uint8_t v[4], const uint8_t *p, int stride, int xinbytes, int yinbytes)
{
uint32_t l00 = *reinterpret_cast<const uint32_t *>(p + -stride - 4);
uint32_t l10 = *reinterpret_cast<const uint32_t *>(p + -stride);
uint32_t l20 = *reinterpret_cast<const uint32_t *>(p + -stride + 4);
uint32_t l01 = *reinterpret_cast<const uint32_t *>(p - 4);
uint32_t l11 = *reinterpret_cast<const uint32_t *>(p);
uint32_t l21 = *reinterpret_cast<const uint32_t *>(p + 4);
uint32_t l02 = *reinterpret_cast<const uint32_t *>(p + stride - 4);
uint32_t l12 = *reinterpret_cast<const uint32_t *>(p + stride);
uint32_t l22 = *reinterpret_cast<const uint32_t *>(p + stride + 4);
double r = 0, g = 0, b = 0, m = 0;
//printf("col:0x%08x [%d, %d]\n", l11, xinbytes, yinbytes);
/* TODO:
toonz の TPixel は char r, g, b, m; のように持っているのでそのまま uin32_t だとエンディアンが変わる.
toonz ビルド時の configuration はコンパイル時に参照できるようにしておくべきだ.
*/
m += ((l00 >> 24) & 0xff);
m += ((l10 >> 24) & 0xff);
m += ((l20 >> 24) & 0xff);
m += ((l01 >> 24) & 0xff);
m += ((l11 >> 24) & 0xff);
m += ((l21 >> 24) & 0xff);
m += ((l02 >> 24) & 0xff);
m += ((l12 >> 24) & 0xff);
m += ((l22 >> 24) & 0xff);
b -= strength * ((l00 >> 16) & 0xff);
b -= strength * ((l10 >> 16) & 0xff);
b -= strength * ((l20 >> 16) & 0xff);
b -= strength * ((l01 >> 16) & 0xff);
b += (1+8*strength) * ((l11 >> 16) & 0xff);
b -= strength * ((l21 >> 16) & 0xff);
b -= strength * ((l02 >> 16) & 0xff);
b -= strength * ((l12 >> 16) & 0xff);
b -= strength * ((l22 >> 16) & 0xff);
g -= strength *((l00 >> 8) & 0xff);
g -= strength *((l10 >> 8) & 0xff);
g -= strength *((l20 >> 8) & 0xff);
g -= strength *((l01 >> 8) & 0xff);
g += (1+8*strength)*((l11 >> 8) & 0xff);
g -= strength *((l21 >> 8) & 0xff);
g -= strength *((l02 >> 8) & 0xff);
g -= strength *((l12 >> 8) & 0xff);
g -= strength *((l22 >> 8) & 0xff);
r -= strength *((l00 >> 0) & 0xff);
r -= strength *((l10 >> 0) & 0xff);
r -= strength *((l20 >> 0) & 0xff);
r -= strength *((l01 >> 0) & 0xff);
r += (1+8*strength)*((l11 >> 0) & 0xff);
r -= strength *((l21 >> 0) & 0xff);
r -= strength *((l02 >> 0) & 0xff);
r -= strength *((l12 >> 0) & 0xff);
r -= strength *((l22 >> 0) & 0xff);
if (r > 255) r = 255; else if (r < 0) r = 0;
if (g > 255) g = 255; else if (g < 0) g = 0;
if (b > 255) b = 255; else if (b < 0) b = 0;
if (m > 255) m = 255; else if (m < 0) m = 0;
v[0] = static_cast<uint8_t>(r);
v[1] = static_cast<uint8_t>(g);
v[2] = static_cast<uint8_t>(b);
v[3] = static_cast<uint8_t>(m);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.