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

### Changed

- **関数ポインタ型の `int` 引数を `size_t` / `int_fast16_t` に修正**
- `ConvertFunc` 系(ピクセル変換関数): `int pixelCount` → `size_t pixelCount`
- `CopyRowDDA_Func` / `CopyQuadDDA_Func`(DDA転送関数): `int count` → `int_fast16_t count`
- `LineFilterFunc`(ラインフィルタ関数): `int count` → `int_fast16_t count`
- 対象12ファイルの実装・ローカル変数も型を統一

- **bit-packed unpackロジック集約 + Index8処理共通化**
- パレットLUT処理を `applyPaletteLUT` 共通関数として切り出し、Index8/IndexN で共有
- `indexN_expandIndex` を末尾詰め方式に変更(チャンクバッファ不要、in-place展開)
Expand Down
44 changes: 22 additions & 22 deletions fleximg/src/fleximg/image/pixel_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct DDAParam {
using CopyRowDDA_Func = void(*)(
uint8_t* dst,
const uint8_t* srcData,
int count,
int_fast16_t count,
const DDAParam* param
);

Expand All @@ -92,7 +92,7 @@ using CopyRowDDA_Func = void(*)(
using CopyQuadDDA_Func = void(*)(
uint8_t* dst,
const uint8_t* srcData,
int count,
int_fast16_t count,
const DDAParam* param
);

Expand Down Expand Up @@ -181,10 +181,10 @@ struct PixelFormatDescriptor {
// ========================================================================
// 変換関数の型定義
// ========================================================================
// 統一シグネチャ: void(*)(void* dst, const void* src, int pixelCount, const PixelAuxInfo* aux)
// 統一シグネチャ: void(*)(void* dst, const void* src, size_t pixelCount, const PixelAuxInfo* aux)

// Straight形式(RGBA8_Straight)との相互変換
using ConvertFunc = void(*)(void* dst, const void* src, int pixelCount, const PixelAuxInfo* aux);
using ConvertFunc = void(*)(void* dst, const void* src, size_t pixelCount, const PixelAuxInfo* aux);
using ToStraightFunc = ConvertFunc;
using FromStraightFunc = ConvertFunc;

Expand Down Expand Up @@ -251,36 +251,36 @@ namespace detail {

// BytesPerPixel別 DDA転写関数(前方宣言)
// 実装は dda.h で提供(FLEXIMG_IMPLEMENTATION部)
void copyRowDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyRowDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyRowDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyRowDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyRowDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);
void copyRowDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);
void copyRowDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);
void copyRowDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);

// BytesPerPixel別 DDA 4ピクセル抽出関数(前方宣言)
void copyQuadDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyQuadDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyQuadDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyQuadDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyQuadDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);
void copyQuadDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);
void copyQuadDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);
void copyQuadDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);

// BitsPerPixel別 bit-packed DDA転写関数(前方宣言)
// 実装は dda.h で提供(bit_packed_index.h インクルード後)
template<int BitsPerPixel, BitOrder Order>
void copyRowDDA_Bit(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyRowDDA_Bit(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);

template<int BitsPerPixel, BitOrder Order>
void copyQuadDDA_Bit(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param);
void copyQuadDDA_Bit(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param);

// 8bit LUT → Nbit 変換(4ピクセル単位展開)
// T = uint32_t: rgb332_toStraight, index8_expandIndex (bpc==4) 等で共用
// T = uint16_t: index8_expandIndex (bpc==2) 等で共用
template<typename T>
void lut8toN(T* d, const uint8_t* s, int pixelCount, const T* lut);
void lut8toN(T* d, const uint8_t* s, size_t pixelCount, const T* lut);

// 便利エイリアス
inline void lut8to32(uint32_t* d, const uint8_t* s, int pixelCount, const uint32_t* lut) {
inline void lut8to32(uint32_t* d, const uint8_t* s, size_t pixelCount, const uint32_t* lut) {
lut8toN(d, s, pixelCount, lut);
}
inline void lut8to16(uint16_t* d, const uint8_t* s, int pixelCount, const uint16_t* lut) {
inline void lut8to16(uint16_t* d, const uint8_t* s, size_t pixelCount, const uint16_t* lut) {
lut8toN(d, s, pixelCount, lut);
}

Expand All @@ -299,7 +299,7 @@ namespace pixel_format {
namespace detail {

template<typename T>
void lut8toN(T* d, const uint8_t* s, int pixelCount, const T* lut) {
void lut8toN(T* d, const uint8_t* s, size_t pixelCount, const T* lut) {
while (pixelCount & 3) {
auto v0 = s[0];
++s;
Expand All @@ -326,8 +326,8 @@ void lut8toN(T* d, const uint8_t* s, int pixelCount, const T* lut) {
}

// 明示的インスタンス化(非inlineを維持)
template void lut8toN<uint16_t>(uint16_t*, const uint8_t*, int, const uint16_t*);
template void lut8toN<uint32_t>(uint32_t*, const uint8_t*, int, const uint32_t*);
template void lut8toN<uint16_t>(uint16_t*, const uint8_t*, size_t, const uint16_t*);
template void lut8toN<uint32_t>(uint32_t*, const uint8_t*, size_t, const uint32_t*);

} // namespace detail
} // namespace pixel_format
Expand Down Expand Up @@ -412,7 +412,7 @@ inline const char* getFormatName(PixelFormatID formatID) {
struct FormatConverter {
// 解決済み変換関数(分岐なし)
using ConvertFunc = void(*)(void* dst, const void* src,
int pixelCount, const void* ctx);
size_t pixelCount, const void* ctx);
ConvertFunc func = nullptr;

// 解決済みコンテキスト(Prepare 時に確定)
Expand Down Expand Up @@ -447,7 +447,7 @@ struct FormatConverter {
} ctx;

// 行変換実行(分岐なし)
void operator()(void* dst, const void* src, int pixelCount) const {
void operator()(void* dst, const void* src, size_t pixelCount) const {
func(dst, src, pixelCount, &ctx);
}

Expand Down
8 changes: 4 additions & 4 deletions fleximg/src/fleximg/image/pixel_format/alpha8.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace FLEXIMG_NAMESPACE {
// ========================================================================

// Alpha8 → RGBA8_Straight(可視化のため全チャンネルにアルファ値を展開)
static void alpha8_toStraight(void* dst, const void* src, int pixelCount, const PixelAuxInfo*) {
static void alpha8_toStraight(void* dst, const void* src, size_t pixelCount, const PixelAuxInfo*) {
FLEXIMG_FMT_METRICS(Alpha8, ToStraight, pixelCount);
const uint8_t* s = static_cast<const uint8_t*>(src);
uint8_t* d = static_cast<uint8_t*>(dst);
for (int i = 0; i < pixelCount; ++i) {
for (size_t i = 0; i < pixelCount; ++i) {
uint8_t alpha = s[i];
d[i*4 + 0] = alpha; // R
d[i*4 + 1] = alpha; // G
Expand All @@ -48,11 +48,11 @@ static void alpha8_toStraight(void* dst, const void* src, int pixelCount, const
}

// RGBA8_Straight → Alpha8(Aチャンネルのみ抽出)
static void alpha8_fromStraight(void* dst, const void* src, int pixelCount, const PixelAuxInfo*) {
static void alpha8_fromStraight(void* dst, const void* src, size_t pixelCount, const PixelAuxInfo*) {
FLEXIMG_FMT_METRICS(Alpha8, FromStraight, pixelCount);
const uint8_t* s = static_cast<const uint8_t*>(src);
uint8_t* d = static_cast<uint8_t*>(dst);
for (int i = 0; i < pixelCount; ++i) {
for (size_t i = 0; i < pixelCount; ++i) {
d[i] = s[i*4 + 3]; // Aチャンネル抽出
}
}
Expand Down
70 changes: 35 additions & 35 deletions fleximg/src/fleximg/image/pixel_format/dda.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ template<size_t BytesPerPixel>
void copyRowDDA_ConstY(
uint8_t* __restrict__ dstRow,
const uint8_t* __restrict__ srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
int_fixed srcX = param->srcX;
Expand Down Expand Up @@ -92,15 +92,15 @@ void copyRowDDA_ConstY(
using T = typename PixelType<BytesPerPixel>::type;
auto src = reinterpret_cast<const T*>(srcRowBase);
auto dst = reinterpret_cast<T*>(dstRow);
int remainder = count & 3;
for (int i = 0; i < remainder; i++) {
int_fast16_t remainder = count & 3;
for (int_fast16_t i = 0; i < remainder; i++) {
// BytesPerPixel 1, 2, 4: ネイティブ型でロード・ストア分離
auto p0 = src[srcX >> INT_FIXED_SHIFT]; srcX += incrX;
dst[0] = p0;
dst += 1;
}
int count4 = count >> 2;
for (int i = 0; i < count4; i++) {
int_fast16_t count4 = count >> 2;
for (int_fast16_t i = 0; i < count4; i++) {
// BytesPerPixel 1, 2, 4: ネイティブ型でロード・ストア分離
auto p0 = src[srcX >> INT_FIXED_SHIFT]; srcX += incrX;
auto p1 = src[srcX >> INT_FIXED_SHIFT]; srcX += incrX;
Expand All @@ -122,7 +122,7 @@ template<size_t BytesPerPixel>
void copyRowDDA_ConstX(
uint8_t* __restrict__ dstRow,
const uint8_t* __restrict__ srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
int_fixed srcY = param->srcY;
Expand All @@ -145,7 +145,7 @@ void copyRowDDA_ConstX(
} else {
using T = typename PixelType<BytesPerPixel>::type;
auto dst = reinterpret_cast<T*>(dstRow);
int remain = count & 3;
int_fast16_t remain = count & 3;
while (remain--) {
sy = srcY >> INT_FIXED_SHIFT;
auto p = *reinterpret_cast<const T*>(srcColBase + static_cast<size_t>(sy * srcStride));
Expand Down Expand Up @@ -185,7 +185,7 @@ template<size_t BytesPerPixel>
void copyRowDDA_Impl(
uint8_t* __restrict__ dstRow,
const uint8_t* __restrict__ srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
int_fixed srcY = param->srcY;
Expand Down Expand Up @@ -248,7 +248,7 @@ template<size_t BytesPerPixel>
void copyRowDDA_Byte(
uint8_t* dst,
const uint8_t* srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
const int_fixed srcY = param->srcY;
Expand All @@ -273,22 +273,22 @@ void copyRowDDA_Byte(
}

// 明示的インスタンス化(各フォーマットから参照される)
template void copyRowDDA_Byte<1>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyRowDDA_Byte<2>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyRowDDA_Byte<3>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyRowDDA_Byte<4>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyRowDDA_Byte<1>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);
template void copyRowDDA_Byte<2>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);
template void copyRowDDA_Byte<3>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);
template void copyRowDDA_Byte<4>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);

// BytesPerPixel別の関数ポインタ取得用ラッパー(非テンプレート)
inline void copyRowDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyRowDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyRowDDA_Byte<1>(dst, srcData, count, param);
}
inline void copyRowDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyRowDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyRowDDA_Byte<2>(dst, srcData, count, param);
}
inline void copyRowDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyRowDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyRowDDA_Byte<3>(dst, srcData, count, param);
}
inline void copyRowDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyRowDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyRowDDA_Byte<4>(dst, srcData, count, param);
}

Expand Down Expand Up @@ -341,7 +341,7 @@ template<size_t BytesPerPixel>
void copyQuadDDA_Byte(
uint8_t* __restrict__ dst,
const uint8_t* __restrict__ srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
constexpr size_t BPP = BytesPerPixel;
Expand All @@ -358,7 +358,7 @@ void copyQuadDDA_Byte(
uint8_t* edgeFlags = param->edgeFlags;

// 全ピクセル境界チェック版(事前範囲チェックなし)
for (int i = 0; i < count; ++i) {
for (int_fast16_t i = 0; i < count; ++i) {
int32_t sx = srcX >> INT_FIXED_SHIFT;
int32_t sy = srcY >> INT_FIXED_SHIFT;
weightsXY[i].fx = static_cast<uint8_t>(static_cast<uint32_t>(srcX) >> (INT_FIXED_SHIFT - 8));
Expand Down Expand Up @@ -450,22 +450,22 @@ void copyQuadDDA_Byte(
}
}
// 明示的インスタンス化
template void copyQuadDDA_Byte<1>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyQuadDDA_Byte<2>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyQuadDDA_Byte<3>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyQuadDDA_Byte<4>(uint8_t*, const uint8_t*, int, const DDAParam*);
template void copyQuadDDA_Byte<1>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);
template void copyQuadDDA_Byte<2>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);
template void copyQuadDDA_Byte<3>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);
template void copyQuadDDA_Byte<4>(uint8_t*, const uint8_t*, int_fast16_t, const DDAParam*);

// BytesPerPixel別の関数ポインタ取得用ラッパー(非テンプレート)
inline void copyQuadDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyQuadDDA_1Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyQuadDDA_Byte<1>(dst, srcData, count, param);
}
inline void copyQuadDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyQuadDDA_2Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyQuadDDA_Byte<2>(dst, srcData, count, param);
}
inline void copyQuadDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyQuadDDA_3Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyQuadDDA_Byte<3>(dst, srcData, count, param);
}
inline void copyQuadDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int count, const DDAParam* param) {
inline void copyQuadDDA_4Byte(uint8_t* dst, const uint8_t* srcData, int_fast16_t count, const DDAParam* param) {
copyQuadDDA_Byte<4>(dst, srcData, count, param);
}

Expand All @@ -486,7 +486,7 @@ template<int BitsPerPixel, BitOrder Order>
void copyRowDDA_Bit_ConstY(
uint8_t* __restrict__ dst,
const uint8_t* __restrict__ srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
constexpr int PixelsPerByte = 8 / BitsPerPixel;
Expand All @@ -510,16 +510,16 @@ void copyRowDDA_Bit_ConstY(
uint8_t pixelOffset = static_cast<uint8_t>(minSx % PixelsPerByte);
const uint8_t* srcByte = srcRow + (minSx / PixelsPerByte);
bit_packed_detail::unpackIndexBits<BitsPerPixel, Order>(
stackBuf, srcByte, static_cast<int>(unpackCount), pixelOffset);
stackBuf, srcByte, static_cast<size_t>(unpackCount), pixelOffset);

// DDAサンプリング(unpack済みバイト配列から読み取り)
for (int i = 0; i < count; ++i) {
for (int_fast16_t i = 0; i < count; ++i) {
dst[i] = stackBuf[(srcX >> INT_FIXED_SHIFT) - minSx];
srcX += incrX;
}
} else {
// バッファに収まらない場合: per-pixel fallback
for (int i = 0; i < count; ++i) {
for (int_fast16_t i = 0; i < count; ++i) {
dst[i] = bit_packed_detail::readPixelDirect<BitsPerPixel, Order>(
srcData, srcX >> INT_FIXED_SHIFT, sy, param->srcStride);
srcX += incrX;
Expand All @@ -532,7 +532,7 @@ template<int BitsPerPixel, BitOrder Order>
inline void copyRowDDA_Bit(
uint8_t* dst,
const uint8_t* srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
const int_fixed srcY = param->srcY;
Expand All @@ -551,7 +551,7 @@ inline void copyRowDDA_Bit(
const int_fixed incrX = param->incrX;
const int32_t srcStride = param->srcStride;

for (int i = 0; i < count; ++i) {
for (int_fast16_t i = 0; i < count; ++i) {
int32_t sx = srcX >> INT_FIXED_SHIFT;
int32_t sy = srcY_var >> INT_FIXED_SHIFT;
srcX += incrX;
Expand All @@ -575,7 +575,7 @@ template<int BitsPerPixel, BitOrder Order>
inline void copyQuadDDA_Bit(
uint8_t* dst,
const uint8_t* srcData,
int count,
int_fast16_t count,
const DDAParam* param
) {
// LovyanGFXスタイル: 2x2グリッドを直接読み取り
Expand All @@ -589,7 +589,7 @@ inline void copyQuadDDA_Bit(
BilinearWeightXY* weightsXY = param->weightsXY;
uint8_t* edgeFlags = param->edgeFlags;

for (int i = 0; i < count; ++i) {
for (int_fast16_t i = 0; i < count; ++i) {
int32_t sx = srcX >> INT_FIXED_SHIFT;
int32_t sy = srcY >> INT_FIXED_SHIFT;

Expand Down
Loading
Loading