ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dib32bpp.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         Win32 subsystem
00003  * LICENSE:         See COPYING in the top level directory
00004  * FILE:            subsystems/win32/win32k/dib/dib32bpp.c
00005  * PURPOSE:         Device Independant Bitmap functions, 32bpp
00006  * PROGRAMMERS:     Jason Filby
00007  *                  Thomas Bluemel
00008  *                  Gregor Anich
00009  */
00010 
00011 #include <win32k.h>
00012 
00013 #define NDEBUG
00014 #include <debug.h>
00015 
00016 VOID
00017 DIB_32BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c)
00018 {
00019   PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta;
00020   PDWORD addr = (PDWORD)byteaddr + x;
00021 
00022   *addr = c;
00023 }
00024 
00025 ULONG
00026 DIB_32BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y)
00027 {
00028   PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta;
00029   PDWORD addr = (PDWORD)byteaddr + x;
00030 
00031   return (ULONG)(*addr);
00032 }
00033 
00034 VOID
00035 DIB_32BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
00036 {
00037   PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y1 * SurfObj->lDelta;
00038   PDWORD addr = (PDWORD)byteaddr + x;
00039   LONG lDelta = SurfObj->lDelta >> 2; // >> 2 == / sizeof(DWORD)
00040 
00041   byteaddr = (PBYTE)addr;
00042   while (y1++ < y2)
00043   {
00044     *addr = (DWORD)c;
00045     addr += lDelta;
00046   }
00047 }
00048 
00049 BOOLEAN
00050 DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
00051 {
00052   LONG     i, j, sx, sy, xColor, f1;
00053   PBYTE    SourceBits, DestBits, SourceLine, DestLine;
00054   PBYTE    SourceBits_4BPP, SourceLine_4BPP;
00055   PDWORD   Source32, Dest32;
00056 
00057   DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
00058     + (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta)
00059     + 4 * BltInfo->DestRect.left;
00060 
00061   switch (BltInfo->SourceSurface->iBitmapFormat)
00062   {
00063   case BMF_1BPP:
00064 
00065     sx = BltInfo->SourcePoint.x;
00066     sy = BltInfo->SourcePoint.y;
00067 
00068     for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
00069     {
00070       sx = BltInfo->SourcePoint.x;
00071       for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
00072       {
00073         if (DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0)
00074         {
00075           DIB_32BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0));
00076         } else {
00077           DIB_32BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1));
00078         }
00079         sx++;
00080       }
00081       sy++;
00082     }
00083     break;
00084 
00085   case BMF_4BPP:
00086     SourceBits_4BPP = (PBYTE)BltInfo->SourceSurface->pvScan0
00087       + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
00088       + (BltInfo->SourcePoint.x >> 1);
00089 
00090     for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
00091     {
00092       SourceLine_4BPP = SourceBits_4BPP;
00093       sx = BltInfo->SourcePoint.x;
00094       f1 = sx & 1;
00095 
00096       for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
00097       {
00098         xColor = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest,
00099           (*SourceLine_4BPP & altnotmask[f1]) >> (4 * (1 - f1)));
00100         DIB_32BPP_PutPixel(BltInfo->DestSurface, i, j, xColor);
00101         if (f1 == 1) {
00102           SourceLine_4BPP++;
00103           f1 = 0;
00104         } else {
00105           f1 = 1;
00106         }
00107         sx++;
00108       }
00109 
00110       SourceBits_4BPP += BltInfo->SourceSurface->lDelta;
00111     }
00112     break;
00113 
00114   case BMF_8BPP:
00115     SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
00116     DestLine = DestBits;
00117 
00118     for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
00119     {
00120       SourceBits = SourceLine;
00121       DestBits = DestLine;
00122 
00123       for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
00124       {
00125         xColor = *SourceBits;
00126         *((PDWORD) DestBits) = (DWORD)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
00127         SourceBits += 1;
00128         DestBits += 4;
00129       }
00130 
00131       SourceLine += BltInfo->SourceSurface->lDelta;
00132       DestLine += BltInfo->DestSurface->lDelta;
00133     }
00134     break;
00135 
00136   case BMF_16BPP:
00137     SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x;
00138     DestLine = DestBits;
00139 
00140     for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
00141     {
00142       SourceBits = SourceLine;
00143       DestBits = DestLine;
00144 
00145       for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
00146       {
00147         xColor = *((PWORD) SourceBits);
00148         *((PDWORD) DestBits) = (DWORD)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
00149         SourceBits += 2;
00150         DestBits += 4;
00151       }
00152 
00153       SourceLine += BltInfo->SourceSurface->lDelta;
00154       DestLine += BltInfo->DestSurface->lDelta;
00155     }
00156     break;
00157 
00158   case BMF_24BPP:
00159     SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0
00160       + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
00161       + 3 * BltInfo->SourcePoint.x;
00162     DestLine = DestBits;
00163 
00164     for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
00165     {
00166       SourceBits = SourceLine;
00167       DestBits = DestLine;
00168 
00169       for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
00170       {
00171         xColor = (*(SourceBits + 2) << 0x10) +
00172           (*(SourceBits + 1) << 0x08) +
00173           (*(SourceBits));
00174         *((PDWORD)DestBits) = (DWORD)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
00175         SourceBits += 3;
00176         DestBits += 4;
00177       }
00178 
00179       SourceLine += BltInfo->SourceSurface->lDelta;
00180       DestLine += BltInfo->DestSurface->lDelta;
00181     }
00182     break;
00183 
00184   case BMF_32BPP:
00185     if (NULL == BltInfo->XlateSourceToDest ||
00186       0 != (BltInfo->XlateSourceToDest->flXlate & XO_TRIVIAL))
00187     {
00188       if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
00189       {
00190         SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
00191         for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
00192         {
00193           RtlMoveMemory(DestBits, SourceBits, 4 * (BltInfo->DestRect.right - BltInfo->DestRect.left));
00194           SourceBits += BltInfo->SourceSurface->lDelta;
00195           DestBits += BltInfo->DestSurface->lDelta;
00196         }
00197       }
00198       else
00199       {
00200         SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
00201           + ((BltInfo->SourcePoint.y
00202           + BltInfo->DestRect.bottom
00203           - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta)
00204           + 4 * BltInfo->SourcePoint.x;
00205         DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + 4 * BltInfo->DestRect.left;
00206         for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
00207         {
00208           RtlMoveMemory(DestBits, SourceBits, 4 * (BltInfo->DestRect.right - BltInfo->DestRect.left));
00209           SourceBits -= BltInfo->SourceSurface->lDelta;
00210           DestBits -= BltInfo->DestSurface->lDelta;
00211         }
00212       }
00213     }
00214     else
00215     {
00216       if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
00217       {
00218         SourceBits = ((PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x);
00219         for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
00220         {
00221           if (BltInfo->DestRect.left < BltInfo->SourcePoint.x)
00222           {
00223             Dest32 = (DWORD *) DestBits;
00224             Source32 = (DWORD *) SourceBits;
00225             for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
00226             {
00227               *Dest32++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32++);
00228             }
00229           }
00230           else
00231           {
00232             Dest32 = (DWORD *) DestBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
00233             Source32 = (DWORD *) SourceBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
00234             for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
00235             {
00236               *Dest32-- = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32--);
00237             }
00238           }
00239           SourceBits += BltInfo->SourceSurface->lDelta;
00240           DestBits += BltInfo->DestSurface->lDelta;
00241         }
00242       }
00243       else
00244       {
00245         SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
00246         DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + 4 * BltInfo->DestRect.left;
00247         for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
00248         {
00249           if (BltInfo->DestRect.left < BltInfo->SourcePoint.x)
00250           {
00251             Dest32 = (DWORD *) DestBits;
00252             Source32 = (DWORD *) SourceBits;
00253             for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
00254             {
00255               *Dest32++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32++);
00256             }
00257           }
00258           else
00259           {
00260             Dest32 = (DWORD *) DestBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
00261             Source32 = (DWORD *) SourceBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
00262             for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
00263             {
00264               *Dest32-- = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32--);
00265             }
00266           }
00267           SourceBits -= BltInfo->SourceSurface->lDelta;
00268           DestBits -= BltInfo->DestSurface->lDelta;
00269         }
00270       }
00271     }
00272     break;
00273 
00274   default:
00275     DPRINT1("DIB_32BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat));
00276     return FALSE;
00277   }
00278 
00279   return TRUE;
00280 }
00281 
00282 BOOLEAN
00283 DIB_32BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
00284                          RECTL*  DestRect,  RECTL *SourceRect,
00285                          XLATEOBJ *ColorTranslation, ULONG iTransColor)
00286 {
00287   LONG X, Y, SourceX, SourceY = 0, wd;
00288   ULONG *DestBits, Source = 0;
00289 
00290   LONG DstHeight;
00291   LONG DstWidth;
00292   LONG SrcHeight;
00293   LONG SrcWidth;
00294 
00295   DstHeight = DestRect->bottom - DestRect->top;
00296   DstWidth = DestRect->right - DestRect->left;
00297   SrcHeight = SourceRect->bottom - SourceRect->top;
00298   SrcWidth = SourceRect->right - SourceRect->left;
00299 
00300   DestBits = (ULONG*)((PBYTE)DestSurf->pvScan0 +
00301     (DestRect->left << 2) +
00302     DestRect->top * DestSurf->lDelta);
00303   wd = DestSurf->lDelta - ((DestRect->right - DestRect->left) << 2);
00304 
00305   for (Y = DestRect->top; Y < DestRect->bottom; Y++)
00306   {
00307     SourceY = SourceRect->top+(Y - DestRect->top) * SrcHeight / DstHeight;
00308     for (X = DestRect->left; X < DestRect->right; X++, DestBits++)
00309     {
00310       SourceX = SourceRect->left+(X - DestRect->left) * SrcWidth / DstWidth;
00311       if (SourceX >= 0 && SourceY >= 0 &&
00312         SourceSurf->sizlBitmap.cx > SourceX && SourceSurf->sizlBitmap.cy > SourceY)
00313       {
00314         Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY);
00315         if (Source != iTransColor)
00316         {
00317           *DestBits = XLATEOBJ_iXlate(ColorTranslation, Source);
00318         }
00319       }
00320     }
00321 
00322     DestBits = (ULONG*)((ULONG_PTR)DestBits + wd);
00323   }
00324 
00325   return TRUE;
00326 }
00327 
00328 typedef union {
00329   ULONG ul;
00330   struct {
00331     UCHAR red;
00332     UCHAR green;
00333     UCHAR blue;
00334     UCHAR alpha;
00335   } col;
00336 } NICEPIXEL32;
00337 
00338 static __inline UCHAR
00339 Clamp8(ULONG val)
00340 {
00341   return (val > 255) ? 255 : (UCHAR)val;
00342 }
00343 
00344 BOOLEAN
00345 DIB_32BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
00346                      RECTL* SourceRect, CLIPOBJ* ClipRegion,
00347                      XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
00348 {
00349   INT Rows, Cols, SrcX, SrcY;
00350   register PULONG Dst;
00351   BLENDFUNCTION BlendFunc;
00352   register NICEPIXEL32 DstPixel, SrcPixel;
00353   UCHAR Alpha, SrcBpp;
00354 
00355   DPRINT("DIB_32BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
00356     SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
00357     DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
00358 
00359   BlendFunc = BlendObj->BlendFunction;
00360   if (BlendFunc.BlendOp != AC_SRC_OVER)
00361   {
00362     DPRINT1("BlendOp != AC_SRC_OVER\n");
00363     return FALSE;
00364   }
00365   if (BlendFunc.BlendFlags != 0)
00366   {
00367     DPRINT1("BlendFlags != 0\n");
00368     return FALSE;
00369   }
00370   if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
00371   {
00372     DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
00373     return FALSE;
00374   }
00375   if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
00376        BitsPerFormat(Source->iBitmapFormat) != 32)
00377   {
00378     DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
00379     return FALSE;
00380   }
00381 
00382   Dst = (PULONG)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
00383     (DestRect->left << 2));
00384   SrcBpp = BitsPerFormat(Source->iBitmapFormat);
00385 
00386   Rows = 0;
00387    SrcY = SourceRect->top;
00388    while (++Rows <= DestRect->bottom - DestRect->top)
00389   {
00390     Cols = 0;
00391     SrcX = SourceRect->left;
00392     while (++Cols <= DestRect->right - DestRect->left)
00393     {
00394       SrcPixel.ul = DIB_GetSource(Source, SrcX, SrcY, ColorTranslation);
00395       SrcPixel.col.red = (SrcPixel.col.red * BlendFunc.SourceConstantAlpha) / 255;
00396       SrcPixel.col.green = (SrcPixel.col.green * BlendFunc.SourceConstantAlpha)  / 255;
00397       SrcPixel.col.blue = (SrcPixel.col.blue * BlendFunc.SourceConstantAlpha) / 255;
00398       SrcPixel.col.alpha = (32 == SrcBpp) ?
00399                         (SrcPixel.col.alpha * BlendFunc.SourceConstantAlpha) / 255 :
00400                         BlendFunc.SourceConstantAlpha ;
00401 
00402       Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
00403            SrcPixel.col.alpha : BlendFunc.SourceConstantAlpha ;
00404 
00405       DstPixel.ul = *Dst;
00406       DstPixel.col.red = Clamp8((DstPixel.col.red * (255 - Alpha)) / 255 + SrcPixel.col.red) ;
00407       DstPixel.col.green = Clamp8((DstPixel.col.green * (255 - Alpha)) / 255 + SrcPixel.col.green) ;
00408       DstPixel.col.blue = Clamp8((DstPixel.col.blue * (255 - Alpha)) / 255 + SrcPixel.col.blue) ;
00409       DstPixel.col.alpha = Clamp8((DstPixel.col.alpha * (255 - Alpha)) / 255 + SrcPixel.col.alpha) ;
00410       *Dst++ = DstPixel.ul;
00411       SrcX = SourceRect->left + (Cols*(SourceRect->right - SourceRect->left))/(DestRect->right - DestRect->left);
00412     }
00413     Dst = (PULONG)((ULONG_PTR)Dest->pvScan0 + ((DestRect->top + Rows) * Dest->lDelta) +
00414                 (DestRect->left << 2));
00415     SrcY = SourceRect->top + (Rows*(SourceRect->bottom - SourceRect->top))/(DestRect->bottom - DestRect->top);
00416   }
00417 
00418   return TRUE;
00419 }
00420 
00421 /* EOF */

Generated on Sun May 27 2012 04:38:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.