diff --git a/src/sys/graphics/main.cpp b/src/sys/graphics/main.cpp index 779c077..4780e11 100755 --- a/src/sys/graphics/main.cpp +++ b/src/sys/graphics/main.cpp @@ -22,14 +22,15 @@ buf2 = new TGfx0(); font = new TDPFont(buf); buf->create(400,400,def_pixfmt_8bpp); -// buf2->create(400,400,(TPixelFmt *)&def_pixfmt_15bpp); - buf2->alias(buf,0,3,8,8); +// buf2->create(400,400,def_pixfmt_15bpp); + buf2->alias(*buf,0,3,8,8); buf2->putPixel(0,0,1); buf2->putPixel(buf2->getMaxX(),buf2->getMaxY(),1); buf2->clear(1); result = font->Load("PACMAN.DPF"); font->SetColor(1); - font->PutText(0,0," loWorld"); + font->PutText(0,0," World"); + buf->copyBuf(0,0,*buf,40,0,79,8); for (r=0; r<=15; r++) { for (g=0; g<=79; g++) if (buf->getPixel(g,r)) printf("*"); else printf(" "); diff --git a/src/sys/graphics/objgfx30.cpp b/src/sys/graphics/objgfx30.cpp index 392c4b6..c145c9e 100755 --- a/src/sys/graphics/objgfx30.cpp +++ b/src/sys/graphics/objgfx30.cpp @@ -5,7 +5,6 @@ #include "objgfx30.h" #include #include -#include #include // TGfx0 constructor @@ -32,9 +31,8 @@ } // TGfx0::TGfx0() bool -TGfx0::alias(TGfx0* SrcObject, UInt32 x1, UInt32 y1, UInt32 x2, UInt32 y2) { +TGfx0::alias(TGfx0& SrcObject, UInt32 x1, UInt32 y1, UInt32 x2, UInt32 y2) { UInt32 tmp; - printf("in alias\n"); if (DataState==og_Owner) return FALSE; if (x2Buffer)+x1*((SrcObject->BPP+7) >> 3)); - LineOfs=((UInt32 *)SrcObject->LineOfs)+y1; - pal = SrcObject->pal; - xRes = SrcObject->xRes; - yRes = SrcObject->yRes; + Owner = &SrcObject; + Buffer =((unsigned char *)(SrcObject.Buffer)+x1*((SrcObject.BPP+7) >> 3)); + LineOfs=((UInt32 *)SrcObject.LineOfs)+y1; + pal = SrcObject.pal; + xRes = SrcObject.xRes; + yRes = SrcObject.yRes; MaxX = (x2-x1); MaxY = (y2-y1); bSize = 0; lSize = 0; - TransparentColor = SrcObject->TransparentColor; + TransparentColor = SrcObject.TransparentColor; DataState = og_Aliasing; - BPP = SrcObject->BPP; + BPP = SrcObject.BPP; // For 8bpp modes the next part doesn't matter - RedFieldPosition = SrcObject->RedFieldPosition; - GreenFieldPosition = SrcObject->GreenFieldPosition; - BlueFieldPosition = SrcObject->BlueFieldPosition; + RedFieldPosition = SrcObject.RedFieldPosition; + GreenFieldPosition = SrcObject.GreenFieldPosition; + BlueFieldPosition = SrcObject.BlueFieldPosition; // The next part is only used by 15/16bpp - RedShifter = SrcObject->RedShifter; - GreenShifter = SrcObject->GreenShifter; - BlueShifter = SrcObject->BlueShifter; + RedShifter = SrcObject.RedShifter; + GreenShifter = SrcObject.GreenShifter; + BlueShifter = SrcObject.BlueShifter; return TRUE; } // TGfx0::alias @@ -96,7 +94,7 @@ if (y1<0) y1=0; if (y2>(Int32)MaxY) y2=MaxY; for (yy=y1; yy<=y2; yy++) - horizLine(x1,x2,yy,colour); + hLine(x1,x2,yy,colour); } // TGfx0::bar void @@ -225,12 +223,12 @@ } // TGfx0::clear void -TGfx0::clone(TGfx0* SrcObject) { +TGfx0::clone(TGfx0& SrcObject) { TPixelFmt pixfmt; - if (SrcObject->DataState==og_None) return; - SrcObject->getPixFmt(pixfmt); - create(SrcObject->MaxX+1,SrcObject->MaxY+1,pixfmt); - if (pal!=NULL) pal = SrcObject->pal; + if (SrcObject.DataState==og_None) return; + SrcObject.getPixFmt(pixfmt); + create(SrcObject.MaxX+1,SrcObject.MaxY+1,pixfmt); + if (pal!=NULL) pal = SrcObject.pal; copy(SrcObject); } // TGfx0::clone @@ -280,22 +278,22 @@ } // TGfx0::create void -TGfx0::copy(TGfx0* SrcObject) { +TGfx0::copy(TGfx0& SrcObject) { UInt32 count, xCount, yCount; UInt32 xx, yy; UInt8 r, g, b; if (Buffer==NULL) return; - if (SrcObject->Buffer==NULL) return; - xCount = SrcObject->MaxX+1; - if (xCount>MaxX+1) xCount=MaxX; - yCount = SrcObject->MaxY+1; + if (SrcObject.Buffer==NULL) return; + xCount = SrcObject.MaxX+1; + if (xCount>MaxX+1) xCount=MaxX+1; + yCount = SrcObject.MaxY+1; if (yCount>MaxY+1) yCount=MaxY; - if ((BPP!=SrcObject->BPP) || (RedShifter!=SrcObject->RedShifter) || - (BlueShifter!=SrcObject->BlueShifter) || - (GreenShifter!=SrcObject->GreenShifter)) { - for (yy=0; yy<=yCount; yy++) - for (xx=0; xx<=xCount; xx++) { - SrcObject->unpackRGB(SrcObject->getPixel(xx,yy),&r,&g,&b); + if ((BPP!=SrcObject.BPP) || (RedShifter!=SrcObject.RedShifter) || + (BlueShifter!=SrcObject.BlueShifter) || + (GreenShifter!=SrcObject.GreenShifter)) { + for (yy=0; yy> 3); // adjust for bpp for (count=0; count<=yCount; count++) ; memcpy(((char*)Buffer+LineOfs[count]), // dest - ((char*)SrcObject->Buffer+SrcObject->LineOfs[count]), // src + ((char*)SrcObject.Buffer+SrcObject.LineOfs[count]), // src xCount); // len } // else } // TGfx0::copy +void +TGfx0::copyBuf(Int32 DestX, Int32 DestY, + TGfx0& SrcObject, Int32 x1, Int32 y1, Int32 x2, Int32 y2) { + UInt32 pixmap[256]; + Int32 xx,yy,count,xCount, yCount; + UInt32 bm; // bit multiplyer + UInt8 r, g, b; + + if ((Buffer==NULL) || (LineOfs==NULL)) return; + if ((SrcObject.Buffer==NULL) || (SrcObject.LineOfs==NULL)) return; + + if ((DestX>(Int32)MaxX) || (DestY>(Int32)MaxY)) return; + + if (x1>x2) { + xx = x1; + x1 = x2; + x2 = xx; + } // if + if (y1>y2) { + yy = y1; + y1 = y2; + y2 = yy; + } // if + + xCount = abs(x2-x1)+1; + yCount = abs(y2-y1)+1; + + if (DestX+xCount>(Int32)MaxX+1) xCount=MaxX-DestX+1; + if (DestY+yCount>(Int32)MaxY+1) yCount=MaxY-DestY+1; + + if (DestX<0) { + xCount += DestX; + x1 -= DestX; + DestX = 0; + } // if + + if (DestY<0) { + yCount += DestY; + y1 -= DestY; + DestY = 0; + } // if + + if ((DestX+xCount<0) || (DestY+yCount<0)) return; + if ((BPP!=SrcObject.BPP) || (RedShifter!=SrcObject.RedShifter) || + (BlueShifter!=SrcObject.BlueShifter) || + (GreenShifter!=SrcObject.GreenShifter)) { + if (SrcObject.BPP==8) { + for (xx=0; xx<256; xx++) + pixmap[xx] = RGB(SrcObject.pal[xx].red, + SrcObject.pal[xx].green, + SrcObject.pal[xx].blue); + for (yy=0; yybpp + else + { + for (yy=0; yy> 3; + x1 *= bm; + DestX *= bm; + xCount *= bm; + for (count=0; countMaxX) || (y<0) || y>MaxY) return TransparentColor; + if ((x<0) || (x>(Int32)MaxX) || (y<0) || y>(Int32)MaxY) + return TransparentColor; switch (BPP) { case 8: asm( @@ -422,10 +512,15 @@ pixfmt.BlueMaskSize=8-BlueShifter; } // TGfx0::getPixFmt -void -TGfx0::horizLine(Int32 x1, Int32 x2, Int32 y, UInt32 colour) { +UInt32 +TGfx0::getTransparentColor(void) { + return TransparentColor; +} -} // TGfx0::horizLine +void +TGfx0::hLine(Int32 x1, Int32 x2, Int32 y, UInt32 colour) { + +} // TGfx0::hLine void TGfx0::putPixel(UInt32 x, UInt32 y, UInt32 colour) { @@ -621,39 +716,39 @@ } // TGfx0::setRGBPalette void -TGfx0::unpackRGB(UInt32 colour, UInt8* red, UInt8* green, UInt8* blue) { +TGfx0::unpackRGB(UInt32 colour, UInt8& red, UInt8& green, UInt8& blue) { switch (BPP) { case 8: if (!pal) { - *red = 0; - *green = 0; - *blue = 0; + red = 0; + green = 0; + blue = 0; return; } if (colour>255) colour=colour & 255; - *red = pal[colour].red; - *green = pal[colour].green; - *blue = pal[colour].blue; + red = pal[colour].red; + green = pal[colour].green; + blue = pal[colour].blue; break; case 15: case 16: - *red = ((colour >> RedFieldPosition) << RedShifter); - *green = ((colour >> GreenFieldPosition) << GreenShifter); - *blue = ((colour >> BlueFieldPosition) << BlueShifter); - if ((*red) && (RedShifter)) *red+=(1 << RedShifter)-1; - if ((*green) && (GreenShifter)) *green+=(1 << GreenShifter)-1; - if ((*blue) && (BlueShifter)) *blue+=(1 << BlueShifter)-1; + red = ((colour >> RedFieldPosition) << RedShifter); + green = ((colour >> GreenFieldPosition) << GreenShifter); + blue = ((colour >> BlueFieldPosition) << BlueShifter); + if ((red) && (RedShifter)) red+=(1 << RedShifter)-1; + if ((green) && (GreenShifter)) green+=(1 << GreenShifter)-1; + if ((blue) && (BlueShifter)) blue+=(1 << BlueShifter)-1; break; case 24: case 32: - *red = colour >> RedFieldPosition; - *green = colour >> GreenFieldPosition; - *blue = colour >> BlueFieldPosition; + red = colour >> RedFieldPosition; + green = colour >> GreenFieldPosition; + blue = colour >> BlueFieldPosition; break; default: - *red = 0; - *green = 0; - *blue = 0; + red = 0; + green = 0; + blue = 0; } return; } // TGfx0:unpackRGB diff --git a/src/sys/graphics/objgfx30.h b/src/sys/graphics/objgfx30.h index 2f8fa04..0951889 100755 --- a/src/sys/graphics/objgfx30.h +++ b/src/sys/graphics/objgfx30.h @@ -145,29 +145,45 @@ UInt8 BlueShifter; public: TGfx0(void); - bool alias(TGfx0*, UInt32, UInt32, UInt32, UInt32); - void arc(UInt32, UInt32, UInt32, UInt32, UInt32, UInt32); - void bar(Int32, Int32, Int32, Int32, UInt32); + bool alias(TGfx0&, UInt32, UInt32, UInt32, UInt32); + void arc(UInt32, UInt32, UInt32, UInt32, UInt32, UInt32); + void bar(Int32, Int32, Int32, Int32, UInt32); // void bSpline - void circle(Int32, Int32, UInt32, UInt32); - bool create(UInt32, UInt32, TPixelFmt); - void clear(UInt32); - void clone(TGfx0*); - void copy(TGfx0*); - UInt8 getBPP(void); - void * getBufferPtr(void); + void circle(Int32, Int32, UInt32, UInt32); + bool create(UInt32, UInt32, TPixelFmt); + void clear(UInt32); + void clone(TGfx0&); + void copy(TGfx0&); + void copyBuf(Int32, Int32, + TGfx0&, Int32, Int32, Int32, Int32); + // cubicBezierCurve + // curve + // drawpoly + void flipX(void); + void flipY(void); + UInt8 getBPP(void); + void * getBufferPtr(void); og_DataState getDataState(void); - UInt32 * getLineOfsPtr(void); - TRGB * getPalPtr(void); - UInt32 getMaxX(void); - UInt32 getMaxY(void); - UInt32 getPixel(UInt32, UInt32); - void getPixFmt(TPixelFmt&); - void horizLine(Int32, Int32, Int32, UInt32); - void putPixel(UInt32, UInt32, UInt32); - UInt32 RGB(UInt8, UInt8, UInt8); - void setRGBPalette(UInt8, UInt8, UInt8, UInt8); - void unpackRGB(UInt32, UInt8*, UInt8*, UInt8*); + UInt32 * getLineOfsPtr(void); + TRGB * getPalPtr(void); + UInt32 getMaxX(void); + UInt32 getMaxY(void); + // getPal + void getPixFmt(TPixelFmt&); + UInt32 getPixel(Int32, Int32); + UInt32 getTransparentColor(void); + void hLine(Int32, Int32, Int32, UInt32); + // line + // loadPal + void putPixel(UInt32, UInt32, UInt32); + // rawLine + // rectangle + UInt32 RGB(UInt8, UInt8, UInt8); + // savePal + void setRGBPalette(UInt8, UInt8, UInt8, UInt8); + void setTransparentColor(UInt32); + void unpackRGB(UInt32, UInt8&, UInt8&, UInt8&); + // vLine ~TGfx0(void); }; // gfx0