// Looks up the pixels to set when writing ascii character void ASCII(char x, char y, int color, int background, char letter, char size) { char data; char q = 0; char z = 0; char d = 0; char b = 0; for (q = 0; q < 5; q++) { data = font[letter][q]; for (z = 0; z < 8 * size; z++) { if ((data & 1) != 0) { for (d = 0; d < size; d++) { for (b = 0; b < size; b++) { SetPix(x + (q * size) + d, y + (z * size) + b, color); } } } else { for (d = 0; d < size; d++) { for (b = 0; b < size; b++) { SetPix(x + (q * size) + d, y + (z * size) + b, background); } } } data >>= 1; } } }
void C4MapCreator::DrawLayer(int32_t x, int32_t y, int32_t size, BYTE col) { int32_t cnt,cnt2; for (cnt=0; cnt<size; cnt++) { x+=Random(9)-4; y+=Random(3)-1; for (cnt2=Random(3); cnt2<5; cnt2++) { SetPix(x+cnt2,y,col); SetPix(x+cnt2+1,y+1,col); } } }
void CSurface8::Circle(int x, int y, int r, BYTE col) { for (int ycnt = -r; ycnt < r; ycnt++) { int lwdt = (int)sqrt(float(r * r - ycnt * ycnt)); for (int xcnt = 2 * lwdt - 1; xcnt >= 0; xcnt--) SetPix(x - lwdt + xcnt, y + ycnt, col); } }
void C4MapCreator::ValidateTextureIndices(C4TextureMap &rTextureMap) { int32_t iX,iY; for (iY=0; iY<MapHgt; iY++) for (iX=0; iX<MapWdt; iX++) if (!rTextureMap.GetEntry(GetPix(iX,iY))) SetPix(iX,iY,0); }
bool CSurface8::Read(CStdStream &hGroup) { int cnt,lcnt; C4BMP256Info BitmapInfo; // read bmpinfo-header if (!hGroup.Read(&BitmapInfo,sizeof(C4BMPInfo))) return false; // is it 8bpp? if (BitmapInfo.Info.biBitCount == 8) { if (!hGroup.Read(((BYTE *) &BitmapInfo)+sizeof(C4BMPInfo),sizeof(BitmapInfo)-sizeof(C4BMPInfo))) return false; if (!hGroup.Advance(BitmapInfo.FileBitsOffset())) return false; } else { // read 24bpp if (BitmapInfo.Info.biBitCount != 24) return false; if (!hGroup.Advance(((C4BMPInfo) BitmapInfo).FileBitsOffset())) return false; } // Create and lock surface if (!Create(BitmapInfo.Info.biWidth,BitmapInfo.Info.biHeight)) return false; if (BitmapInfo.Info.biBitCount == 8) { // Copy palette for (cnt=0; cnt<256; cnt++) { pPal->Colors[cnt] = C4RGB(BitmapInfo.Colors[cnt].rgbRed, BitmapInfo.Colors[cnt].rgbGreen, BitmapInfo.Colors[cnt].rgbBlue); } } // create line buffer int iBufSize=DWordAligned(BitmapInfo.Info.biWidth*BitmapInfo.Info.biBitCount/8); BYTE *pBuf = new BYTE[iBufSize]; // Read lines for (lcnt=Hgt-1; lcnt>=0; lcnt--) { if (!hGroup.Read(pBuf, iBufSize)) { Clear(); delete [] pBuf; return false; } BYTE *pPix=pBuf; for (int x=0; x<BitmapInfo.Info.biWidth; ++x) switch (BitmapInfo.Info.biBitCount) { case 8: SetPix(x, lcnt, *pPix++); break; case 24: return false; break; } } // free buffer again delete [] pBuf; return true; }
void C4MapCreator::SetSpot(int32_t x, int32_t y, int32_t rad, BYTE col) { int32_t ycnt, xcnt, lwdt, dpy; for (ycnt = -rad; ycnt <= rad; ycnt++) { lwdt = (int32_t)sqrt(double(rad * rad - ycnt * ycnt)); dpy = y + ycnt; for (xcnt = -lwdt; xcnt < lwdt + (lwdt == 0); xcnt++) SetPix(x + xcnt, dpy, col); } }
//altered --> https://bitbucket.org/xerpi void rectfill(u8* screen, int x, int y, int w, int h, u32 colour) { int i, j; for (i = 0; i < w; ++i) { for (j = 0; j < h; ++j) { SetPix(screen, x+i, y+j, colour); } } }
//#define Circle(screen, cx, cy, radius, colour) (Ellipse(screen, cx, cy, radius, radius, 0, colour)); //not at all happy with LCD output, too be nixxed &or deprecated for floodfill void CircleFill(u8* screen, int xCen, int yCen, int radius, u32 colour) { Circle(screen, xCen, yCen, radius, colour); int x,y; for(y = -radius;y <= radius;y++){ for(x = -radius;x <= radius;x++) if(x*x + y*y <= radius*radius + radius * .8f) SetPix(screen, xCen + x, yCen + y, colour); } }
//Revised --> http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C void line(u8* screen, int x0, int y0, int x1, int y1, u32 colour) { int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1; int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; int err = (dx>dy ? dx : -dy)/2, e2; for(;;){ SetPix(screen,x0,y0,colour); if (x0==x1 && y0==y1) break; e2 = err; if (e2 >-dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } }
void CSurface8::AllowColor(BYTE iRngLo, BYTE iRngHi, BOOL fAllowZero) { // change colors int xcnt, ycnt; if (iRngHi < iRngLo) return; for (ycnt = 0; ycnt < Hgt; ycnt++) { for (xcnt = 0; xcnt < Wdt; xcnt++) { BYTE px = GetPix(xcnt, ycnt); if (px || !fAllowZero) if ((px < iRngLo) || (px > iRngHi)) SetPix(xcnt, ycnt, iRngLo + px % (iRngHi - iRngLo + 1)); } } }
void CSurface8::HLine(int iX, int iX2, int iY, int iCol) { for (int cx=iX; cx<=iX2; cx++) SetPix(cx,iY,iCol); }
void CSurface8::MapBytes(BYTE *bpMap) { if (!bpMap) return; for (int cnt=0; cnt<Wdt*Hgt; cnt++) SetPix(cnt%Wdt, cnt/Wdt, bpMap[GetPix(cnt%Wdt, cnt/Wdt)]); }
int main() { gfxInitDefault(); gfxSet3D(true); // uncomment if using stereoscopic 3D gfxFlushBuffers(); transparent = BLACK; gfxSetScreenFormat(GFX_TOP, GSP_BGR8_OES); gfxSetScreenFormat(GFX_BOTTOM, GSP_BGR8_OES); InitParx(BLACK); /* ParxLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); ParxRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL); ParxBot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); ClrParx(ParxLeft, BLACK); ClrParx(ParxRight, BLACK); ClrParx(ParxBot, BLACK); */ char* str[256]; int l, k, j, i=20, posx = 100, posy = 100; TBGR rgbsam; TBGR rgb; u64 time; // Main loop while (aptMainLoop()) { // gspWaitForVBlank(); // ParxLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); // ParxRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL); // ParxBot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); hidScanInput(); u32 kDown = hidKeysHeld(); if (kDown & KEY_START) break; // break in order to return to hbmenu if (kDown & KEY_A) { CanvasString(ParxBot, CopyRight(), 10,10, LIGHT_GREEN); } if (kDown & KEY_B) { time= osGetTime(); rgb.r= 0xCC; rgb.g= 0x33; rgb.b= 0xCC; for (k=0;k<400;k++) for (l=0;l<240;l++) { SetPixL(k,l,rgb); //TopLCD SetPixR(k,l,rgb); if (k<320) SetPixB(k,l,rgb); //BotLCD } time = osGetTime() - time; sprintf(str, "%i:ms ParxPro SetPix L/R/B,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if (kDown & KEY_X) { TestPattern(); } if (kDown & KEY_Y) { InitParx(BLACK); // PasBotfill(ParxBot); rgb.r= 0xFF; rgb.g= 0x00; rgb.b= 0x8F; PasClrSrc(ParxBot, rgb); CanvasString(ParxBot, "InitParx", 10,10, GREEN); } if(kDown & KEY_CPAD_DOWN) { rgb.r= 0x00; rgb.g= 0x00; rgb.b= 0XFF; PasTopfill(ParxLeft, rgb); PasTopfill(ParxRight, rgb); } if(kDown & KEY_CPAD_UP) { rgb.r= 0xFF; rgb.g= 0x00; rgb.b= 0x00; PasTopfill(ParxLeft, rgb); PasTopfill(ParxRight, rgb); } if(kDown & KEY_CPAD_RIGHT) { rgb.r= 0x00; rgb.g= 0xFF; rgb.b= 0x00; time= osGetTime(); PasTopfill(ParxLeft, rgb); PasTopfill(ParxRight, rgb); time = osGetTime() - time; sprintf(str, "%i:ms L&R BGRTop,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if(kDown & KEY_CPAD_LEFT) { rgb.r= 0x00; rgb.g= 0x11; rgb.b= 0x00; time= osGetTime(); HexTopfill(ParxLeft); HexTopfill(ParxRight); time = osGetTime() - time; sprintf(str, "%i:ms L&R TopMapLED,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if(kDown & KEY_R) { InitBufSingle(BLACK); Topfill2; // ClrParx(ParxBot, BLACK); // sprintf(str, "Dergibal Rad:%i X:%i Y:%i", i, posx, posy); // CanvasString(ParxBot, str, 0, 0, RED); } if(kDown & KEY_L) { InitBufDub(BLACK); Topfill1; // ClrParx(ParxBot, BLACK); // sprintf(str, "Dergibal Rad:%i X:%i Y:%i", i, posx, posy); // CanvasString(ParxBot, str, 0, 0, RED); } if(kDown & KEY_DUP) { for (k=0;k<400;k++) for (l=0;l<240;l++) { if (k<320) PSetPixT(ParxRight,k,l, GetPixB(k,l)); } } if(kDown & KEY_DDOWN) { time= osGetTime(); rgb.r= 0xCC; rgb.g= 0x11; rgb.b= 0xCC; for (k=0;k<400;k++) for (l=0;l<240;l++) { PSetPixT(ParxRight,k,l, rgb); //TopLCD PSetPixT(ParxLeft,k,l, rgb); if (k<320) PSetPixB(ParxBot,k,l, rgb); //BotLCD } time = osGetTime() - time; sprintf(str, "%i:ms ParxPro,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if(kDown & KEY_DRIGHT) { ClrParx(ParxBot, BLACK); rgb.r= 0xEE; rgb.g= 0x00; rgb.b= 0xCC; time= osGetTime(); for (k=0;k<400;k++) for (l=0;l<240;l++) SetPixL(k,l,rgb); //TopLCD time = osGetTime() - time; sprintf(str, "Left %i:ms ParxPro,kdl", time); CanvasString(ParxBot, str, 10,10, LIGHT_GREEN); time= osGetTime(); for (k=0;k<400;k++) for (l=0;l<240;l++) SetPixR(k,l,rgb); time = osGetTime() - time; sprintf(str, "Right %i:ms ParxPro,kdl", time); CanvasString(ParxBot, str, 10,20, LIGHT_GREEN); } if(kDown & KEY_DLEFT) { // SetTopFramebuffers(0); time= osGetTime(); for (k=0;k<400;k++) for (l=0;l<240;l++) { SetPix(ParxRight,k,l,BLACK); SetPix(ParxLeft,k,l,BLACK); if (k<320) SetPix(ParxBot,k,l,BLACK); } time = osGetTime() - time; sprintf(str, "%i:ms Parx-GDI,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } //gfxString(ParxRight, str, 30,30, 3, rgb); //gfxString(ParxLeft, str, 30,30, 3, rgb); //for (l=1;l<16;l++) print3d(rgb,10*l,10*l,l-1,3,str); //render rainbow // renderEffect(); //copy buffer to lower screen (don't have to do it every frame) // memcpy(gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), buffer, size); //wait & swap // gfxSwapBuffersGpu(); // gspWaitForEvent(GSPGPU_EVENT_VBlank0, false); // Flush and swap framebuffers // gfxFlushBuffers(); // gfxSwapBuffers(); RefreshBuffer(); //Wait for VBlank gspWaitForVBlank(); } gfxExit(); return 0; }
// Takes ownership of the pix and destroys it. ImageData::ImageData(bool vertical, Pix* pix) : page_number_(0), vertical_text_(vertical) { SetPix(pix); }
int main() { gfxInitDefault(); gfxSet3D(true); // uncomment if using stereoscopic 3D gfxFlushBuffers(); transparent = BLACK; gfxSetScreenFormat(GFX_TOP, GSP_BGR8_OES); gfxSetScreenFormat(GFX_BOTTOM, GSP_BGR8_OES); InitParx(BLACK); /* ParxLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); ParxRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL); ParxBot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); ClrParx(ParxLeft, BLACK); ClrParx(ParxRight, BLACK); ClrParx(ParxBot, BLACK); */ char* str[256]; int l, k, j, i=20, posx = 100, posy = 100; TBGR rgbsam; TBGR rgb; u64 time; u8* tempScr; bool Dbuf; circlePosition pos; touchPosition touch; // Main loop while (aptMainLoop()) { // gspWaitForVBlank(); // ParxLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); // ParxRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL); // ParxBot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); hidScanInput(); u32 kDown = hidKeysHeld(); //Read the CirclePad position hidCircleRead(&pos); //Print the CirclePad position //- printf("\x1b[2;0H%04d; %04d", pos.dx, pos.dy); //Read the touch screen coordinates hidTouchRead(&touch); //Print the touch screen coordinates // printf("\x1b[2;0H%03d; %03d", touch.px, touch.py); if (kDown & KEY_START) break; // break in order to return to hbmenu if (kDown & KEY_A) { CanvasString(ParxBot, CopyRight(), 10,10, LIGHT_GREEN); } if (kDown & KEY_B) { time= osGetTime(); rgb.r= 0xCC; rgb.g= 0x33; rgb.b= 0xCC; for (k=0;k<400;k++) for (l=0;l<240;l++) { SetPixL(k,l,rgb); //TopLCD SetPixR(k,l,rgb); if (k<320) SetPixB(k,l,rgb); //BotLCD } time = osGetTime() - time; sprintf(str, "%i:ms ParxPro SetPix L/R/B,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if (kDown & KEY_X) { TestPattern(); } if (kDown & KEY_Y) { InitParx(BLACK); // PasBotfill(ParxBot); rgb.r= 0xFF; rgb.g= 0x00; rgb.b= 0x8F; PasClrSrc(ParxBot, rgb); CanvasString(ParxBot, "InitParx", 10,10, GREEN); } if(kDown & KEY_CPAD_DOWN) { rgb.r= 0x00; rgb.g= 0x00; rgb.b= 0XFF; PasTopfill(ParxLeft, rgb); PasTopfill(ParxRight, rgb); } if(kDown & KEY_CPAD_UP) { rgb.r= 0xFF; rgb.g= 0x00; rgb.b= 0x00; PasTopfill(ParxLeft, rgb); PasTopfill(ParxRight, rgb); } if(kDown & KEY_CPAD_RIGHT) { rgb.r= 0x00; rgb.g= 0xFF; rgb.b= 0x00; time= osGetTime(); PasTopfill(ParxLeft, rgb); PasTopfill(ParxRight, rgb); time = osGetTime() - time; sprintf(str, "%i:ms L&R BGRTop,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if(kDown & KEY_CPAD_LEFT) { rgb.r= 0x00; rgb.g= 0x11; rgb.b= 0x00; time= osGetTime(); HexTopfill(ParxLeft); HexTopfill(ParxRight); time = osGetTime() - time; sprintf(str, "%i:ms L&R TopMapLED,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if(kDown & KEY_R) { //InitBufSingle(BLACK); ClrParx(ParxBot, BLACK); //i of linearSpaceFree(); //no effect //i of vramSpaceFree(); //reads as Zero //i of mappableSpaceFree(); //no change in alloc & free sprintf(str, "v:%i m:%i l:%i", vramSpaceFree, mappableSpaceFree, linearSpaceFree); CanvasString(ParxBot, str, 0, 10, RED); Topfill2; sprintf(str, "v:%i m:%i l:%i", vramSpaceFree, mappableSpaceFree, linearSpaceFree); CanvasString(ParxBot, str, 0, 20, RED); // Topfill3; // sprintf(str, "Topfill3 Free :%i", vramSpaceFree); //CanvasString(ParxBot, str, 0, 40, RED); //sprintf(str, "Topfill3 Free :%i", ); //CanvasString(ParxBot, str, 0, 40, RED); } if(kDown & KEY_L) { if (Dbuf) InitBufDub(BLACK); else InitBufSingle(BLACK); Topfill1; ClrParx(ParxBot, BLACK); // sprintf(str, "Dergibal Rad:%i X:%i Y:%i", i, posx, posy); if (Dbuf) CanvasString(ParxBot, "InitBufDub", 0, 40, RED); else CanvasString(ParxBot, "InitBufSingle", 0, 40, RED); (BLACK); Dbuf = !Dbuf; } if(kDown & KEY_DUP) { for (k=0;k<400;k++) for (l=0;l<240;l++) { if (k<320) PSetPixT(ParxRight,k,l, GetPixB(k,l)); } } if(kDown & KEY_DDOWN) { time= osGetTime(); rgb.r= 0xCC; rgb.g= 0x11; rgb.b= 0xCC; for (k=0;k<400;k++) for (l=0;l<240;l++) { PSetPixT(ParxRight,k,l, rgb); //TopLCD PSetPixT(ParxLeft,k,l, rgb); if (k<320) PSetPixB(ParxBot,k,l, rgb); //BotLCD } time = osGetTime() - time; sprintf(str, "%i:ms ParxPro,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } if(kDown & KEY_DRIGHT) { ClrParx(ParxBot, BLACK); rgb.r= 0xEE; rgb.g= 0x00; rgb.b= 0xCC; time= osGetTime(); for (k=0;k<400;k++) for (l=0;l<240;l++) SetPixL(k,l,rgb); //TopLCD time = osGetTime() - time; sprintf(str, "Left %i:ms ParxPro,kdl", time); CanvasString(ParxBot, str, 10,10, LIGHT_GREEN); time= osGetTime(); //ParxLeft = GetSrcL(-1); // good!! //tempScr = GetSrcL(0); // good!! //tempScr = GetSrcL(1); // good!! // for (k=0;k<400;k++) // { // ParxLeft = GetSrcL(-1); // good!! // for (l=0;l<80;l++) PSetPixT(ParxRight,k,l, GetPixL(k,l)); // // ParxLeft = GetSrcL(0); // good!! // for (l=80;l<160;l++) PSetPixT(ParxRight,k,l, GetPixL(k,l)); // ParxLeft = GetSrcL(1); // good!! // for (l=160;l<240;l++) PSetPixT(ParxRight,k,l, GetPixL(k,l)); // //assignment to eg PSetPixT(GetSrcR(-1),k,l, GetPixL(k,l)) poops out // } time = osGetTime() - time; sprintf(str, "ParxLeft = GetSrcL(-1&0&1); %i:ms ,kdl", time); CanvasString(ParxBot, str, 10,20, LIGHT_GREEN); time= osGetTime(); //SetSrcR(0,tempScr); // No Good //SetSrcL(-1,ParxLeft); // //sprintf(str, "SetSrcL(-1,ParxLeft); %i:ms ,kdl", time); //CanvasString(ParxBot, str, 10,40, LIGHT_GREEN); //BufSub(-1); //BufSub(-2); //BufSub(-3); //SetSrcL(-1,ParxLeft); // sprintf(str, "SetSrcL(1,ParxLeft); %i:ms ,kdl", time); CanvasString(ParxBot, str, 10,50, LIGHT_GREEN); //SetSrcR(0,ParxRight); // //sprintf(str, "SetSrcR(0,ParxRight) %i:ms ,kdl", time); //CanvasString(ParxBot, str, 10,60, LIGHT_GREEN); // for (k=0;k<400;k++) // for (l=0;l<240;l++) PSetPixT(GetSrcR(0),k,l,rgb); //GetSrcR(0) works time = osGetTime() - time; sprintf(str, "SetSrc L&R(-1,(ParxLeft & ParxRight); %i:ms ,kdl", time); CanvasString(ParxBot, str, 10,30, LIGHT_GREEN); } if(kDown & KEY_DLEFT) { // SetTopFramebuffers(0); time= osGetTime(); for (k=0;k<400;k++) for (l=0;l<240;l++) { SetPix(ParxRight,k,l,BLACK); SetPix(ParxLeft,k,l,BLACK); if (k<320) SetPix(ParxBot,k,l,BLACK); } time = osGetTime() - time; sprintf(str, "%i:ms Parx-GDI,kdl", time); CanvasString(ParxBot, str, 10,10, GREEN); } //gfxString(ParxRight, str, 30,30, 3, rgb); //gfxString(ParxLeft, str, 30,30, 3, rgb); //for (l=1;l<16;l++) print3d(rgb,10*l,10*l,l-1,3,str); //render rainbow // renderEffect(); //copy buffer to lower screen (don't have to do it every frame) // memcpy(gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), buffer, size); //wait & swap // gfxSwapBuffersGpu(); // gspWaitForEvent(GSPGPU_EVENT_VBlank0, false); // Flush and swap framebuffers // gfxFlushBuffers(); // gfxSwapBuffers(); RefreshBuffer(); //Wait for VBlank gspWaitForVBlank(); } gfxExit(); return 0; }
void CSurface8::Wipe() { for (int i = 0; i < Wdt * Hgt; ++i) SetPix(i % Wdt, i / Wdt, 0); }
bool CSurface8::Read(CStdStream &hGroup, bool fOwnPal) { int cnt, lcnt, iLineRest; CBitmap256Info BitmapInfo; // read bmpinfo-header if (!hGroup.Read(&BitmapInfo, sizeof(CBitmapInfo))) return FALSE; // is it 8bpp? if (BitmapInfo.Info.biBitCount == 8) { if (!hGroup.Read(((BYTE *)&BitmapInfo) + sizeof(CBitmapInfo), sizeof(BitmapInfo) - sizeof(CBitmapInfo))) return FALSE; if (!hGroup.Advance(BitmapInfo.FileBitsOffset())) return FALSE; } else { // read 24bpp if (BitmapInfo.Info.biBitCount != 24) return FALSE; if (!hGroup.Advance(((CBitmapInfo)BitmapInfo).FileBitsOffset())) return FALSE; } // no 8bpp-surface in newgfx! // needs to be kept for some special surfaces // f8BitSfc=false; // Create and lock surface if (!Create(BitmapInfo.Info.biWidth, BitmapInfo.Info.biHeight, fOwnPal)) return FALSE; if (BitmapInfo.Info.biBitCount == 8) { if (HasOwnPal()) { // Copy palette for (cnt = 0; cnt < 256; cnt++) { pPal->Colors[cnt * 3 + 0] = BitmapInfo.Colors[cnt].rgbRed; pPal->Colors[cnt * 3 + 1] = BitmapInfo.Colors[cnt].rgbGreen; pPal->Colors[cnt * 3 + 2] = BitmapInfo.Colors[cnt].rgbBlue; pPal->Alpha[cnt] = 0; } } } // create line buffer int iBufSize = DWordAligned(BitmapInfo.Info.biWidth * BitmapInfo.Info.biBitCount / 8); BYTE *pBuf = new BYTE[iBufSize]; // Read lines iLineRest = DWordAligned(BitmapInfo.Info.biWidth) - BitmapInfo.Info.biWidth; for (lcnt = Hgt - 1; lcnt >= 0; lcnt--) { if (!hGroup.Read(pBuf, iBufSize)) { Clear(); delete[] pBuf; return FALSE; } BYTE *pPix = pBuf; for (int x = 0; x < BitmapInfo.Info.biWidth; ++x) switch (BitmapInfo.Info.biBitCount) { case 8: SetPix(x, lcnt, *pPix++); break; case 24: return false; break; } } // free buffer again delete[] pBuf; return TRUE; }
void CSurface8::Polygon(int iNum, int *ipVtx, int iCol) { // Variables for polygon drawer int c, x1, x2, y; int top = INT_MAX; int bottom = INT_MIN; int *i1, *i2; CPolyEdge *edge, *next_edge, *edgebuf; CPolyEdge *active_edges = NULL; CPolyEdge *inactive_edges = NULL; BOOL use_qpb = FALSE; // Poly Buf if (iNum <= QuickPolyBufSize) { edgebuf = QuickPolyBuf; use_qpb = TRUE; } else if (!(edgebuf = new CPolyEdge[iNum])) { return; } // Fill the edge table edge = edgebuf; i1 = ipVtx; i2 = ipVtx + (iNum - 1) * 2; for (c = 0; c < iNum; c++) { if (i1[1] != i2[1]) { fill_edge_structure(edge, i1, i2); if (edge->bottom >= edge->y) { if (edge->y < top) top = edge->y; if (edge->bottom > bottom) bottom = edge->bottom; inactive_edges = add_edge(inactive_edges, edge, FALSE); edge++; } } i2 = i1; i1 += 2; } // For each scanline in the polygon... for (c = top; c <= bottom; c++) { // Check for newly active edges edge = inactive_edges; while ((edge) && (edge->y == c)) { next_edge = edge->next; inactive_edges = remove_edge(inactive_edges, edge); active_edges = add_edge(active_edges, edge, TRUE); edge = next_edge; } // Draw horizontal line segments edge = active_edges; while ((edge) && (edge->next)) { x1 = edge->x >> POLYGON_FIX_SHIFT; x2 = (edge->next->x + edge->next->w) >> POLYGON_FIX_SHIFT; y = c; // Fix coordinates if (x1 > x2) Swap(x1, x2); // Set line for (int xcnt = x2 - x1; xcnt >= 0; xcnt--) SetPix(x1 + xcnt, y, iCol); edge = edge->next->next; } // Update edges, sorting and removing dead ones edge = active_edges; while (edge) { next_edge = edge->next; if (c >= edge->bottom) { active_edges = remove_edge(active_edges, edge); } else { edge->x += edge->dx; while ((edge->prev) && (edge->x + edge->w / 2 < edge->prev->x + edge->prev->w / 2)) { if (edge->next) edge->next->prev = edge->prev; edge->prev->next = edge->next; edge->next = edge->prev; edge->prev = edge->prev->prev; edge->next->prev = edge; if (edge->prev) edge->prev->next = edge; else active_edges = edge; } } edge = next_edge; } } // Clear scratch memory if (!use_qpb) delete[] edgebuf; }
// Takes ownership of the pix and destroys it. ImageData::ImageData(Pix* pix) : page_number_(0), partial_boxes_(false) { SetPix(pix); }
void C4MapCreator::Create(CSurface8 *sfcMap, C4SLandscape &rLScape, C4TextureMap &rTexMap, BOOL fLayers, int32_t iPlayerNum) { double fullperiod = 20.0 * pi; BYTE ccol; int32_t cx, cy; // Safeties if (!sfcMap) return; iPlayerNum = BoundBy<int32_t>(iPlayerNum, 1, C4S_MaxPlayer); // Set creator variables MapBuf = sfcMap; MapWdt = MapBuf->Wdt; MapHgt = MapBuf->Hgt; // Reset map (0 is sky) MapBuf->ClearBox8Only(0, 0, MapBuf->Wdt, MapBuf->Hgt); // Surface ccol = rTexMap.GetIndexMatTex(rLScape.Material, "Smooth") + MapIFT; float amplitude = (float)rLScape.Amplitude.Evaluate(); float phase = (float)rLScape.Phase.Evaluate(); float period = (float)rLScape.Period.Evaluate(); if (rLScape.MapPlayerExtend) period *= Min(iPlayerNum, C4S_MaxMapPlayerExtend); float natural = (float)rLScape.Random.Evaluate(); int32_t level0 = Min(MapWdt, MapHgt) / 2; int32_t maxrange = level0 * 3 / 4; double cy_curve, cy_natural; // -1.0 - +1.0 ! double rnd_cy, rnd_tend; // -1.0 - +1.0 ! rnd_cy = (double)(Random(2000 + 1) - 1000) / 1000.0; rnd_tend = (double)(Random(200 + 1) - 100) / 20000.0; for (cx = 0; cx < MapWdt; cx++) { rnd_cy += rnd_tend; rnd_tend += (double)(Random(100 + 1) - 50) / 10000; if (rnd_tend > +0.05) rnd_tend = +0.05; if (rnd_tend < -0.05) rnd_tend = -0.05; if (rnd_cy < -0.5) rnd_tend += 0.01; if (rnd_cy > +0.5) rnd_tend -= 0.01; cy_natural = rnd_cy * natural / 100.0; cy_curve = sin(fullperiod * period / 100.0 * (float)cx / (float)MapWdt + 2.0 * pi * phase / 100.0) * amplitude / 100.0; cy = level0 + BoundBy((int32_t)((float)maxrange * (cy_curve + cy_natural)), -maxrange, +maxrange); SetPix(cx, cy, ccol); } // Raise bottom to surface for (cx = 0; cx < MapWdt; cx++) for (cy = MapHgt - 1; (cy >= 0) && !GetPix(cx, cy); cy--) SetPix(cx, cy, ccol); // Raise liquid level Exclusive = 0; ccol = rTexMap.GetIndexMatTex(rLScape.Liquid, "Smooth"); int32_t wtr_level = rLScape.LiquidLevel.Evaluate(); for (cx = 0; cx < MapWdt; cx++) for (cy = MapHgt * (100 - wtr_level) / 100; cy < MapHgt; cy++) SetPix(cx, cy, ccol); Exclusive = -1; // Layers if (fLayers) { // Base material Exclusive = rTexMap.GetIndexMatTex(rLScape.Material, "Smooth") + MapIFT; int32_t cnt, clayer, layer_num, sptx, spty; // Process layer name list for (clayer = 0; clayer < C4MaxNameList; clayer++) if (rLScape.Layers.Name[clayer][0]) { // Draw layers ccol = rTexMap.GetIndexMatTex(rLScape.Layers.Name[clayer], "Rough") + MapIFT; layer_num = rLScape.Layers.Count[clayer]; layer_num = layer_num * MapWdt * MapHgt / 15000; for (cnt = 0; cnt < layer_num; cnt++) { // Place layer sptx = Random(MapWdt); for (spty = 0; (spty < MapHgt) && (GetPix(sptx, spty) != Exclusive); spty++) ; spty += 5 + Random((MapHgt - spty) - 10); DrawLayer(sptx, spty, Random(15), ccol); } } Exclusive = -1; } }