plugins.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <v8.h>
  2. #include <kinc/log.h>
  3. using namespace v8;
  4. static Isolate *isolate;
  5. extern "C" {
  6. void texsynth_inpaint(int w, int h, void *output_ptr, void *image_ptr, void *mask_ptr, bool tiling);
  7. }
  8. namespace {
  9. void krom_texsynth_inpaint(const FunctionCallbackInfo<Value> &args) {
  10. HandleScope scope(args.GetIsolate());
  11. int32_t w = args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value();
  12. int32_t h = args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value();
  13. Local<ArrayBuffer> bufferOut = Local<ArrayBuffer>::Cast(args[2]);
  14. std::shared_ptr<BackingStore> contentOut = bufferOut->GetBackingStore();
  15. Local<ArrayBuffer> bufferImage = Local<ArrayBuffer>::Cast(args[3]);
  16. std::shared_ptr<BackingStore> contentImage = bufferImage->GetBackingStore();
  17. Local<ArrayBuffer> bufferMask = Local<ArrayBuffer>::Cast(args[4]);
  18. std::shared_ptr<BackingStore> contentMask = bufferMask->GetBackingStore();
  19. bool tiling = args[5]->ToBoolean(isolate)->Value();
  20. texsynth_inpaint(w, h, contentOut->Data(), contentImage->Data(), contentMask->Data(), tiling);
  21. }
  22. }
  23. #define SET_FUNCTION(object, name, fn)\
  24. object->Set(String::NewFromUtf8(isolate, name).ToLocalChecked(),\
  25. FunctionTemplate::New(isolate, fn, Local<v8::Value>(), Local<v8::Signature>(), 0,\
  26. v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasNoSideEffect, nullptr))
  27. void plugin_embed(Isolate *_isolate, Local<ObjectTemplate> global) {
  28. isolate = _isolate;
  29. Isolate::Scope isolate_scope(isolate);
  30. HandleScope handle_scope(isolate);
  31. Local<ObjectTemplate> krom_texsynth = ObjectTemplate::New(isolate);
  32. SET_FUNCTION(krom_texsynth, "inpaint", krom_texsynth_inpaint);
  33. global->Set(String::NewFromUtf8(isolate, "Krom_texsynth").ToLocalChecked(), krom_texsynth);
  34. }