Advertisement
Guest User

Untitled

a guest
Aug 18th, 2023
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. __inline void __ClipPrimitive(CFrameBuffer* fbDesc, int* dw, int* dh)
  2. {
  3.     if(*dw > fbDesc->width)
  4.         *dw = fbDesc->width - 1;
  5.  
  6.     if(*dh > fbDesc->height)
  7.         *dh = fbDesc->height - 1;
  8. }
  9.  
  10. void CGraphics::PutPixel(int x, int y, CColor color)
  11. {
  12.     if(x < 0 || y < 0)
  13.         return;
  14.    
  15.     char* col = &backBuffer[(y * fbDesc.width + x) * 3];
  16.     col[0] = color.R;
  17.     col[1] = color.G;
  18.     col[2] = color.B;
  19. }
  20.  
  21. void CGraphics::PutPixelAlpha(int x, int y, CColor color, float alpha)
  22. {
  23.     if(x < 0 || y < 0)
  24.         return;
  25.    
  26.     char* col = &backBuffer[(y * fbDesc.width + x) * 3];
  27.  
  28.     col[0] = (byte)(color.R * alpha + col[0] * (1.0f - alpha));
  29.     col[1] = (byte)(color.G * alpha + col[1] * (1.0f - alpha));
  30.     col[2] = (byte)(color.B * alpha + col[2] * (1.0f - alpha));
  31. }
  32.  
  33. void CGraphics::DrawImage(CImage* img, int x, int y)
  34. {
  35.     if(img)
  36.     {
  37.         if(!img->IsTransparent)
  38.         {
  39.             for(int i = 0; i < img->Height; i++)
  40.             {
  41.                 for(int j = 0; j < img->Width; j++)
  42.                 {
  43.                     if(j >= fbDesc.width)
  44.                         break;
  45.  
  46.                     CColor col;
  47.                     unsigned char* pixels = &img->Pixels[((img->Height - i - 1) * img->Width + j) * 3];
  48.  
  49.                     col.R = pixels[2];
  50.                     col.G = pixels[1];
  51.                     col.B = pixels[0];
  52.  
  53.                     PutPixel(x + j, y + i, col);
  54.                 }
  55.  
  56.                 if(i >= fbDesc.height)
  57.                     break;
  58.             }
  59.         }
  60.         else
  61.         {
  62.             for(int i = 0; i < img->Height; i++)
  63.             {
  64.                 for(int j = 0; j < img->Width; j++)
  65.                 {
  66.                     if(j >= fbDesc.width)
  67.                         break;
  68.  
  69.                     CColor col;
  70.                     unsigned char* pixels = &img->Pixels[((img->Height - i - 1) * img->Width + j) * 4];
  71.  
  72.                     col.R = pixels[2];
  73.                     col.G = pixels[1];
  74.                     col.B = pixels[0];
  75.                     float alpha = (float)pixels[3] / 255;
  76.  
  77.                     PutPixelAlpha(x + j, y + i, col, alpha);
  78.                 }
  79.  
  80.                 if(i >= fbDesc.height)
  81.                     break;
  82.             }
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement