Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Bitmap Class Reference

#include <Bitmap.h>

List of all members.

Public Types

typedef Bitmap::BitmapColour_s BitmapColour
enum  Margin {
  Left = 0, Right = 1, Top = 2, Bottom = 3,
  All
}

Public Member Functions

 Bitmap (const int width, const int height, const int bpp=1, bool expandable=true, const int maxwidth=-1, const int maxheight=-1) throw (BitmapError)
 Create a new bitmap with the given parameters.
 ~Bitmap ()
void paint (const int x, const int y, const int w, const int h, const Byte *b) throw (BitmapError)
 Paint a bitmap onto the master bitmap.
void rule (const int x, const int y, const int w, const int h) throw (BitmapError)
 Draws on the master bitmap a block (a `rule' in TeX terms) of height h and width w pixels.
void strut (const int x, const int y, const int l, const int r, const int t, const int b) throw (BitmapError)
 Draws a `strut' on the master bitmap.
void write (const string filename, const string format) throw (BitmapError)
 Writes the bitmap out to the specified file.
void freeze ()
 Freeze the bitmap and bounding box.
void crop ()
 Crops the bitmap.
void crop (Margin spec, int pixels, bool absolute=false) throw (BitmapError)
 Specifies a crop.
void blur ()
 Makes a very simple-minded attempt to antialias the bitmap by blurring it.
void clear ()
 Resets the bitmap to its initial state.
void setTransparent (const bool sw)
 Sets the current bitmap to be transparent, if possible.
void setRGB (const bool fg, const BitmapColour *)
 Sets the foreground or background colour.
void scaleDown (const int factor) throw (BitmapError)
 Scales down the bitmap by a numerical factor.
bool empty () const
 Is the bitmap empty? If nothing has (yet) been written to the bitmap, or if everything that was written was out of bounds, then the bitmap is empty.
bool overlaps () const
 Does the bitmap overlap its canvas? This can only be true before a (implicit or explicit) call to freeze, since that normalizes the bounding box variables.
int * boundingBox ()
 Obtain a bounding box for the current bitmap.
int getWidth () const
 Returns the total width of the bitmap.
int getHeight () const
 Returns the total height of the bitmap.
void mark (const double x, const double y)
 Marks a particular spot in the bitmap.
BitmapMarkgetMark ()
 Obtains the mark for this bitmap.
const_iterator begin ()
 Returns the beginning of a sequence of bitmap rows.
const_iterator end () const
 Returns the end of a sequence of bitmap rows.

Static Public Member Functions

void cropDefault (Margin spec, int pixels, bool absolute=false) throw (BitmapError)
 Specifies a default crop.
void setDefaultRGB (const bool fg, const BitmapColour *)
 Sets the default foreground or background colours.
verbosities verbosity (const verbosities level)
 Sets the verbosity of the current class.
void logBitmapInfo (const char *prefix)
 Sets whether bitmap information is logged.

Public Attributes

const_iterator runningIterator_

Static Public Attributes

const_iterator endIterator_


Member Typedef Documentation

typedef struct Bitmap::BitmapColour_s Bitmap::BitmapColour
 


Member Enumeration Documentation

enum Bitmap::Margin
 

Enumeration values:
Left 
Right 
Top 
Bottom 
All 


Constructor & Destructor Documentation

Bitmap::Bitmap const int  w,
const int  h,
const int  bpp = 1,
bool  expandable = true,
const int  maxwidth = -1,
const int  maxheight = -1
throw (BitmapError)
 

Create a new bitmap with the given parameters.

Coordinates on the bitmap run from 0 to W-1, and 0 to H-1, with point (0,0) in the top-left corner, the x-axis increasing to the right, and the y-axis increasing downwards.

Parameters:
w the width of the bitmap, in pixels
h the height of the bitmap, in pixels
bpp the number of bits-per-pixel (default is 1)
expandable if true (the default), the bitmap is expandable; if false, the bitmap is fixed at the specified size
maxwidth if expandable is true, and maxwidth is greater than or equal to w, this is the maximum horizontal size the bitmap will expand to; if it is less than w (which includes negative, the default), the maximum width is set to a default multiplier of the width w
maxheight if expandable is true, and maxheight is greater than or equal to h, this is the maximum vertical size the bitmap will expand to; if maxheight is less than h (which includes negative, the default), the maximum vertical size will be such that maxheight/h==maxwidth/w
Exceptions:
BitmapError if the arguments are inconsistent

Bitmap::~Bitmap  ) 
 


Member Function Documentation

Bitmap::const_iterator Bitmap::begin  ) 
 

Returns the beginning of a sequence of bitmap rows.

Freezes the bitmap as a side-effect.

void Bitmap::blur  ) 
 

Makes a very simple-minded attempt to antialias the bitmap by blurring it.

Opening the DVI file with a magnification setting, and then calling scaleDown will generally produce a much better effect.

Freezes the bitmap as a side-effect.

int * Bitmap::boundingBox  ) 
 

Obtain a bounding box for the current bitmap.

This returns a four-element array consisting of, in order,

  • [0] = the coordinate of the leftmost blackened pixel,
  • [1] = the coordinate of the topmost blackened pixel,
  • [2] = one more than the coordinate of the rightmost blackened pixel, and
  • [3] = one more than the coordinate of the bottommost blackened pixel.
Thus [2]-[0] is the number of pixels which the blackened area occupies. Note that `blackened pixels' here includes those notionally blackened by the strut() method. If the bitmap has been cropped, this bounding box reflects the crop margins.

The returned array occupies static storage, and is always current as of the last time this method was called.

The methods getWidth() and getHeight() return the size of the bitmap irrespective of the bounding box and any cropping.

It is possible for the bounding-box to be bigger than the bitmap, if rules or bitmaps have been painted on the bitmap in such a way that they overlap the boundaries of the bitmap, and if it is called before an explicit or implicit call to freeze(). This can also be detected by a call to overlaps() before any call to freeze(). It is never bigger than the bitmap after the bitmap is frozen.

Note that the order of the four dimensions is not that of the Postscript BoundingBox, which is (llx, lly, urx, ury) rather than here, effectively, (ulx, uly, lrx, lry). This is because the position of the upper-left corner (ulx, uly) is the natural TeX reference point.

Returns:
the position of the bitmap bounding-box, in the order (ulx, uly, lrx, lry)

void Bitmap::clear  ) 
 

Resets the bitmap to its initial state.

This clears the bitmap by setting all the pixels to white, unfreezing it, and resetting the bounding box and crops to their initial states. It does not deallocate any memory, however, so if the bitmap has expanded in the past, the reset bitmap is the same size.

It does not reset the transparency flag or adjust the colour setting, or reset the pixel depth. This latter behaviour may change in future.

void Bitmap::crop Margin  spec,
int  pixels,
bool  absolute = false
throw (BitmapError)
 

Specifies a crop.

If the absolute flag is true, then set up a crop for the margin specified in spec: for the left and right margins, the crop in pixels is a distance from the left margin; for the top and bottom crops, it is from the top margin. If the absolute flag is false, then the distance in the pixels parameter is the distance `outward' of the eventual bounding-box, or at the edge of the bitmap, whichever comes first.

Since the implication of this is that a call

   .crop(All, x, true);
 
would set the crop box to be zero size, this combination is forbidden.

Parameters:
spec the margin the crop is being specified for
pixels the size of the margin, or the position when absolute is true
absolute if true, then the margin specified is an absolute position relative to the left or top margin as appropriate; if false, then it is relative to the eventual size and position of the bounding box
Exceptions:
BitmapError if spec=All when absolute is true

void Bitmap::crop  ) 
 

Crops the bitmap.

This applies the cropping specified in methods crop(Margin,int,bool) and cropDefault.

Freezes the bitmap as a side-effect.

void Bitmap::cropDefault Margin  spec,
int  pixels,
bool  absolute = false
throw (BitmapError) [static]
 

Specifies a default crop.

This is exactly the same as crop(Margin,int,bool), except that it specifies this for all the bitmaps subsequently created by this class.

Parameters:
spec the margin the crop is being specified for
pixels the size of the margin, or the position when absolute is true
absolute if true, then the margin specified is an absolute position relative to the left or top margin as appropriate; if false, then it is relative to the eventual size and position of the bounding box
Exceptions:
BitmapError if spec=All when absolute is true
See also:
crop(Margin,int,bool)

bool Bitmap::empty  )  const [inline]
 

Is the bitmap empty? If nothing has (yet) been written to the bitmap, or if everything that was written was out of bounds, then the bitmap is empty.

Returns:
true if the bitmap is empty

Bitmap::const_iterator Bitmap::end  )  const
 

Returns the end of a sequence of bitmap rows.

void Bitmap::freeze  ) 
 

Freeze the bitmap and bounding box.

This prevents any further changes to the bitmap by the methods paint(), rule() and strut(). Other methods in this class such as crop() and blur() call this method implicitly.

If method boundingBox() is called before this method, it is possible for it to report a size larger than the bitmap, if rules or bitmaps have been placed so that they overlap the bitmap's boundaries. The call to freeze normalises the bounding box so that this is no longer the case.

int Bitmap::getHeight  )  const [inline]
 

Returns the total height of the bitmap.

This may not the the initial size of the bitmap, if it has expanded since then.

Returns:
height of bitmap

Bitmap::BitmapMark * Bitmap::getMark  ) 
 

Obtains the mark for this bitmap.

Returns:
a pointer to the mark information, or 0 if no mark has been registered. This points to static storage, which should not be deleted, and which may be overwritten.
See also:
mark

int Bitmap::getWidth  )  const [inline]
 

Returns the total width of the bitmap.

This may not the the initial size of the bitmap, if it has expanded since then.

Returns:
width of bitmap

void Bitmap::logBitmapInfo const char *  prefix  )  [inline, static]
 

Sets whether bitmap information is logged.

If logging is enabled, then the details of the bitmaps are sent to the stdout prefixed by the given string.

Parameters:
prefix if non-null, then bitmap activity is logged on stdout with this prefix; if null, such logging is turned off

void Bitmap::mark const double  x,
const double  y
 

Marks a particular spot in the bitmap.

This spot can be retrieved later using getMark. The top-left pixel in the bitmap has mark coordinates (0,0). The input coordinates are not restricted to be on the bitmap.

Parameters:
x the x-coordinate of the mark, increasing to the right
y the y-coordinate of the mark, increasing downwards
See also:
BitmapMark

bool Bitmap::overlaps  )  const
 

Does the bitmap overlap its canvas? This can only be true before a (implicit or explicit) call to freeze, since that normalizes the bounding box variables.

Returns:
true if the bitmap overlaps its canvas; always false after any call to freeze()

void Bitmap::paint const int  x,
const int  y,
const int  w,
const int  h,
const Byte b
throw (BitmapError)
 

Paint a bitmap onto the master bitmap.

The bitmap to be added is given in a one-dimensional array b, which is w pixels wide and h high. Like the master bitmap, the x axis runs horizontally and the y axis vertically downwards.

The pixel at position (x,y) on the new bitmap is at position b[y*w+x] in the input bitmap array. This new bitmap is painted onto the master bitmap with its top left corner pixel (namely position (0,0)) occupying pixel (x,y) on the master bitmap, and pixel (a,b) occupying pixel (x+a,y+b) unless this would be off the master bitmap.

Any parts of the new bitmap falling outside the boundary of the master are cropped.

Parameters:
x the pixel in the top-left corner of the new bitmap (coordinate (0,0)) is located at position (x,y) of the master bitmap XXX NO, should be the reference point!!!
y (see parameter x)
w the width of the new bitmap, in pixels
h the height of the new bitmap, in pixels
b the new bitmap, as a one-dimensional array
Exceptions:
BitmapError if this is called after method freeze()

void Bitmap::rule const int  x,
const int  y,
const int  w,
const int  h
throw (BitmapError)
 

Draws on the master bitmap a block (a `rule' in TeX terms) of height h and width w pixels.

The bottom left corner of the rule occupies pixel (x,y) on the master bitmap.

Parameters:
x the (pixel in the) bottom-left corner of the rule is located at position (x,y) of the master bitmap
y (see parameter x)
w the width of the new rule, in pixels
h the height of the new rule, in pixels
Exceptions:
BitmapError if this is called after method freeze()

void Bitmap::scaleDown const int  factor  )  throw (BitmapError)
 

Scales down the bitmap by a numerical factor.

The resulting bitmap has a linear dimension smaller than the original by the given factor. The pixels in the resulting bitmap are resampled so that this gives a basic anti-aliasing effect.

We throw an exception if you try to scale down an empty bitmap, simply on the grounds that this is probably an error, and you want to know about it.

Freezes the bitmap as a side-effect.

Parameters:
factor the scaling factor, in the range 2..8
Exceptions:
BitmapError if the scaling factor is outside the range 2..8, or if the bitmap is empty

void Bitmap::setDefaultRGB const bool  fg,
const BitmapColour rgb
[static]
 

Sets the default foreground or background colours.

This is just like setRGB, except that it applies to all bitmaps subsequently created by this class.

Parameters:
fg if true, sets the foreground colour; if false, the background
rgb the colour the ground is set to

void Bitmap::setRGB const bool  fg,
const BitmapColour rgb
 

Sets the foreground or background colour.

Parameters:
fg if true, sets the foreground colour; if false, the background
rgb the colour the ground is set to

void Bitmap::setTransparent const bool  sw  )  [inline]
 

Sets the current bitmap to be transparent, if possible.

Parameters:
sw if true, the current bitmap is set to be transparent

void Bitmap::strut const int  x,
const int  y,
const int  l,
const int  r,
const int  t,
const int  b
throw (BitmapError)
 

Draws a `strut' on the master bitmap.

This is essentially the same as the rule() method, except that it doesn't draw in any pixels. Its only effect is to make sure that the boundingbox includes at least the x-values [x-l,x+r-1], and the y-values [y-t+1,y+b]. That is, the area indicated by the strut is l+r pixels wide by t+b pixels deep. The parameters l, r, t, and b must all be non-negative. This implies that the call rule(x, y, w, h) has the same effect on the bounding box as rule(x, y, 0, w, h, 0).

Parameters:
x the x-coordinate of the reference point of the strut
y the y-coordinate of the reference point of the strut
l bounding box must be leftwards of x-l
r bounding box must be rightwards of x+r
t bounding box must be above y-t
b bounding box must be below y+b
Exceptions:
BitmapError if this is called after method freeze(), or if one of l, r, t, b is negative

verbosities Bitmap::verbosity const verbosities  level  )  [inline, static]
 

Sets the verbosity of the current class.

Parameters:
level the required verbosity
Returns:
the previous verbosity level

void Bitmap::write const string  filename,
const string  format
throw (BitmapError)
 

Writes the bitmap out to the specified file.

The format parameter specifies the format of this file, and should be one of the bitmap types listed in the sequence starting with BitmapImage#firstBitmapImageFormat; if this is not available, we try writing out in the default format, and if that fails in turn (something is clearly badly wrong) we throw an error.

Freezes the bitmap as a side-effect.

Parameters:
filename the name of the output filename
format one of the format names known to class BitmapImage
Exceptions:
BitmapError if we cannot write out a bitmap even in the default format
See also:
BitmapImage


Member Data Documentation

Bitmap::const_iterator Bitmap::endIterator_ [static]
 

const_iterator Bitmap::runningIterator_
 


The documentation for this class was generated from the following files:
Generated on Sun Aug 21 18:21:03 2005 for dvi2bitmap by doxygen 1.3.8