- sync to 1.3.0
parent
3900d0f4d6
commit
4990220173
|
@ -0,0 +1,147 @@
|
|||
#ifndef GD_H
|
||||
#define GD_H 1
|
||||
|
||||
/* gd.h: declarations file for the gifdraw module.
|
||||
|
||||
Written by Tom Boutell, 5/94.
|
||||
Copyright 1994, Cold Spring Harbor Labs.
|
||||
Permission granted to use this code in any fashion provided
|
||||
that this notice is retained and any alterations are
|
||||
labeled as such. It is requested, but not required, that
|
||||
you share extensions to this module with us so that we
|
||||
can incorporate them into new versions. */
|
||||
|
||||
/* stdio is needed for file I/O. */
|
||||
#include <stdio.h>
|
||||
|
||||
/* This can't be changed, it's part of the GIF specification. */
|
||||
|
||||
#define gdMaxColors 256
|
||||
|
||||
/* Image type. See functions below; you will not need to change
|
||||
the elements directly. Use the provided macros to
|
||||
access sx, sy, the color table, and colorsTotal for
|
||||
read-only purposes. */
|
||||
|
||||
typedef struct gdImageStruct {
|
||||
unsigned char ** pixels;
|
||||
int sx;
|
||||
int sy;
|
||||
int colorsTotal;
|
||||
int red[gdMaxColors];
|
||||
int green[gdMaxColors];
|
||||
int blue[gdMaxColors];
|
||||
int open[gdMaxColors];
|
||||
int transparent;
|
||||
int *polyInts;
|
||||
int polyAllocated;
|
||||
struct gdImageStruct *brush;
|
||||
struct gdImageStruct *tile;
|
||||
int brushColorMap[gdMaxColors];
|
||||
int tileColorMap[gdMaxColors];
|
||||
int styleLength;
|
||||
int stylePos;
|
||||
int *style;
|
||||
int interlace;
|
||||
} gdImage;
|
||||
|
||||
typedef gdImage * gdImagePtr;
|
||||
|
||||
typedef struct {
|
||||
/* # of characters in font */
|
||||
int nchars;
|
||||
/* First character is numbered... (usually 32 = space) */
|
||||
int offset;
|
||||
/* Character width and height */
|
||||
int w;
|
||||
int h;
|
||||
/* Font data; array of characters, one row after another.
|
||||
Easily included in code, also easily loaded from
|
||||
data files. */
|
||||
char *data;
|
||||
} gdFont;
|
||||
|
||||
/* Text functions take these. */
|
||||
typedef gdFont *gdFontPtr;
|
||||
|
||||
/* For backwards compatibility only. Use gdImageSetStyle()
|
||||
for MUCH more flexible line drawing. Also see
|
||||
gdImageSetBrush(). */
|
||||
#define gdDashSize 4
|
||||
|
||||
/* Special colors. */
|
||||
|
||||
#define gdStyled (-2)
|
||||
#define gdBrushed (-3)
|
||||
#define gdStyledBrushed (-4)
|
||||
#define gdTiled (-5)
|
||||
|
||||
/* NOT the same as the transparent color index.
|
||||
This is used in line styles only. */
|
||||
#define gdTransparent (-6)
|
||||
|
||||
/* Functions to manipulate images. */
|
||||
|
||||
gdImagePtr gdImageCreate(int sx, int sy);
|
||||
gdImagePtr gdImageCreateFromGif(FILE *fd);
|
||||
gdImagePtr gdImageCreateFromGd(FILE *in);
|
||||
gdImagePtr gdImageCreateFromXbm(FILE *fd);
|
||||
void gdImageDestroy(gdImagePtr im);
|
||||
void gdImageSetPixel(gdImagePtr im, int x, int y, int color);
|
||||
int gdImageGetPixel(gdImagePtr im, int x, int y);
|
||||
void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
/* For backwards compatibility only. Use gdImageSetStyle()
|
||||
for much more flexible line drawing. */
|
||||
void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
/* Corners specified (not width and height). Upper left first, lower right
|
||||
second. */
|
||||
void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
/* Solid bar. Upper left corner first, lower right corner second. */
|
||||
void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
int gdImageBoundsSafe(gdImagePtr im, int x, int y);
|
||||
void gdImageChar(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
|
||||
void gdImageCharUp(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
|
||||
void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
|
||||
void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
|
||||
void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
|
||||
void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
|
||||
|
||||
/* Point type for use in polygon drawing. */
|
||||
|
||||
typedef struct {
|
||||
int x, y;
|
||||
} gdPoint, *gdPointPtr;
|
||||
|
||||
void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c);
|
||||
void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c);
|
||||
|
||||
int gdImageColorAllocate(gdImagePtr im, int r, int g, int b);
|
||||
int gdImageColorClosest(gdImagePtr im, int r, int g, int b);
|
||||
int gdImageColorExact(gdImagePtr im, int r, int g, int b);
|
||||
void gdImageColorDeallocate(gdImagePtr im, int color);
|
||||
void gdImageColorTransparent(gdImagePtr im, int color);
|
||||
void gdImageGif(gdImagePtr im, FILE *out);
|
||||
void gdImageGd(gdImagePtr im, FILE *out);
|
||||
void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color);
|
||||
void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color);
|
||||
void gdImageFill(gdImagePtr im, int x, int y, int color);
|
||||
void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h);
|
||||
/* Stretches or shrinks to fit, as needed */
|
||||
void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
|
||||
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
|
||||
void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
|
||||
void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels);
|
||||
/* On or off (1 or 0) */
|
||||
void gdImageInterlace(gdImagePtr im, int interlaceArg);
|
||||
|
||||
/* Macros to access information about images. READ ONLY. Changing
|
||||
these values will NOT have the desired result. */
|
||||
#define gdImageSX(im) ((im)->sx)
|
||||
#define gdImageSY(im) ((im)->sy)
|
||||
#define gdImageColorsTotal(im) ((im)->colorsTotal)
|
||||
#define gdImageRed(im, c) ((im)->red[(c)])
|
||||
#define gdImageGreen(im, c) ((im)->green[(c)])
|
||||
#define gdImageBlue(im, c) ((im)->blue[(c)])
|
||||
#define gdImageGetTransparent(im) ((im)->transparent)
|
||||
#define gdImageGetInterlaced(im) ((im)->interlace)
|
||||
#endif
|
|
@ -0,0 +1,113 @@
|
|||
#include <stdio.h>
|
||||
#include "gd.h"
|
||||
#include "gdfontg.h"
|
||||
#include "gdfonts.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Input and output files */
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
/* Input and output images */
|
||||
gdImagePtr im_in, im_out;
|
||||
|
||||
/* Brush image */
|
||||
gdImagePtr brush;
|
||||
|
||||
/* Color indexes */
|
||||
int white;
|
||||
int blue;
|
||||
int red;
|
||||
int green;
|
||||
|
||||
/* Points for polygon */
|
||||
gdPoint points[3];
|
||||
|
||||
/* Create output image, 128 by 128 pixels. */
|
||||
im_out = gdImageCreate(128, 128);
|
||||
|
||||
/* First color allocated is background. */
|
||||
white = gdImageColorAllocate(im_out, 255, 255, 255);
|
||||
|
||||
/* Set transparent color. */
|
||||
gdImageColorTransparent(im_out, white);
|
||||
|
||||
/* Try to load demoin.gif and paste part of it into the
|
||||
output image. */
|
||||
|
||||
in = fopen("demoin.gif", "rb");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't load source image; this demo\n");
|
||||
fprintf(stderr, "is much more impressive if demoin.gif\n");
|
||||
fprintf(stderr, "is available.\n");
|
||||
im_in = 0;
|
||||
} else {
|
||||
im_in = gdImageCreateFromGif(in);
|
||||
fclose(in);
|
||||
/* Now copy, and magnify as we do so */
|
||||
gdImageCopyResized(im_out, im_in,
|
||||
16, 16, 0, 0, 96, 96, 127, 127);
|
||||
}
|
||||
red = gdImageColorAllocate(im_out, 255, 0, 0);
|
||||
green = gdImageColorAllocate(im_out, 0, 255, 0);
|
||||
blue = gdImageColorAllocate(im_out, 0, 0, 255);
|
||||
/* Rectangle */
|
||||
gdImageLine(im_out, 8, 8, 120, 8, green);
|
||||
gdImageLine(im_out, 120, 8, 120, 120, green);
|
||||
gdImageLine(im_out, 120, 120, 8, 120, green);
|
||||
gdImageLine(im_out, 8, 120, 8, 8, green);
|
||||
/* Circle */
|
||||
gdImageArc(im_out, 64, 64, 30, 10, 0, 360, blue);
|
||||
/* Arc */
|
||||
gdImageArc(im_out, 64, 64, 20, 20, 45, 135, blue);
|
||||
/* Flood fill */
|
||||
gdImageFill(im_out, 4, 4, blue);
|
||||
/* Polygon */
|
||||
points[0].x = 32;
|
||||
points[0].y = 0;
|
||||
points[1].x = 0;
|
||||
points[1].y = 64;
|
||||
points[2].x = 64;
|
||||
points[2].y = 64;
|
||||
gdImageFilledPolygon(im_out, points, 3, green);
|
||||
/* Brush. A fairly wild example also involving a line style! */
|
||||
if (im_in) {
|
||||
int style[8];
|
||||
brush = gdImageCreate(8, 8);
|
||||
gdImageCopyResized(brush, im_in,
|
||||
0, 0, 0, 0,
|
||||
gdImageSX(brush), gdImageSY(brush),
|
||||
gdImageSX(im_in), gdImageSY(im_in));
|
||||
gdImageSetBrush(im_out, brush);
|
||||
/* With a style, so they won't overprint each other.
|
||||
Normally, they would, yielding a fat-brush effect. */
|
||||
style[0] = 0;
|
||||
style[1] = 0;
|
||||
style[2] = 0;
|
||||
style[3] = 0;
|
||||
style[4] = 0;
|
||||
style[5] = 0;
|
||||
style[6] = 0;
|
||||
style[7] = 1;
|
||||
gdImageSetStyle(im_out, style, 8);
|
||||
/* Draw the styled, brushed line */
|
||||
gdImageLine(im_out, 0, 127, 127, 0, gdStyledBrushed);
|
||||
}
|
||||
/* Text */
|
||||
gdImageString(im_out, gdFontGiant, 16, 16, "hi", red);
|
||||
gdImageStringUp(im_out, gdFontSmall, 32, 32, "hi", red);
|
||||
/* Make output image interlaced (allows "fade in" in some viewers,
|
||||
and in the latest web browsers) */
|
||||
gdImageInterlace(im_out, 1);
|
||||
out = fopen("demoout.gif", "wb");
|
||||
/* Write GIF */
|
||||
gdImageGif(im_out, out);
|
||||
fclose(out);
|
||||
gdImageDestroy(im_out);
|
||||
if (im_in) {
|
||||
gdImageDestroy(im_in);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,21 @@
|
|||
|
||||
#ifndef _GDFONTG_H_
|
||||
#define _GDFONTG_H_ 1
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.51 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-Misc-Fixed-Bold-R-Normal-Sans-15-140-75-75-C-90-ISO8859-2
|
||||
at Mon Jan 26 14:45:58 1998.
|
||||
The original bdf was holding following copyright:
|
||||
"Libor Skarvada, libor@informatics.muni.cz"
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontGiant;
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
|||
|
||||
#ifndef _GDFONTL_H_
|
||||
#define _GDFONTL_H_ 1
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-misc-fixed-medium-r-normal--16-140-75-75-c-80-iso8859-2
|
||||
at Tue Jan 6 19:39:27 1998.
|
||||
|
||||
The original bdf was holding following copyright:
|
||||
"Libor Skarvada, libor@informatics.muni.cz"
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontLarge;
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,20 @@
|
|||
|
||||
#ifndef _GDFONTMB_H_
|
||||
#define _GDFONTMB_H_ 1
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-misc-fixed-bold-r-normal-sans-13-94-100-100-c-70-iso8859-2
|
||||
at Thu Jan 8 13:54:57 1998.
|
||||
No copyright info was found in the original bdf.
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontMediumBold;
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,20 @@
|
|||
|
||||
#ifndef _GDFONTS_H_
|
||||
#define _GDFONTS_H_ 1
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-misc-fixed-medium-r-semicondensed-sans-12-116-75-75-c-60-iso8859-2
|
||||
at Thu Jan 8 14:13:20 1998.
|
||||
No copyright info was found in the original bdf.
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontSmall;
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,21 @@
|
|||
|
||||
#ifndef _GDFONTT_H_
|
||||
#define _GDFONTT_H_ 1
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-Misc-Fixed-Medium-R-Normal--8-80-75-75-C-50-ISO8859-2
|
||||
at Thu Jan 8 13:49:54 1998.
|
||||
The original bdf was holding following copyright:
|
||||
"Libor Skarvada, libor@informatics.muni.cz"
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontTiny;
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue