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
8 changes: 8 additions & 0 deletions fleximg/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

- **コーディングスタイル違反の包括的修正**
- 固定小数点Q16.16メンバを `int32_t` → `int_fixed` に統一(AffinePrecomputed, SinkNode, SourceNode)
- 関数引数を `int` → `int_fast16_t` に修正(viewport, image_buffer, pixel_format, render_types 等14ファイル)
- 構造体メンバを `int` → `int16_t` に修正(RendererNode, BlurNode, MatteNode, PerfMetrics 等)
- ローカル変数・ループカウンタの型を終端変数に一致させる修正(auto + static_castパターン)
- 配列インデックスの型を `uint_fast8_t` / `size_t` に整理(EntryPool, RenderContext, FormatMetrics 等)
- PerfMetrics の count/allocCount メンバを `uint32_t` に統一

- **関数ポインタ型の `int` 引数を `size_t` / `int_fast16_t` に修正**
- `ConvertFunc` 系(ピクセル変換関数): `int pixelCount` → `size_t pixelCount`
- `CopyRowDDA_Func` / `CopyQuadDDA_Func`(DDA転送関数): `int count` → `int_fast16_t count`
Expand Down
6 changes: 3 additions & 3 deletions fleximg/demo/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,12 @@ class NodeGraphEvaluatorWrapper {

// フォーマット別データ
val formats = val::array();
for (int f = 0; f < FormatIdx::Count; f++) {
for (uint_fast8_t f = 0; f < FormatIdx::Count; f++) {
val fmtData = val::object();
fmtData.set("name", formatNames[f]);

val ops = val::array();
for (int o = 0; o < OpType::Count; o++) {
for (uint_fast8_t o = 0; o < OpType::Count; o++) {
val opData = val::object();
opData.set("name", opNames[o]);
opData.set("callCount", metrics.data[f][o].callCount);
Expand All @@ -863,7 +863,7 @@ class NodeGraphEvaluatorWrapper {

// 操作別合計
val opTotals = val::array();
for (int o = 0; o < OpType::Count; o++) {
for (uint_fast8_t o = 0; o < OpType::Count; o++) {
val opTotal = val::object();
opTotal.set("name", opNames[o]);
auto t = metrics.totalByOp(o);
Expand Down
70 changes: 35 additions & 35 deletions fleximg/src/fleximg/core/format_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ namespace core {
//

namespace FormatIdx {
constexpr int RGBA8_Straight = 0;
constexpr int RGB565_LE = 1;
constexpr int RGB565_BE = 2;
constexpr int RGB332 = 3;
constexpr int RGB888 = 4;
constexpr int BGR888 = 5;
constexpr int Alpha8 = 6;
constexpr int Grayscale8 = 7;
constexpr int Index8 = 8;
constexpr int Count = 9;
constexpr uint_fast8_t RGBA8_Straight = 0;
constexpr uint_fast8_t RGB565_LE = 1;
constexpr uint_fast8_t RGB565_BE = 2;
constexpr uint_fast8_t RGB332 = 3;
constexpr uint_fast8_t RGB888 = 4;
constexpr uint_fast8_t BGR888 = 5;
constexpr uint_fast8_t Alpha8 = 6;
constexpr uint_fast8_t Grayscale8 = 7;
constexpr uint_fast8_t Index8 = 8;
constexpr uint_fast8_t Count = 9;
}

// ========================================================================
// 操作タイプ
// ========================================================================

namespace OpType {
constexpr int ToStraight = 0; // 各フォーマット → RGBA8_Straight
constexpr int FromStraight = 1; // RGBA8_Straight → 各フォーマット
constexpr int BlendUnder = 2; // 各フォーマット → Straight dst (under合成)
constexpr int Count = 3;
constexpr uint_fast8_t ToStraight = 0; // 各フォーマット → RGBA8_Straight
constexpr uint_fast8_t FromStraight = 1; // RGBA8_Straight → 各フォーマット
constexpr uint_fast8_t BlendUnder = 2; // 各フォーマット → Straight dst (under合成)
constexpr uint_fast8_t Count = 3;
}

// ========================================================================
Expand All @@ -74,7 +74,7 @@ struct FormatOpEntry {
pixelCount = 0;
}

void record(int pixels) {
void record(size_t pixels) {
callCount++;
pixelCount += static_cast<uint64_t>(pixels);
}
Expand All @@ -90,25 +90,25 @@ struct FormatMetrics {
}

void reset() {
for (int f = 0; f < FormatIdx::Count; ++f) {
for (int o = 0; o < OpType::Count; ++o) {
for (uint_fast8_t f = 0; f < FormatIdx::Count; ++f) {
for (uint_fast8_t o = 0; o < OpType::Count; ++o) {
data[f][o].reset();
}
}
}

void record(int formatIdx, int opType, int pixels) {
if (formatIdx >= 0 && formatIdx < FormatIdx::Count &&
opType >= 0 && opType < OpType::Count) {
void record(uint_fast8_t formatIdx, uint_fast8_t opType, size_t pixels) {
if (formatIdx < FormatIdx::Count &&
opType < OpType::Count) {
data[formatIdx][opType].record(pixels);
}
}

// 全フォーマットの合計(操作タイプ別)
FormatOpEntry totalByOp(int opType) const {
FormatOpEntry totalByOp(uint_fast8_t opType) const {
FormatOpEntry total;
if (opType >= 0 && opType < OpType::Count) {
for (int f = 0; f < FormatIdx::Count; ++f) {
if (opType < OpType::Count) {
for (uint_fast8_t f = 0; f < FormatIdx::Count; ++f) {
total.callCount += data[f][opType].callCount;
total.pixelCount += data[f][opType].pixelCount;
}
Expand All @@ -117,10 +117,10 @@ struct FormatMetrics {
}

// 全操作の合計(フォーマット別)
FormatOpEntry totalByFormat(int formatIdx) const {
FormatOpEntry totalByFormat(uint_fast8_t formatIdx) const {
FormatOpEntry total;
if (formatIdx >= 0 && formatIdx < FormatIdx::Count) {
for (int o = 0; o < OpType::Count; ++o) {
if (formatIdx < FormatIdx::Count) {
for (uint_fast8_t o = 0; o < OpType::Count; ++o) {
total.callCount += data[formatIdx][o].callCount;
total.pixelCount += data[formatIdx][o].pixelCount;
}
Expand All @@ -131,8 +131,8 @@ struct FormatMetrics {
// 全体合計
FormatOpEntry total() const {
FormatOpEntry t;
for (int f = 0; f < FormatIdx::Count; ++f) {
for (int o = 0; o < OpType::Count; ++o) {
for (uint_fast8_t f = 0; f < FormatIdx::Count; ++f) {
for (uint_fast8_t o = 0; o < OpType::Count; ++o) {
t.callCount += data[f][o].callCount;
t.pixelCount += data[f][o].pixelCount;
}
Expand All @@ -142,17 +142,17 @@ struct FormatMetrics {

// スナップショット(現在の状態を保存)
void saveSnapshot(FormatOpEntry snapshot[FormatIdx::Count][OpType::Count]) const {
for (int f = 0; f < FormatIdx::Count; ++f) {
for (int o = 0; o < OpType::Count; ++o) {
for (uint_fast8_t f = 0; f < FormatIdx::Count; ++f) {
for (uint_fast8_t o = 0; o < OpType::Count; ++o) {
snapshot[f][o] = data[f][o];
}
}
}

// スナップショットから復元
void restoreSnapshot(const FormatOpEntry snapshot[FormatIdx::Count][OpType::Count]) {
for (int f = 0; f < FormatIdx::Count; ++f) {
for (int o = 0; o < OpType::Count; ++o) {
for (uint_fast8_t f = 0; f < FormatIdx::Count; ++f) {
for (uint_fast8_t o = 0; o < OpType::Count; ++o) {
data[f][o] = snapshot[f][o];
}
}
Expand All @@ -179,9 +179,9 @@ struct FormatMetrics {
return s_instance;
}
void reset() {}
void record(int, int, int) {}
FormatOpEntry totalByOp(int) const { return FormatOpEntry{}; }
FormatOpEntry totalByFormat(int) const { return FormatOpEntry{}; }
void record(uint_fast8_t, uint_fast8_t, size_t) {}
FormatOpEntry totalByOp(uint_fast8_t) const { return FormatOpEntry{}; }
FormatOpEntry totalByFormat(uint_fast8_t) const { return FormatOpEntry{}; }
FormatOpEntry total() const { return FormatOpEntry{}; }
void saveSnapshot(FormatOpEntry[FormatIdx::Count][OpType::Count]) const {}
void restoreSnapshot(const FormatOpEntry[FormatIdx::Count][OpType::Count]) {}
Expand Down
9 changes: 5 additions & 4 deletions fleximg/src/fleximg/core/memory/pool_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,15 @@ void* PoolAllocator::allocate(size_t size) {
uint32_t needBitmap = (1U << blocksNeeded) - 1;

// 探索方向を決定(交互に切り替えてフラグメンテーション軽減)
int start = searchFromHead_ ? 0 : static_cast<int>(blockCount_ - blocksNeeded);
int end = searchFromHead_ ? static_cast<int>(blockCount_ - blocksNeeded + 1) : -1;
int step = searchFromHead_ ? 1 : -1;
size_t start = searchFromHead_ ? 0 : blockCount_ - blocksNeeded;
size_t end = blockCount_ - blocksNeeded + 1;
bool forward = searchFromHead_;

searchFromHead_ = !searchFromHead_; // 次回は逆方向

// ビットマップで連続空きブロックを探索
for (int i = start; i != end; i += step) {
for (size_t idx = 0; idx < end; ++idx) {
size_t i = forward ? idx : (start - idx);
uint32_t shiftedNeed = needBitmap << i;

if ((allocatedBitmap_ & shiftedNeed) == 0) {
Expand Down
16 changes: 8 additions & 8 deletions fleximg/src/fleximg/core/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class Node {
: context_(nullptr)
{
prepareResponse_.status = PrepareStatus::Idle;
initPorts(static_cast<int>(other.inputs_.size()),
static_cast<int>(other.outputs_.size()));
initPorts(static_cast<int_fast16_t>(other.inputs_.size()),
static_cast<int_fast16_t>(other.outputs_.size()));
}

// ムーブコンストラクタ: ポート構造をムーブし、ownerを修正
Expand All @@ -78,8 +78,8 @@ class Node {
Node& operator=(const Node& other) {
if (this != &other) {
disconnectAll();
initPorts(static_cast<int>(other.inputs_.size()),
static_cast<int>(other.outputs_.size()));
initPorts(static_cast<int_fast16_t>(other.inputs_.size()),
static_cast<int_fast16_t>(other.outputs_.size()));
prepareResponse_.status = PrepareStatus::Idle;
context_ = nullptr;
}
Expand Down Expand Up @@ -539,7 +539,7 @@ class Node {
const FormatConverter* converter = nullptr);

// 派生クラス用:ポート初期化
void initPorts(int inputCount, int outputCount);
void initPorts(int_fast16_t inputCount, int_fast16_t outputCount);
};

} // namespace core
Expand Down Expand Up @@ -613,13 +613,13 @@ ImageBuffer Node::convertFormat(ImageBuffer&& buffer, PixelFormatID target,
}

// 派生クラス用:ポート初期化
void Node::initPorts(int inputCount, int outputCount) {
void Node::initPorts(int_fast16_t inputCount, int_fast16_t outputCount) {
inputs_.resize(static_cast<size_t>(inputCount));
outputs_.resize(static_cast<size_t>(outputCount));
for (int i = 0; i < inputCount; ++i) {
for (int_fast16_t i = 0; i < inputCount; ++i) {
inputs_[static_cast<size_t>(i)] = Port(this, i);
}
for (int i = 0; i < outputCount; ++i) {
for (int_fast16_t i = 0; i < outputCount; ++i) {
outputs_[static_cast<size_t>(i)] = Port(this, i);
}
}
Expand Down
20 changes: 10 additions & 10 deletions fleximg/src/fleximg/core/perf_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ static_assert(NodeType::VerticalBlur == 11,
// ノード別メトリクス
struct NodeMetrics {
uint32_t time_us = 0; // 処理時間(マイクロ秒)
int count = 0; // 呼び出し回数
uint32_t requestedPixels = 0; // 上流に要求したピクセル数
uint32_t usedPixels = 0; // 実際に使用したピクセル数
uint32_t count = 0; // 呼び出し回数
uint32_t requestedPixels = 0; // 上流に要求したピクセル数
uint32_t usedPixels = 0; // 実際に使用したピクセル数
uint32_t theoreticalMinPixels = 0; // 理論最小ピクセル数(分割時の推定値)
uint32_t allocatedBytes = 0; // このノードが確保したバイト数
int allocCount = 0; // 確保回数
uint32_t allocatedBytes = 0; // このノードが確保したバイト数
uint32_t allocCount = 0; // 確保回数
uint32_t maxAllocBytes = 0; // 一回の最大確保バイト数
int maxAllocWidth = 0; // その時の幅
int maxAllocHeight = 0; // その時の高さ
int16_t maxAllocWidth = 0; // その時の幅
int16_t maxAllocHeight = 0; // その時の高さ

void reset() {
*this = NodeMetrics{};
Expand All @@ -112,13 +112,13 @@ struct NodeMetrics {
}

// メモリ確保を記録
void recordAlloc(size_t bytes, int width, int height) {
void recordAlloc(size_t bytes, int_fast16_t width, int_fast16_t height) {
allocatedBytes += static_cast<uint32_t>(bytes);
allocCount++;
if (static_cast<uint32_t>(bytes) > maxAllocBytes) {
maxAllocBytes = static_cast<uint32_t>(bytes);
maxAllocWidth = width;
maxAllocHeight = height;
maxAllocWidth = static_cast<int16_t>(width);
maxAllocHeight = static_cast<int16_t>(height);
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions fleximg/src/fleximg/core/render_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class RenderContext {
RenderResponse& acquireResponse() {
// nextHint_から開始して循環探索
uint_fast8_t idx = nextHint_;
for (int i = 0; i < MAX_RESPONSES; ++i) {
for (uint_fast8_t i = 0; i < MAX_RESPONSES; ++i) {
idx = (idx + 1) & (MAX_RESPONSES - 1);
if (!responsePool_[idx].inUse) {
responsePool_[idx].inUse = true;
Expand Down Expand Up @@ -154,8 +154,8 @@ class RenderContext {
void resetScanlineResources() {
#ifdef FLEXIMG_DEBUG
// 未返却チェック
int inUseCount = 0;
for (int i = 0; i < MAX_RESPONSES; ++i) {
uint_fast8_t inUseCount = 0;
for (uint_fast8_t i = 0; i < MAX_RESPONSES; ++i) {
if (responsePool_[i].inUse) ++inUseCount;
}
if (inUseCount > 1) {
Expand All @@ -167,7 +167,7 @@ class RenderContext {
#endif
}
#endif
for (int i = 0; i < MAX_RESPONSES; ++i) {
for (uint_fast8_t i = 0; i < MAX_RESPONSES; ++i) {
if (responsePool_[i].inUse) {
responsePool_[i].clear();
responsePool_[i].inUse = false;
Expand Down
12 changes: 6 additions & 6 deletions fleximg/src/fleximg/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ inline Matrix2x2_fixed inverseFixed(const AffineMatrix& m) {

struct AffinePrecomputed {
Matrix2x2_fixed invMatrix; // 逆行列(2x2部分)
int32_t invTxFixed = 0; // 逆変換オフセットX(Q16.16)
int32_t invTyFixed = 0; // 逆変換オフセットY(Q16.16)
int32_t rowOffsetX = 0; // ピクセル中心オフセット: invMatrix.b >> 1
int32_t rowOffsetY = 0; // ピクセル中心オフセット: invMatrix.d >> 1
int32_t dxOffsetX = 0; // ピクセル中心オフセット: invMatrix.a >> 1
int32_t dxOffsetY = 0; // ピクセル中心オフセット: invMatrix.c >> 1
int_fixed invTxFixed = 0; // 逆変換オフセットX(Q16.16)
int_fixed invTyFixed = 0; // 逆変換オフセットY(Q16.16)
int_fixed rowOffsetX = 0; // ピクセル中心オフセット: invMatrix.b >> 1
int_fixed rowOffsetY = 0; // ピクセル中心オフセット: invMatrix.d >> 1
int_fixed dxOffsetX = 0; // ピクセル中心オフセット: invMatrix.a >> 1
int_fixed dxOffsetY = 0; // ピクセル中心オフセット: invMatrix.c >> 1

bool isValid() const { return invMatrix.valid; }
};
Expand Down
4 changes: 2 additions & 2 deletions fleximg/src/fleximg/image/image_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ImageBuffer {

// サイズ指定コンストラクタ
// alloc = nullptr の場合、DefaultAllocator を使用
ImageBuffer(int w, int h, PixelFormatID fmt = PixelFormatIDs::RGBA8_Straight,
ImageBuffer(int_fast16_t w, int_fast16_t h, PixelFormatID fmt = PixelFormatIDs::RGBA8_Straight,
InitPolicy init = DefaultInitPolicy,
core::memory::IAllocator* alloc = nullptr)
: view_(nullptr, fmt, 0, static_cast<int16_t>(w), static_cast<int16_t>(h))
Expand Down Expand Up @@ -296,7 +296,7 @@ class ImageBuffer {
resolved = resolveConverter(view_.formatID, target, auxPtr);
}
if (resolved) {
for (int y = 0; y < view_.height; ++y) {
for (int_fast16_t y = 0; y < view_.height; ++y) {
// ViewPortのx,yオフセットを考慮
const uint8_t* srcRow = static_cast<const uint8_t*>(view_.data)
+ (view_.y + y) * view_.stride
Expand Down
Loading
Loading