Bitmap Struct Reference


Public Methods

struct Bitmap* Bitmap_ctor (struct Bitmap *ptr_bitmap)
struct Bitmap* Bitmap_ctor_Ex1 (struct Bitmap *ptr_bitmap, char *filename)
struct Bitmap* Bitmap_ctor_Ex2 (struct Bitmap *ptr_bitmap, int width, int height, int bpp)
struct Bitmap* Bitmap_ctor_Ex3 (struct Bitmap *ptr_bitmap, struct Bitmap *templ)
void Bitmap_dtor (struct Bitmap *ptr_bitmap, int memory_flag)
void Bitmap_fill (struct Bitmap *ptr_bitmap, color_t color)
void Bitmap_clear (struct Bitmap *ptr_bitmap)
bool Bitmap_load (struct Bitmap *ptr_bitmap, struct Input *input)
bool Bitmap_store (struct Bitmap *ptr_bitmap, struct Output *output)
int Bitmap_get_w (struct Bitmap *ptr_bitmap)
int Bitmap_get_h (struct Bitmap *ptr_bitmap)

Public Attributes

int w
int h


Detailed Description

A structure for creating and working with simple bitmap object. Using this structure, you can create a bitmap object in one of four ways:

  1. Create an empty bitmap object the same way Bitmap_ctor does;
  2. Create a Bitmap object using a resource;
  3. Create an empty bitmap with memory allocated for it;
  4. Create a Bitmap object that is an exact copy of an another bitmap.
Make sure to create every Bitmap object using one of the "constructor" functions, and to release each Bitmap object with the Bitmap_dtor function.

Use the Bitmap_fill function to fill a bitmap with the color marked by the second function parameter's pointer. The second parameter also specifies the type color, via the color_t type function. This function is defined in the header, and described in the "Typedefs" section. * a header and described in the "Typedefs" section. You can implement operations with streams using the Bitmap_load and Bitmap_storefunctions.

Please study the examples for these functions carefully.
See also:
Bitmaps and Bitmap Sequences


Member Function Documentation

void Bitmap_clear ( struct Bitmap * ptr_bitmap )
 

Fills whole bitmap by white color.

Parameters:
ptr_bitmap   A pointer to the initialized Bitmap object
Returns:
None
   #include <cybiko.h>
     ...
     struct Bitmap bitmap;
     ...
     Bitmap_fill( &bitmap, CLR_DKGRAY );
     ...
     // It is the same as Bitmap_fill( ptr_bitmap, CLR_WHITE );
     Bitmap_clear( &bitmap );
     ...
     Bitmap_dtor( &bitmap, LEAVE_MEMORY );
See also:
Bitmap_fill.

struct Bitmap * Bitmap_ctor ( struct Bitmap * ptr_bitmap )
 

The simple Bitmap constructor.
Creates an empty bitmap. First you must create a Bitmap object and transfer the pointer on it into this function.

Parameters:
ptr_bitmap   A pointer to the Bitmap structure
Returns:
A pointer to an initialized Bitmap object
   #include <cybiko.h>
     ...
     struct Bitmap bitmap;
     Bitmap_ctor( &bitmap );
     ...
     Bitmap_dtor( &bitmap, LEAVE_MEMORY );

struct Bitmap * Bitmap_ctor_Ex1 ( struct Bitmap * ptr_bitmap,
char * filename )
 

The first extended version of the Bitmap_ctor function.
It creates an empty bitmap from a resource file.

Parameters:
ptr_bitmap   A pointer to the Bitmap structure
filename   The name of a resource file
Returns:
A pointer to an initialized Bitmap object
   #include <cybiko.h>
     ...
     struct Bitmap bmp;
     // Creates a bitmap from the file "root.ico".
     Bitmap_ctor_Ex1( &bmp, "root.ico" );
     ...
     Bitmap_dtor( &bmp, LEAVE_MEMORY );
See also:
Bitmap_ctor

struct Bitmap * Bitmap_ctor_Ex2 ( struct Bitmap * ptr_bitmap,
int width,
int height,
int bpp )
 

The second extended version of the Bitmap_ctor function.
It creates an empty bitmap and allocates memory for it.

Parameters:
ptr_bitmap   A pointer to the Bitmap structure
width   The width of the bitmap object
height   The height of the bitmap object
bpp   The number of bits per pixel that you need to allocate - 2 bits for a four color display, and 1 bit for a monochrome display
Returns:
A pointer to an initialized Bitmap object
   #include <cybiko.h>
     ...
     struct Bitmap bmp;
     // SCREEN_WIDTH and SCREEN_HEIGHT are described in the 'Defines' section.
     Bitmap_ctor_Ex2( &bmp, SCREEN_WIDTH, SCREEN_HEIGHT, 2 );
     ...
     Bitmap_dtor( &bmp, LEAVE_MEMORY );
See also:
Bitmap_ctor

struct Bitmap * Bitmap_ctor_Ex3 ( struct Bitmap * ptr_bitmap,
struct Bitmap * templ )
 

The third extended version of the Bitmap_ctor function.
Builds the exact copy of another bitmap.

Parameters:
ptr_bitmap   A pointer to destination Bitmap object
templ   A pointer to template Bitmap object
Returns:
A pointer to initialized Bitmap object
   #include <cybiko.h>
     ...
     struct Bitmap  bitmap_templ;
     struct Bitmap  bitmap;
     Bitmap_ctor_Ex1( &bitmap_templ, "bmp.pic" );
     ...
     // Working with the 'ptr_bitmap_templ' bitmap.
     ...
     Bitmap_ctor_Ex3( &bitmap, &bitmap_templ );
     ...
     Bitmap_dtor( &bitmap, LEAVE_MEMORY );
     Bitmap_dtor( &bitmap_templ, LEAVE_MEMORY );
See also:
Bitmap_ctor

void Bitmap_dtor ( struct Bitmap * ptr_bitmap,
int memory_flag )
 

Destructor.
This function deletes a Bitmap object.

Parameters:
ptr_bitmap   A pointer to the initialized Bitmap object
memory_flag   Can be FREE_MEMORY or LEAVE_MEMORY. If memory_flag is FREE_MEMORY when destructor frees memory, allocated for the object. FREE_MEMORY used if memory was allocated by malloc(). If object was static or allocated in stack use LEAVE_MEMORY
Returns:
None
   #include <cybiko.h>
     ...
     struct Bitmap bitmap;
     // SCREEN_WIDTH and SCREEN_HEIGHT are defined in the "cyber-graph.h" file.
     Bitmap_ctor_Ex2( &bitmap, SCREEN_WIDTH, SCREEN_HEIGHT, 2 );
     ...
     Bitmap_dtor( &bitmap, LEAVE_MEMORY );
See also:
FREE_MEMORY, LEAVE_MEMORY.

void Bitmap_fill ( struct Bitmap * ptr_bitmap,
color_t color )
 

Fills whole bitmap by a color pointed on the color_t value.
The color_t type is described in the 'Typedefs' section.

Parameters:
ptr_bitmap   A pointer to the initialized Bitmap object
color   The color_t value. This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK
Returns:
None
   #include <cybiko.h>
     ...
     struct Bitmap bitmap;
     ...
     Bitmap_fill( &bitmap, CLR_BLACK );
     ...
     Bitmap_dtor( &bitmap, LEAVE_MEMORY );
See also:
Bitmap_clear, CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, CLR_BLACK.

int Bitmap_get_h ( struct Bitmap * ptr_bitmap )
 

Returns physical height of the Bitmap (in pixels).

Parameters:
ptr_bitmap   A pointer to the BitmapSequence structure
Returns:
A physical height of the Bitmap (in pixels)
   #include <cybiko.h>
     ...
     struct Bitmap gfx_bmp;
     int height_gfx, width_gfx;
     ...
     // Returns physical height of the Bitmap object
     height_gfx = Bitmap_get_h( &gfx_bmp );
     // Returns physical width of the Bitmap object
     width_gfx = Bitmap_get_w( &gfx_bmp );
     ...
See also:
Bitmap_get_w.

int Bitmap_get_w ( struct Bitmap * ptr_bitmap )
 

Returns physical width of the Bitmap (in pixels).

Parameters:
ptr_bitmap   A pointer to the BitmapSequence structure
Returns:
A physical width of the Bitmap (in pixels)
   #include <cybiko.h>
     ...
     struct Bitmap gfx_bmp;
     int height_gfx, width_gfx;
     ...
     // Returns physical height of the Bitmap object
     height_gfx = Bitmap_get_h( &gfx_bmp );
     // Returns physical width of the Bitmap object
     width_gfx = Bitmap_get_w( &gfx_bmp );
     ...
See also:
Bitmap_get_h.

bool Bitmap_load ( struct Bitmap * ptr_bitmap,
struct Input * input )
 

Loads bitmap from an opened stream.

Parameters:
ptr_bitmap   A pointer to the initialized Bitmap object
input   A pointer to Input stream
Returns:
TRUE if a bitmap object was loaded successfully
   #include <cybiko.h>
     ...
     struct Input * ptr_input;
     struct Bitmap  bmp;
     ...
     Bitmap_ctor(&bmp);
     ...
     // Your make file must have the archive resource "bmp.pic" linked by filer.exe.
     // For example, see the Cybiko Compiler's Introduction Section
     ptr_input = open_resource_Ex( "bmp.pic" );
     if( !Bitmap_load( &bmp, ptr_input ) )
         return FALSE;
     else
     ...
     Bitmap_dtor( &bmp, LEAVE_MEMORY );
     Input_dtor( ptr_input, LEAVE_MEMORY );
See also:
Bitmap_store.

bool Bitmap_store ( struct Bitmap * ptr_bitmap,
struct Output * output )
 

Stores bitmap to an opened stream.

Parameters:
ptr_bitmap   A pointer to the initialized Bitmap object
output   A pointer to Output stream
Returns:
TRUE if a bitmap object was stored successfully
   #include <cybiko.h>
     ...
     struct Output * ptr_output;
     bool   fBmp_store;
     struct Bitmap bmp;
     struct module_t main_module;
     ...
     init_module( &main_module ); // Application module initialization
     ...
     Bitmap_ctor_Ex2( &bmp, SCREEN_WIDTH, SCREEN_HEIGHT, 2 );
     ...
     // Your make file must have the archive resource "bmp.pic" linked by filer.exe.
     // For example, see the Cybiko Compiler's Introduction Section.
     ptr_output = Archive_open_write_Ex( main_module.m_process->module->archive, "bmp.pic" );
     fBmp_store = Bitmap_store( &bmp, ptr_output );
     ...
     Bitmap_dtor( &bmp, LEAVE_MEMORY );
     Output_dtor( ptr_output, FREE_MEMORY );
See also:
Bitmap_load.


Member Data Documentation

int h
 

Establishes a physical bitmap height (in pixels).

int w
 

Establishes a physical bitmap width (in pixels).