ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/gdimg.h
Revision: 264
Committed: Mon Aug 27 18:21:11 2012 UTC (6 years, 9 months ago) by gpertea
File size: 2038 byte(s)
Log Message:
minor refactoring etc

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
20 void init(int w=64, int h=64, const char* fname=NULL, int bg_rgb=defaultBg);
21 GDImg(int w=64, int h=64, const char* fname=NULL, int bg_rgb=defaultBg) {
22 init(w,h, fname, bg_rgb);
23 }
24 GDImg(int w,int h, int bg_rgb) {
25 init(w,h, (const char*)NULL, bg_rgb);
26 }
27 ~GDImg();
28 void write(const char* fname=NULL); //automatically write GIF
29 void setTransparent(int cidx); // -1 means 'no transparency'
30 void setTransparent(bool v=true) {
31 setTransparent(v ? (int) bgColor : (int)-1);
32 }
33 int color(byte r, byte g, byte b);
34 int color(int rgb) {
35 return color( (byte)(rgb>>16) & 255,
36 (byte)(rgb>>8) & 255,
37 (byte)(rgb & 255)); }
38 int colorAllocate(byte r, byte g, byte b) { return color(r,g,b); }
39 int colorAllocate(int rgb) { return color(rgb); }
40 void setColorIdx(int color) { currentColor=color; } //current color for drawing operations
41 int setColor(int r, int g, int b) {
42 currentColor=this->color(r,g,b);
43 return currentColor;
44 }
45 int setColor(int rgb) {
46 currentColor=this->color(rgb);
47 return currentColor;
48 }
49 void setPixel(int x, int y, int color=-1) {
50 if (color==-1) color=currentColor;
51 gdImageSetPixel(img, x,y,color);
52 }
53 int getPixel(int x, int y) { return gdImageGetPixel(img, x, y); }
54 void setBg(int rgb);
55 void clear(int color=-1) {
56 if (color==-1) color=bgColor;
57 fillRectangle(0,0,imgW,imgH,color);
58 }
59 void line(int x1, int y1, int x2, int y2, int color=-1);
60 void rectangle(int x1, int y1, int x2, int y2, int color=-1);
61 void fillRectangle(int x1, int y1, int x2, int y2, int color=-1);
62 void fillPolygon(gdPointPtr points, int ptotal, int color=-1);
63 };
64
65 #endif