Image Interpolation with Geometric Contour Stencils
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Macros | Typedefs | Functions | Variables
pen.h File Reference

Vector drawing abstraction. More...

#include "basic.h"
Include dependency graph for pen.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pentrans
 Coordinate transformation matrix. More...
 
struct  penstruct
 Pen drawing object. More...
 

Macros

#define PEN_DEFAULT_NUMDIGITS   2
 Default number of digits for writing floats. More...
 
#define PEN_MAXDIGITS   8
 Maximum number of digits supported by PenWriteFloat() More...
 

Typedefs

typedef struct penstruct pen
 Pen drawing object. More...
 

Functions

penNewPen ()
 Create a new pen. More...
 
void FreePen (pen *Pen)
 Free all memory associated with a pen. More...
 
FILE * PenGetFile (pen *Pen)
 Get the stdio FILE* pointer associated with a pen. More...
 
int PenDrawLine (pen *Pen, float x1, float y1, float x2, float y2)
 Draw a line. More...
 
int PenDrawRectangle (pen *Pen, float x1, float y1, float x2, float y2)
 Draw a rectangle. More...
 
int PenDrawQBezier (pen *Pen, float x1, float y1, float x2, float y2, float x3, float y3)
 Draw a quadratic Bezier curve. More...
 
int PenDrawCircle (pen *Pen, float x, float y, float r)
 Draw a circle. More...
 
int PenDrawEllipse (pen *Pen, float x, float y, float rx, float ry, float Theta)
 Draw an ellipse. More...
 
pentrans PenGetTrans (pen *Pen)
 Get the pen canvas transformation. More...
 
void PenSetTrans (pen *Pen, pentrans Trans)
 (Re)set the pen canvas transformation More...
 
void PenTransformCanvas (pen *Pen, double a, double b, double c, double d, double e, double f)
 Transform the pen's canvas. More...
 
void PenTranslateCanvas (pen *Pen, double tx, double ty)
 Translate the pen's canvas. More...
 
void PenScaleCanvas (pen *Pen, double XScale, double YScale)
 Scale the pen's canvas. More...
 
void PenRotateCanvas (pen *Pen, double Theta)
 Rotate the pen's canvas. More...
 
void PenXSkewCanvas (pen *Pen, double Skew)
 Horizontally skew the pen's canvas. More...
 
void PenYSkewCanvas (pen *Pen, double Skew)
 Vertically skew the pen's canvas. More...
 
int PenColorToIndex (pen *Pen, const float *Color)
 Find the pen palette index of a color. More...
 
int PenDefineColor (pen *Pen, const float *Color)
 Add a color to a pen's palette. More...
 
int PenSetColor (pen *Pen, const float *Color)
 Set the current pen drawing color. More...
 
void PenWriteDouble (FILE *File, double Value, int NumDigits)
 Write a floating-point value without trailing zeros. More...
 
int PenGetNumDigits (pen *Pen)
 Get the number of digits used for writing floats. More...
 
void PenSetNumDigits (pen *Pen, int NumDigits)
 Set the number of digits used for writing floats. More...
 
void TransformEllipse (float *x, float *y, float *rx, float *ry, float *Theta, pentrans Trans)
 Compute canvas transformation for an ellipse. More...
 
float EstArcLenQBezier (float x1, float y1, float x2, float y2, float x3, float y3, pentrans Trans)
 Estimate arc length of a quadratic Bezier curve. More...
 
float EstArcLenEllipse (float x, float y, float rx, float ry, float Theta, pentrans Trans)
 Estimate the arc length of an ellipse. More...
 
int PenRenderToImage (pen *Pen, float *Image, int Width, int Height)
 Set pen to render to a raster image. More...
 
int EpsOpen (pen *Pen, const char *FileName, float Width, float Height)
 Start writing a new EPS file. More...
 
int EpsClose (pen *Pen)
 Finish writing an EPS file. More...
 
int WriteASCII85 (FILE *File, const uint8_t *Data, int NumBytes)
 Write ASCII85 encoded data. More...
 
int EpsWriteGrayImage (FILE *File, const uint8_t *Image, int Width, int Height)
 Writes a grayscale image to an EPS file. More...
 
int EpsWriteColorImage (FILE *File, const uint8_t *Image, int Width, int Height)
 Writes an RGB color image to an EPS file. More...
 
int SvgOpen (pen *Pen, const char *FileName, float Width, float Height)
 Start writing a new SVG file. More...
 
int SvgClose (pen *Pen)
 Finish writing an SVG file. More...
 

Variables

const pentrans IdentityPenTrans
 Identity transform. More...
 

Detailed Description

Vector drawing abstraction.

Author
Pascal Getreuer getre.nosp@m.uer@.nosp@m.gmail.nosp@m..com

Copyright (c) 2010-2011, Pascal Getreuer All rights reserved.

This program is free software: you can use, modify and/or redistribute it under the terms of the simplified BSD License. You should have received a copy of this license along this program. If not, see http://www.opensource.org/licenses/bsd-license.html.

Definition in file pen.h.

Macro Definition Documentation

#define PEN_DEFAULT_NUMDIGITS   2

Default number of digits for writing floats.

Definition at line 22 of file pen.h.

#define PEN_MAXDIGITS   8

Maximum number of digits supported by PenWriteFloat()

Definition at line 24 of file pen.h.

Typedef Documentation

typedef struct penstruct pen

Pen drawing object.

Function Documentation

int EpsClose ( pen Pen)

Finish writing an EPS file.

Parameters
Penthe pen object
Returns
1 on success, 0 on failure

Definition at line 996 of file pen.c.

int EpsOpen ( pen Pen,
const char *  FileName,
float  Width,
float  Height 
)

Start writing a new EPS file.

Parameters
Penthe pen object
FileNamethe EPS file name
Width,Heightdimensions of the SVG canvas
Returns
1 on success, 0 on failure

Definition at line 933 of file pen.c.

int EpsWriteColorImage ( FILE *  File,
const uint8_t *  Image,
int  Width,
int  Height 
)

Writes an RGB color image to an EPS file.

Parameters
Filethe stdio file handle to write to
Imageinterleaved RGB color image data
Width,Heightthe image dimensions

The image is plotted on the canvas in the rectangle [0,Width] x [0,Height] where the lower-left corner is at the origin.

This routine only writes the image data. EpsOpen should be called first, then this routine and other drawing commands, and finally EpsClose.

For relative simplicity, the image data is written uncompressed in ASCII85 encoding. The file size is approximately 25% larger than in the PGM file format.

Definition at line 1144 of file pen.c.

int EpsWriteGrayImage ( FILE *  File,
const uint8_t *  Image,
int  Width,
int  Height 
)

Writes a grayscale image to an EPS file.

Parameters
Filethe stdio file handle to write to
Imagegrayscale image data
Width,Heightthe image dimensions

The image is plotted on the canvas in the rectangle [0,Width] x [0,Height] where the lower-left corner is at the origin.

This routine only writes the image data. EpsOpen should be called first, then this routine and other drawing commands, and finally EpsClose.

For relative simplicity, the image data is written uncompressed in ASCII85 encoding. The file size is approximately 25% larger than in the PGM file format.

Definition at line 1100 of file pen.c.

float EstArcLenEllipse ( float  x,
float  y,
float  rx,
float  ry,
float  Theta,
pentrans  Trans 
)

Estimate the arc length of an ellipse.

Parameters
x,y,rx,ry,Thetaparameters for pen::DrawEllipse
Transthe canvas transformation
Returns
estimated arc length

Definition at line 616 of file pen.c.

float EstArcLenQBezier ( float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3,
pentrans  Trans 
)

Estimate arc length of a quadratic Bezier curve.

Parameters
Penthe pen object
x1,y1,x2,y2,x3,y3starting point, control point, and endpoint
Returns
estimated arc length

Computes a crude overestimate of the arc length.

Definition at line 589 of file pen.c.

void FreePen ( pen Pen)

Free all memory associated with a pen.

Parameters
Penthe pen object to free

Definition at line 139 of file pen.c.

pen* NewPen ( )

Create a new pen.

Returns
a pen*, or NULL on allocation failure

Allocates a new pen object. The caller must call FreePen() to free the pen when done.

Definition at line 121 of file pen.c.

int PenColorToIndex ( pen Pen,
const float *  Color 
)

Find the pen palette index of a color.

Parameters
Penthe pen object
Colorcolor to find
Returns
palette index, or -1 if not in palette

Definition at line 454 of file pen.c.

int PenDefineColor ( pen Pen,
const float *  Color 
)

Add a color to a pen's palette.

Parameters
Penthe pen object
Colorcolor to add
Returns
1 on success, 0 on failure

Color is added to Pen->Palette if it is not already in the palette. The palette is reallocated if more space is needed.

Definition at line 480 of file pen.c.

int PenDrawCircle ( pen Pen,
float  x,
float  y,
float  r 
)

Draw a circle.

Parameters
Penthe pen object
x,ycircle center
rcircle radius
Returns
1 on success, 0 on failure

This function is a wrapper for pen::DrawEllipse.

Definition at line 213 of file pen.c.

int PenDrawEllipse ( pen Pen,
float  x,
float  y,
float  rx,
float  ry,
float  Theta 
)

Draw an ellipse.

Parameters
Penthe pen object
x,ycenter of the ellipse
rx,ryradii of the ellipse
Thetaellipse rotation
Returns
1 on success, 0 on failure

This function is a wrapper for pen::DrawEllipse.

Definition at line 229 of file pen.c.

int PenDrawLine ( pen Pen,
float  x1,
float  y1,
float  x2,
float  y2 
)

Draw a line.

Parameters
Penthe pen object
x1,y1,x2,y2endpoints of the line
Returns
1 on success, 0 on failure

This function is a wrapper for pen::DrawLine.

Definition at line 167 of file pen.c.

int PenDrawQBezier ( pen Pen,
float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3 
)

Draw a quadratic Bezier curve.

Parameters
Penthe pen object
x1,y1,x2,y2,x3,y3starting point, control point, and endpoint
Returns
1 on success, 0 on failure

This function is a wrapper for pen::DrawQBezier.

Definition at line 197 of file pen.c.

int PenDrawRectangle ( pen Pen,
float  x1,
float  y1,
float  x2,
float  y2 
)

Draw a rectangle.

Parameters
Penthe pen object
x1,y1,x2,y2corners of the rectangle
Returns
1 on success, 0 on failure

Definition at line 179 of file pen.c.

FILE* PenGetFile ( pen Pen)

Get the stdio FILE* pointer associated with a pen.

Parameters
Penthe pen object

Definition at line 153 of file pen.c.

int PenGetNumDigits ( pen Pen)

Get the number of digits used for writing floats.

Parameters
Penthe pen object
Returns
number of digits

Gets the number of digits used in PenWriteDouble().

Definition at line 301 of file pen.c.

pentrans PenGetTrans ( pen Pen)

Get the pen canvas transformation.

Parameters
Penthe pen object
Returns
pentrans canvas transformation

Gets pen::Trans. This is useful in combination with PenSetTrans() to save and later restore the canvas transformation.

Definition at line 330 of file pen.c.

int PenRenderToImage ( pen Pen,
float *  Image,
int  Width,
int  Height 
)

Set pen to render to a raster image.

Parameters
Penthe pen object
Imagethe row-major interleaved RGB image to render to
Width,Heightdimensions of Image
Returns
1 on success, 0 on failure

Definition at line 774 of file pen.c.

void PenRotateCanvas ( pen Pen,
double  Theta 
)

Rotate the pen's canvas.

Parameters
Penthe pen object
Thetacounter-clockwise rotation in radians

Definition at line 413 of file pen.c.

void PenScaleCanvas ( pen Pen,
double  XScale,
double  YScale 
)

Scale the pen's canvas.

Parameters
Penthe pen object
XScale,YScalescale factors

Definition at line 401 of file pen.c.

int PenSetColor ( pen Pen,
const float *  Color 
)

Set the current pen drawing color.

Parameters
Penthe pen object
Colorthe drawing color
Returns
the color's palette index, or -1 if not in palette

Definition at line 520 of file pen.c.

void PenSetNumDigits ( pen Pen,
int  NumDigits 
)

Set the number of digits used for writing floats.

Parameters
Penthe pen object
NumDigitsthe number of digits

Sets the number of digits used in PenWriteDouble().

Definition at line 314 of file pen.c.

void PenSetTrans ( pen Pen,
pentrans  Trans 
)

(Re)set the pen canvas transformation

Parameters
Penthe pen object
Transthe pentrans canvas transformation

Sets pen::Trans to Trans. This is useful in combination with PenGetTrans() to save and later restore the canvas transformation.

Definition at line 344 of file pen.c.

void PenTransformCanvas ( pen Pen,
double  a,
double  b,
double  c,
double  d,
double  e,
double  f 
)

Transform the pen's canvas.

Parameters
Penthe pen object
Transthe pentrans canvas transformation

Definition at line 356 of file pen.c.

void PenTranslateCanvas ( pen Pen,
double  tx,
double  ty 
)

Translate the pen's canvas.

Parameters
Penthe pen object
tx,tytranslation

Definition at line 389 of file pen.c.

void PenWriteDouble ( FILE *  File,
double  Value,
int  NumDigits 
)

Write a floating-point value without trailing zeros.

Parameters
Filethe file or stream
Valuefloating-point value to write
NumDigitsValue is written in decimal notation using up to NumDigits digits after the decimal point. Trailing zeros are omitted.

Definition at line 245 of file pen.c.

void PenXSkewCanvas ( pen Pen,
double  Skew 
)

Horizontally skew the pen's canvas.

Parameters
Penthe pen object
Skewskew amount

Definition at line 429 of file pen.c.

void PenYSkewCanvas ( pen Pen,
double  Skew 
)

Vertically skew the pen's canvas.

Parameters
Penthe pen object
Skewskew amount

Definition at line 441 of file pen.c.

int SvgClose ( pen Pen)

Finish writing an SVG file.

Parameters
Penthe pen object
Returns
1 on success, 0 on failure

Definition at line 1426 of file pen.c.

int SvgOpen ( pen Pen,
const char *  FileName,
float  Width,
float  Height 
)

Start writing a new SVG file.

Parameters
Penthe pen object
FileNamethe SVG file name
Width,Heightdimensions of the SVG canvas
Returns
1 on success, 0 on failure

Definition at line 1359 of file pen.c.

void TransformEllipse ( float *  x,
float *  y,
float *  rx,
float *  ry,
float *  Theta,
pentrans  Trans 
)

Compute canvas transformation for an ellipse.

Parameters
x,y,rx,ry,Thetaparameters for pen::DrawEllipse
Transthe canvas transformation

The input values of the parameters x, y, rx, ry, Theta are the untransformed parameters as given to pen::DrawEllipse. They are replaced with transformed values.

Definition at line 545 of file pen.c.

int WriteASCII85 ( FILE *  File,
const uint8_t *  Data,
int  NumBytes 
)

Write ASCII85 encoded data.

Parameters
Filethe destination stream or File
Databinary data to encode
NumBytesnumber of bytes in Data
Returns
1 on success, 0 on failure

Definition at line 1015 of file pen.c.

Variable Documentation

const pentrans IdentityPenTrans

Identity transform.

Definition at line 25 of file pen.c.