00001
00008 #ifndef __GDC2_H_
00009 #define __GDC2_H_
00010
00011 #include <stdio.h>
00012
00013
00014 #include "LgiOsDefs.h"
00015 #include "LgiInc.h"
00016 #include "LgiClass.h"
00017 #include "Progress.h"
00018 #include "GFile.h"
00019 #include "GMem.h"
00020 #include "Core.h"
00021 #include "GContainers.h"
00022
00023
00024 #ifdef WIN32
00025 #include "wingdi.h"
00026 #endif
00027 #ifndef AC_SRC_OVER
00028 #define AC_SRC_OVER 0
00029 #endif
00030 #ifndef AC_SRC_ALPHA
00031 #define AC_SRC_ALPHA 1
00032 #endif
00033 #include "GLibrary.h"
00034
00035
00036
00038 #define LGI_DEFAULT_GAMMA 1.0
00039
00040 #ifndef LGI_PI
00042 #define LGI_PI 3.141592654
00043 #endif
00044
00046 #define LGI_DegToRad(i) ((i)*LGI_PI/180)
00047
00049 #define LGI_RadToDeg(i) ((i)*180/LGI_PI)
00050
00051 #ifdef WIN32
00053 #define GDC_USE_ASM
00054 #endif
00055
00057 #define GDC_SET 0
00059 #define GDC_AND 1
00061 #define GDC_OR 2
00063 #define GDC_XOR 3
00065 #define GDC_ALPHA 4
00066 #define GDC_REMAP 5
00067 #define GDC_MAXOP 6
00068 #define GDC_CACHE_SIZE 4
00069
00070
00071 #define GDCC_MONO 0
00072 #define GDCC_GREY 1
00073 #define GDCC_INDEX 2
00074 #define GDCC_R 3
00075 #define GDCC_G 4
00076 #define GDCC_B 5
00077 #define GDCC_ALPHA 6
00078
00079
00080 #define GDC_8BIT 0
00081 #define GDC_16BIT 1
00082 #define GDC_24BIT 2
00083 #define GDC_32BIT 3
00084 #define GDC_MAXFMT 4
00085
00086
00087 #define GDC_8I 0 // 8 bit paletted
00088 #define GDC_5R6G5B 1 // 16 bit
00089 #define GDC_8B8G8B 2 // 24 bit
00090 #define GDC_8A8R8G8B 3 // 32 bit
00091 #define GDC_MAXSPACE 4
00092
00093
00094 #define GDC_PAL_CHANGE 0x1
00095 #define GDC_BITS_CHANGE 0x2
00096
00097
00098
00100 #define GDC_FILL_TO_DIFFERENT 0
00102 #define GDC_FILL_TO_BORDER 1
00104 #define GDC_FILL_NEAR 2
00105
00106
00107
00109 #define GDC_REDUCE_TYPE 0
00111 #define REDUCE_NONE 0
00113 #define REDUCE_NEAREST 1
00115 #define REDUCE_HALFTONE 2
00117 #define REDUCE_ERROR_DIFFUSION 3
00119 #define REDUCE_DL1 4
00121 #define GDC_HALFTONE_BASE_INDEX 1
00123 #define GDC_PALETTE_TYPE 2
00125 #define PALTYPE_ALLOC 0
00127 #define PALTYPE_RGB_CUBE 1
00129 #define PALTYPE_HSL 2
00131 #define GDC_PROMOTE_ON_LOAD 3
00132 #define GDC_MAX_OPTION 4
00133
00134
00135
00136 #define GDC_OWN_MEMORY 0x0001
00137 #define GDC_ON_SCREEN 0x0002
00138 #define GDC_ALPHA_CHANNEL 0x0004
00139 #define GDC_UPDATED_PALETTE 0x0008
00140
00141
00142 #define GDC_OWN_APPLICATOR 0x0001
00143 #define GDC_CACHED_APPLICATOR 0x0002
00144 #define GDC_OWN_PALETTE 0x0004
00145 #define GDC_DRAW_ON_ALPHA 0x0008
00146
00147
00148 #define GDC_RGN_NONE 0 // No clipping
00149 #define GDC_RGN_SIMPLE 1 // Single rectangle
00150 #define GDC_RGN_COMPLEX 2 // Many rectangles
00151
00152
00153 #define GDCERR_NONE 0
00154 #define GDCERR_ERROR 1
00155 #define GDCERR_CANT_SET_SCAN_WIDTH 2
00156 #define GDC_INVALIDMODE -1
00157
00158
00159 #define GDCFNT_TRANSPARENT 0x0001 // not set - SOLID
00160 #define GDCFNT_UNDERLINE 0x0002
00161
00162
00163 #define GDCPAL_JASC 1
00164 #define GDCPAL_MICROSOFT 2
00165
00166
00167 #define BMPWIDTH(bits) ((((bits)+31)/32)*4)
00168
00169
00170
00171
00190 typedef uint32 COLOUR;
00191
00193 typedef uint8 ALPHA;
00194
00195
00196
00197 #define BitWidth(bits, cropbits) ( (((bits)+(cropbits)-1)/(cropbits)) * 4 )
00198
00199 #ifdef WIN32
00200 #pragma pack(push, before_pack)
00201 #pragma pack(1)
00202 #endif
00203
00204 #if defined WIN32
00205
00206 #ifndef __BIG_ENDIAN__
00207 #define C24R 0
00208 #define C24G 1
00209 #define C24B 2
00210 #else
00211 #define C24R 2
00212 #define C24G 1
00213 #define C24B 0
00214 #endif
00215
00216 class LgiClass Pixel24
00217 {
00218 public:
00219 static int Size;
00220
00221 uchar b, g, r;
00222
00223 Pixel24 *Next() { return this + 1; }
00224 };
00225
00226 #ifndef __BIG_ENDIAN__
00227 #define C32B 0
00228 #define C32G 1
00229 #define C32R 2
00230 #define C32A 3
00231 #else
00232 #define C32B 3
00233 #define C32G 2
00234 #define C32R 1
00235 #define C32A 0
00236 #endif
00237
00238 class LgiClass Pixel32
00239 {
00240 public:
00241 static int Size;
00242
00243 uchar b, g, r, a;
00244
00245 Pixel32 *Next() { return this + 1; }
00246 };
00247
00248 #elif defined LINUX
00249
00250 #ifndef __BIG_ENDIAN__
00251 #define C24B 0
00252 #define C24G 1
00253 #define C24R 2
00254 #else
00255 #define C24B 2
00256 #define C24G 1
00257 #define C24R 0
00258 #endif
00259
00260 class LgiClass Pixel24
00261 {
00262 public:
00263 static int Size;
00264
00265 uchar b, g, r;
00266
00267 Pixel24 *Next() { return (Pixel24*) ((char*)this + Size); }
00268 };
00269
00270 #ifndef __BIG_ENDIAN__
00271 #define C32B 0
00272 #define C32G 1
00273 #define C32R 2
00274 #define C32A 3
00275 #else
00276 #define C32B 3
00277 #define C32G 2
00278 #define C32R 1
00279 #define C32A 0
00280 #endif
00281
00282 class LgiClass Pixel32
00283 {
00284 public:
00285 static int Size;
00286
00287 uchar b, g, r, a;
00288
00289 Pixel32 *Next() { return this + 1; }
00290 };
00291
00292 #elif defined BEOS
00293
00294 #ifndef __BIG_ENDIAN__
00295 #define C24B 0
00296 #define C24G 1
00297 #define C24R 2
00298 #else
00299 #define C24B 2
00300 #define C24G 1
00301 #define C24R 0
00302 #endif
00303
00304 class LgiClass Pixel24
00305 {
00306 public:
00307 static int Size;
00308
00309 uchar b, g, r;
00310
00311 Pixel24 *Next() { return this + 1; }
00312 };
00313
00314 #ifndef __BIG_ENDIAN__
00315 #define C32B 0
00316 #define C32G 1
00317 #define C32R 2
00318 #define C32A 3
00319 #else
00320 #define C32B 3
00321 #define C32G 2
00322 #define C32R 1
00323 #define C32A 0
00324 #endif
00325
00326 class LgiClass Pixel32
00327 {
00328 public:
00329 static int Size;
00330
00331 uchar b, g, r, a;
00332
00333 Pixel32 *Next() { return this + 1; }
00334 };
00335
00336 #elif defined MAC
00337
00338 #ifdef __BIG_ENDIAN__
00339 #define C24B 2
00340 #define C24G 1
00341 #define C24R 0
00342 #else
00343 #define C24B 0
00344 #define C24G 1
00345 #define C24R 2
00346 #endif
00347
00348 class LgiClass Pixel24
00349 {
00350 public:
00351 static int Size;
00352
00353 uchar r, g, b;
00354
00355 Pixel24 *Next() { return this + 1; }
00356 };
00357
00358
00359 #ifdef __BIG_ENDIAN__
00360 #define C32A 0
00361 #define C32B 1
00362 #define C32G 2
00363 #define C32R 3
00364 #else
00365 #define C32A 3
00366 #define C32B 2
00367 #define C32G 1
00368 #define C32R 0
00369 #endif
00370
00371 class LgiClass Pixel32
00372 {
00373 public:
00374 static int Size;
00375 uchar r, g, b, a;
00376
00377 Pixel32 *Next() { return this + 1; }
00378 };
00379
00380 #endif
00381
00383 #define Rgb15(r, g, b) ( ((r&0xF8)<<7) | ((g&0xF8)<<2) | ((b&0xF8)>>3))
00384 #define Rgb32To15(c32) ( ((c32&0xF8)>>3) | ((c32&0xF800)>>6) | ((c32&0xF80000)>>9) )
00385 #define Rgb24To15(c24) ( (B24(c24)>>3) | ((G24(c24)<<2)&0x3E0) | ((R24(c24)<<7)&0x7C00) )
00386 #define Rgb16To15(c16) ( ((c16&0xFFC0)>>1) | (c16&0x1F) )
00388 #define R15(c15) ( (uchar) ((c15>>10)&0x1F) )
00390 #define G15(c15) ( (uchar) ((c15>>5)&0x1F) )
00392 #define B15(c15) ( (uchar) ((c15)&0x1F) )
00393
00394 #define Rc15(c) ( (((c) & 0x7C00) >> 7) | (((c) & 0x7C00) >> 12) )
00395 #define Gc15(c) ( (((c) & 0x03E0) >> 2) | (((c) & 0x03E0) >> 7) )
00396 #define Bc15(c) ( (((c) & 0x001F) << 3) | (((c) & 0x001F) >> 2) )
00397
00399 #define Rgb16(r, g, b) ( ((r&0xF8)<<8) | ((g&0xFC)<<3) | ((b&0xF8)>>3))
00400 #define Rgb32To16(c32) ( ((c32&0xF8)>>3) | ((c32&0xFC00)>>5) | ((c32&0xF80000)>>8) )
00401 #define Rgb24To16(c24) ( (B24(c24)>>3) | ((G24(c24)<<3)&0x7E0) | ((R24(c24)<<8)&0xF800) )
00402 #define Rgb15To16(c15) ( ((c15&0x7FE0)<<1) | (c15&0x1F) )
00404 #define R16(c16) ( (uchar) ((c16>>11)&0x1F) )
00406 #define G16(c16) ( (uchar) ((c16>>5)&0x3F) )
00408 #define B16(c16) ( (uchar) ((c16)&0x1F) )
00409
00410 #define Rc16(c) ( (((c) & 0xF800) >> 8) | (((c) & 0xF800) >> 13) )
00411 #define Gc16(c) ( (((c) & 0x07E0) >> 3) | (((c) & 0x07E0) >> 9) )
00412 #define Bc16(c) ( (((c) & 0x001F) << 3) | (((c) & 0x001F) >> 2) )
00413
00415 #define R24(c24) ( ((c24)>>(C24R*8)) & 0xff )
00417 #define G24(c24) ( ((c24)>>(C24G*8)) & 0xff )
00419 #define B24(c24) ( ((c24)>>(C24B*8)) & 0xff )
00420
00422 #define Rgb24(r, g, b) ( (((r)&0xFF) << (C24R*8)) | (((g)&0xFF) << (C24G*8)) | (((b)&0xFF) << (C24B*8)) )
00423 #define Rgb32To24(c32) Rgb24(R32(c32), G32(c32), B32(c32))
00424 #define Rgb15To24(c15) ( ((c15&0x7C00)>>7) | ((c15&0x3E0)<<6) | ((c15&0x1F)<<19) )
00425 #define Rgb16To24(c16) ( ((c16&0xF800)>>8) | ((c16&0x7E0)<<5) | ((c16&0x1F)<<19) )
00426
00427
00428
00429
00430
00431
00432
00434 #define R32(c32) ( (uchar) (c32 >> (C32R << 3)) )
00436 #define G32(c32) ( (uchar) (c32 >> (C32G << 3)) )
00438 #define B32(c32) ( (uchar) (c32 >> (C32B << 3)) )
00440 #define A32(c32) ( (uchar) (c32 >> (C32A << 3)) )
00441
00442 #define RgbPreMul(c, a) ( Div255Lut[(c)*a] )
00443 #define Rgb32(r, g, b) ( (((r)&0xFF)<<(C32R<<3)) | (((g)&0xFF)<<(C32G<<3)) | (((b)&0xFF)<<(C32B<<3)) | (0xFF<<(C32A<<3)) )
00444 #define Rgba32(r, g, b, a) ( (((r)&0xFF)<<(C32R<<3)) | (((g)&0xFF)<<(C32G<<3)) | (((b)&0xFF)<<(C32B<<3)) | (((a)&0xFF)<<(C32A<<3)) )
00445 #define Rgbpa32(r, g, b, a) ( (RgbPreMul(r, a)<<(C32R<<3)) | (RgbPreMul(g, a)<<(C32G<<3)) | (RgbPreMul(b, a)<<(C32B<<3)) | ((a&0xFF)<<(C32A<<3)) )
00446 #define Rgb24To32(c24) Rgba32( R24(c24), G24(c24), B24(c24), 255 )
00447 #define Rgb15To32(c15) ( ((c15&0x7C00)<<9) | ((c15&0x3E0)<<6) | ((c15&0x1F)<<3) | (0xFF<<(C32A*8)) )
00448 #define Rgb16To32(c16) ( ((c16&0xF800)<<8) | ((c16&0x7E0)<<5) | ((c16&0x1F)<<3) | (0xFF<<(C32A*8)) )
00449
00450
00451
00459 #define Hls32(h, l, s) ( ((h)<<16) | ((l)<<8) | (s) )
00462 #define H32(c) ( ((c)>>16)&0xFFFF )
00465 #define L32(c) ( ((c)>>8)&0xFF )
00468 #define S32(c) ( (c)&0xFF )
00471 #define HUE_UNDEFINED 1024
00474 #define HlsIsUndefined(Hls) (H32(Hls) == HUE_UNDEFINED)
00475
00476
00477 #define Div255Lut (GdcDevice::GetInst()->GetDiv255())
00478
00481 LgiFunc COLOUR RgbToHls(COLOUR Rgb24);
00484 LgiFunc COLOUR HlsToRgb(COLOUR Hsl32);
00485
00486 #ifdef WIN32
00487 #pragma pack(pop, before_pack)
00488 #endif
00489
00490
00491 class GFilter;
00492 class GSurface;
00493
00494 #include "GRect.h"
00495 #include "GFont.h"
00496
00498 class LgiClass GdcPt2
00499 {
00500 public:
00501 int x, y;
00502
00503 GdcPt2(int Ix = 0, int Iy = 0)
00504 {
00505 x = Ix;
00506 y = Iy;
00507 }
00508
00509 GdcPt2(const GdcPt2 &p)
00510 {
00511 x = p.x;
00512 y = p.y;
00513 }
00514
00515 bool Inside(GRect &r)
00516 {
00517 return (x >= r.x1) AND
00518 (x <= r.x2) AND
00519 (y >= r.y1) AND
00520 (y <= r.y2);
00521 }
00522 };
00523
00525 class LgiClass GdcPt3
00526 {
00527 public:
00528 int x, y, z;
00529 };
00530
00531 #include "GColour.h"
00532
00533 class LgiClass GBmpMem
00534 {
00535 public:
00536 uchar *Base;
00537 int x, y, Bits, Line;
00538 int Flags;
00539
00540 GBmpMem();
00541 ~GBmpMem();
00542 };
00543
00544
00545 #define GAPP_ALPHA_A 1
00546 #define GAPP_ALPHA_PAL 2
00547 #define GAPP_BACKGROUND 3
00548 #define GAPP_ANGLE 4
00549 #define GAPP_BOUNDS 5
00550
00556 class LgiClass GApplicator
00557 {
00558 protected:
00559 GBmpMem *Dest;
00560 GBmpMem *Alpha;
00561 GPalette *Pal;
00562 int Op;
00563
00564 public:
00565 COLOUR c;
00566
00567 GApplicator() { c = 0; }
00568 GApplicator(COLOUR Colour) { c = Colour; }
00569 virtual ~GApplicator() { }
00570
00572 virtual int GetVar(int Var) { return 0; }
00574 virtual int SetVar(int Var, int Value) { return 0; }
00575
00577 void SetOp(int o) { Op = o; }
00579 int GetOp() { return Op; }
00581 int GetBits() { return (Dest) ? Dest->Bits : 0; }
00583 int GetFlags() { return (Dest) ? Dest->Flags : 0; }
00585 GPalette *GetPal() { return Pal; }
00586
00588 virtual bool SetSurface(GBmpMem *d, GPalette *p = 0, GBmpMem *a = 0) = 0;
00590 virtual void SetPtr(int x, int y) = 0;
00592 virtual void IncX() = 0;
00594 virtual void IncY() = 0;
00596 virtual void IncPtr(int X, int Y) = 0;
00597
00599 virtual void Set() = 0;
00601 virtual COLOUR Get() = 0;
00603 virtual void VLine(int height) = 0;
00605 virtual void Rectangle(int x, int y) = 0;
00607 virtual bool Blt(GBmpMem *Src, GPalette *SPal, GBmpMem *SrcAlpha = 0) = 0;
00608 };
00609
00611 class LgiClass GApplicatorFactory
00612 {
00613 public:
00614 GApplicatorFactory();
00615 virtual ~GApplicatorFactory();
00616
00618 static GApplicator *NewApp(int Bits, int Op);
00619 virtual GApplicator *Create(int Bits, int Op) { return NULL; }
00620 };
00621
00622 class LgiClass GApp15 : public GApplicatorFactory
00623 {
00624 public:
00625 GApplicator *Create(int Bits, int Op);
00626 };
00627
00628 class LgiClass GApp16 : public GApplicatorFactory
00629 {
00630 public:
00631 GApplicator *Create(int Bits, int Op);
00632 };
00633
00634 class LgiClass GApp24 : public GApplicatorFactory
00635 {
00636 public:
00637 GApplicator *Create(int Bits, int Op);
00638 };
00639
00640 class LgiClass GApp32 : public GApplicatorFactory
00641 {
00642 public:
00643 GApplicator *Create(int Bits, int Op);
00644 };
00645
00646 class LgiClass GApp8 : public GApplicatorFactory
00647 {
00648 public:
00649 GApplicator *Create(int Bits, int Op);
00650 };
00651
00652 class GAlphaFactory : public GApplicatorFactory
00653 {
00654 public:
00655 GApplicator *Create(int Bits, int Op);
00656 };
00657
00658 #define OrgX(x) x -= OriginX
00659 #define OrgY(y) y -= OriginY
00660 #define OrgXy(x, y) x -= OriginX; y -= OriginY
00661 #define OrgPt(p) p.x -= OriginX; p.y -= OriginY
00662 #define OrgRgn(r) r.Offset(-OriginX, -OriginY)
00663
00665 class LgiClass GSurface
00666 {
00667 friend class GFilter;
00668 friend class GView;
00669 friend class GWindow;
00670
00671 void Init();
00672
00673 protected:
00674 int Flags;
00675 int PrevOp;
00676 GRect Clip;
00677 GBmpMem *pMem;
00678 GSurface *pAlphaDC;
00679 GPalette *pPalette;
00680 GApplicator *pApp;
00681 GApplicator *pAppCache[GDC_CACHE_SIZE];
00682 int OriginX, OriginY;
00683
00684
00685 GApplicator *CreateApplicator(int Op = GDC_SET, int Bits = 0);
00686 uint32 LineBits;
00687 uint32 LineMask;
00688 uint32 LineReset;
00689
00690 #if WIN32NATIVE
00691 OsPainter hDC;
00692 OsBitmap hBmp;
00693 #elif defined __GTK_H__
00694
00695 Gtk::cairo_t *Cairo;
00696 #endif
00697
00698 public:
00699 GSurface();
00700 GSurface(GSurface *pDC);
00701 virtual ~GSurface();
00702
00703
00704 #if defined(__GTK_H__)
00705
00707 virtual Gtk::GdkDrawable *GetDrawable() { return 0; }
00708
00709
00710
00711
00712
00715 virtual Gtk::cairo_t *GetCairo() { return Cairo; }
00716
00718 virtual GdcPt2 GetSize() = 0;
00719
00720 #elif defined(WIN32)
00721
00722 virtual HDC StartDC() { return hDC; }
00723 virtual void EndDC() {}
00724
00725 #elif defined MAC
00726
00727 virtual CGColorSpaceRef GetColourSpace() { return 0; }
00728
00729 #endif
00730
00731 virtual OsBitmap GetBitmap();
00732 virtual OsPainter Handle();
00733 virtual void SetClient(GRect *c) { }
00734
00735
00736 virtual bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false) { return false; }
00737 virtual void Update(int Flags) {}
00738
00739
00741 virtual bool HasAlpha() { return pAlphaDC != 0; }
00743 virtual bool HasAlpha(bool b);
00745 bool DrawOnAlpha() { return ((Flags & GDC_DRAW_ON_ALPHA) != 0); }
00747 bool DrawOnAlpha(bool Draw);
00749 GSurface *AlphaDC() { return pAlphaDC; }
00750
00751
00752 virtual bool Applicator(GApplicator *pApp);
00753 virtual GApplicator *Applicator();
00754
00755
00756 virtual GPalette *Palette();
00757 virtual void Palette(GPalette *pPal, bool bOwnIt = true);
00758
00759
00760 virtual GRect ClipRgn(GRect *Rgn);
00761 virtual GRect ClipRgn();
00762
00764 virtual COLOUR Colour() { return pApp->c; }
00766 virtual COLOUR Colour
00767 (
00769 COLOUR c,
00771 int Bits = 0
00772 );
00774 virtual GColour Colour
00775 (
00777 GColour c
00778 );
00780 virtual int Op() { return (pApp) ? pApp->GetOp() : 0; }
00783 virtual int Op(int Op);
00785 virtual int X() { return (pMem) ? pMem->x : 0; }
00787 virtual int Y() { return (pMem) ? pMem->y : 0; }
00789 virtual int GetLine() { return (pMem) ? pMem->Line : 0; }
00791 virtual int DpiX() { return 100; }
00793 virtual int DpiY() { return 100; }
00795 virtual int GetBits() { return (pMem) ? pMem->Bits : 0; }
00797 virtual int PixelSize() { return GetBits() == 24 ? Pixel24::Size : GetBits() >> 3; }
00798 virtual int GetFlags() { return Flags; }
00800 virtual class GScreenDC *IsScreen() { return 0; }
00802 virtual bool IsPrint() { return false; }
00804 virtual uchar *operator[](int y);
00805
00807 virtual void GetOrigin(int &x, int &y) { x = OriginX; y = OriginY; }
00809 virtual void SetOrigin(int x, int y) { OriginX = x; OriginY = y; }
00810
00812 virtual void Set(int x, int y);
00814 virtual COLOUR Get(int x, int y);
00815
00816
00817
00819 virtual void HLine(int x1, int x2, int y);
00821 virtual void VLine(int x, int y1, int y2);
00823 virtual void Line(int x1, int y1, int x2, int y2);
00824
00825 virtual uint LineStyle(uint32 Bits, uint32 Reset = 0x80000000)
00826 {
00827 uint32 B = LineBits;
00828 LineBits = Bits;
00829 LineMask = LineReset = Reset;
00830 return B;
00831 }
00832 virtual uint LineStyle() { return LineBits; }
00833
00834
00835
00837 virtual void Circle(double cx, double cy, double radius);
00839 virtual void FilledCircle(double cx, double cy, double radius);
00841 virtual void Arc(double cx, double cy, double radius, double start, double end);
00843 virtual void FilledArc(double cx, double cy, double radius, double start, double end);
00845 virtual void Ellipse(double cx, double cy, double x, double y);
00847 virtual void FilledEllipse(double cx, double cy, double x, double y);
00848
00849
00850
00852 virtual void Box(int x1, int y1, int x2, int y2);
00854 virtual void Box
00855 (
00857 GRect *a = NULL
00858 );
00860 virtual void Rectangle(int x1, int y1, int x2, int y2);
00862 virtual void Rectangle
00863 (
00865 GRect *a = NULL
00866 );
00868 virtual void Blt
00869 (
00871 int x,
00873 int y,
00875 GSurface *Src,
00877 GRect *a = NULL
00878 );
00880 virtual void StretchBlt(GRect *d, GSurface *Src, GRect *s);
00881
00882
00883
00885 virtual void Polygon(int Points, GdcPt2 *Data);
00887 virtual void Bezier(int Threshold, GdcPt2 *Pt);
00889 virtual void FloodFill
00890 (
00892 int x,
00894 int y,
00896 int Mode,
00898 COLOUR Border = 0,
00900 GRect *Bounds = NULL
00901 );
00902 };
00903
00908 class LgiClass GScreenDC : public GSurface
00909 {
00910 class GScreenPrivate *d;
00911
00912 public:
00913 GScreenDC();
00914 virtual ~GScreenDC();
00915
00916
00917 #if WIN32NATIVE
00918
00919 GScreenDC(GViewI *view);
00920 GScreenDC(HWND hwnd);
00921 GScreenDC(HDC hdc, HWND hwnd, bool Release = false);
00922 GScreenDC(HBITMAP hBmp, int Sx, int Sy);
00923
00924 bool Create(HDC hdc);
00925 void SetSize(int x, int y);
00926
00927 #else
00928
00930 GScreenDC(GView *view, void *Param = 0);
00931
00932 #if defined MAC
00933
00934 GScreenDC(GWindow *wnd, void *Param = 0);
00935 GRect GetPos();
00936
00937 #else // GTK
00938
00940 GScreenDC(int x, int y, int bits);
00942 GScreenDC(Gtk::GdkDrawable *Drawable);
00944 GScreenDC(OsView View);
00945
00946 Gtk::GdkDrawable *GetDrawable();
00947 Gtk::cairo_t *GetCairo();
00948
00949 GdcPt2 GetSize();
00950
00951 #endif
00952
00953 GView *GetView();
00954 OsPainter Handle();
00955 int GetFlags();
00956 GRect *GetClient();
00957
00958 #endif
00959
00960
00961 void GetOrigin(int &x, int &y);
00962 void SetOrigin(int x, int y);
00963
00964 GRect ClipRgn();
00965 GRect ClipRgn(GRect *Rgn);
00966 void SetClient(GRect *c);
00967
00968 COLOUR Colour();
00969 COLOUR Colour(COLOUR c, int Bits = 0);
00970 GColour Colour(GColour c);
00971
00972 int Op();
00973 int Op(int Op);
00974
00975 int X();
00976 int Y();
00977
00978 GPalette *Palette();
00979 void Palette(GPalette *pPal, bool bOwnIt = true);
00980
00981 uint LineStyle();
00982 uint LineStyle(uint Bits, uint32 Reset = 0x80000000);
00983
00984 int GetBits();
00985 GScreenDC *IsScreen() { return this; }
00986 uchar *operator[](int y) { return NULL; }
00987
00988
00989 void Set(int x, int y);
00990 COLOUR Get(int x, int y);
00991 void HLine(int x1, int x2, int y);
00992 void VLine(int x, int y1, int y2);
00993 void Line(int x1, int y1, int x2, int y2);
00994 void Circle(double cx, double cy, double radius);
00995 void FilledCircle(double cx, double cy, double radius);
00996 void Arc(double cx, double cy, double radius, double start, double end);
00997 void FilledArc(double cx, double cy, double radius, double start, double end);
00998 void Ellipse(double cx, double cy, double x, double y);
00999 void FilledEllipse(double cx, double cy, double x, double y);
01000 void Box(int x1, int y1, int x2, int y2);
01001 void Box(GRect *a);
01002 void Rectangle(int x1, int y1, int x2, int y2);
01003 void Rectangle(GRect *a = NULL);
01004 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01005 void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
01006 void Polygon(int Points, GdcPt2 *Data);
01007 void Bezier(int Threshold, GdcPt2 *Pt);
01008 void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
01009 };
01010
01013 class GBlitRegions
01014 {
01015
01016 GRect SrcBounds;
01017 GRect DstBounds;
01018
01019
01020 GRect SrcBlt;
01021 GRect DstBlt;
01022
01023 public:
01025 GRect SrcClip;
01027 GRect DstClip;
01028
01030 GBlitRegions
01031 (
01033 GSurface *Dst,
01035 int x1,
01037 int y1,
01039 GSurface *Src,
01041 GRect *SrcRc = 0
01042 )
01043 {
01044
01045 if (Src) SrcBounds.Set(0, 0, Src->X()-1, Src->Y()-1);
01046 else SrcBounds.ZOff(-1, -1);
01047 if (Dst) DstBounds.Set(0, 0, Dst->X()-1, Dst->Y()-1);
01048 else DstBounds.ZOff(-1, -1);
01049
01050
01051 if (SrcRc)
01052 {
01053 SrcBlt = *SrcRc;
01054 SrcBlt.Bound(&SrcBounds);
01055 }
01056 else SrcBlt = SrcBounds;
01057
01058 DstBlt = SrcBlt;
01059 DstBlt.Offset(x1-DstBlt.x1, y1-DstBlt.y1);
01060
01061
01062 DstClip = DstBlt;
01063 DstClip.Bound(&DstBounds);
01064
01065
01066 SrcClip = SrcBlt;
01067 SrcClip.x1 += DstClip.x1 - DstBlt.x1;
01068 SrcClip.y1 += DstClip.y1 - DstBlt.y1;
01069 SrcClip.x2 -= DstBlt.x2 - DstClip.x2;
01070 SrcClip.y2 -= DstBlt.y2 - DstClip.y2;
01071 }
01072
01074 bool Valid()
01075 {
01076 return DstClip.Valid() && SrcClip.Valid();
01077 }
01078
01079 void Dump()
01080 {
01081 printf("SrcBounds: %s\n", SrcBounds.GetStr());
01082 printf("DstBounds: %s\n", DstBounds.GetStr());
01083
01084 printf("SrcBlt: %s\n", SrcBlt.GetStr());
01085 printf("DstBlt: %s\n", DstBlt.GetStr());
01086
01087 printf("SrcClip: %s\n", SrcClip.GetStr());
01088 printf("DstClip: %s\n", DstClip.GetStr());
01089 }
01090 };
01091
01092 #ifdef MAC
01093 class CGImg
01094 {
01095 class CGImgPriv *d;
01096
01097 void Create(int x, int y, int Bits, int Line, uchar *data, uchar *palette, GRect *r);
01098
01099 public:
01100 CGImg(int x, int y, int Bits, int Line, uchar *data, uchar *palette, GRect *r);
01101 CGImg(GSurface *pDC);
01102 ~CGImg();
01103
01104 operator CGImageRef();
01105 };
01106 #endif
01107
01112 class LgiClass GMemDC : public GSurface
01113 {
01114 protected:
01115 class GMemDCPrivate *d;
01116
01117 #if defined WIN32
01118 PBITMAPINFO GetInfo();
01119 #endif
01120
01121 public:
01123 GMemDC
01124 (
01126 int x = 0,
01128 int y = 0,
01130 int bits = 0
01131 );
01132 GMemDC(GSurface *pDC);
01133 virtual ~GMemDC();
01134
01135 #if WIN32NATIVE
01136
01137 HDC StartDC();
01138 void EndDC();
01139 void Update(int Flags);
01140 void UpsideDown(bool upsidedown);
01141
01142
01143
01144 GRect ClipRgn(GRect *Rgn);
01145
01146 #else
01147
01148 GRect ClipRgn() { return Clip; }
01149
01150 #if defined MAC
01151
01152 OsPainter Handle();
01153 OsBitmap GetBitmap();
01154 CGColorSpaceRef GetColourSpace();
01155 CGImg *GetImg(GRect *Sub = 0);
01156 GRect ClipRgn(GRect *Rgn);
01157
01158 #else // GTK
01159
01160 Gtk::GdkImage *GetImage();
01161 GdcPt2 GetSize();
01162 Gtk::cairo_t *GetCairo();
01163
01164 #endif
01165
01166 #endif
01167
01168 void SetClient(GRect *c);
01169
01171 bool Lock();
01176 bool Unlock();
01177
01178 void SetOrigin(int x, int y);
01179 void Empty();
01180
01181 bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false);
01182 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01183 void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
01184
01185 void HLine(int x1, int x2, int y, COLOUR a, COLOUR b);
01186 void VLine(int x, int y1, int y2, COLOUR a, COLOUR b);
01187 };
01188
01194 class LgiClass GPrintDC
01195 #if defined WIN32
01196 : public GScreenDC
01197 #else
01198 : public GSurface
01199 #endif
01200 {
01201 #ifdef __GTK_H__
01202 friend class PrintPainter;
01203 double Xc(int x);
01204 double Yc(int y);
01205 #endif
01206
01207 class GPrintDCPrivate *d;
01208
01209 public:
01210 GPrintDC(void *Handle, const char *PrintJobName);
01211 ~GPrintDC();
01212
01213 bool IsPrint() { return true; }
01214
01215 int X();
01216 int Y();
01217 int GetBits();
01218
01220 int DpiX();
01221
01223 int DpiY();
01224
01226 bool StartPage();
01228 void EndPage();
01229
01230 #if defined __GTK_H__
01231
01232 OsPainter Handle();
01233 COLOUR Colour();
01234 COLOUR Colour(COLOUR c, int Bits = 0);
01235 GColour Colour(GColour c);
01236 GdcPt2 GetSize() { return GdcPt2(X(), Y()); }
01237
01238 void Set(int x, int y);
01239 COLOUR Get(int x, int y);
01240 void HLine(int x1, int x2, int y);
01241 void VLine(int x, int y1, int y2);
01242 void Line(int x1, int y1, int x2, int y2);
01243 void Circle(double cx, double cy, double radius);
01244 void FilledCircle(double cx, double cy, double radius);
01245 void Arc(double cx, double cy, double radius, double start, double end);
01246 void FilledArc(double cx, double cy, double radius, double start, double end);
01247 void Ellipse(double cx, double cy, double x, double y);
01248 void FilledEllipse(double cx, double cy, double x, double y);
01249 void Box(int x1, int y1, int x2, int y2);
01250 void Box(GRect *a = NULL);
01251 void Rectangle(int x1, int y1, int x2, int y2);
01252 void Rectangle(GRect *a = NULL);
01253 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01254 void StretchBlt(GRect *d, GSurface *Src, GRect *s);
01255 void Polygon(int Points, GdcPt2 *Data);
01256 void Bezier(int Threshold, GdcPt2 *Pt);
01257 void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
01258
01259 #endif
01260
01261 };
01262
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347 class LgiClass GGlobalColour
01348 {
01349 class GGlobalColourPrivate *d;
01350
01351 public:
01352 GGlobalColour();
01353 ~GGlobalColour();
01354
01355
01356 COLOUR AddColour(COLOUR c24);
01357 bool AddBitmap(GSurface *pDC);
01358 bool AddBitmap(GImageList *il);
01359
01360
01361 bool MakeGlobalPalette();
01362
01363
01364
01365 GPalette *GetPalette();
01366
01367
01368 COLOUR GetColour(COLOUR c24);
01369 bool RemapBitmap(GSurface *pDC);
01370 };
01371
01372 #ifdef WIN32
01373 typedef int (__stdcall *MsImg32_AlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
01374 #endif
01375
01377 class LgiClass GdcDevice
01378 {
01379 friend class GScreenDC;
01380 friend class GImageList;
01381
01382 static GdcDevice *pInstance;
01383 class GdcDevicePrivate *d;
01384
01385 #ifdef WIN32
01386 MsImg32_AlphaBlend AlphaBlend;
01387 #endif
01388
01389 public:
01390 GdcDevice();
01391 ~GdcDevice();
01392 static GdcDevice *GetInst() { return pInstance; }
01393
01395 int GetBits();
01397 int X();
01399 int Y();
01400
01401 GGlobalColour *GetGlobalColour();
01402
01404 int GetOption(int Opt);
01406 int SetOption(int Opt, int Value);
01407
01409 ulong *GetCharSquares();
01411 uchar *GetDiv255();
01412
01413
01414 void SetGamma(double Gamma);
01415 double GetGamma();
01416
01417
01418 void SetSystemPalette(int Start, int Size, GPalette *Pal);
01419 GPalette *GetSystemPalette();
01420 void SetColourPaletteType(int Type);
01421 COLOUR GetColour(COLOUR Rgb24, GSurface *pDC = NULL);
01422 };
01423
01435 class LgiClass GInlineBmp
01436 {
01437 public:
01439 int X;
01441 int Y;
01443 int Bits;
01445 uint32 *Data;
01446
01448 GSurface *Create();
01449 };
01450
01451
01452 #include "GFilter.h"
01453
01454
01455 #define GdcD GdcDevice::GetInst()
01456
01458 LgiFunc GSurface *ConvertDC
01459 (
01461 GSurface *pDC,
01463 int Bits
01464 );
01465
01481 LgiFunc GSurface *LoadDC
01482 (
01484 char *Name,
01486 bool UseOSLoader = true
01487 );
01488
01490 LgiFunc bool WriteDC(char *Name, GSurface *pDC);
01491
01493 LgiFunc COLOUR CBit(int DstBits, COLOUR c, int SrcBits = 24, GPalette *Pal = 0);
01494
01495 #ifdef __cplusplus
01497 LgiClass GColour GdcMixColour(GColour a, GColour b, float HowMuchA = 0.5);
01498 #endif
01499
01501 LgiFunc COLOUR GdcMixColour(COLOUR a, COLOUR b, float HowMuchA = 0.5);
01502
01504 LgiFunc COLOUR GdcGreyScale(COLOUR c, int Bits = 24);
01505
01507 enum GColourReducePalette
01508 {
01509 CR_PAL_NONE = -1,
01510 CR_PAL_CUBE = 0,
01511 CR_PAL_OPT,
01512 CR_PAL_FILE
01513 };
01514
01516 enum GColourReduceMatch
01517 {
01518 CR_MATCH_NONE = -1,
01519 CR_MATCH_NEAR = 0,
01520 CR_MATCH_HALFTONE,
01521 CR_MATCH_ERROR
01522 };
01523
01525 class GReduceOptions
01526 {
01527 public:
01529 GColourReducePalette PalType;
01530
01532 GColourReduceMatch MatchType;
01533
01535 int Colours;
01536
01538 GPalette *Palette;
01539
01540 GReduceOptions()
01541 {
01542 Palette = 0;
01543 Colours = 256;
01544 PalType = CR_PAL_NONE;
01545 MatchType = CR_MATCH_NONE;
01546 }
01547 };
01548
01550 LgiFunc bool GReduceBitDepth(GSurface *pDC, int Bits, GPalette *Pal = 0, GReduceOptions *Reduce = 0);
01551
01552 struct GColourStop
01553 {
01554 COLOUR Colour;
01555 double Pos;
01556 };
01557
01559 LgiFunc void LgiFillGradient(GSurface *pDC, GRect &r, bool Vert, GArray<GColourStop> &Stops);
01560
01561 #ifdef WIN32
01563 LgiFunc void LgiDrawIcon(GSurface *pDC, int Dx, int Dy, HICON ico);
01564 #endif
01565
01566 #endif