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 #ifdef WIN32
00532 #pragma pack(push, before_pack)
00533 #pragma pack(1)
00534 #endif
00535
00537 class LgiClass GdcRGB
00538 {
00539 public:
00540 uchar R, G, B;
00541 #ifndef MAC
00542 uchar Flags;
00543 #endif
00544
00545 void Set(uchar r, uchar g, uchar b, uchar f = 0)
00546 {
00547 R = r;
00548 G = g;
00549 B = b;
00550 #ifndef MAC
00551 Flags = f;
00552 #endif
00553 }
00554 };
00555
00556 #ifdef WIN32
00557 #pragma pack(pop, before_pack)
00558 #endif
00559
00561 class LgiClass GPalette
00562 {
00563 protected:
00564 #if WIN32NATIVE
00565 HPALETTE hPal;
00566 LOGPALETTE *Data;
00567 #else
00568 int Size;
00569 GdcRGB *Data;
00570 #endif
00571 uchar *Lut;
00572
00573 public:
00574 GPalette();
00575 virtual ~GPalette();
00576
00577 #if WIN32NATIVE
00578 HPALETTE Handle() { return hPal; }
00579 #endif
00580
00581 GPalette(GPalette *pPal);
00582 GPalette(uchar *pPal, int s = 256);
00583 void Set(GPalette *pPal);
00584 void Set(uchar *pPal, int s = 256);
00585
00586 int GetSize();
00587 GdcRGB *operator [](int i);
00588 bool Update();
00589 bool SetSize(int s = 256);
00590 void SwapRAndB();
00591 int MatchRgb(COLOUR Rgb);
00592 void CreateCube();
00593 void CreateGreyScale();
00594 bool Load(GFile &F);
00595 bool Save(GFile &F, int Format);
00596 uchar *MakeLut(int Bits = 16);
00597
00598 bool operator ==(GPalette &p);
00599 bool operator !=(GPalette &p);
00600 };
00601
00602 class LgiClass GBmpMem
00603 {
00604 public:
00605 uchar *Base;
00606 int x, y, Bits, Line;
00607 int Flags;
00608
00609 GBmpMem();
00610 ~GBmpMem();
00611 };
00612
00613
00614 #define GAPP_ALPHA_A 1
00615 #define GAPP_ALPHA_PAL 2
00616 #define GAPP_BACKGROUND 3
00617 #define GAPP_ANGLE 4
00618 #define GAPP_BOUNDS 5
00619
00625 class LgiClass GApplicator
00626 {
00627 protected:
00628 GBmpMem *Dest;
00629 GBmpMem *Alpha;
00630 GPalette *Pal;
00631 int Op;
00632
00633 public:
00634 COLOUR c;
00635
00636 GApplicator() { c = 0; }
00637 GApplicator(COLOUR Colour) { c = Colour; }
00638 virtual ~GApplicator() { }
00639
00641 virtual int GetVar(int Var) { return 0; }
00643 virtual int SetVar(int Var, int Value) { return 0; }
00644
00646 void SetOp(int o) { Op = o; }
00648 int GetOp() { return Op; }
00650 int GetBits() { return (Dest) ? Dest->Bits : 0; }
00652 int GetFlags() { return (Dest) ? Dest->Flags : 0; }
00654 GPalette *GetPal() { return Pal; }
00655
00657 virtual bool SetSurface(GBmpMem *d, GPalette *p = 0, GBmpMem *a = 0) = 0;
00659 virtual void SetPtr(int x, int y) = 0;
00661 virtual void IncX() = 0;
00663 virtual void IncY() = 0;
00665 virtual void IncPtr(int X, int Y) = 0;
00666
00668 virtual void Set() = 0;
00670 virtual COLOUR Get() = 0;
00672 virtual void VLine(int height) = 0;
00674 virtual void Rectangle(int x, int y) = 0;
00676 virtual bool Blt(GBmpMem *Src, GPalette *SPal, GBmpMem *SrcAlpha = 0) = 0;
00677 };
00678
00680 class LgiClass GApplicatorFactory
00681 {
00682 public:
00683 GApplicatorFactory();
00684 virtual ~GApplicatorFactory();
00685
00687 static GApplicator *NewApp(int Bits, int Op);
00688 virtual GApplicator *Create(int Bits, int Op) { return NULL; }
00689 };
00690
00691 class LgiClass GApp15 : public GApplicatorFactory
00692 {
00693 public:
00694 GApplicator *Create(int Bits, int Op);
00695 };
00696
00697 class LgiClass GApp16 : public GApplicatorFactory
00698 {
00699 public:
00700 GApplicator *Create(int Bits, int Op);
00701 };
00702
00703 class LgiClass GApp24 : public GApplicatorFactory
00704 {
00705 public:
00706 GApplicator *Create(int Bits, int Op);
00707 };
00708
00709 class LgiClass GApp32 : public GApplicatorFactory
00710 {
00711 public:
00712 GApplicator *Create(int Bits, int Op);
00713 };
00714
00715 class LgiClass GApp8 : public GApplicatorFactory
00716 {
00717 public:
00718 GApplicator *Create(int Bits, int Op);
00719 };
00720
00721 class GAlphaFactory : public GApplicatorFactory
00722 {
00723 public:
00724 GApplicator *Create(int Bits, int Op);
00725 };
00726
00727 #define OrgX(x) x -= OriginX
00728 #define OrgY(y) y -= OriginY
00729 #define OrgXy(x, y) x -= OriginX; y -= OriginY
00730 #define OrgPt(p) p.x -= OriginX; p.y -= OriginY
00731 #define OrgRgn(r) r.Offset(-OriginX, -OriginY)
00732
00734 class LgiClass GSurface
00735 {
00736 friend class GFilter;
00737 friend class GView;
00738 friend class GWindow;
00739
00740 void Init();
00741
00742 protected:
00743 int Flags;
00744 int PrevOp;
00745 GRect Clip;
00746 GBmpMem *pMem;
00747 GSurface *pAlphaDC;
00748 GPalette *pPalette;
00749 GApplicator *pApp;
00750 GApplicator *pAppCache[GDC_CACHE_SIZE];
00751 int OriginX, OriginY;
00752
00753
00754 GApplicator *CreateApplicator(int Op = GDC_SET, int Bits = 0);
00755 uint32 LineBits;
00756 uint32 LineMask;
00757 uint32 LineReset;
00758
00759 #if WIN32NATIVE
00760 OsPainter hDC;
00761 OsBitmap hBmp;
00762 #elif defined __GTK_H__
00763
00764 Gtk::cairo_t *Cairo;
00765 #endif
00766
00767 public:
00768 GSurface();
00769 GSurface(GSurface *pDC);
00770 virtual ~GSurface();
00771
00772
00773 #if defined(__GTK_H__)
00774
00776 virtual Gtk::GdkDrawable *GetDrawable() { return 0; }
00777
00778
00779
00780
00781
00784 virtual Gtk::cairo_t *GetCairo() { return Cairo; }
00785
00787 virtual GdcPt2 GetSize() = 0;
00788
00789 #elif defined(WIN32)
00790
00791 virtual HDC StartDC() { return hDC; }
00792 virtual void EndDC() {}
00793
00794 #elif defined MAC
00795
00796 virtual CGColorSpaceRef GetColourSpace() { return 0; }
00797
00798 #endif
00799
00800 virtual OsBitmap GetBitmap();
00801 virtual OsPainter Handle();
00802 virtual void SetClient(GRect *c) { }
00803
00804
00805 virtual bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false) { return false; }
00806 virtual void Update(int Flags) {}
00807
00808
00810 virtual bool HasAlpha() { return pAlphaDC != 0; }
00812 virtual bool HasAlpha(bool b);
00814 bool DrawOnAlpha() { return ((Flags & GDC_DRAW_ON_ALPHA) != 0); }
00816 bool DrawOnAlpha(bool Draw);
00818 GSurface *AlphaDC() { return pAlphaDC; }
00819
00820
00821 virtual bool Applicator(GApplicator *pApp);
00822 virtual GApplicator *Applicator();
00823
00824
00825 virtual GPalette *Palette();
00826 virtual void Palette(GPalette *pPal, bool bOwnIt = true);
00827
00828
00829 virtual GRect ClipRgn(GRect *Rgn);
00830 virtual GRect ClipRgn();
00831
00833 virtual COLOUR Colour() { return pApp->c; }
00835 virtual COLOUR Colour
00836 (
00838 COLOUR c,
00840 int Bits = 0
00841 );
00843 virtual int Op() { return (pApp) ? pApp->GetOp() : 0; }
00846 virtual int Op(int Op);
00848 virtual int X() { return (pMem) ? pMem->x : 0; }
00850 virtual int Y() { return (pMem) ? pMem->y : 0; }
00852 virtual int GetLine() { return (pMem) ? pMem->Line : 0; }
00854 virtual int DpiX() { return 100; }
00856 virtual int DpiY() { return 100; }
00858 virtual int GetBits() { return (pMem) ? pMem->Bits : 0; }
00860 virtual int PixelSize() { return GetBits() == 24 ? Pixel24::Size : GetBits() >> 3; }
00861 virtual int GetFlags() { return Flags; }
00863 virtual class GScreenDC *IsScreen() { return 0; }
00865 virtual bool IsPrint() { return false; }
00867 virtual uchar *operator[](int y);
00868
00870 virtual void GetOrigin(int &x, int &y) { x = OriginX; y = OriginY; }
00872 virtual void SetOrigin(int x, int y) { OriginX = x; OriginY = y; }
00873
00875 virtual void Set(int x, int y);
00877 virtual COLOUR Get(int x, int y);
00878
00879
00880
00882 virtual void HLine(int x1, int x2, int y);
00884 virtual void VLine(int x, int y1, int y2);
00886 virtual void Line(int x1, int y1, int x2, int y2);
00887
00888 virtual uint LineStyle(uint32 Bits, uint32 Reset = 0x80000000)
00889 {
00890 uint32 B = LineBits;
00891 LineBits = Bits;
00892 LineMask = LineReset = Reset;
00893 return B;
00894 }
00895 virtual uint LineStyle() { return LineBits; }
00896
00897
00898
00900 virtual void Circle(double cx, double cy, double radius);
00902 virtual void FilledCircle(double cx, double cy, double radius);
00904 virtual void Arc(double cx, double cy, double radius, double start, double end);
00906 virtual void FilledArc(double cx, double cy, double radius, double start, double end);
00908 virtual void Ellipse(double cx, double cy, double x, double y);
00910 virtual void FilledEllipse(double cx, double cy, double x, double y);
00911
00912
00913
00915 virtual void Box(int x1, int y1, int x2, int y2);
00917 virtual void Box
00918 (
00920 GRect *a = NULL
00921 );
00923 virtual void Rectangle(int x1, int y1, int x2, int y2);
00925 virtual void Rectangle
00926 (
00928 GRect *a = NULL
00929 );
00931 virtual void Blt
00932 (
00934 int x,
00936 int y,
00938 GSurface *Src,
00940 GRect *a = NULL
00941 );
00943 virtual void StretchBlt(GRect *d, GSurface *Src, GRect *s);
00944
00945
00946
00948 virtual void Polygon(int Points, GdcPt2 *Data);
00950 virtual void Bezier(int Threshold, GdcPt2 *Pt);
00952 virtual void FloodFill
00953 (
00955 int x,
00957 int y,
00959 int Mode,
00961 COLOUR Border = 0,
00963 GRect *Bounds = NULL
00964 );
00965 };
00966
00971 class LgiClass GScreenDC : public GSurface
00972 {
00973 class GScreenPrivate *d;
00974
00975 public:
00976 GScreenDC();
00977 virtual ~GScreenDC();
00978
00979
00980 #if WIN32NATIVE
00981
00982 GScreenDC(GViewI *view);
00983 GScreenDC(HWND hwnd);
00984 GScreenDC(HDC hdc, HWND hwnd, bool Release = false);
00985 GScreenDC(HBITMAP hBmp, int Sx, int Sy);
00986
00987 bool Create(HDC hdc);
00988 void SetSize(int x, int y);
00989
00990 #else
00991
00993 GScreenDC(GView *view, void *Param = 0);
00994
00995 #if defined MAC
00996
00997 GScreenDC(GWindow *wnd, void *Param = 0);
00998 GRect GetPos();
00999
01000 #else // GTK
01001
01003 GScreenDC(int x, int y, int bits);
01005 GScreenDC(Gtk::GdkDrawable *Drawable);
01007 GScreenDC(OsView View);
01008
01009 Gtk::GdkDrawable *GetDrawable();
01010 Gtk::cairo_t *GetCairo();
01011
01012 GdcPt2 GetSize();
01013
01014 #endif
01015
01016 GView *GetView();
01017 OsPainter Handle();
01018 int GetFlags();
01019 GRect *GetClient();
01020
01021 #endif
01022
01023
01024 void GetOrigin(int &x, int &y);
01025 void SetOrigin(int x, int y);
01026
01027 GRect ClipRgn();
01028 GRect ClipRgn(GRect *Rgn);
01029 void SetClient(GRect *c);
01030
01031 COLOUR Colour();
01032 COLOUR Colour(COLOUR c, int Bits = 0);
01033
01034 int Op();
01035 int Op(int Op);
01036
01037 int X();
01038 int Y();
01039
01040 GPalette *Palette();
01041 void Palette(GPalette *pPal, bool bOwnIt = true);
01042
01043 uint LineStyle();
01044 uint LineStyle(uint Bits, uint32 Reset = 0x80000000);
01045
01046 int GetBits();
01047 GScreenDC *IsScreen() { return this; }
01048 uchar *operator[](int y) { return NULL; }
01049
01050
01051 void Set(int x, int y);
01052 COLOUR Get(int x, int y);
01053 void HLine(int x1, int x2, int y);
01054 void VLine(int x, int y1, int y2);
01055 void Line(int x1, int y1, int x2, int y2);
01056 void Circle(double cx, double cy, double radius);
01057 void FilledCircle(double cx, double cy, double radius);
01058 void Arc(double cx, double cy, double radius, double start, double end);
01059 void FilledArc(double cx, double cy, double radius, double start, double end);
01060 void Ellipse(double cx, double cy, double x, double y);
01061 void FilledEllipse(double cx, double cy, double x, double y);
01062 void Box(int x1, int y1, int x2, int y2);
01063 void Box(GRect *a);
01064 void Rectangle(int x1, int y1, int x2, int y2);
01065 void Rectangle(GRect *a = NULL);
01066 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01067 void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
01068 void Polygon(int Points, GdcPt2 *Data);
01069 void Bezier(int Threshold, GdcPt2 *Pt);
01070 void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
01071 };
01072
01075 class GBlitRegions
01076 {
01077
01078 GRect SrcBounds;
01079 GRect DstBounds;
01080
01081
01082 GRect SrcBlt;
01083 GRect DstBlt;
01084
01085 public:
01087 GRect SrcClip;
01089 GRect DstClip;
01090
01092 GBlitRegions
01093 (
01095 GSurface *Dst,
01097 int x1,
01099 int y1,
01101 GSurface *Src,
01103 GRect *SrcRc = 0
01104 )
01105 {
01106
01107 if (Src) SrcBounds.Set(0, 0, Src->X()-1, Src->Y()-1);
01108 else SrcBounds.ZOff(-1, -1);
01109 if (Dst) DstBounds.Set(0, 0, Dst->X()-1, Dst->Y()-1);
01110 else DstBounds.ZOff(-1, -1);
01111
01112
01113 if (SrcRc)
01114 {
01115 SrcBlt = *SrcRc;
01116 SrcBlt.Bound(&SrcBounds);
01117 }
01118 else SrcBlt = SrcBounds;
01119
01120 DstBlt = SrcBlt;
01121 DstBlt.Offset(x1-DstBlt.x1, y1-DstBlt.y1);
01122
01123
01124 DstClip = DstBlt;
01125 DstClip.Bound(&DstBounds);
01126
01127
01128 SrcClip = SrcBlt;
01129 SrcClip.x1 += DstClip.x1 - DstBlt.x1;
01130 SrcClip.y1 += DstClip.y1 - DstBlt.y1;
01131 SrcClip.x2 -= DstBlt.x2 - DstClip.x2;
01132 SrcClip.y2 -= DstBlt.y2 - DstClip.y2;
01133 }
01134
01136 bool Valid()
01137 {
01138 return DstClip.Valid() && SrcClip.Valid();
01139 }
01140
01141 void Dump()
01142 {
01143 printf("SrcBounds: %s\n", SrcBounds.GetStr());
01144 printf("DstBounds: %s\n", DstBounds.GetStr());
01145
01146 printf("SrcBlt: %s\n", SrcBlt.GetStr());
01147 printf("DstBlt: %s\n", DstBlt.GetStr());
01148
01149 printf("SrcClip: %s\n", SrcClip.GetStr());
01150 printf("DstClip: %s\n", DstClip.GetStr());
01151 }
01152 };
01153
01154 #ifdef MAC
01155 class CGImg
01156 {
01157 class CGImgPriv *d;
01158
01159 void Create(int x, int y, int Bits, int Line, uchar *data, uchar *palette, GRect *r);
01160
01161 public:
01162 CGImg(int x, int y, int Bits, int Line, uchar *data, uchar *palette, GRect *r);
01163 CGImg(GSurface *pDC);
01164 ~CGImg();
01165
01166 operator CGImageRef();
01167 };
01168 #endif
01169
01174 class LgiClass GMemDC : public GSurface
01175 {
01176 protected:
01177 class GMemDCPrivate *d;
01178
01179 #if defined WIN32
01180 PBITMAPINFO GetInfo();
01181 #endif
01182
01183 public:
01185 GMemDC
01186 (
01188 int x = 0,
01190 int y = 0,
01192 int bits = 0
01193 );
01194 GMemDC(GSurface *pDC);
01195 virtual ~GMemDC();
01196
01197 #if WIN32NATIVE
01198
01199 HDC StartDC();
01200 void EndDC();
01201 void Update(int Flags);
01202 void UpsideDown(bool upsidedown);
01203
01204
01205
01206 GRect ClipRgn(GRect *Rgn);
01207
01208 #else
01209
01210 GRect ClipRgn() { return Clip; }
01211
01212 #if defined MAC
01213
01214 OsPainter Handle();
01215 OsBitmap GetBitmap();
01216 CGColorSpaceRef GetColourSpace();
01217 CGImg *GetImg(GRect *Sub = 0);
01218 GRect ClipRgn(GRect *Rgn);
01219
01220 #else // GTK
01221
01222 Gtk::GdkImage *GetImage();
01223 GdcPt2 GetSize();
01224 Gtk::cairo_t *GetCairo();
01225
01226 #endif
01227
01228 #endif
01229
01230 void SetClient(GRect *c);
01231
01233 bool Lock();
01238 bool Unlock();
01239
01240 void SetOrigin(int x, int y);
01241 void Empty();
01242
01243 bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false);
01244 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01245 void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
01246
01247 void HLine(int x1, int x2, int y, COLOUR a, COLOUR b);
01248 void VLine(int x, int y1, int y2, COLOUR a, COLOUR b);
01249 };
01250
01256 class LgiClass GPrintDC
01257 #if defined WIN32
01258 : public GScreenDC
01259 #else
01260 : public GSurface
01261 #endif
01262 {
01263 #ifdef __GTK_H__
01264 friend class PrintPainter;
01265 double Xc(int x);
01266 double Yc(int y);
01267 #endif
01268
01269 class GPrintDCPrivate *d;
01270
01271 public:
01272 GPrintDC(void *Handle, char *PrintJobName);
01273 ~GPrintDC();
01274
01275 bool IsPrint() { return true; }
01276
01277 int X();
01278 int Y();
01279 int GetBits();
01280
01282 int DpiX();
01283
01285 int DpiY();
01286
01288 bool StartPage();
01290 void EndPage();
01291
01292 #if defined __GTK_H__
01293
01294 OsPainter Handle();
01295 COLOUR Colour();
01296 COLOUR Colour(COLOUR c, int Bits = 0);
01297 GdcPt2 GetSize() { return GdcPt2(X(), Y()); }
01298
01299 void Set(int x, int y);
01300 COLOUR Get(int x, int y);
01301 void HLine(int x1, int x2, int y);
01302 void VLine(int x, int y1, int y2);
01303 void Line(int x1, int y1, int x2, int y2);
01304 void Circle(double cx, double cy, double radius);
01305 void FilledCircle(double cx, double cy, double radius);
01306 void Arc(double cx, double cy, double radius, double start, double end);
01307 void FilledArc(double cx, double cy, double radius, double start, double end);
01308 void Ellipse(double cx, double cy, double x, double y);
01309 void FilledEllipse(double cx, double cy, double x, double y);
01310 void Box(int x1, int y1, int x2, int y2);
01311 void Box(GRect *a = NULL);
01312 void Rectangle(int x1, int y1, int x2, int y2);
01313 void Rectangle(GRect *a = NULL);
01314 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01315 void StretchBlt(GRect *d, GSurface *Src, GRect *s);
01316 void Polygon(int Points, GdcPt2 *Data);
01317 void Bezier(int Threshold, GdcPt2 *Pt);
01318 void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
01319
01320 #endif
01321
01322 };
01323
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408 class LgiClass GGlobalColour
01409 {
01410 class GGlobalColourPrivate *d;
01411
01412 public:
01413 GGlobalColour();
01414 ~GGlobalColour();
01415
01416
01417 COLOUR AddColour(COLOUR c24);
01418 bool AddBitmap(GSurface *pDC);
01419 bool AddBitmap(GImageList *il);
01420
01421
01422 bool MakeGlobalPalette();
01423
01424
01425
01426 GPalette *GetPalette();
01427
01428
01429 COLOUR GetColour(COLOUR c24);
01430 bool RemapBitmap(GSurface *pDC);
01431 };
01432
01433 #ifdef WIN32
01434 typedef int (__stdcall *MsImg32_AlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
01435 #endif
01436
01438 class LgiClass GdcDevice
01439 {
01440 friend class GScreenDC;
01441 friend class GImageList;
01442
01443 static GdcDevice *pInstance;
01444 class GdcDevicePrivate *d;
01445
01446 #ifdef WIN32
01447 MsImg32_AlphaBlend AlphaBlend;
01448 #endif
01449
01450 public:
01451 GdcDevice();
01452 ~GdcDevice();
01453 static GdcDevice *GetInst() { return pInstance; }
01454
01456 int GetBits();
01458 int X();
01460 int Y();
01461
01462 GGlobalColour *GetGlobalColour();
01463
01465 int GetOption(int Opt);
01467 int SetOption(int Opt, int Value);
01468
01470 ulong *GetCharSquares();
01472 uchar *GetDiv255();
01473
01474
01475 void SetGamma(double Gamma);
01476 double GetGamma();
01477
01478
01479 void SetSystemPalette(int Start, int Size, GPalette *Pal);
01480 GPalette *GetSystemPalette();
01481 void SetColourPaletteType(int Type);
01482 COLOUR GetColour(COLOUR Rgb24, GSurface *pDC = NULL);
01483 };
01484
01496 class LgiClass GInlineBmp
01497 {
01498 public:
01500 int X;
01502 int Y;
01504 int Bits;
01506 uint32 *Data;
01507
01509 GSurface *Create();
01510 };
01511
01512
01513 #include "GFilter.h"
01514
01515
01516 #define GdcD GdcDevice::GetInst()
01517
01519 LgiFunc GSurface *ConvertDC
01520 (
01522 GSurface *pDC,
01524 int Bits
01525 );
01526
01542 LgiFunc GSurface *LoadDC
01543 (
01545 char *Name,
01547 bool UseOSLoader = true
01548 );
01549
01551 LgiFunc bool WriteDC(char *Name, GSurface *pDC);
01552
01554 LgiFunc COLOUR CBit(int DstBits, COLOUR c, int SrcBits = 24, GPalette *Pal = 0);
01555
01557 LgiFunc COLOUR GdcMixColour(COLOUR a, COLOUR b, double HowMuchA = 0.5);
01558
01560 LgiFunc COLOUR GdcGreyScale(COLOUR c, int Bits = 24);
01561
01563 enum GColourReducePalette
01564 {
01565 CR_PAL_NONE = -1,
01566 CR_PAL_CUBE = 0,
01567 CR_PAL_OPT,
01568 CR_PAL_FILE
01569 };
01570
01572 enum GColourReduceMatch
01573 {
01574 CR_MATCH_NONE = -1,
01575 CR_MATCH_NEAR = 0,
01576 CR_MATCH_HALFTONE,
01577 CR_MATCH_ERROR
01578 };
01579
01581 class GReduceOptions
01582 {
01583 public:
01585 GColourReducePalette PalType;
01586
01588 GColourReduceMatch MatchType;
01589
01591 int Colours;
01592
01594 GPalette *Palette;
01595
01596 GReduceOptions()
01597 {
01598 Palette = 0;
01599 Colours = 256;
01600 PalType = CR_PAL_NONE;
01601 MatchType = CR_MATCH_NONE;
01602 }
01603 };
01604
01606 LgiFunc bool GReduceBitDepth(GSurface *pDC, int Bits, GPalette *Pal = 0, GReduceOptions *Reduce = 0);
01607
01608 struct GColourStop
01609 {
01610 COLOUR Colour;
01611 double Pos;
01612 };
01613
01615 LgiFunc void LgiFillGradient(GSurface *pDC, GRect &r, bool Vert, GArray<GColourStop> &Stops);
01616
01617 #endif