Skip to content

Commit 58ae8bf

Browse files
CedricGuillemetCopilotCopilot
authored
Add BABYLON_NATIVE_DISABLE_IMAGE_LOADING CMake option (#1677)
## Summary Adds a new CMake option `BABYLON_NATIVE_DISABLE_IMAGE_LOADING` (default `OFF`) that strips all bimg / bx / stb / WebP image-decoding code from the `NativeEngine` plugin. Useful for embedders that decode textures themselves and want to reduce binary size. ## What it does when `ON` - `bimg`, `bimg_encode`, `bimg_decode` are no longer linked into `NativeEngine`. - `BABYLON_NATIVE_PLUGIN_NATIVEENGINE_WEBP` is forced `OFF` (libwebp is not fetched/built). - All `<bimg/...>`, `<bx/...>`, `<stb/...>`, `<webp/...>` includes are guarded out. - All bimg-using helpers (`Cast`, `TransformImage`, `GetPixelMapper`, `ReorientImage`, `ParseImage`, `PrepareImage`, `LoadTextureFromImage`, `LoadCubeTextureFromImages`, related `static_assert`s) are excluded from compilation. - The following `NativeEngine` instance methods stay registered but throw a `Napi::Error` (`"Image loading is disabled in this build (BABYLON_NATIVE_DISABLE_IMAGE_LOADING)."`) when invoked: - `loadTexture` - `loadRawTexture` - `loadRawTexture2DArray` - `loadCubeTexture` - `loadCubeTextureWithMips` - `createImageBitmap` - `resizeImageBitmap` - `ReadTexture`'s bimg-based format-conversion path also throws; raw readback when source/target formats match continues to work. - `FlipImage` is kept available because it's also used by `ReadTexture`. ## Binary size impact Measured on Windows x64 Release `Playground.exe` (MSVC, default options): | Build | `Playground.exe` | |---|---| | Image loading `ON` (default) | 3,610,112 bytes | | Image loading `OFF` | 3,152,384 bytes | | **Saved** | **457,728 bytes (~447 KiB, ~12.7%)** | ## How to use ``` cmake -B buildNoImage -A x64 -DBABYLON_NATIVE_DISABLE_IMAGE_LOADING=ON cmake --build buildNoImage --target Playground --config Release ``` ## Validation - `cmake -B buildImage -DBABYLON_NATIVE_DISABLE_IMAGE_LOADING=OFF` configure Γ£ö - `cmake -B buildNoImage -DBABYLON_NATIVE_DISABLE_IMAGE_LOADING=ON` configure Γ£ö (libwebp not fetched) - Playground Release build Γ£ö for both - Default behavior unchanged (option defaults to `OFF`). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a5d50ae commit 58ae8bf

15 files changed

Lines changed: 148 additions & 54 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ option(BABYLON_NATIVE_PLUGIN_NATIVECAPTURE "Include Babylon Native Plugin Native
124124
option(BABYLON_NATIVE_PLUGIN_NATIVEENCODING "Include Babylon Native Plugin NativeEncoding." ON)
125125
option(BABYLON_NATIVE_PLUGIN_NATIVEENGINE "Include Babylon Native Plugin NativeEngine." ON)
126126
option(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_WEBP "Include Babylon Native Plugin NativeEngine - WebP." ON)
127+
option(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES "Enable image loading in NativeEngine (LoadTexture, image bitmap, bimg, WebP)." ON)
128+
if(NOT BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES)
129+
# WebP support relies on image loading code paths; force it off when image loading is disabled.
130+
set(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_WEBP OFF CACHE BOOL "Include Babylon Native Plugin NativeEngine - WebP." FORCE)
131+
endif()
127132
option(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_COMPILESHADERS "Include Babylon Native Plugin NativeEngine - Compile Shaders." ON)
128133
option(BABYLON_NATIVE_PLUGIN_NATIVEINPUT "Include Babylon Native Plugin NativeInput." ON)
129134
option(BABYLON_NATIVE_PLUGIN_NATIVEOPTIMIZATIONS "Include Babylon Native Plugin NativeOptimizations." ON)

Core/Graphics/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ target_compile_definitions(Graphics
3838
target_link_libraries(Graphics
3939
PRIVATE JsRuntimeInternal
4040
PRIVATE bgfx
41-
PRIVATE bimg
42-
PRIVATE bimg_encode
43-
PRIVATE bimg_decode
4441
PRIVATE minz
4542
PRIVATE bx)
4643

@@ -98,7 +95,6 @@ target_link_libraries(GraphicsDeviceContext
9895
INTERFACE JsRuntimeInternal
9996
INTERFACE arcana
10097
INTERFACE bgfx
101-
INTERFACE bimg
10298
INTERFACE bx)
10399

104100
if(APPLE)

Core/Graphics/Source/Texture.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
#include <Babylon/Graphics/Texture.h>
22
#include <Babylon/Graphics/DeviceContext.h>
33
#include <cassert>
4-
#include <bimg/bimg.h>
4+
#include <cstring>
55

66
namespace
77
{
88
const bgfx::Memory* GetZeroImageMemory(uint16_t width, uint16_t height, bool hasMips, uint16_t numLayers, bgfx::TextureFormat::Enum format)
99
{
10-
bgfx::ReleaseFn releaseFn{[](void*, void* userData) {
11-
bimg::imageFree(static_cast<bimg::ImageContainer*>(userData));
12-
}};
13-
14-
bimg::ImageContainer* image = bimg::imageAlloc(&Babylon::Graphics::DeviceContext::GetDefaultAllocator(), static_cast<bimg::TextureFormat::Enum>(format), width, height, 1/*depth*/, numLayers, false/*cubeMap*/, hasMips);
15-
const bgfx::Memory* mem = bgfx::makeRef(image->m_data, image->m_size, releaseFn, image);
16-
bx::memSet(image->m_data, 0, image->m_size);
10+
bgfx::TextureInfo info{};
11+
bgfx::calcTextureSize(info, width, height, /*depth*/ 1, /*cubeMap*/ false, hasMips, numLayers, format);
12+
const bgfx::Memory* mem = bgfx::alloc(info.storageSize);
13+
std::memset(mem->data, 0, mem->size);
1714
return mem;
1815
}
1916
}

Plugins/NativeEncoding/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ target_link_libraries(NativeEncoding
1212
PUBLIC napi
1313
PRIVATE GraphicsDevice
1414
PRIVATE GraphicsDeviceContext
15-
PRIVATE JsRuntimeInternal)
15+
PRIVATE JsRuntimeInternal
16+
PRIVATE bimg
17+
PRIVATE bimg_encode)
1618

1719
set_property(TARGET NativeEncoding PROPERTY FOLDER Plugins)
1820
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})

Plugins/NativeEngine/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@ target_link_libraries(NativeEngine
3030
PUBLIC napi
3131
PRIVATE arcana
3232
PRIVATE bgfx
33-
PRIVATE bimg
34-
PRIVATE bimg_encode
35-
PRIVATE bimg_decode
3633
PRIVATE bx
3734
PRIVATE minz
3835
PRIVATE GraphicsDevice
3936
PRIVATE GraphicsDeviceContext
4037
PRIVATE JsRuntime)
4138

39+
if(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES)
40+
target_compile_definitions(NativeEngine
41+
PRIVATE BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES)
42+
target_link_libraries(NativeEngine
43+
PRIVATE bimg
44+
PRIVATE bimg_encode
45+
PRIVATE bimg_decode)
46+
endif()
47+
4248
if(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_WEBP)
4349
target_compile_definitions(NativeEngine
4450
PRIVATE WEBP)

Plugins/NativeEngine/Source/NativeEngine.cpp

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414

1515
#include <bgfx/bgfx.h>
1616

17+
#ifdef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1718
#include <bimg/bimg.h>
1819
#include <bimg/decode.h>
1920
#include <bimg/encode.h>
2021

2122
#include <stb/stb_image_resize.h>
2223
#include <bx/math.h>
24+
#endif
2325

2426
#include <cmath>
2527

26-
#ifdef WEBP
28+
#if defined(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES) && defined(WEBP)
2729
#include <webp/decode.h>
2830
#endif
2931

@@ -73,6 +75,23 @@ namespace Babylon
7375
constexpr uint64_t SCREENMODE = BGFX_STATE_BLEND_FUNC_SEPARATE(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_COLOR, BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_ALPHA);
7476
}
7577

78+
void FlipImage(gsl::span<uint8_t> image, uint32_t height)
79+
{
80+
const size_t rowPitch{image.size() / height};
81+
82+
std::vector<uint8_t> buffer(rowPitch);
83+
for (size_t row = 0; row < height / 2; row++)
84+
{
85+
uint8_t* frontPtr{image.data() + (row * rowPitch)};
86+
uint8_t* backPtr{image.data() + ((height - row - 1) * rowPitch)};
87+
88+
std::memcpy(buffer.data(), frontPtr, rowPitch);
89+
std::memcpy(frontPtr, backPtr, rowPitch);
90+
std::memcpy(backPtr, buffer.data(), rowPitch);
91+
}
92+
}
93+
94+
#ifdef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
7695
static_assert(static_cast<bgfx::TextureFormat::Enum>(bimg::TextureFormat::Count) == bgfx::TextureFormat::Count);
7796
static_assert(static_cast<bgfx::TextureFormat::Enum>(bimg::TextureFormat::RGBA8) == bgfx::TextureFormat::RGBA8);
7897
static_assert(static_cast<bgfx::TextureFormat::Enum>(bimg::TextureFormat::RGB8) == bgfx::TextureFormat::RGB8);
@@ -101,22 +120,6 @@ namespace Babylon
101120
}
102121
}
103122

104-
void FlipImage(gsl::span<uint8_t> image, uint32_t height)
105-
{
106-
const size_t rowPitch{image.size() / height};
107-
108-
std::vector<uint8_t> buffer(rowPitch);
109-
for (size_t row = 0; row < height / 2; row++)
110-
{
111-
uint8_t* frontPtr{image.data() + (row * rowPitch)};
112-
uint8_t* backPtr{image.data() + ((height - row - 1) * rowPitch)};
113-
114-
std::memcpy(buffer.data(), frontPtr, rowPitch);
115-
std::memcpy(frontPtr, backPtr, rowPitch);
116-
std::memcpy(backPtr, buffer.data(), rowPitch);
117-
}
118-
}
119-
120123
std::function<std::pair<uint32_t, uint32_t>(uint32_t x, uint32_t y)> GetPixelMapper(bimg::Orientation::Enum orientation, uint32_t width, uint32_t height)
121124
{
122125
// clang-format off
@@ -412,6 +415,7 @@ namespace Babylon
412415
}
413416
}
414417
}
418+
#endif // BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
415419

416420
auto RenderTargetSamplesToBgfxMsaaFlag(uint32_t renderTargetSamples)
417421
{
@@ -1311,6 +1315,9 @@ namespace Babylon
13111315

13121316
void NativeEngine::LoadTexture(const Napi::CallbackInfo& info)
13131317
{
1318+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1319+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
1320+
#else
13141321
const auto texture = info[0].As<Napi::Pointer<Graphics::Texture>>().Get();
13151322
const auto data = info[1].As<Napi::TypedArray>();
13161323
const auto generateMips = info[2].As<Napi::Boolean>().Value();
@@ -1338,6 +1345,7 @@ namespace Babylon
13381345
onSuccessRef.Call({});
13391346
}
13401347
});
1348+
#endif
13411349
}
13421350

13431351
void NativeEngine::CopyTexture(NativeDataStream::Reader& data)
@@ -1352,6 +1360,9 @@ namespace Babylon
13521360

13531361
void NativeEngine::LoadRawTexture(const Napi::CallbackInfo& info)
13541362
{
1363+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1364+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
1365+
#else
13551366
const auto texture{info[0].As<Napi::Pointer<Graphics::Texture>>().Get()};
13561367
const auto data{info[1].As<Napi::TypedArray>()};
13571368
const auto width{static_cast<uint16_t>(info[2].As<Napi::Number>().Uint32Value())};
@@ -1369,10 +1380,14 @@ namespace Babylon
13691380
bimg::ImageContainer* image{bimg::imageAlloc(&Graphics::DeviceContext::GetDefaultAllocator(), format, width, height, 1, 1, false, false, bytes)};
13701381
image = PrepareImage(Graphics::DeviceContext::GetDefaultAllocator(), image, invertY, false, generateMips);
13711382
LoadTextureFromImage(texture, image, false);
1383+
#endif
13721384
}
13731385

13741386
void NativeEngine::LoadRawTexture2DArray(const Napi::CallbackInfo& info)
13751387
{
1388+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1389+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
1390+
#else
13761391
const auto texture{info[0].As<Napi::Pointer<Graphics::Texture>>().Get()};
13771392
const auto data = info[1].As<Napi::TypedArray>();
13781393
const auto width{static_cast<uint16_t>(info[2].As<Napi::Number>().Uint32Value())};
@@ -1414,10 +1429,14 @@ namespace Babylon
14141429
texture->Update2D(i, 0, 0, 0, width, height, dataCopy);
14151430
}
14161431
}
1432+
#endif
14171433
}
14181434

14191435
void NativeEngine::LoadCubeTexture(const Napi::CallbackInfo& info)
14201436
{
1437+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1438+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
1439+
#else
14211440
const auto texture = info[0].As<Napi::Pointer<Graphics::Texture>>().Get();
14221441
const auto data{info[1].As<Napi::Array>()};
14231442
const auto generateMips{info[2].As<Napi::Boolean>().Value()};
@@ -1454,10 +1473,14 @@ namespace Babylon
14541473
onSuccessRef.Call({});
14551474
}
14561475
});
1476+
#endif
14571477
}
14581478

14591479
void NativeEngine::LoadCubeTextureWithMips(const Napi::CallbackInfo& info)
14601480
{
1481+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1482+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
1483+
#else
14611484
const auto texture = info[0].As<Napi::Pointer<Graphics::Texture>>().Get();
14621485
const auto data{info[1].As<Napi::Array>()};
14631486
const auto invertY{info[2].As<Napi::Boolean>().Value()};
@@ -1498,6 +1521,7 @@ namespace Babylon
14981521
onSuccessRef.Call({});
14991522
}
15001523
});
1524+
#endif
15011525
}
15021526

15031527
Napi::Value NativeEngine::GetTextureWidth(const Napi::CallbackInfo& info)
@@ -1673,12 +1697,16 @@ namespace Babylon
16731697
// If the source texture format does not match the target texture format, convert it.
16741698
if (targetTextureInfo.format != sourceTextureInfo.format)
16751699
{
1700+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1701+
throw std::runtime_error{"Texture format conversion is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF)."};
1702+
#else
16761703
std::vector<uint8_t> convertedTextureBuffer(targetTextureInfo.storageSize);
16771704
if (!bimg::imageConvert(&Graphics::DeviceContext::GetDefaultAllocator(), convertedTextureBuffer.data(), bimg::TextureFormat::Enum(targetTextureInfo.format), textureBuffer.data(), bimg::TextureFormat::Enum(sourceTextureInfo.format), sourceTextureInfo.width, sourceTextureInfo.height, /*depth*/ 1))
16781705
{
1679-
throw std::runtime_error{"Texture conversion to RBGA8 failed."};
1706+
throw std::runtime_error{"Texture conversion to RGBA8 failed."};
16801707
}
16811708
textureBuffer = convertedTextureBuffer;
1709+
#endif
16821710
}
16831711

16841712
// Ensure the final texture buffer has the expected size.
@@ -1963,6 +1991,9 @@ namespace Babylon
19631991

19641992
Napi::Value NativeEngine::CreateImageBitmap(const Napi::CallbackInfo& info)
19651993
{
1994+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
1995+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
1996+
#else
19661997
const Napi::Env env{info.Env()};
19671998
bimg::ImageContainer* image{nullptr};
19681999
bool allocatedImage{false};
@@ -2018,10 +2049,14 @@ namespace Babylon
20182049
}
20192050

20202051
return imageBitmap;
2052+
#endif
20212053
}
20222054

20232055
Napi::Value NativeEngine::ResizeImageBitmap(const Napi::CallbackInfo& info)
20242056
{
2057+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
2058+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
2059+
#else
20252060
const auto imageBitmap = info[0].As<Napi::Object>();
20262061
const auto bufferWidth = info[1].As<Napi::Number>().Uint32Value();
20272062
const auto bufferHeight = info[2].As<Napi::Number>().Uint32Value();
@@ -2066,6 +2101,7 @@ namespace Babylon
20662101
}
20672102
bimg::imageFree(image);
20682103
return Napi::Value::From(env, outputData);
2104+
#endif
20692105
}
20702106

20712107
void NativeEngine::SetRenderResetCallback(const Napi::CallbackInfo& info)

Plugins/NativeEngine/Source/NativeEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
#include <bgfx/bgfx.h>
1919
#include <bgfx/platform.h>
20+
#ifdef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
2021
#include <bimg/bimg.h>
2122
#include <bx/allocator.h>
23+
#endif
2224

2325
#include <gsl/gsl>
2426

Plugins/TestUtils/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ target_link_libraries(TestUtils
1616
PRIVATE GraphicsDevice
1717
PRIVATE GraphicsDeviceContext)
1818

19+
if(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES)
20+
target_compile_definitions(TestUtils
21+
PRIVATE BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES)
22+
target_link_libraries(TestUtils
23+
PRIVATE bimg
24+
PRIVATE bimg_encode
25+
PRIVATE bimg_decode)
26+
endif()
27+
1928
target_compile_definitions(TestUtils PRIVATE GRAPHICS_API=${GRAPHICS_API})
2029

2130
if(APPLE)

Plugins/TestUtils/Source/TestUtils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
#include <bgfx/bgfx.h>
44
#include <bgfx/platform.h>
5+
#ifdef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
56
#include <bimg/decode.h>
67
#include <bimg/encode.h>
8+
#endif
79
#include <bx/file.h>
810

911
#include <Babylon/JsRuntime.h>
@@ -27,6 +29,9 @@ namespace Babylon::Plugins::Internal
2729

2830
void TestUtils::WritePNG(const Napi::CallbackInfo& info)
2931
{
32+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
33+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
34+
#else
3035
const auto buffer = info[0].As<Napi::Uint8Array>();
3136
const auto width = info[1].As<Napi::Number>().Uint32Value();
3237
const auto height = info[2].As<Napi::Number>().Uint32Value();
@@ -48,21 +53,29 @@ namespace Babylon::Plugins::Internal
4853
bimg::imageWritePng(&writer, width, height, width * 4, buffer.Data(), bimg::TextureFormat::RGBA8, false);
4954
writer.close();
5055
}
56+
#endif
5157
}
5258

5359
Napi::Value TestUtils::DecodeImage(const Napi::CallbackInfo& info)
5460
{
61+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
62+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
63+
#else
5564
Image* image = new Image;
5665
const auto buffer = info[0].As<Napi::ArrayBuffer>();
5766

5867
image->m_Image = bimg::imageParse(&Graphics::DeviceContext::GetDefaultAllocator(), buffer.Data(), static_cast<uint32_t>(buffer.ByteLength()));
5968

6069
auto finalizer = [](Napi::Env, Image* image) { delete image; };
6170
return Napi::External<Image>::New(info.Env(), image, std::move(finalizer));
71+
#endif
6272
}
6373

6474
Napi::Value TestUtils::GetImageData(const Napi::CallbackInfo& info)
6575
{
76+
#ifndef BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES
77+
throw Napi::Error::New(info.Env(), "Image loading is disabled in this build (BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES=OFF).");
78+
#else
6679
const auto imageData = info[0].As<Napi::External<Image>>().Data();
6780

6881
if (!imageData || !imageData->m_Image || !imageData->m_Image->m_size)
@@ -75,6 +88,7 @@ namespace Babylon::Plugins::Internal
7588
memcpy(data.Data(), ptr, imageData->m_Image->m_size);
7689

7790
return Napi::Value::From(info.Env(), data);
91+
#endif
7892
}
7993

8094
void TestUtils::GetFrameBufferData(const Napi::CallbackInfo& info)

0 commit comments

Comments
 (0)