「Bitmap」の編集履歴(バックアップ)一覧に戻る

Bitmap - (2006/01/14 (土) 00:35:38) のソース

注意:このデータはpng対応前のものです。次の更新で上書きされる可能性があります。
*Bitmap
ビットマップのクラス。ビットマップは、いわゆる画像そのものを表わします。
画面にビットマップを表示するためにはスプライト[[Sprite]]などを使う必要があります。
(RGGSヘルプより)

**変数
private: unsigned short  width
private: unsigned short  height
サイズ。

private: bool disposed
すでに解放されてるかどうか。

private: unsigned int* bmpixels
カラーコードの配列。カラーコードは0xFFBBGGRRです。

public : unsigned int transparency
透過色。

**関数
Bitmap(unsigned short w = 0, unsigned short h = 0)
指定したサイズのBitmapを生成します。

Bitmap(const char* path)
pathにある画像ファイルを読み込み、Bitmapを生成します。

void dispose()
Bitmapを解放します。

bool isDisposed()
ビットマップがすでに解放されている場合に真を返します。

unsigned short getWidth()
ビットマップの幅を取得します。

unsigned short getHeight()
ビットマップの高さを取得します。

void get_rect(Rect* rec)
ビットマップの矩形([[Rect]])を取得します。

bool blt(unsigned short x, unsigned short y, Bitmap* src_bitmap, Rect* src_rect, float opacity = 255) 
src_bitmap の矩形 src_rect ([[Rect]]) から、このビットマップの座標 (x, y) にブロック転送を行います。
opacity には不透明度を 0 ~ 255 の範囲で指定できます。

bool clear(unsigned int ccolor = transparency)
ビットマップ全体をccolorでクリアします。

unsigned int get_pixel(unsigned short x, unsigned short y)
点 (x, y) の色(PSP用カラーコード)を取得します。

bool set_pixel(unsigned short x, unsigned short y, unsigned int pix)
点 (x, y) の色を pix(PSP用カラーコード)に設定します。

**定義
> //==============================================================================
> // ■ Bitmap
> //------------------------------------------------------------------------------
> // ビットマップのクラス。ビットマップは、いわゆる画像そのものを表わします。
> // 画面にビットマップを表示するためにはスプライト (Sprite) などを使う必要があります。(RGGSヘルプより)
> //==============================================================================
> 
> #ifndef RPG2K_Bitmap
> #define RPG2K_Bitmap
> 
> #include "Color.h"
> #include "Rect.h"
> 
> class Bitmap{
>   unsigned short  width;
>   unsigned short  height;
>   bool disposed;
>   unsigned int* bmpixels;
> public:
>   unsigned int transparency;
>   // コンストラクタ
>   Bitmap(unsigned short w = 0, unsigned short h = 0){
>     bmpixels = (unsigned int*)calloc(w*h, sizeof(unsigned int));
>     width = w;
>     height = h;
>     disposed = false;
>     transparency = 0;
>   }
>   Bitmap(const char* path){
>     disposed = false;
>     fileopen(path);
>   }
>   // デストラクタ
>   ~Bitmap(){
>     dispose();
>   }
>   unsigned short getWidth(){ return width;}
>   unsigned short getHeight(){ return height;}
>   
>   //解放
>   void dispose(){
>     if(!disposed){
>       free(bmpixels);
>       disposed = true;
>       width = 0;
>       height = 0;
>     }
>   }
>   bool isDisposed(){ return disposed;}
>   
>   // ファイルから開く 注:開発中のため独自形式のみ対応
>   bool fileopen(const char* path){
>     if(disposed) return false;
>     unsigned short w;
>     pspBasicStream file;
>     // ファイルオープン
>     if(!file.fileopen(path, false)) return false;
>     // 画像幅取得 (独自形式の先頭2バイト)
>     file.read(&w, 2);
>     width  = (unsigned short)w;
>     // 画像高さ取得 (ファイルサイズ-2 /幅)
>     height = (file.getLength()-2)/width;
>     // ビットマップを開放
>     free(bmpixels);
>     // 画像読み込み
>     bmpixels = (unsigned int*)calloc(width*height, sizeof(unsigned int));
>     unsigned short x,y;
>     for (y = 0; y < height; ++y){
>       // ファイルから1ライン読み込み
>       unsigned int* line = &bmpixels[y * width];
>       file.read(line, width*4);
>       for (x = 0; x < width; ++x)
>       {
>         line[x] = 0xFF000000 + RGBcode(line[x]);
>       }
>     }
>     file.close();
>     return true;
>   }
>   // ビットマップをクリア
>   bool clear(unsigned int ccolor = 0){
>     if(disposed) return false;
>     unsigned short x,y;
>     for (y = 0; y < height; ++y){
>       unsigned int* line = &bmpixels[y * width];
>       for (x = 0; x < width; ++x)
>       {
>         if(ccolor==0) line[x] = transparency;
>         else line[x] = ccolor;
>       }
>     }
>     return true;
>   }
>   // ピクセル取得/設定
>   unsigned int get_pixel(unsigned short x, unsigned short y){
>     if(x > width || y > height || disposed) return false;
>     return bmpixels[y*width+x];
>   }
>   bool set_pixel(unsigned short x, unsigned short y, unsigned int pix){
>     if(x > width || y > height || disposed) return false;
>     bmpixels[y*width+x] = pix;
>     return true;
>   }
>   void get_rect(Rect* rec){
>     (*rec).width  = width;
>     (*rec).height = height;
>   }
>   
>   // src_bitmap の矩形 src_rect (Rect) から、このビットマップの座標 (x, y) にブロック転送
>   bool blt(unsigned short x, unsigned short y, Bitmap* src_bitmap, Rect* src_rect, float opacity = 255){
>     if(x > width || y > height || disposed) return false;
>     unsigned short a,b;
>     for (a = 0; a < (*src_rect).height; ++a)
>     {
>       if(a >= height) break;
>       unsigned int* line = &bmpixels[(y + a) * width];
>       for (b = 0; b < (*src_rect).width; ++b)
>       {
>         if(b >= width) break;
>         if(opacity == 0 || (*src_bitmap).get_pixel((*src_rect).x + b, (*src_rect).y + a) == (*src_bitmap).transparency) break;
>         if(opacity == 255){
>           line[b+x] = (*src_bitmap).get_pixel((*src_rect).x + b, (*src_rect).y + a);
>         }else{
>           Color C1,C2;
>           C1.setBGRcode(line[b+x]);
>           C2.setBGRcode((*src_bitmap).get_pixel((*src_rect).x + b, (*src_rect).y + a));
>           C2.opacity = opacity;
>           C1.conposit(&C2);
>           line[b+x] = C1.getPSPBGRcode();
>         }
>       }
>     }
>     return true;
>   }
>   // X方向に反転
>   //Bitmap* reversalX(){
>   //  
>   //}
> };
> #endif
記事メニュー
人気記事ランキング
目安箱バナー