Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ on:
branches: [main]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Check clang-format
uses: jidicula/clang-format-action@v4.14.0
with:
clang-format-version: '21'
check-path: 'src'

test:
runs-on: ubuntu-latest
steps:
Expand Down
132 changes: 71 additions & 61 deletions src/fleximg/core/affine_capability.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,79 @@ namespace FLEXIMG_NAMESPACE {

class AffineCapability {
public:
AffineCapability() = default;
virtual ~AffineCapability() = default;

// ========================================
// 行列アクセサ
// ========================================

void setMatrix(const AffineMatrix &m) { localMatrix_ = m; }
const AffineMatrix &matrix() const { return localMatrix_; }

// ========================================
// 便利なセッター(AffineNode と同一API)
// ========================================

// 回転を設定(a,b,c,d のみ変更、tx,ty は維持)
void setRotation(float radians) {
float c = std::cos(radians);
float s = std::sin(radians);
localMatrix_.a = c;
localMatrix_.b = -s;
localMatrix_.c = s;
localMatrix_.d = c;
}

// スケールを設定(a,b,c,d のみ変更、tx,ty は維持)
void setScale(float sx, float sy) {
localMatrix_.a = sx;
localMatrix_.b = 0;
localMatrix_.c = 0;
localMatrix_.d = sy;
}

// 平行移動を設定(tx,ty のみ変更、a,b,c,d は維持)
void setTranslation(float tx, float ty) {
localMatrix_.tx = tx;
localMatrix_.ty = ty;
}

// 回転+スケールを設定(a,b,c,d のみ変更、tx,ty は維持)
void setRotationScale(float radians, float sx, float sy) {
float c = std::cos(radians);
float s = std::sin(radians);
localMatrix_.a = c * sx;
localMatrix_.b = -s * sy;
localMatrix_.c = s * sx;
localMatrix_.d = c * sy;
}

// ========================================
// ユーティリティ
// ========================================

// ローカル変換が設定されているか(単位行列でないか)
bool hasLocalTransform() const {
return localMatrix_.a != 1.0f || localMatrix_.b != 0.0f ||
localMatrix_.c != 0.0f || localMatrix_.d != 1.0f ||
localMatrix_.tx != 0.0f || localMatrix_.ty != 0.0f;
}
AffineCapability() = default;
virtual ~AffineCapability() = default;

// ========================================
// 行列アクセサ
// ========================================

void setMatrix(const AffineMatrix &m)
{
localMatrix_ = m;
}
const AffineMatrix &matrix() const
{
return localMatrix_;
}

// ========================================
// 便利なセッター(AffineNode と同一API)
// ========================================

// 回転を設定(a,b,c,d のみ変更、tx,ty は維持)
void setRotation(float radians)
{
float c = std::cos(radians);
float s = std::sin(radians);
localMatrix_.a = c;
localMatrix_.b = -s;
localMatrix_.c = s;
localMatrix_.d = c;
}

// スケールを設定(a,b,c,d のみ変更、tx,ty は維持)
void setScale(float sx, float sy)
{
localMatrix_.a = sx;
localMatrix_.b = 0;
localMatrix_.c = 0;
localMatrix_.d = sy;
}

// 平行移動を設定(tx,ty のみ変更、a,b,c,d は維持)
void setTranslation(float tx, float ty)
{
localMatrix_.tx = tx;
localMatrix_.ty = ty;
}

// 回転+スケールを設定(a,b,c,d のみ変更、tx,ty は維持)
void setRotationScale(float radians, float sx, float sy)
{
float c = std::cos(radians);
float s = std::sin(radians);
localMatrix_.a = c * sx;
localMatrix_.b = -s * sy;
localMatrix_.c = s * sx;
localMatrix_.d = c * sy;
}

// ========================================
// ユーティリティ
// ========================================

// ローカル変換が設定されているか(単位行列でないか)
bool hasLocalTransform() const
{
return localMatrix_.a != 1.0f || localMatrix_.b != 0.0f || localMatrix_.c != 0.0f || localMatrix_.d != 1.0f ||
localMatrix_.tx != 0.0f || localMatrix_.ty != 0.0f;
}

protected:
AffineMatrix localMatrix_; // ローカル変換行列(デフォルトは単位行列)
AffineMatrix localMatrix_; // ローカル変換行列(デフォルトは単位行列)
};

} // namespace FLEXIMG_NAMESPACE
} // namespace FLEXIMG_NAMESPACE

#endif // FLEXIMG_AFFINE_CAPABILITY_H
#endif // FLEXIMG_AFFINE_CAPABILITY_H
56 changes: 28 additions & 28 deletions src/fleximg/core/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include "types.h"

#include <cstdio> // printf
#include <cstdlib> // std::abort
#include <cstdio> // printf
#include <cstdlib> // std::abort

// ========================================================================
// デバッグログマクロ
Expand All @@ -31,18 +31,18 @@
//

#ifdef ARDUINO
#define FLEXIMG_DEBUG_LOG(fmt, ...) \
do { \
printf(fmt "\n", ##__VA_ARGS__); \
fflush(stdout); \
vTaskDelay(1); \
} while (0)
#define FLEXIMG_DEBUG_LOG(fmt, ...) \
do { \
printf(fmt "\n", ##__VA_ARGS__); \
fflush(stdout); \
vTaskDelay(1); \
} while (0)
#else
#define FLEXIMG_DEBUG_LOG(fmt, ...) \
do { \
printf(fmt "\n", ##__VA_ARGS__); \
fflush(stdout); \
} while (0)
#define FLEXIMG_DEBUG_LOG(fmt, ...) \
do { \
printf(fmt "\n", ##__VA_ARGS__); \
fflush(stdout); \
} while (0)
#endif

#ifdef FLEXIMG_DEBUG
Expand All @@ -60,24 +60,24 @@
//

#ifdef FLEXIMG_DEBUG
#define FLEXIMG_ASSERT(cond, msg) \
do { \
if (!(cond)) { \
FLEXIMG_DEBUG_LOG("ASSERT FAIL: %s", msg); \
std::abort(); \
} \
} while (0)
#define FLEXIMG_ASSERT(cond, msg) \
do { \
if (!(cond)) { \
FLEXIMG_DEBUG_LOG("ASSERT FAIL: %s", msg); \
std::abort(); \
} \
} while (0)
#else
#define FLEXIMG_ASSERT(cond, msg) ((void)0)
#endif

#define FLEXIMG_REQUIRE(cond, msg) \
do { \
if (!(cond)) { \
FLEXIMG_DEBUG_LOG("REQUIRE FAIL: %s", msg); \
std::abort(); \
} \
} while (0)
#define FLEXIMG_REQUIRE(cond, msg) \
do { \
if (!(cond)) { \
FLEXIMG_DEBUG_LOG("REQUIRE FAIL: %s", msg); \
std::abort(); \
} \
} while (0)

// ========================================================================
// Deprecated attribute
Expand All @@ -94,4 +94,4 @@
#define FLEXIMG_VERSION_MINOR 0
#define FLEXIMG_VERSION_PATCH 0

#endif // FLEXIMG_COMMON_H
#endif // FLEXIMG_COMMON_H
78 changes: 43 additions & 35 deletions src/fleximg/core/data_range_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,56 @@ namespace core {

class DataRangeCache {
public:
DataRangeCache() = default;
DataRangeCache() = default;

/// @brief キャッシュから取得を試みる
/// @param request リクエスト(キー)
/// @param out 取得結果の格納先
/// @return true=キャッシュヒット, false=キャッシュミス
bool tryGet(const RenderRequest &request, DataRange &out) const {
if (!valid_) {
return false;
/// @brief キャッシュから取得を試みる
/// @param request リクエスト(キー)
/// @param out 取得結果の格納先
/// @return true=キャッシュヒット, false=キャッシュミス
bool tryGet(const RenderRequest &request, DataRange &out) const
{
if (!valid_) {
return false;
}
if (cachedOrigin_.x != request.origin.x || cachedOrigin_.y != request.origin.y ||
cachedWidth_ != request.width) {
return false;
}
out = cachedRange_;
return true;
}
if (cachedOrigin_.x != request.origin.x ||
cachedOrigin_.y != request.origin.y || cachedWidth_ != request.width) {
return false;
}
out = cachedRange_;
return true;
}

/// @brief キャッシュに設定
/// @param request リクエスト(キー)
/// @param range 範囲(値)
void set(const RenderRequest &request, const DataRange &range) {
cachedOrigin_ = request.origin;
cachedWidth_ = request.width;
cachedRange_ = range;
valid_ = true;
}
/// @brief キャッシュに設定
/// @param request リクエスト(キー)
/// @param range 範囲(値)
void set(const RenderRequest &request, const DataRange &range)
{
cachedOrigin_ = request.origin;
cachedWidth_ = request.width;
cachedRange_ = range;
valid_ = true;
}

/// @brief キャッシュ無効化(Prepare時に呼び出し)
void invalidate() { valid_ = false; }
/// @brief キャッシュ無効化(Prepare時に呼び出し)
void invalidate()
{
valid_ = false;
}

/// @brief キャッシュが有効か問い合わせ(テスト/デバッグ用)
bool isValid() const { return valid_; }
/// @brief キャッシュが有効か問い合わせ(テスト/デバッグ用)
bool isValid() const
{
return valid_;
}

private:
Point cachedOrigin_ = {0, 0};
int16_t cachedWidth_ = 0;
DataRange cachedRange_ = {0, 0};
bool valid_ = false;
Point cachedOrigin_ = {0, 0};
int16_t cachedWidth_ = 0;
DataRange cachedRange_ = {0, 0};
bool valid_ = false;
};

} // namespace core
} // namespace FLEXIMG_NAMESPACE
} // namespace core
} // namespace FLEXIMG_NAMESPACE

#endif // FLEXIMG_DATA_RANGE_CACHE_H
#endif // FLEXIMG_DATA_RANGE_CACHE_H
Loading
Loading