#ifndef drg_h #define drg_h /* $Id: drg.h,v 1.21 2014/03/12 22:14:50 dkl Exp $ */ #include #include #include #include #include "carto.h" #define MAXLN 512 // longest line of input text we allow #define DEF_PAD 0 #define GRAINS 15 // this results in 30 second chunks #define STRAY_PIXEL_THRESHHOLD 5 // TODO: purge this #define FUDGE 128 #define TOPOROOT "/topo" #define GRAIN_IN_DEGREES (1.0/(8.0*(double)GRAINS)) // one grain in degrees #define DEFAULT_BORDER "/topo/images/border" #define CREDIT_FONT "/topo/etc/fonts/100dpi/timB08.bdf" #define USER_FONT "/topo/etc/fonts/100dpi/helvR12.bdf" #define INFO_FONT "/topo/etc/fonts/100dpi/helvR08.bdf" #define ERROR_CANT_MALLOC_IMAGE_STRING "Can't malloc image buffer" #define min(x,y) (((x) < (y)) ? (x) : (y)) #define max(x,y) (((x) > (y)) ? (x) : (y)) typedef struct { int ulx, uly, llx, lly, urx, ury, lrx, lry, xmin, xmax, ymin, ymax; } poly; typedef struct { int x1, x2, y1, y2; } rect; typedef unsigned long Pixel; typedef char * charp; class drg { public: //drg (); drg (const char *, int dpi, char *args); //drg (const char *, int dpi, int proj, int datum); drg (const char *nm=NULL, int dp=250, int p=0, int da=0, int e=0); drg (drg *, drg *); // does not duplicate image drg (const char *, int ); // main constructor drg (drg *); // does not duplicate image drg (const char *); // for use with images which have no DPI ~drg (); drg *BustOut (char *newName); // busts out a child void Log(char *); // write message to the logfile int Use4(); // make 4-bit data int Use8(); // make 8-bit data int ClipTo (int, int, int, int); int Trim (); int WriteCorners (); int ReadCorners (); int ReadTFW (); int WriteTFW (); int ReadXWD (int); int WriteXWD (); int ReadDRG (char *); int WriteDRG (); int ScanCmap(); int TrimCmap(); int ShiftCmap(); int SquishCmap(); int AddColor(XColor *); int HasColor(XColor *); void AddColormap(drg *ofMe); void MergeColormap(drg *intoMe); void MapTo(drg *toMe); int Shrink (int thresh, int pad); int Bbox (int stray_threshhold, int padbbox); void DrawBorder (const char *borderName); int DrawLines (char *); void DrawLine (int, int, int, int, unsigned long); int AddImage (int, int, const char *); int PatchAt (int, int, const char *); int PatchCenteredAt (int, int, const char *); int PatchAtLatLong (double, double, const char *); int PatchCenteredAtLatLong (double, double, const char *); void BreakDown(); void SquareUp(); void MakeBigger(int); void MakeThumbnail(); // make me a thumbnail of myself void AddThumbnail(int, int); void AddCorners(); void AddLegend(); void AddDecorations(char *); void AddComment(char *); void AddLabel(char *, int x, int y); void AddCollar(char *); void AddCredit(); void AddSerial(); void AddSeries(); void AddNotice(); void AddInfo1(); void AddInfo2(); void AddTitle(); void AddTickMarks(); void AddMapNames(); void AddTicksToTrimmed(); unsigned ImageSize (); void DrawString(char *text, int x, int y, int alignment); void DrawString(char *text, int x, int y, int alignment, char *font); //inline Pixel GetPixel (register int x, register int y); //inline void PutPixel (register int x, register int y, Pixel pix); Pixel GetPixel (register int x, register int y); void PutPixel (register int x, register int y, Pixel pix); void SetName (char *); inline void SetCredit (char *cr) {credit = cr;}; inline void SetComment (char *co) {comment = co;}; inline void SetNotice (char *no) {notice = no;}; inline void SetInfo1 (char *i1) {info1 = i1;}; inline void SetInfo2 (char *i2) {info2 = i2;}; inline void SetSeries (char *se) {series = se;}; inline void SetSerial (char *sl) {serial = sl;}; inline void SetLegend (char *le) {legend = le;}; inline void SetTitle (char *ti) {title = ti;}; inline void SetState (char *st) {state = st;}; inline void SetDate (char *da) {date = da;}; void SetGzip (Bool setting) {writeGzipped = setting;}; void SetDPI (int setting) {dpi = setting;}; int GetDPI () {return dpi;}; void SetHiLat (double lat) { hiLat = lat;} ; void SetLowLat (double lat) { lowLat = lat;} ; void SetHiLong (double lon) { hiLong = lon;} ; void SetLowLong (double lon) { lowLong = lon;} ; int GetX (double, double); int GetY (double, double); double GetLatOf (int, int); double GetLongOf (int, int); double GetLowLat () { return lowLat; } ; double GetLowLong () { return lowLong; } ; double GetHiLat () { return hiLat; } ; double GetHiLong () { return hiLong; } ; inline int GetCollar () { return collar; } ; inline int GetULX () { return ulx; }; inline int GetULY () { return uly; }; int GetURX () { return urx; }; int GetURY () { return ury; }; int GetLRX () { return lrx; }; int GetLRY () { return lry; }; int GetLLX () { return llx; }; int GetLLY () { return lly; }; double GetXoffset () { return xoffset; } ; void SetXoffset (double xo) { xoffset = xo;} ; double GetYoffset () { return yoffset; } ; void SetYoffset (double yo) { yoffset = yo;} ; void SetXscale (double xs) { xscale = xs;} ; void SetYscale (double ys) { yscale = ys;} ; int GetClosestColor (int r, int g, int b); int GetFarthestColor (int r, int g, int b); int GetProjection () { return proj; }; int GetDatum () { return datum; }; int IsOnThisMap (double, double); int IsOnThisImage (double, double); void Error (const char *); // from xwd.c static void _swapshort (char *, unsigned); static void _swaplong (char *, unsigned); char *name, *path, *indx, *toporoot; XImage *image; XWDFileHeader *header; XColor *colors; int ncolors; poly *neat; // the corners of the map Bool debug, verbose, writeGzipped, logging; carto *cart; // the projection information unsigned long whitePixel, blackPixel; // the coordinates of the map corners int ulx, uly, llx, lly, urx, ury, lrx, lry; int collar; int dpi, orig_dpi; // decorations char *title, *state, *credit, *notice, *series; char *info1, *legend, *comment, *serial, *date, *info2; private: void dataInit (); // common to constructors void rootInit (); // common to constructors void nameInit (const char *); // common to constructors void mapInit (); // common to constructors int proj; // the projection AEA or UTM int datum; // the datum NAD27, NAD83 int ellips; // the ellipsoid clrk66, WGS84 rect *nonwhite; // holds minimum nonwhite rect Bool Read (char *ptr, int size, int nitems, FILE *stream); double xscale, yscale, xoffset, yoffset; double lowLat, hiLat, lowLong, hiLong; double dpi_scale; // scale of dpi to original void DrawSteepLine (int, int, int, int, unsigned long); void DrawShallowLine (int, int, int, int, unsigned long); }; #define drgError(foo) { fprintf (stderr,foo); exit(1) } #define sameColor(c1, c2) ((c1.red == c2.red) && \ (c1.green == c2.green) && \ (c1.blue == c2.blue)) #endif