Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __inline void __ClipPrimitive(CFrameBuffer* fbDesc, int* dw, int* dh)
- {
- if(*dw > fbDesc->width)
- *dw = fbDesc->width - 1;
- if(*dh > fbDesc->height)
- *dh = fbDesc->height - 1;
- }
- void CGraphics::PutPixel(int x, int y, CColor color)
- {
- if(x < 0 || y < 0)
- return;
- char* col = &backBuffer[(y * fbDesc.width + x) * 3];
- col[0] = color.R;
- col[1] = color.G;
- col[2] = color.B;
- }
- void CGraphics::PutPixelAlpha(int x, int y, CColor color, float alpha)
- {
- if(x < 0 || y < 0)
- return;
- char* col = &backBuffer[(y * fbDesc.width + x) * 3];
- col[0] = (byte)(color.R * alpha + col[0] * (1.0f - alpha));
- col[1] = (byte)(color.G * alpha + col[1] * (1.0f - alpha));
- col[2] = (byte)(color.B * alpha + col[2] * (1.0f - alpha));
- }
- void CGraphics::DrawImage(CImage* img, int x, int y)
- {
- if(img)
- {
- if(!img->IsTransparent)
- {
- for(int i = 0; i < img->Height; i++)
- {
- for(int j = 0; j < img->Width; j++)
- {
- if(j >= fbDesc.width)
- break;
- CColor col;
- unsigned char* pixels = &img->Pixels[((img->Height - i - 1) * img->Width + j) * 3];
- col.R = pixels[2];
- col.G = pixels[1];
- col.B = pixels[0];
- PutPixel(x + j, y + i, col);
- }
- if(i >= fbDesc.height)
- break;
- }
- }
- else
- {
- for(int i = 0; i < img->Height; i++)
- {
- for(int j = 0; j < img->Width; j++)
- {
- if(j >= fbDesc.width)
- break;
- CColor col;
- unsigned char* pixels = &img->Pixels[((img->Height - i - 1) * img->Width + j) * 4];
- col.R = pixels[2];
- col.G = pixels[1];
- col.B = pixels[0];
- float alpha = (float)pixels[3] / 255;
- PutPixelAlpha(x + j, y + i, col, alpha);
- }
- if(i >= fbDesc.height)
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement