Imagine++
Public Member Functions | Friends | List of all members
Imagine::NativeBitmap Class Reference

Native bitmap: image stored in graphics card format, fast to display. More...

#include "Imagine/Graphics.h"

Public Member Functions

 NativeBitmap ()
 Empty constructor.
 
 NativeBitmap (int w, int h)
 Constructor with dimensions. More...
 
 NativeBitmap (const NativeBitmap &I)
 Copy constructor.
 
 ~NativeBitmap ()
 Destructor.
 
const NativeBitmapoperator= (const NativeBitmap &I)
 Assignment.
 
void setColorImage (int x, int y, const byte *r, const byte *g, const byte *b, int w, int h)
 Set color image. More...
 
void setColorImage (const IntPoint2 &p, const byte *r, const byte *g, const byte *b, int w, int h)
 Set color image. More...
 
void setColorImage (int x, int y, const Color *cols, int w, int h)
 Set color image. More...
 
void setColorImage (const IntPoint2 &p, const Color *cols, int w, int h)
 Set color image. More...
 
void setColorImage (int x, int y, const byte *rgb, int w, int h)
 Set color image. More...
 
void setColorImage (const IntPoint2 &p, const byte *rgb, int w, int h)
 Set color image. More...
 
void setGreyImage (int x, int y, const byte *g, int w, int h)
 Set grey image. More...
 
void setGreyImage (const IntPoint2 &p, const byte *g, int w, int h)
 Set grey image. More...
 
void setPoint (int x, int y, Color col)
 Set point. More...
 
void setPoint (const IntPoint2 &p, Color col)
 Set point. More...
 

Friends

void putNativeBitmap (int x, int y, const NativeBitmap &bm, bool xorMode, double fact)
 Display native bitmap. More...
 
void putNativeBitmap (const IntPoint2 &p, const NativeBitmap &bm, bool xorMode=false, double fact=1.)
 Display native bitmap. More...
 

Detailed Description

Use it if you want to display the image many times (for example in an animation).

Examples:
Graphics/test/example.cpp, and Graphics/test/test.cpp.

Constructor & Destructor Documentation

◆ NativeBitmap()

Imagine::NativeBitmap::NativeBitmap ( int  w,
int  h 
)

Contructs a native bitmap of dimensions (w,h)

Parameters
w,hdimensions
NativeBitmap bm(sz,sz); // with dimensions

Member Function Documentation

◆ setColorImage() [1/6]

void Imagine::NativeBitmap::setColorImage ( int  x,
int  y,
const byte *  r,
const byte *  g,
const byte *  b,
int  w,
int  h 
)

Fills part of a native bitmap with a bitmap.

Parameters
x,ytop left position in native bitmap
r,g,bsource to be copied into native bitmap
w,hdimensions
byte r2[sz*sz],g2[sz*sz],b2[sz*sz]; // Set color image (3 arrays)
for (int y=0;y<sz;y++) {
for (int x=0;x<sz;x++) {
r2[x+sz*y]=x;
g2[x+sz*y]=y;
b2[x+sz*y]=(x+y);
}
}
bm.setColorImage(0,0,r2,g2,b2,sz,sz); // twice the same (just to check both variants)
bm.setColorImage(IntPoint2(0,0),r2,g2,b2,sz,sz); // ...

Examples:
Graphics/test/example.cpp, and Graphics/test/test.cpp.

◆ setColorImage() [2/6]

void Imagine::NativeBitmap::setColorImage ( const IntPoint2 p,
const byte *  r,
const byte *  g,
const byte *  b,
int  w,
int  h 
)
inline

Fills part of a native bitmap with a bitmap.

Parameters
ptop left position in native bitmap
r,g,bsource to be copied into native bitmap
w,hdimensions
byte r2[sz*sz],g2[sz*sz],b2[sz*sz]; // Set color image (3 arrays)
for (int y=0;y<sz;y++) {
for (int x=0;x<sz;x++) {
r2[x+sz*y]=x;
g2[x+sz*y]=y;
b2[x+sz*y]=(x+y);
}
}
bm.setColorImage(0,0,r2,g2,b2,sz,sz); // twice the same (just to check both variants)
bm.setColorImage(IntPoint2(0,0),r2,g2,b2,sz,sz); // ...

◆ setColorImage() [3/6]

void Imagine::NativeBitmap::setColorImage ( int  x,
int  y,
const Color cols,
int  w,
int  h 
)

Fills part of a native bitmap with a bitmap.

Parameters
x,ytop left position in native bitmap
colssource to be copied into native bitmap
w,hdimensions
Color cols2[64*64]; // Set color image (Color array)
for (int y=0;y<64;y++)
for (int x=0;x<64;x++)
cols2[x+64*y]=Color((x+y)%256,0,0);
bm.setColorImage(32,32,cols2,64,64); // twice the same (just to check both variants)
bm.setColorImage(IntPoint2(32,32),cols2,64,64); // ...

◆ setColorImage() [4/6]

void Imagine::NativeBitmap::setColorImage ( const IntPoint2 p,
const Color cols,
int  w,
int  h 
)
inline

Fills part of a native bitmap with a bitmap.

Parameters
ptop left position in native bitmap
colssource to be copied into native bitmap
w,hdimensions
Color cols2[64*64]; // Set color image (Color array)
for (int y=0;y<64;y++)
for (int x=0;x<64;x++)
cols2[x+64*y]=Color((x+y)%256,0,0);
bm.setColorImage(32,32,cols2,64,64); // twice the same (just to check both variants)
bm.setColorImage(IntPoint2(32,32),cols2,64,64); // ...

◆ setColorImage() [5/6]

void Imagine::NativeBitmap::setColorImage ( int  x,
int  y,
const byte *  rgb,
int  w,
int  h 
)
inline

Fills part of a native bitmap with a bitmap.

Parameters
x,ytop left position in native bitmap
rgbsource to be copied into native bitmap
w,hdimensions
byte rgb2[3*64*64]; // Set color image (1 array)
for (int y=0;y<64;y++)
for (int x=0;x<64;x++) {
rgb2[3*(x+64*y)]=x;
rgb2[3*(x+64*y)+1]=y;
rgb2[3*(x+64*y)+2]=x+y;
}
bm.setColorImage(64,0,rgb2,64,64); // twice the same (just to check both variants)
bm.setColorImage(IntPoint2(64,0),rgb2,64,64); // ...

◆ setColorImage() [6/6]

void Imagine::NativeBitmap::setColorImage ( const IntPoint2 p,
const byte *  rgb,
int  w,
int  h 
)
inline

Fills part of a native bitmap with a bitmap.

Parameters
ptop left position in native bitmap
rgbsource to be copied into native bitmap
w,hdimensions
byte rgb2[3*64*64]; // Set color image (1 array)
for (int y=0;y<64;y++)
for (int x=0;x<64;x++) {
rgb2[3*(x+64*y)]=x;
rgb2[3*(x+64*y)+1]=y;
rgb2[3*(x+64*y)+2]=x+y;
}
bm.setColorImage(64,0,rgb2,64,64); // twice the same (just to check both variants)
bm.setColorImage(IntPoint2(64,0),rgb2,64,64); // ...

◆ setGreyImage() [1/2]

void Imagine::NativeBitmap::setGreyImage ( int  x,
int  y,
const byte *  g,
int  w,
int  h 
)

Fills part of a native bitmap with a grey bitmap.

Parameters
x,ytop left position in native bitmap
gsource to be copied into native bitmap
w,hdimensions
byte grey2[64*64]; // Set grey image
for (int y=0;y<64;y++)
for (int x=0;x<64;x++)
grey2[(x+64*y)]=x+2*y;
bm.setGreyImage(0,64,grey2,64,64); // twice the same (just to check both variants)
bm.setGreyImage(IntPoint2(0,64),grey2,64,64); // ...

Examples:
Graphics/test/test.cpp.

◆ setGreyImage() [2/2]

void Imagine::NativeBitmap::setGreyImage ( const IntPoint2 p,
const byte *  g,
int  w,
int  h 
)
inline

Fills part of a native bitmap with a grey bitmap.

Parameters
ptop left position in native bitmap
gsource to be copied into native bitmap
w,hdimensions
byte grey2[64*64]; // Set grey image
for (int y=0;y<64;y++)
for (int x=0;x<64;x++)
grey2[(x+64*y)]=x+2*y;
bm.setGreyImage(0,64,grey2,64,64); // twice the same (just to check both variants)
bm.setGreyImage(IntPoint2(0,64),grey2,64,64); // ...

◆ setPoint() [1/2]

void Imagine::NativeBitmap::setPoint ( int  x,
int  y,
Color  col 
)

Set color of one point in a native bitmap.

Parameters
x,yposition
colColor to be copied into native bitmap
for (int x=0;x<sz;x++) { // Set point
bm.setPoint(x,x,RED); // twice the same (just to check both variants)
bm.setPoint(x,x,RED);
} // ...

Examples:
Graphics/test/example.cpp, and Graphics/test/test.cpp.

◆ setPoint() [2/2]

void Imagine::NativeBitmap::setPoint ( const IntPoint2 p,
Color  col 
)
inline

Set color of one point in a native bitmap.

Parameters
pposition
colColor to be copied into native bitmap
for (int x=0;x<sz;x++) { // Set point
bm.setPoint(x,x,RED); // twice the same (just to check both variants)
bm.setPoint(x,x,RED);
} // ...

Friends And Related Function Documentation

◆ putNativeBitmap [1/2]

void putNativeBitmap ( int  x,
int  y,
const NativeBitmap bm,
bool  xorMode,
double  fact 
)
friend

Displays native bitmap into active window

Parameters
x,ydrawing position (top left in window)
bmthe native bitmap to display
xorModeXOR drawing (default=off). Used twice, recovers the original content
factscaling factor (default=1.)
putNativeBitmap(0,0,bm); // Put native bitmap
putNativeBitmap(IntPoint2(300,0),bm,false,1.5);
putNativeBitmap(0,300,bm,false,0.75);
for (int i=0;i<1024;i+=8) {
putNativeBitmap(i,200,bm,true,0.5); // use XOR to display/undisplay
milliSleep(100);
putNativeBitmap(i,200,bm,true,0.5);
} // ...

◆ putNativeBitmap [2/2]

void putNativeBitmap ( const IntPoint2 p,
const NativeBitmap bm,
bool  xorMode = false,
double  fact = 1. 
)
friend

Displays native bitmap into active window

Parameters
pdrawing position (top left in window)
bmthe native bitmap to display
xorModeXOR drawing (default=off). Used twice, recovers the original content
factscaling factor (default=1.)
putNativeBitmap(0,0,bm); // Put native bitmap
putNativeBitmap(IntPoint2(300,0),bm,false,1.5);
putNativeBitmap(0,300,bm,false,0.75);
for (int i=0;i<1024;i+=8) {
putNativeBitmap(i,200,bm,true,0.5); // use XOR to display/undisplay
milliSleep(100);
putNativeBitmap(i,200,bm,true,0.5);
} // ...


The documentation for this class was generated from the following file: