//--------------------------------------------------------- inline void CWKSP_TIN::_Draw_Triangle_Line(CWKSP_Map_DC &dc_Map, int xa, int xb, int y, double za, double zb) { int Color; double dz; if( (dz = xb - xa) > 0.0 ) { dz = (zb - za) / dz; if( xa < 0 ) { za -= dz * xa; xa = 0; } if( xb >= dc_Map.m_rDC.GetWidth() ) { xb = dc_Map.m_rDC.GetWidth() - 1; } for(int x=xa; x<=xb; x++, za+=dz) { DRAW_PIXEL(x, y, za); } } else if( xa >= 0 && xa < dc_Map.m_rDC.GetWidth() ) { DRAW_PIXEL(xa, y, za); } }
void FindObjectMain::draw_pixel(VFrame *frame, int x, int y) { if(!(x >= 0 && y >= 0 && x < frame->get_w() && y < frame->get_h())) return; #define DRAW_PIXEL(x, y, components, do_yuv, max, type) \ { \ type **rows = (type**)frame->get_rows(); \ rows[y][x * components] = max - rows[y][x * components]; \ if(!do_yuv) \ { \ rows[y][x * components + 1] = max - rows[y][x * components + 1]; \ rows[y][x * components + 2] = max - rows[y][x * components + 2]; \ } \ else \ { \ rows[y][x * components + 1] = (max / 2 + 1) - rows[y][x * components + 1]; \ rows[y][x * components + 2] = (max / 2 + 1) - rows[y][x * components + 2]; \ } \ if(components == 4) \ rows[y][x * components + 3] = max; \ } switch(frame->get_color_model()) { case BC_RGB888: DRAW_PIXEL(x, y, 3, 0, 0xff, unsigned char); break; case BC_RGBA8888: DRAW_PIXEL(x, y, 4, 0, 0xff, unsigned char); break; case BC_RGB_FLOAT: DRAW_PIXEL(x, y, 3, 0, 1.0, float); break; case BC_RGBA_FLOAT: DRAW_PIXEL(x, y, 4, 0, 1.0, float); break; case BC_YUV888: DRAW_PIXEL(x, y, 3, 1, 0xff, unsigned char); break; case BC_YUVA8888: DRAW_PIXEL(x, y, 4, 1, 0xff, unsigned char); break; case BC_RGB161616: DRAW_PIXEL(x, y, 3, 0, 0xffff, uint16_t); break; case BC_YUV161616: DRAW_PIXEL(x, y, 3, 1, 0xffff, uint16_t); break; case BC_RGBA16161616: DRAW_PIXEL(x, y, 4, 0, 0xffff, uint16_t); break; case BC_YUVA16161616: DRAW_PIXEL(x, y, 4, 1, 0xffff, uint16_t); break; } }
void Draw_FilledCircle(int x0, int y0, int r, int backgroundColor, int borderColor, int Draw_Border) { for (int x = -r; x <= r; x++) { int dy = (int)(sqrt(r*r - x*x)); for (int y = -dy; y <= dy; y++) { DRAW_PIXEL(x0+x, y0+y, backgroundColor); } } if (Draw_Border) Draw_Circle(x0,y0,r,borderColor); }
void ScreenDimmer::draw(const Common::Rect &r) { // We're going to emulate QuickDraw's srcOr+gray mode here // In this mode, every other y column is all black (odd-columns). // Basically, every row does three black and then one transparent // repeatedly. // The output is identical to the original uint32 black = g_system->getScreenFormat().RGBToColor(0, 0, 0); Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getWorkArea(); byte bytesPerPixel = g_system->getScreenFormat().bytesPerPixel; // We're currently doing it to the whole screen to simplify the code for (int y = 0; y < 480; y++) { byte *dst = (byte *)screen->getBasePtr(0, y); for (int x = 0; x < 640; x += 4) { if (y & 1) { DRAW_PIXEL(); DRAW_PIXEL(); SKIP_PIXEL(); DRAW_PIXEL(); } else { SKIP_PIXEL(); DRAW_PIXEL(); DRAW_PIXEL(); DRAW_PIXEL(); } } } }
void Draw_FilledRectangle(int x0, int y0, int width, int height, int backgroundColor, int borderColor, int Draw_Border) { // Draw background for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { DRAW_PIXEL(x0 + x, y0 + y, backgroundColor); } } // Draw border if (Draw_Border) Draw_Rectangle(x0, y0, width, height, borderColor); }
// Implemented with Bresenham's algorithm (taken from the site // http://rosettacode.org/wiki/Bitmap/Bresenham's_line_algorithm void Draw_Line(int x0, int y0, int x1, int y1, int lineColor) { 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(;;) { DRAW_PIXEL(x0, y0, lineColor); if (x0==x1 && y0==y1) break; e2 = err; if (e2 >-dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } }
UINT32 uv201_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { bitmap.fill(get_black_pen(machine()), cliprect); if (!(m_cmd & COMMAND_ENB)) { return 0; } for (int y = 0; y < SCREEN_HEIGHT; y++) { for (int x = 0; x < VISAREA_WIDTH; x++) { int pixel = m_bg; DRAW_PIXEL(y, x); } } for (int i = 0; i < 16; i++) { UINT8 xy_hi = (m_cmd & COMMAND_A_B) ? RAM(RAM_XY_HI_A) : RAM(RAM_XY_HI_B); UINT8 y_lo = (m_cmd & COMMAND_A_B) ? RAM(RAM_Y_LO_A) : RAM(RAM_Y_LO_B); UINT16 y = (BIT(xy_hi, 7) << 8) | y_lo; int xord = xy_hi & 0x0f; UINT8 rp_hi_color = RAM_XORD(RAM_RP_HI_COLOR); UINT8 rp_lo = RAM_XORD(RAM_RP_LO); UINT16 rp = ((rp_hi_color << 8) | rp_lo) & 0x1fff; if (rp < 0x800) rp |= 0x2000; UINT8 dx_int_xcopy = RAM_XORD(RAM_DX_INT_XCOPY); int color = ((dx_int_xcopy & 0x60) >> 2) | (BIT(rp_hi_color, 5) << 2) | (BIT(rp_hi_color, 6) << 1) | (BIT(rp_hi_color, 7)); UINT8 dx = dx_int_xcopy & 0x1f; UINT8 dy = RAM_XORD(RAM_DY); int xcopy = BIT(dx_int_xcopy, 7); UINT8 x = RAM_XORD(RAM_X); if (LOG) logerror("Object %u xord %u y %u x %u dy %u dx %u xcopy %u color %u rp %04x\n", i, xord, y, x, dy, dx, xcopy, color, rp); if (rp == 0) continue; if (y > SCREEN_HEIGHT) continue; for (int sy = 0; sy < dy; sy++) { for (int sx = 0; sx < dx; sx++) { UINT8 data = m_in_db_func(rp); for (int bit = 0; bit < 8; bit++) { int pixel = ((BIT(data, 7) ? color : m_bg) ^ m_fmod) & 0x1f; if (m_cmd & COMMAND_Y_ZM) { int scanline = y + (sy * 2); if (m_cmd & COMMAND_X_ZM) { int dot = (x * 2) + (sx * 16) + (bit * 2); DRAW_PIXEL(scanline, dot); DRAW_PIXEL(scanline, dot + 1); DRAW_PIXEL(scanline + 1, dot); DRAW_PIXEL(scanline + 1, dot + 1); } else { int dot = x + (sx * 8) + bit; DRAW_PIXEL(scanline, dot); DRAW_PIXEL(scanline + 1, dot); } } else { int scanline = y + sy; if (m_cmd & COMMAND_X_ZM) { int dot = (x * 2) + (sx * 16) + (bit * 2); DRAW_PIXEL(scanline, dot); DRAW_PIXEL(scanline, dot + 1); } else { int dot = x + (sx * 8) + bit; DRAW_PIXEL(scanline, dot); } } data <<= 1; } if (!xcopy) rp++; } if (xcopy) rp++; } } return 0; }
void Draw_VerticalLine(int x0, int y0, int length, int lineColor) { for (int i = 0; i < length; i++) { DRAW_PIXEL(x0, y0 + i, lineColor); } }
void plot4points(int x0, int y0, int x, int y, int borderColor) { DRAW_PIXEL(x0 + x, y0 + y, borderColor); if (x != 0) DRAW_PIXEL(x0 - x, y0 + y, borderColor); if (y != 0) DRAW_PIXEL(x0 + x, y0 - y, borderColor); if (x != 0 && y != 0) DRAW_PIXEL(x0 - x, y0 - y, borderColor); }
void Draw_HorizontalLine(int x0, int y0, int length, int lineColor) { for (int i = 0; i < length; i++) { DRAW_PIXEL(i + x0, y0, lineColor); } }
void DrawAlphaGradientCircleLine (const SAlphaGradientCircleLineCtx &Ctx, int x, int y) { int xStart = Ctx.xDest - x; int xEnd = Ctx.xDest + x + 1; const RECT &rcClip = Ctx.pDest->GetClipRect(); if (xEnd <= rcClip.left || xStart >= rcClip.right) return; // See which lines we need to paint int yLine = Ctx.yDest - y; bool bPaintTop = (yLine >= rcClip.top && yLine < rcClip.bottom); WORD *pCenterTop = Ctx.pDest->GetRowStart(yLine) + Ctx.xDest; yLine = Ctx.yDest + y; bool bPaintBottom = ((y > 0) && (yLine >= rcClip.top && yLine < rcClip.bottom)); WORD *pCenterBottom = Ctx.pDest->GetRowStart(yLine) + Ctx.xDest; // Compute radius increment int iRadius = y; int d = -y; int deltaE = 3; int deltaSE = -2 * y + 1; // Loop int xPos = 0; // This will skip the center pixel in the circle (avoids a divide by // zero in the inner loop). if (y == 0) { xPos = 1; d += deltaSE; deltaE += 2; iRadius++; } // Blt the line while (xPos <= x) { // Figure out the radius of the pixel at this location if (d < 0) { d += deltaE; deltaE += 2; deltaSE += 2; } else { d += deltaSE; deltaE += 2; // deltaSE += 0; iRadius++; } // Compute the transparency based on the radius DWORD dwTrans = 255 - (255 * iRadius / Ctx.iRadius); if (dwTrans > 255) { xPos++; continue; } #define DRAW_PIXEL(pos) \ { \ DWORD dwDest = (DWORD)*(pos); \ DWORD dwRedDest = (dwDest >> 11) & 0x1f; \ DWORD dwGreenDest = (dwDest >> 5) & 0x3f; \ DWORD dwBlueDest = dwDest & 0x1f; \ \ *(pos) = (WORD)((dwTrans * (Ctx.dwBlue - dwBlueDest) >> 8) + dwBlueDest | \ ((dwTrans * (Ctx.dwGreen - dwGreenDest) >> 8) + dwGreenDest) << 5 | \ ((dwTrans * (Ctx.dwRed - dwRedDest) >> 8) + dwRedDest) << 11); \ } // Paint if (Ctx.xDest - xPos < rcClip.right && Ctx.xDest - xPos >= rcClip.left) { if (bPaintTop) DRAW_PIXEL(pCenterTop - xPos); if (bPaintBottom) DRAW_PIXEL(pCenterBottom - xPos); } if (xPos > 0 && Ctx.xDest + xPos < rcClip.right && Ctx.xDest + xPos >= rcClip.left) { if (bPaintTop) DRAW_PIXEL(pCenterTop + xPos); if (bPaintBottom) DRAW_PIXEL(pCenterBottom + xPos); } #undef DRAW_PIXEL xPos++; } }
void DrawGlowRingLine (const SGlowRingLineCtx &Ctx, int x, int y) { int xStart = Ctx.xDest - x; int xEnd = Ctx.xDest + x + 1; const RECT &rcClip = Ctx.pDest->GetClipRect(); if (xEnd <= rcClip.left || xStart >= rcClip.right) return; // See which lines we need to paint int yLine = Ctx.yDest - y; bool bPaintTop = (yLine >= rcClip.top && yLine < rcClip.bottom); WORD *pCenterTop = Ctx.pDest->GetRowStart(yLine) + Ctx.xDest; yLine = Ctx.yDest + y; bool bPaintBottom = ((y > 0) && (yLine >= rcClip.top && yLine < rcClip.bottom)); WORD *pCenterBottom = Ctx.pDest->GetRowStart(yLine) + Ctx.xDest; // Compute radius increment int iRadius = y; int d = -y; int deltaE = 3; int deltaSE = -2 * y + 1; // Loop int xPos = 0; // This will skip the center pixel in the circle (avoids a divide by // zero in the inner loop). if (y == 0) { xPos = 1; d += deltaSE; deltaE += 2; iRadius++; } // Blt the line while (xPos <= x) { // Figure out the radius of the pixel at this location if (d < 0) { d += deltaE; deltaE += 2; deltaSE += 2; } else { d += deltaSE; deltaE += 2; // deltaSE += 0; iRadius++; } // Compute the index into the ramp based on radius and ring thickness // (If we're outside the ramp, then continue) int iIndex = Ctx.iRadius - iRadius; if (iIndex >= Ctx.iRingThickness || iIndex < 0) { xPos++; continue; } // Compute the transparency DWORD dwOpacity = Ctx.byOpacity[iIndex]; // Optimize opaque painting if (dwOpacity >= 255) { WORD wColor = Ctx.wColor[iIndex]; if (Ctx.xDest - xPos < rcClip.right && Ctx.xDest - xPos >= rcClip.left) { if (bPaintTop) *(pCenterTop - xPos) = wColor; if (bPaintBottom) *(pCenterBottom - xPos) = wColor; } if (xPos > 0 && Ctx.xDest + xPos < rcClip.right && Ctx.xDest + xPos >= rcClip.left) { if (bPaintTop) *(pCenterTop + xPos) = wColor; if (bPaintBottom) *(pCenterBottom + xPos) = wColor; } } else if (dwOpacity == 0) ; else { DWORD dwRed = Ctx.dwRed[iIndex]; DWORD dwGreen = Ctx.dwGreen[iIndex]; DWORD dwBlue = Ctx.dwBlue[iIndex]; // Draw transparent #define DRAW_PIXEL(pos) \ { \ DWORD dwDest = (DWORD)*(pos); \ DWORD dwRedDest = (dwDest >> 11) & 0x1f; \ DWORD dwGreenDest = (dwDest >> 5) & 0x3f; \ DWORD dwBlueDest = dwDest & 0x1f; \ \ *(pos) = (WORD)((dwOpacity * (dwBlue - dwBlueDest) >> 8) + dwBlueDest | \ ((dwOpacity * (dwGreen - dwGreenDest) >> 8) + dwGreenDest) << 5 | \ ((dwOpacity * (dwRed - dwRedDest) >> 8) + dwRedDest) << 11); \ } // Paint if (Ctx.xDest - xPos < rcClip.right && Ctx.xDest - xPos >= rcClip.left) { if (bPaintTop) DRAW_PIXEL(pCenterTop - xPos); if (bPaintBottom) DRAW_PIXEL(pCenterBottom - xPos); } if (xPos > 0 && Ctx.xDest + xPos < rcClip.right && Ctx.xDest + xPos >= rcClip.left) { if (bPaintTop) DRAW_PIXEL(pCenterTop + xPos); if (bPaintBottom) DRAW_PIXEL(pCenterBottom + xPos); } #undef DRAW_PIXEL } xPos++; } }
void CGlowingRingPainter::DrawLine (int x, int y) // DrawLine // // Draws a line { int xStart = m_xDest - x; int xEnd = m_xDest + x + 1; if (xEnd <= m_rcClip.left || xStart >= m_rcClip.right) return; // See which lines we need to paint int yLine = m_yDest - y; bool bPaintTop = (yLine >= m_rcClip.top && yLine < m_rcClip.bottom); CG32bitPixel *pCenterTop = m_Dest.GetPixelPos(m_xDest, yLine); yLine = m_yDest + y; bool bPaintBottom = ((y > 0) && (yLine >= m_rcClip.top && yLine < m_rcClip.bottom)); CG32bitPixel *pCenterBottom = m_Dest.GetPixelPos(m_xDest, yLine); // Compute radius increment int iRadius = y; int d = -y; int deltaE = 3; int deltaSE = -2 * y + 1; // Loop int xPos = 0; // This will skip the center pixel in the circle (avoids a divide by // zero in the inner loop). if (y == 0) { xPos = 1; d += deltaSE; deltaE += 2; iRadius++; } // Blt the line while (xPos <= x) { // Figure out the radius of the pixel at this location if (d < 0) { d += deltaE; deltaE += 2; deltaSE += 2; } else { d += deltaSE; deltaE += 2; // deltaSE += 0; iRadius++; } // Compute the index into the ramp based on radius and ring thickness // (If we're outside the ramp, then continue) int iIndex = m_iRadius - iRadius; if (iIndex >= m_iWidth || iIndex < 0) { xPos++; continue; } // Compute the transparency CG32bitPixel rgbColor = m_pColorRamp->GetAt(iIndex); BYTE byOpacity = rgbColor.GetAlpha(); // Optimize opaque painting if (byOpacity == 0x00) ; else if (byOpacity == 0xff) { if (m_xDest - xPos < m_rcClip.right && m_xDest - xPos >= m_rcClip.left) { if (bPaintTop) *(pCenterTop - xPos) = rgbColor; if (bPaintBottom) *(pCenterBottom - xPos) = rgbColor; } if (xPos > 0 && m_xDest + xPos < m_rcClip.right && m_xDest + xPos >= m_rcClip.left) { if (bPaintTop) *(pCenterTop + xPos) = rgbColor; if (bPaintBottom) *(pCenterBottom + xPos) = rgbColor; } } else { BYTE *pAlphaInv = CG32bitPixel::AlphaTable(byOpacity ^ 0xff); WORD wRed = rgbColor.GetRed(); WORD wGreen = rgbColor.GetGreen(); WORD wBlue = rgbColor.GetBlue(); // Draw transparent #define DRAW_PIXEL(pos) \ { \ BYTE byRedResult = (BYTE)Min((WORD)0xff, (WORD)(pAlphaInv[(pos)->GetRed()] + wRed)); \ BYTE byGreenResult = (BYTE)Min((WORD)0xff, (WORD)(pAlphaInv[(pos)->GetGreen()] + wGreen)); \ BYTE byBlueResult = (BYTE)Min((WORD)0xff, (WORD)(pAlphaInv[(pos)->GetBlue()] + wBlue)); \ \ *(pos) = CG32bitPixel(byRedResult, byGreenResult, byBlueResult); \ } // Paint if (m_xDest - xPos < m_rcClip.right && m_xDest - xPos >= m_rcClip.left) { if (bPaintTop) DRAW_PIXEL(pCenterTop - xPos); if (bPaintBottom) DRAW_PIXEL(pCenterBottom - xPos); } if (xPos > 0 && m_xDest + xPos < m_rcClip.right && m_xDest + xPos >= m_rcClip.left) { if (bPaintTop) DRAW_PIXEL(pCenterTop + xPos); if (bPaintBottom) DRAW_PIXEL(pCenterBottom + xPos); } #undef DRAW_PIXEL } xPos++; } }
//--------------------------------------------------------- void CWKSP_TIN::_Draw_Triangle(CWKSP_Map_DC &dc_Map, TPoint p[3]) { int i, j, y, y_j, Color; double x, x_a, dx, dx_a, dy, z, z_a, dz, dz_a; TPoint pp; //----------------------------------------------------- SORT_POINTS_Y(1, 0); SORT_POINTS_Y(2, 0); SORT_POINTS_Y(2, 1); //----------------------------------------------------- if( p[2].y == p[0].y ) { if( p[0].y >= 0 && p[0].y < dc_Map.m_rDC.GetHeight() ) { SORT_POINTS_X(1, 0); SORT_POINTS_X(2, 0); SORT_POINTS_X(2, 1); //--------------------------------------------- if( p[2].x == p[0].x ) { if( p[0].x >= 0 && p[0].x < dc_Map.m_rDC.GetWidth() ) { DRAW_PIXEL(p[0].x, p[0].y, p[0].z > p[1].z ? (p[0].z > p[2].z ? p[0].z : p[2].z) : (p[1].z > p[2].z ? p[1].z : p[2].z) ); } } //--------------------------------------------- else { _Draw_Triangle_Line(dc_Map, p[0].x, p[1].x, p[0].y, p[0].z, p[1].z); _Draw_Triangle_Line(dc_Map, p[1].x, p[2].x, p[0].y, p[1].z, p[2].z); } } } //----------------------------------------------------- else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= dc_Map.m_rDC.GetHeight() && p[2].y >= dc_Map.m_rDC.GetHeight())) ) { dy = p[2].y - p[0].y; dx_a = (p[2].x - p[0].x) / dy; dz_a = (p[2].z - p[0].z) / dy; x_a = p[0].x; z_a = p[0].z; for(i=0, j=1; i<2; i++, j++) { if( (dy = p[j].y - p[i].y) > 0.0 ) { dx = (p[j].x - p[i].x) / dy; dz = (p[j].z - p[i].z) / dy; x = p[i].x; z = p[i].z; if( (y = p[i].y) < 0 ) { x -= y * dx; z -= y * dz; y = 0; x_a = p[0].x - p[0].y * dx_a; z_a = p[0].z - p[0].y * dz_a; } if( (y_j = p[j].y) > dc_Map.m_rDC.GetHeight() ) { y_j = dc_Map.m_rDC.GetHeight(); } for( ; y<y_j; y++, x+=dx, z+=dz, x_a+=dx_a, z_a+=dz_a) { if( x < x_a ) { _Draw_Triangle_Line(dc_Map, (int)x, (int)x_a, y, z, z_a); } else { _Draw_Triangle_Line(dc_Map, (int)x_a, (int)x, y, z_a, z); } } } } } }