--- nono/lib/bitmap.cpp 2026/04/29 17:05:26 1.1.1.5 +++ nono/lib/bitmap.cpp 2026/04/29 17:05:30 1.1.1.6 @@ -55,6 +55,45 @@ BitmapBase::Create(uint width_, uint hei } } +// コピーコンストラクタ +BitmapBase::BitmapBase(const BitmapBase& src) +{ + width = src.width; + height = src.height; + stride = src.stride; + depth = src.depth; + + owned_buf = src.owned_buf; + // src.buf は src.owned_buf かクラス外のどこか (か NULL) を指している。 + if (src.buf == src.owned_buf.get()) { + buf = owned_buf.get(); + } else { + buf = src.buf; + } +} + +// コピー代入演算子 +BitmapBase& +BitmapBase::operator=(const BitmapBase& src) +{ + owned_buf.Reset(); + + width = src.width; + height = src.height; + stride = src.stride; + depth = src.depth; + + owned_buf = src.owned_buf; + // src.buf は src.owned_buf かクラス外のどこか (か NULL) を指している。 + if (src.buf == src.owned_buf.get()) { + buf = owned_buf.get(); + } else { + buf = src.buf; + } + + return *this; +} + // 全域をコピーしてくる。 void BitmapBase::CopyFrom(const BitmapBase *src) @@ -102,6 +141,67 @@ BitmapI1::GetPtr(int x, int y) const return NULL; } +// 1ラスタを読み込む/書き出すマクロ。副作用もりもり。 +#define Load(bits, src) do { \ + bits = 0; \ + for (int x = 0; x < stride; x++) { \ + bits <<= 8; \ + bits |= *src++; \ + } \ +} while (0) +#define Store(bits, dst) do { \ + for (int x = stride - 1; x >= 0; x--) { \ + *dst++ = (bits >> (x * 8)) & 0xff; \ + } \ +} while (0) + +// このビットマップ(フォント)をボールドにした新しいビットマップを返す。 +BitmapI1 +BitmapI1::ConvertToBold() const +{ + assert(stride <= 8); + + BitmapI1 dst(width, height); + const uint8 *s = buf; + uint8 *d = dst.buf; + for (int y = 0; y < height; y++) { + uint64 bits; + Load(bits, s); + bits |= bits >> 1; + Store(bits, d); + } + return dst; +} + +// このビットマップ(フォント)をイタリックにした新しいビットマップを返す。 +BitmapI1 +BitmapI1::ConvertToItalic() const +{ + assert(stride <= 7); + + BitmapI1 dst(width, height); + int half = height / 2; + const uint8 *s = buf; + uint8 *d = dst.buf; + int y; + + // 上段は、右端が sticky な右シフト。 + for (y = 0; y <= half; y++) { + uint64 bits; + Load(bits, s); + bits = (bits >> 1) | (bits & 1); + Store(bits, d); + } + + // 下段は、シフトしないのでコピー。 + memcpy(d, s, stride * (height - y)); + + return dst; +} + +#undef Load +#undef Store + // // 8bpp ビットマップ