inc/memgfx.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 2000 Jim Kent.  This source code may be freely used         *
00003  * for personal, academic, and non-profit purposes.  Commercial use          *
00004  * permitted only by explicit agreement with Jim Kent (jim_kent@pacbell.net) *
00005  *****************************************************************************/
00006 /* Memgfx - stuff to do graphics in memory buffers.
00007  * Typically will just write these out as .gif files.
00008  * This stuff is byte-a-pixel for simplicity.
00009  * It can do 256 colors.
00010  */
00011 #ifndef MEMGFX_H
00012 #define MEMGFX_H
00013 
00014 #ifndef GFXPOLY_H
00015 #include "gfxPoly.h"
00016 #endif
00017 
00018 #define MG_WHITE 0
00019 #define MG_BLACK 1
00020 #define MG_RED 2
00021 #define MG_GREEN 3
00022 #define MG_BLUE 4
00023 #define MG_CYAN 5
00024 #define MG_MAGENTA 6
00025 #define MG_YELLOW 7
00026 #define MG_GRAY 8
00027 #define MG_FREE_COLORS_START 9
00028 
00029 
00030 typedef unsigned char Color;
00031 
00032 struct rgbColor
00033     {
00034     unsigned char r, g, b;
00035     };
00036 
00037 extern struct rgbColor mgFixedColors[9];  /* Contains MG_WHITE - MG_GRAY */
00038 
00039 struct memGfx
00040     {
00041     Color *pixels;
00042     int width, height;
00043     struct rgbColor colorMap[256];
00044     int colorsUsed;
00045     int clipMinX, clipMaxX;
00046     int clipMinY, clipMaxY;
00047     struct colHash *colorHash;  /* Hash for fast look up of color. */
00048     };
00049 
00050 struct memGfx *mgNew(int width, int height);
00051 /* Get a new thing to draw on in memory. */
00052 
00053 void mgFree(struct memGfx **pmg);
00054 /* Free up memory raster. */
00055 
00056 void mgClearPixels(struct memGfx *mg);
00057 /* Set all pixels to background. */
00058 
00059 void mgSetClip(struct memGfx *mg, int x, int y, int width, int height);
00060 /* Set clipping rectangle. */
00061 
00062 void mgUnclip(struct memGfx *mg);
00063 /* Set clipping rect cover full thing. */
00064 
00065 Color mgFindColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b);
00066 /* Returns closest color in color map to rgb values.  If it doesn't
00067  * already exist in color map and there's room, it will create
00068  * exact color in map. */
00069 
00070 Color mgClosestColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b);
00071 /* Returns closest color in color map to r,g,b */
00072 
00073 Color mgAddColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b);
00074 /* Adds color to end of color map if there's room. */
00075 
00076 int mgColorsFree(struct memGfx *mg);
00077 /* Returns # of unused colors in color map. */
00078 
00079 
00080 #define _mgBpr(mg) ((mg)->width)
00081 /* Get what to add to get to next line */
00082 
00083 #define _mgPixAdr(mg,x,y) ((mg)->pixels+_mgBpr(mg) * (y) + (x))
00084 /* Get pixel address */
00085 
00086 #define _mgPutDot(mg, x, y, color) (*_mgPixAdr(mg,x,y) = (color))
00087 /* Unclipped plot a dot */
00088 
00089 #define _mgGetDot(mg, x, y) (*_mgPixAdr(mg,x,y))
00090 /* Unclipped get a dot, you do not want to use this, this is special for
00091  * verticalText only */
00092 
00093 #define mgPutDot(mg,x,y,color) if ((x)>=(mg)->clipMinX && (x) < (mg)->clipMaxX && (y)>=(mg)->clipMinY  && (y) < (mg)->clipMaxY) _mgPutDot(mg,x,y,color)
00094 /* Clipped put dot */
00095 
00096 #define mgGetDot(mg,x,y) ((x)>=(mg)->clipMinX && (x) < (mg)->clipMaxX && (y)>=(mg)->clipMinY  && (y) < (mg)->clipMaxY) ? _mgGetDot(mg,x,y) : 0
00097 /* Clipped get dot, you do not want to use this, this is special for
00098  * verticalText only */
00099 
00100 void mgPutSeg(struct memGfx *mg, int x, int y, int width, Color *dots);
00101 /* Put a series of dots starting at x, y and going to right width pixels. */
00102 
00103 void mgPutSegZeroClear(struct memGfx *mg, int x, int y, int width, Color *dots);
00104 /* Put a series of dots starting at x, y and going to right width pixels.
00105  * Don't put zero dots though. */
00106 
00107 void mgDrawBox(struct memGfx *mg, int x, int y, int width, int height, Color color);
00108 /* Draw a (horizontal) box */
00109 
00110 void mgDrawLine(struct memGfx *mg, int x1, int y1, int x2, int y2, Color color);
00111 /* Draw a line from one point to another. */
00112 
00113 void mgDrawHorizontalLine(struct memGfx *mg, int y1, Color color);
00114 /*special case of mgDrawLine*/
00115 
00116 void mgLineH(struct memGfx *mg, int y, int x1, int x2, Color color);
00117 /* Draw horizizontal line width pixels long starting at x/y in color */
00118 
00119 void mgSaveGif(struct memGfx *mg, char *name);
00120 /* Save memory bitmap as a gif. */
00121 
00122 boolean mgSaveToGif(FILE *gif_file, struct memGfx *screen);
00123 /* Save GIF to an already open file. */
00124 
00125 struct memGfx *mgLoadGif(char *name);
00126 /* Create memory image based on gif file. 
00127  * Note this is based on a very old gif reader
00128  * that only handles the GIF87a version. 
00129  * This is the same that mgSaveGif creates at
00130  * least.  This version of gif was always
00131  * color mapped. */
00132 
00133 typedef void (*TextBlit)(int bitWidth, int bitHeight, int bitX, int bitY,
00134         unsigned char *bitData, int bitDataRowBytes, 
00135         struct memGfx *dest, int destX, int destY, 
00136         Color color, Color backgroundColor);
00137 /* This defines the type of a function that takes a rectangular
00138  * area of a bitplane and expands it into a rectangular area
00139  * of a full color screen. */
00140 
00141 void mgTextBlit(int bitWidth, int bitHeight, int bitX, int bitY,
00142         unsigned char *bitData, int bitDataRowBytes, 
00143         struct memGfx *dest, int destX, int destY, 
00144         Color color, Color backgroundColor);
00145 /* This function leaves the background as it was. */
00146 
00147 void mgTextBlitSolid(int bitWidth, int bitHeight, int bitX, int bitY,
00148         unsigned char *bitData, int bitDataRowBytes, 
00149         struct memGfx *dest, int destX, int destY, 
00150         Color color, Color backgroundColor);
00151 /* This function sets the background to the background color. */
00152 
00153 typedef struct font_hdr MgFont;
00154 /* Type of our font.  */
00155 
00156 MgFont *mgTinyFont();
00157 MgFont *mgSmallFont();
00158 MgFont *mgMediumFont();
00159 MgFont *mgLargeFont();
00160 MgFont *mgHugeFont();
00161 MgFont *mgTinyBoldFont();
00162 MgFont *mgSmallBoldFont();
00163 MgFont *mgMediumBoldFont();
00164 MgFont *mgLargeBoldFont();
00165 MgFont *mgHugeBoldFont();
00166 MgFont *mgTinyFixedFont();
00167 MgFont *mgSmallFixedFont();
00168 MgFont *mgMediumFixedFont();
00169 MgFont *mgLargeFixedFont();
00170 MgFont *mgHugeFixedFont();
00171 
00172 void mgText(struct memGfx *mg, int x, int y, Color color, 
00173         MgFont *font, char *text);
00174 /* Draw a line of text with upper left corner x,y. */
00175 
00176 void mgTextCentered(struct memGfx *mg, int x, int y, int width, int height, 
00177         Color color, MgFont *font, char *text);
00178 /* Draw a line of text centered in box defined by x/y/width/height */
00179 
00180 void mgTextRight(struct memGfx *mg, int x, int y, int width, int height, 
00181         Color color, MgFont *font, char *text);
00182 /* Draw a line of text right justified in box defined by x/y/width/height */
00183 
00184 int mgFontPixelHeight(MgFont *font);
00185 /* How high in pixels is font? */
00186 
00187 int mgFontLineHeight(MgFont *font);
00188 /* How many pixels to next line ideally? */
00189 
00190 int mgFontWidth(MgFont *font, char *chars, int charCount);
00191 /* How wide are a couple of letters? */
00192 
00193 int mgFontStringWidth(MgFont *font, char *string);
00194 /* How wide is a string? */
00195 
00196 int mgFontCharWidth(MgFont *font, char c);
00197 /* How wide is a character? */
00198 
00199 void mgFillUnder(struct memGfx *mg, int x1, int y1, int x2, int y2, 
00200         int bottom, Color color);
00201 /* Draw a 4 sided filled figure that has line x1/y1 to x2/y2 at
00202  * it's top, a horizontal line at bottom at it's bottom,  and
00203  * vertical lines from the bottom to y1 on the left and bottom to
00204  * y2 on the right. */
00205 
00206 struct memGfx *mgRotate90(struct memGfx *in);
00207 /* Create a copy of input that is rotated 90 degrees clockwise. */
00208 
00209 void mgCircle(struct memGfx *mg, int xCen, int yCen, int rad, 
00210         Color color, boolean filled);
00211 /* Draw a circle using a stepping algorithm.  Doesn't correct
00212  * for non-square pixels. */
00213 
00214 void mgDrawPoly(struct memGfx *mg, struct gfxPoly *poly, Color color,
00215         boolean filled);
00216 /* Draw polygon, possibly filled in color. */
00217 
00218 #endif /* MEMGFX_H */

Generated on Tue Dec 25 18:39:29 2007 for blat by  doxygen 1.5.2