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

dib4bpp.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/dib4bpp.c
00005  * PURPOSE:         Device Independant Bitmap functions, 4bpp
00006  * PROGRAMMERS:     Jason Filby
00007  */
00008 
00009 
00010 #include <win32k.h>
00011 
00012 #define NDEBUG
00013 #include <debug.h>
00014 
00015 VOID
00016 DIB_4BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c)
00017 {
00018    PBYTE addr = (PBYTE)SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
00019    *addr = (*addr & notmask[x&1]) | (BYTE)(c << ((1-(x&1))<<2));
00020 }
00021 
00022 ULONG
00023 DIB_4BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y)
00024 {
00025    PBYTE addr = (PBYTE)SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
00026    return (*addr >> ((1-(x&1))<<2)) & 0x0f;
00027 }
00028 
00029 VOID
00030 DIB_4BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
00031 {
00032   PBYTE  addr = (PBYTE)SurfObj->pvScan0 + (x1>>1) + y * SurfObj->lDelta;
00033   LONG  cx = x1;
00034 
00035   while(cx < x2)
00036   {
00037     *addr = (*addr & notmask[x1&1]) | (BYTE)(c << ((1-(x1&1))<<2));
00038     if((++x1 & 1) == 0)
00039       ++addr;
00040     ++cx;
00041   }
00042 }
00043 
00044 VOID
00045 DIB_4BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
00046 {
00047   PBYTE  addr = SurfObj->pvScan0;
00048   int  lDelta = SurfObj->lDelta;
00049 
00050   addr += (x>>1) + y1 * lDelta;
00051   while(y1++ < y2)
00052   {
00053     *addr = (*addr & notmask[x&1]) | (BYTE)(c << ((1-(x&1))<<2));
00054     addr += lDelta;
00055   }
00056 }
00057 
00058 #ifndef _USE_DIBLIB_
00059 BOOLEAN
00060 DIB_4BPP_BitBltSrcCopy(PBLTINFO BltInfo)
00061 {
00062   LONG     i, j, sx, sy, f2, xColor;
00063   PBYTE    SourceBits_24BPP, SourceLine_24BPP;
00064   PBYTE    DestBits, DestLine, SourceBits_8BPP, SourceLine_8BPP;
00065   PBYTE    SourceBits, SourceLine;
00066 
00067   DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 +
00068              (BltInfo->DestRect.left >> 1) +
00069              BltInfo->DestRect.top * BltInfo->DestSurface->lDelta;
00070 
00071   switch (BltInfo->SourceSurface->iBitmapFormat)
00072   {
00073     case BMF_1BPP:
00074       sx = BltInfo->SourcePoint.x;
00075       sy = BltInfo->SourcePoint.y;
00076 
00077       for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
00078       {
00079         sx = BltInfo->SourcePoint.x;
00080         for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
00081         {
00082           if(DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0)
00083           {
00084             DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0));
00085           }
00086           else
00087           {
00088             DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1));
00089           }
00090           sx++;
00091         }
00092         sy++;
00093       }
00094       break;
00095 
00096     case BMF_4BPP:
00097       sy = BltInfo->SourcePoint.y;
00098 
00099       for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
00100       {
00101         sx = BltInfo->SourcePoint.x;
00102 
00103         for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
00104         {
00105           if (NULL != BltInfo->XlateSourceToDest)
00106           {
00107             DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, DIB_4BPP_GetPixel(BltInfo->SourceSurface, sx, sy)));
00108           }
00109           else
00110           {
00111             DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, DIB_4BPP_GetPixel(BltInfo->SourceSurface, sx, sy));
00112           }
00113           sx++;
00114         }
00115         sy++;
00116       }
00117       break;
00118 
00119     case BMF_8BPP:
00120       SourceBits_8BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
00121 
00122       for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
00123       {
00124         SourceLine_8BPP = SourceBits_8BPP;
00125         DestLine = DestBits;
00126         f2 = BltInfo->DestRect.left & 1;
00127 
00128         for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
00129         {
00130           *DestLine = (*DestLine & notmask[f2]) |
00131             (BYTE)((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *SourceLine_8BPP)) << ((4 * (1 - f2))));
00132           if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
00133           SourceLine_8BPP++;
00134         }
00135 
00136         SourceBits_8BPP += BltInfo->SourceSurface->lDelta;
00137         DestBits += BltInfo->DestSurface->lDelta;
00138       }
00139       break;
00140 
00141     case BMF_16BPP:
00142       SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x;
00143       DestLine = DestBits;
00144 
00145       for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
00146       {
00147         SourceBits = SourceLine;
00148         DestBits = DestLine;
00149         f2 = BltInfo->DestRect.left & 1;
00150 
00151         for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
00152         {
00153           xColor = *((PWORD) SourceBits);
00154           *DestBits = (*DestBits & notmask[f2]) |
00155             (BYTE)((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor)) << ((4 * (1 - f2))));
00156           if(f2 == 1) { DestBits++; f2 = 0; } else { f2 = 1; }
00157           SourceBits += 2;
00158         }
00159 
00160         SourceLine += BltInfo->SourceSurface->lDelta;
00161         DestLine += BltInfo->DestSurface->lDelta;
00162       }
00163       break;
00164 
00165     case BMF_24BPP:
00166       SourceBits_24BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x * 3;
00167 
00168       for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
00169       {
00170         SourceLine_24BPP = SourceBits_24BPP;
00171         DestLine = DestBits;
00172         f2 = BltInfo->DestRect.left & 1;
00173 
00174         for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
00175         {
00176           xColor = (*(SourceLine_24BPP + 2) << 0x10) +
00177              (*(SourceLine_24BPP + 1) << 0x08) +
00178              (*(SourceLine_24BPP));
00179           *DestLine = (*DestLine & notmask[f2]) |
00180             (BYTE)((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor)) << ((4 * (1 - f2))));
00181           if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
00182           SourceLine_24BPP+=3;
00183         }
00184 
00185         SourceBits_24BPP += BltInfo->SourceSurface->lDelta;
00186         DestBits += BltInfo->DestSurface->lDelta;
00187       }
00188       break;
00189 
00190     case BMF_32BPP:
00191       SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
00192       DestLine = DestBits;
00193 
00194       for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
00195       {
00196         SourceBits = SourceLine;
00197         DestBits = DestLine;
00198         f2 = BltInfo->DestRect.left & 1;
00199 
00200         for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
00201         {
00202           xColor = *((PDWORD) SourceBits);
00203           *DestBits = (*DestBits & notmask[f2]) |
00204             (BYTE)((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor)) << ((4 * (1 - f2))));
00205           if(f2 == 1) { DestBits++; f2 = 0; } else { f2 = 1; }
00206           SourceBits += 4;
00207         }
00208 
00209         SourceLine += BltInfo->SourceSurface->lDelta;
00210         DestLine += BltInfo->DestSurface->lDelta;
00211       }
00212       break;
00213 
00214     default:
00215       DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat));
00216       return FALSE;
00217   }
00218   return(TRUE);
00219 }
00220 
00221 BOOLEAN
00222 DIB_4BPP_BitBlt(PBLTINFO BltInfo)
00223 {
00224   LONG DestX, DestY;
00225   LONG SourceX, SourceY;
00226   LONG PatternY = 0;
00227   ULONG Dest, Source = 0, Pattern = 0;
00228   BOOLEAN UsesSource;
00229   BOOLEAN UsesPattern;
00230   PULONG DestBits;
00231   LONG RoundedRight;
00232   static const ULONG ExpandSolidColor[16] =
00233   {
00234     0x00000000 /* 0 */,
00235     0x11111111 /* 1 */,
00236     0x22222222 /* 2 */,
00237     0x33333333 /* 3 */,
00238     0x44444444 /* 4 */,
00239     0x55555555 /* 5 */,
00240     0x66666666 /* 6 */,
00241     0x77777777 /* 7 */,
00242     0x88888888 /* 8 */,
00243     0x99999999 /* 9 */,
00244     0xAAAAAAAA /* 10 */,
00245     0xBBBBBBBB /* 11 */,
00246     0xCCCCCCCC /* 12 */,
00247     0xDDDDDDDD /* 13 */,
00248     0xEEEEEEEE /* 14 */,
00249     0xFFFFFFFF /* 15 */,
00250   };
00251 
00252   UsesSource = ROP4_USES_SOURCE(BltInfo->Rop4);
00253   UsesPattern = ROP4_USES_PATTERN(BltInfo->Rop4);
00254 
00255   SourceY = BltInfo->SourcePoint.y;
00256   RoundedRight = BltInfo->DestRect.right -
00257     ((BltInfo->DestRect.right - BltInfo->DestRect.left) & 0x7);
00258 
00259   if (UsesPattern)
00260   {
00261     if (BltInfo->PatternSurface)
00262     {
00263       PatternY = (BltInfo->DestRect.top + BltInfo->BrushOrigin.y) %
00264         BltInfo->PatternSurface->sizlBitmap.cy;
00265     }
00266     else
00267     {
00268       if (BltInfo->Brush)
00269         Pattern = ExpandSolidColor[BltInfo->Brush->iSolidColor];
00270     }
00271   }
00272 
00273   for (DestY = BltInfo->DestRect.top; DestY < BltInfo->DestRect.bottom; DestY++)
00274   {
00275     DestBits = (PULONG)(
00276       (PBYTE)BltInfo->DestSurface->pvScan0 +
00277       (BltInfo->DestRect.left >> 1) +
00278       DestY * BltInfo->DestSurface->lDelta);
00279     SourceX = BltInfo->SourcePoint.x;
00280     DestX = BltInfo->DestRect.left;
00281 
00282     if (DestX & 0x1)
00283     {
00284       Dest = DIB_4BPP_GetPixel(BltInfo->DestSurface, DestX, DestY);
00285 
00286       if (UsesSource)
00287       {
00288         Source = DIB_GetSource(BltInfo->SourceSurface, SourceX, SourceY, BltInfo->XlateSourceToDest);
00289       }
00290 
00291       if (BltInfo->PatternSurface)
00292       {
00293         Pattern = DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY);
00294       }
00295 
00296       DIB_4BPP_PutPixel(BltInfo->DestSurface, DestX, DestY, DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern) & 0xF);
00297 
00298       DestX++;
00299       SourceX++;
00300       DestBits = (PULONG)((ULONG_PTR)DestBits + 1);
00301     }
00302 
00303     for (; DestX < RoundedRight; DestX += 8, SourceX += 8, DestBits++)
00304     {
00305       Dest = *DestBits;
00306       if (UsesSource)
00307       {
00308         Source =
00309           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 1, SourceY, BltInfo->XlateSourceToDest)) |
00310           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 0, SourceY, BltInfo->XlateSourceToDest) << 4) |
00311           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 3, SourceY, BltInfo->XlateSourceToDest) << 8) |
00312           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 2, SourceY, BltInfo->XlateSourceToDest) << 12) |
00313           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 5, SourceY, BltInfo->XlateSourceToDest) << 16) |
00314           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 4, SourceY, BltInfo->XlateSourceToDest) << 20) |
00315           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 7, SourceY, BltInfo->XlateSourceToDest) << 24) |
00316           (DIB_GetSource(BltInfo->SourceSurface, SourceX + 6, SourceY, BltInfo->XlateSourceToDest) << 28);
00317       }
00318       if (BltInfo->PatternSurface)
00319       {
00320         Pattern = DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 1) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY);
00321         Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 0) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << 4;
00322         Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 3) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << 8;
00323         Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 2) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << 12;
00324         Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 5) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << 16;
00325         Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 4) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << 20;
00326         Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 7) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << 24;
00327         Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 6) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << 28;
00328       }
00329       *DestBits = DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern);
00330     }
00331 
00332     /* Process the rest of pixel on the line */
00333     for (; DestX < BltInfo->DestRect.right; DestX++, SourceX++)
00334     {
00335       Dest = DIB_4BPP_GetPixel(BltInfo->DestSurface, DestX, DestY);
00336       if (UsesSource)
00337       {
00338         Source = DIB_GetSource(BltInfo->SourceSurface, SourceX, SourceY, BltInfo->XlateSourceToDest);
00339       }
00340       if (BltInfo->PatternSurface)
00341       {
00342         Pattern = DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY);
00343       }
00344       DIB_4BPP_PutPixel(BltInfo->DestSurface, DestX, DestY, DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern) & 0xF);
00345     }
00346 
00347     SourceY++;
00348     if (BltInfo->PatternSurface)
00349     {
00350       PatternY++;
00351       PatternY %= BltInfo->PatternSurface->sizlBitmap.cy;
00352     }
00353   }
00354 
00355   return TRUE;
00356 }
00357 
00358 /* BitBlt Optimize */
00359 BOOLEAN
00360 DIB_4BPP_ColorFill(SURFOBJ* DestSurface, RECTL* DestRect, ULONG color)
00361 {
00362   LONG DestY;
00363 
00364   for (DestY = DestRect->top; DestY < DestRect->bottom; DestY++)
00365   {
00366     DIB_4BPP_HLine(DestSurface, DestRect->left, DestRect->right, DestY, color);
00367   }
00368   return TRUE;
00369 }
00370 #endif // !_USE_DIBLIB_
00371 
00372 BOOLEAN
00373 DIB_4BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
00374                         RECTL*  DestRect,  RECTL *SourceRect,
00375                         XLATEOBJ *ColorTranslation, ULONG iTransColor)
00376 {
00377   return FALSE;
00378 }
00379 
00380 /* EOF */

Generated on Sat May 26 2012 04:36:59 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.