ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/gdimg.h
Revision: 2
Committed: Mon Mar 22 22:03:27 2010 UTC (9 years, 3 months ago) by gpertea
File size: 1925 byte(s)
Log Message:
added my gclib source files

Line File contents
1 #ifndef _GDIMG_
2 #define _GDIMG_
3 #include "GBase.h"
4 #include "gd.h"
5
6
7 class GDImg {
8 protected:
9 gdImagePtr img;
10 int imgW;
11 int imgH;
12 FILE* fout;
13 int currentColor;
14 int bgColor; //preallocated white by default
15 void setFile(const char* fname);
16 void setFile(FILE* f);
17 static int defaultBg;
18 public:
19 GDImg(int w=64, int h=64, const char* fname=NULL, int bg_rgb=defaultBg);
20 GDImg(int w,int h, int bg_rgb) {
21 GDImg(w,h, (const char*)NULL, bg_rgb);
22 }
23 ~GDImg();
24 void write(const char* fname=NULL); //automatically write GIF
25 void setTransparent(int cidx); // -1 means 'no transparency'
26 void setTransparent(bool v=true) {
27 setTransparent(v ? (int) bgColor : (int)-1);
28 }
29 int color(byte r, byte g, byte b);
30 int color(int rgb) {
31 return color( (byte)(rgb>>16) & 255,
32 (byte)(rgb>>8) & 255,
33 (byte)(rgb & 255)); }
34 int colorAllocate(byte r, byte g, byte b) { return color(r,g,b); }
35 int colorAllocate(int rgb) { return color(rgb); }
36 void setColorIdx(int color) { currentColor=color; } //current color for drawing operations
37 int setColor(int r, int g, int b) {
38 currentColor=this->color(r,g,b);
39 return currentColor;
40 }
41 int setColor(int rgb) {
42 currentColor=this->color(rgb);
43 return currentColor;
44 }
45 void setPixel(int x, int y, int color=-1) {
46 if (color==-1) color=currentColor;
47 gdImageSetPixel(img, x,y,color);
48 }
49 int getPixel(int x, int y) { return gdImageGetPixel(img, x, y); }
50 void setBg(int rgb);
51 void clear(int color=-1) {
52 if (color==-1) color=bgColor;
53 fillRectangle(0,0,imgW,imgH,color);
54 }
55 void line(int x1, int y1, int x2, int y2, int color=-1);
56 void rectangle(int x1, int y1, int x2, int y2, int color=-1);
57 void fillRectangle(int x1, int y1, int x2, int y2, int color=-1);
58 void fillPolygon(gdPointPtr points, int ptotal, int color=-1);
59 };
60
61 #endif