Skip to content

Commit 578f6c9

Browse files
authored
feat(codec): make BMP support configurable (#500)
BMP support is currently compiled into `skity-codec` unconditionally. Add `SKITY_ENABLE_CODEC_BMP`, defaulting to `ON` like the existing GIF/WebP options, so consumers can configure `-DSKITY_ENABLE_CODEC_BMP=OFF` to omit the built-in BMP implementation and its codec registration. Update codec tests to retain BMP coverage when enabled and verify BMP input is rejected when disabled. The separate Apple ImageIO implementation is unchanged. Validation on macOS arm64: - Default configuration: 47/47 codec unit tests passed via `tools/test-runner.py`. - `SKITY_ENABLE_CODEC_BMP=OFF`: 36/36 codec unit tests passed via `tools/test-runner.py`; BMP source excluded from the build. - `tools/code_format_check.py`, `tools/cpplint_check.py`, and `git diff --check`.
1 parent 68f05b0 commit 578f6c9

5 files changed

Lines changed: 32 additions & 6 deletions

File tree

‎module/codec/CMakeLists.txt‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target_include_directories(skity-codec PRIVATE ${SKITY_ROOT}/include)
1616

1717
option(SKITY_ENABLE_CODEC_WEBP "Enable WebP Codec" ON)
1818
option(SKITY_ENABLE_CODEC_GIF "Enable GIF Codec" ON)
19+
option(SKITY_ENABLE_CODEC_BMP "Enable BMP Codec" ON)
1920

2021
target_include_directories(
2122
skity-codec
@@ -29,8 +30,6 @@ target_sources(
2930
skity-codec
3031
PRIVATE
3132
${CMAKE_CURRENT_LIST_DIR}/include/skity/codec/codec.hpp
32-
${CMAKE_CURRENT_LIST_DIR}/src/codec/bmp_codec.cc
33-
${CMAKE_CURRENT_LIST_DIR}/src/codec/bmp_codec.hpp
3433
${CMAKE_CURRENT_LIST_DIR}/src/codec/codec.cc
3534
${CMAKE_CURRENT_LIST_DIR}/src/codec/codec_priv.cc
3635
${CMAKE_CURRENT_LIST_DIR}/src/codec/codec_priv.hpp
@@ -39,6 +38,17 @@ target_sources(
3938
${CMAKE_CURRENT_LIST_DIR}/src/codec/data_stream.hpp
4039
)
4140

41+
if (SKITY_ENABLE_CODEC_BMP)
42+
target_sources(
43+
skity-codec
44+
PRIVATE
45+
${CMAKE_CURRENT_LIST_DIR}/src/codec/bmp_codec.cc
46+
${CMAKE_CURRENT_LIST_DIR}/src/codec/bmp_codec.hpp
47+
)
48+
49+
target_compile_definitions(skity-codec PRIVATE -DSKITY_ENABLE_CODEC_BMP=1)
50+
endif()
51+
4252
if (SKITY_ENABLE_CODEC_WEBP)
4353
target_sources(
4454
skity-codec

‎module/codec/src/codec/codec.cc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#include <skity/io/data.hpp>
88
#include <vector>
99

10+
#if SKITY_ENABLE_CODEC_BMP
11+
#include "src/codec/bmp_codec.hpp"
12+
#endif
1013
#if SKITY_ENABLE_CODEC_GIF
1114
#include "src/codec/gif_codec.hpp"
1215
#endif
13-
#include "src/codec/bmp_codec.hpp"
1416
#include "src/codec/jpeg_codec.hpp"
1517
#include "src/codec/png_codec.hpp"
1618

@@ -26,7 +28,9 @@ static std::mutex codec_mutex = {};
2628
void Codec::SetupCodecs() {
2729
codec_list.clear();
2830

31+
#if SKITY_ENABLE_CODEC_BMP
2932
codec_list.emplace_back(std::make_shared<BMPCodec>());
33+
#endif
3034
codec_list.emplace_back(std::make_shared<PNGCodec>());
3135
codec_list.emplace_back(std::make_shared<JPEGCodec>());
3236
#if SKITY_ENABLE_CODEC_GIF

‎test/ut/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ target_link_libraries(skity_unit_test
127127
)
128128

129129
if (${SKITY_CODEC_MODULE})
130+
target_compile_definitions(skity_unit_test PRIVATE
131+
SKITY_ENABLE_CODEC_BMP=$<BOOL:${SKITY_ENABLE_CODEC_BMP}>
132+
)
130133
target_sources(skity_unit_test
131134
PUBLIC
132135
codec/bmp_codec_test.cc

‎test/ut/codec/bmp_codec_test.cc‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <skity/render/canvas.hpp>
1313

1414
TEST(BMPCodecTest, RecognizeFileType) {
15-
auto png_data = skity::Data::MakeFromFileName(SKITY_TEST_PNG_FILE);
16-
1715
const unsigned char bmp_header[] = {
1816
'B', 'M', // signature
1917
0x36, 0x00, 0x00, 0x00, // file size = 54
@@ -37,14 +35,21 @@ TEST(BMPCodecTest, RecognizeFileType) {
3735

3836
auto codec = skity::Codec::MakeFromData(bmp_data);
3937

38+
#if SKITY_ENABLE_CODEC_BMP
4039
ASSERT_TRUE(codec != nullptr) << "MakeFromData returned nullptr for BMP data";
40+
auto png_data = skity::Data::MakeFromFileName(SKITY_TEST_PNG_FILE);
41+
ASSERT_TRUE(png_data != nullptr);
4142

4243
EXPECT_TRUE(codec->RecognizeFileType(
4344
reinterpret_cast<const char*>(bmp_header), sizeof(bmp_header)));
4445
EXPECT_FALSE(codec->RecognizeFileType(
4546
reinterpret_cast<const char*>(png_data->Bytes()), png_data->Size()));
47+
#else
48+
EXPECT_EQ(codec, nullptr);
49+
#endif
4650
}
4751

52+
#if SKITY_ENABLE_CODEC_BMP
4853
TEST(BMPCodecTest, Decode24Bit) {
4954
const unsigned char bmp_24bit[] = {
5055
'B', 'M', // signature
@@ -425,4 +430,5 @@ TEST(BMPCodecTest, InvalidSize) {
425430
auto codec = skity::Codec::MakeFromData(data);
426431

427432
EXPECT_TRUE(codec == nullptr);
428-
}
433+
}
434+
#endif

‎test/ut/codec/codec_scale_test.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ TEST(CodecScaleTest, PNGDecodeScaledContent) {
522522
}
523523
}
524524

525+
#if SKITY_ENABLE_CODEC_BMP
525526
TEST(CodecScaleTest, BMPDecodeScaled) {
526527
// BMP has no native scaling; encode a solid 64x64 image and decode it at
527528
// half size through the shared resampler. A minimal 1x1 24-bit header is
@@ -563,6 +564,8 @@ TEST(CodecScaleTest, BMPDecodeScaled) {
563564
}
564565
}
565566

567+
#endif
568+
566569
TEST(CodecScaleTest, GIFDecodeScaled) {
567570
// Single-frame GIF (color wheel): intrinsic decode via wuffs, then
568571
// resampled to the target. Dimensions are asserted relative to the

0 commit comments

Comments
 (0)