The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

dvi2bitmap  dvi2bitmap1.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Bitmap Class Reference

Represents an abstract bitmap. More...

#include <Bitmap.h>

Classes

struct  BitmapColour_s
 
class  const_iterator
 Iterator class. More...
 

Public Types

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

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. More...
 
 ~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. More...
 
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. More...
 
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. More...
 
void write (const string filename, const string format) throw (BitmapError)
 Writes the bitmap out to the specified file. More...
 
void freeze ()
 Freeze the bitmap and bounding box. More...
 
void crop ()
 Crops the bitmap. More...
 
void crop (Margin spec, int pixels, bool absolute=false) throw (BitmapError)
 Specifies a crop. More...
 
void blur ()
 Makes a very simple-minded attempt to antialias the bitmap by blurring it. More...
 
void clear ()
 Resets the bitmap to its initial state. More...
 
void setTransparent (const bool sw)
 Sets the current bitmap to be transparent, if possible. More...
 
void setRGB (const bool fg, const BitmapColour *)
 Sets the foreground or background colour. More...
 
void scaleDown (const int factor) throw (BitmapError)
 Scales down the bitmap by a numerical factor. More...
 
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. More...
 
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. More...
 
int * boundingBox ()
 Obtain a bounding box for the current bitmap. More...
 
int getWidth () const
 Returns the total width of the bitmap. More...
 
int getHeight () const
 Returns the total height of the bitmap. More...
 
void mark (DviFilePosition *)
 Marks a particular spot in the bitmap. More...
 
DviFilePositiongetMark ()
 Obtains the mark for this bitmap. More...
 
const_iterator begin ()
 Returns the beginning of a sequence of bitmap rows. More...
 
const_iterator end () const
 Returns the end of a sequence of bitmap rows. More...
 

Static Public Member Functions

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

Public Attributes

const_iterator runningIterator_
 

Static Public Attributes

static const_iterator endIterator_
 

Detailed Description

Represents an abstract bitmap.

The bitmaps written to file are subclasses of the class BitmapImage.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
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
wthe width of the bitmap, in pixels
hthe height of the bitmap, in pixels
bppthe number of bits-per-pixel (default is 1)
expandableif true (the default), the bitmap is expandable; if false, the bitmap is fixed at the specified size
maxwidthif 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
maxheightif 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
BitmapErrorif the arguments are inconsistent

References normal, and Util::verbosity_.

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.

References freeze(), and runningIterator_.

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.

References empty(), and freeze().

Referenced by main().

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 in the horizontal direction. 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)

Referenced by main().

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.

References Bottom, Left, normal, Right, and Top.

Referenced by main().

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.

References Bottom, freeze(), Left, normal, Right, and Top.

Referenced by main().

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
specthe margin the crop is being specified for
pixelsthe size of the margin, or the position when absolute is true
absoluteif 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
BitmapErrorif spec=All when absolute is true
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
specthe margin the crop is being specified for
pixelsthe size of the margin, or the position when absolute is true
absoluteif 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
BitmapErrorif spec=All when absolute is true
See Also
crop(Margin,int,bool)

Referenced by main().

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

Referenced by blur(), and main().

Bitmap::const_iterator Bitmap::end ( ) const

Returns the end of a sequence of bitmap rows.

References endIterator_.

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.

Referenced by begin(), blur(), and crop().

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
DviFilePosition * 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

References DviFilePosition::copy(), DviFilePosition::shift(), and DviFile::unit_pixels.

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
static void Bitmap::logBitmapInfo ( const char *  prefix)
inlinestatic

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
prefixif non-null, then bitmap activity is logged on stdout with this prefix; if null, such logging is turned off

Referenced by main().

void Bitmap::mark ( DviFilePosition p)

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
pa DviFilePosition representing the marked position

References DviFilePosition::getX(), DviFilePosition::getY(), normal, and DviFile::unit_pixels.

Referenced by main().

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()

References normal.

Referenced by main().

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
xthe pixel in the top-left corner of the new bitmap (coordinate (0,0)) is located at position (x,y) of the master bitmap
y(see parameter x)
wthe width of the new bitmap, in pixels
hthe height of the new bitmap, in pixels
bthe new bitmap, as a one-dimensional array
Exceptions
BitmapErrorif this is called after method freeze()

References debug, and Util::verbosity_.

Referenced by main().

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
xthe (pixel in the) bottom-left corner of the rule is located at position (x,y) of the master bitmap
y(see parameter x)
wthe width of the new rule, in pixels
hthe height of the new rule, in pixels
Exceptions
BitmapErrorif this is called after method freeze()

References normal, and Util::verbosity_.

Referenced by main().

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
factorthe scaling factor, in the range 2..8
Exceptions
BitmapErrorif the scaling factor is outside the range 2..8, or if the bitmap is empty

References normal, DviFile::unit_pixels, and Util::verbosity_.

Referenced by main().

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
fgif true, sets the foreground colour; if false, the background
rgbthe colour the ground is set to

References Bitmap::BitmapColour_s::blue, Bitmap::BitmapColour_s::green, normal, and Bitmap::BitmapColour_s::red.

Referenced by main().

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

Sets the foreground or background colour.

Parameters
fgif true, sets the foreground colour; if false, the background
rgbthe colour the ground is set to

References Bitmap::BitmapColour_s::blue, Bitmap::BitmapColour_s::green, normal, and Bitmap::BitmapColour_s::red.

Referenced by main().

void Bitmap::setTransparent ( const bool  sw)
inline

Sets the current bitmap to be transparent, if possible.

Parameters
swif true, the current bitmap is set to be transparent

Referenced by main().

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
xthe x-coordinate of the reference point of the strut
ythe y-coordinate of the reference point of the strut
lbounding box must be leftwards of x-l
rbounding box must be rightwards of x+r
tbounding box must be above y-t
bbounding box must be below y+b
Exceptions
BitmapErrorif this is called after method freeze(), or if one of l, r, t, b is negative

References normal, and Util::verbosity_.

Referenced by main().

static verbosities Bitmap::verbosity ( const verbosities  level)
inlinestatic

Sets the verbosity of the current class.

Parameters
levelthe required verbosity
Returns
the previous verbosity level

Referenced by main().

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
filenamethe name of the output filename
formatone of the format names known to class BitmapImage
Exceptions
BitmapErrorif we cannot write out a bitmap even in the default format
See Also
BitmapImage

References BitmapImage::fileExtension(), BitmapImage::firstBitmapImageFormat(), DviFilePosition::getX(), DviFilePosition::getY(), BitmapImage::newBitmapImage(), normal, BitmapImage::setBitmap(), BitmapImage::setBitmapRow(), BitmapImage::setRGB(), BitmapImage::setTransparent(), DviFile::unit_pixels, Util::verbosity_, and BitmapImage::write().

Referenced by main().

Member Data Documentation

Bitmap::const_iterator Bitmap::endIterator_
static

Referenced by end().

const_iterator Bitmap::runningIterator_

Referenced by begin().


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

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.