The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
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[@]dogado.de.
dvi2bitmap
dvi2bitmap1.0
|
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... | |
DviFilePosition * | getMark () |
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_ |
Represents an abstract bitmap.
The bitmaps written to file are subclasses of the class BitmapImage.
typedef struct Bitmap::BitmapColour_s Bitmap::BitmapColour |
enum Bitmap::Margin |
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.
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 |
BitmapError | if the arguments are inconsistent |
References normal, and Util::verbosity_.
Bitmap::~Bitmap | ( | ) |
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 | ( | ) |
int * Bitmap::boundingBox | ( | ) |
Obtain a bounding box for the current bitmap.
This returns a four-element array consisting of, in order,
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.
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.
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 |
BitmapError | if spec=All when absolute is true |
|
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.
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 |
BitmapError | if spec=All when absolute is true |
Referenced by main().
|
inline |
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.
|
inline |
Returns the total height of the bitmap.
This may not the the initial size of the bitmap, if it has expanded since then.
DviFilePosition * Bitmap::getMark | ( | ) |
Obtains the mark for this bitmap.
References DviFilePosition::copy(), DviFilePosition::shift(), and DviFile::unit_pixels.
|
inline |
Returns the total width of the bitmap.
This may not the the initial size of the bitmap, if it has expanded since then.
|
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.
prefix | if 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.
p | a DviFilePosition representing the marked position |
References DviFilePosition::getX(), DviFilePosition::getY(), normal, and DviFile::unit_pixels.
Referenced by main().
bool Bitmap::overlaps | ( | ) | const |
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.
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 |
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 |
BitmapError | if 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.
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 |
BitmapError | if 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.
factor | the scaling factor, in the range 2..8 |
BitmapError | if 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().
|
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.
fg | if true, sets the foreground colour; if false, the background |
rgb | the 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.
fg | if true, sets the foreground colour; if false, the background |
rgb | the colour the ground is set to |
References Bitmap::BitmapColour_s::blue, Bitmap::BitmapColour_s::green, normal, and Bitmap::BitmapColour_s::red.
Referenced by main().
|
inline |
Sets the current bitmap to be transparent, if possible.
sw | if 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)
.
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 |
BitmapError | if this is called after method freeze() , or if one of l, r, t, b is negative |
References normal, and Util::verbosity_.
Referenced by main().
|
inlinestatic |
Sets the verbosity of the current class.
level | the required verbosity |
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.
filename | the name of the output filename |
format | one of the format names known to class BitmapImage |
BitmapError | if we cannot write out a bitmap even in the default format |
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().
|
static |
Referenced by end().
const_iterator Bitmap::runningIterator_ |
Referenced by begin().
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.
Health stats visible at Monitor.