--- nono/lib/bitmap.cpp 2026/04/29 17:05:12 1.1.1.2 +++ nono/lib/bitmap.cpp 2026/04/29 17:05:15 1.1.1.3 @@ -31,8 +31,8 @@ BitmapBase::~BitmapBase() { } -// 作成 -void +// 作成。width_ * height_ が面積を持っていれば true を返す。 +bool BitmapBase::Create(int width_, int height_, int depth_) { assert(depth_ == 1 || depth_ == 8 || depth_ == 24); @@ -45,6 +45,8 @@ BitmapBase::Create(int width_, int heigh } else { stride = width * depth_ / 8; } + + return (width > 0 && height > 0); } @@ -79,10 +81,13 @@ BitmapI1::~BitmapI1() void BitmapI1::Create(int width_, int height_) { - inherited::Create(width_, height_, 1); - - owned_buf.reset(new uint8[stride * height]); - buf = owned_buf.get(); + if (inherited::Create(width_, height_, 1)) { + owned_buf.reset(new uint8[stride * height]); + buf = owned_buf.get(); + } else { + owned_buf.reset(); + buf = NULL; + } } // カラーコード cc で全体を塗りつぶす。 @@ -126,19 +131,24 @@ BitmapI8::~BitmapI8() void BitmapI8::Create(int width_, int height_) { - inherited::Create(width_, height_, 8); - - owned_buf.reset(new uint8[stride * height]); - buf = owned_buf.get(); + if (inherited::Create(width_, height_, 8)) { + owned_buf.reset(new uint8[stride * height]); + buf = owned_buf.get(); + } else { + owned_buf.reset(); + buf = NULL; + } } // 元データを指定して作成 void BitmapI8::Create(const void *buf_, int width_, int height_) { - inherited::Create(width_, height_, 8); - - buf = static_cast(const_cast(buf_)); + if (inherited::Create(width_, height_, 8)) { + buf = static_cast(const_cast(buf_)); + } else { + buf = NULL; + } } // カラーコード cc で全体を塗りつぶす。 @@ -183,10 +193,13 @@ BitmapRGB::~BitmapRGB() void BitmapRGB::Create(int width_, int height_) { - inherited::Create(width_, height_, 24); - - owned_buf.reset(new uint8[stride * height]); - buf = owned_buf.get(); + if (inherited::Create(width_, height_, 24)) { + owned_buf.reset(new uint8[stride * height]); + buf = owned_buf.get(); + } else { + owned_buf.reset(); + buf = NULL; + } } // 色 c で全体を塗りつぶす。