Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendib1bpp.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/dib1bpp.c 00005 * PURPOSE: Device Independant Bitmap functions, 1bpp 00006 * PROGRAMMERS: Jason Filby 00007 */ 00008 00009 #include <win32k.h> 00010 00011 #define NDEBUG 00012 #include <debug.h> 00013 00014 VOID 00015 DIB_1BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c) 00016 { 00017 PBYTE addr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + (x >> 3); 00018 00019 if (0 == (c & 0x01)) 00020 *addr &= ~MASK1BPP(x); 00021 else 00022 *addr |= MASK1BPP(x); 00023 } 00024 00025 ULONG 00026 DIB_1BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y) 00027 { 00028 PBYTE addr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + (x >> 3); 00029 00030 return (*addr & MASK1BPP(x) ? 1 : 0); 00031 } 00032 00033 VOID 00034 DIB_1BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c) 00035 { 00036 while(x1 < x2) 00037 { 00038 DIB_1BPP_PutPixel(SurfObj, x1, y, c); 00039 x1++; 00040 } 00041 } 00042 00043 VOID 00044 DIB_1BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c) 00045 { 00046 while(y1 < y2) 00047 { 00048 DIB_1BPP_PutPixel(SurfObj, x, y1, c); 00049 y1++; 00050 } 00051 } 00052 00053 static 00054 void 00055 DIB_1BPP_BitBltSrcCopy_From1BPP ( 00056 SURFOBJ* DestSurf, 00057 SURFOBJ* SourceSurf, 00058 XLATEOBJ* pxlo, 00059 PRECTL DestRect, 00060 POINTL *SourcePoint ) 00061 { 00062 // The 'window' in this sense is the x-position that corresponds 00063 // to the left-edge of the 8-pixel byte we are currently working with. 00064 // dwx is current x-window, dwx2 is the 'last' window we need to process. 00065 int dwx, dwx2; // Destination window x-position 00066 int swx; // Source window y-position 00067 00068 // Left and right edges of source and dest rectangles 00069 int dl = DestRect->left; // dest left 00070 int dr = DestRect->right-1; // dest right (inclusive) 00071 int sl = SourcePoint->x; // source left 00072 int sr = sl + dr - dl; // source right (inclusive) 00073 00074 // Which direction are we going? 00075 int xinc; 00076 int yinc; 00077 int ySrcDelta, yDstDelta; 00078 00079 // The following 4 variables are used for the y-sweep 00080 int dy; // dest y 00081 int dy1; // dest y start 00082 int dy2; // dest y end 00083 int sy1; // src y start 00084 00085 int shift; 00086 BYTE srcmask, dstmask, xormask; 00087 00088 // 'd' and 's' are the dest & src buffer pointers that I use on my x-sweep 00089 // 'pd' and 'ps' are the dest & src buffer pointers used on the inner y-sweep 00090 PBYTE d, pd; // dest ptrs 00091 PBYTE s, ps; // src ptrs 00092 00093 shift = (dl-sl)&7; 00094 00095 xormask = 0xFF * (BYTE)XLATEOBJ_iXlate(pxlo, 0); 00096 00097 if ( DestRect->top <= SourcePoint->y ) 00098 { 00099 // Moving up (scan top -> bottom) 00100 dy1 = DestRect->top; 00101 dy2 = DestRect->bottom - 1; 00102 sy1 = SourcePoint->y; 00103 yinc = 1; 00104 ySrcDelta = SourceSurf->lDelta; 00105 yDstDelta = DestSurf->lDelta; 00106 } 00107 else 00108 { 00109 // Moving down (scan bottom -> top) 00110 dy1 = DestRect->bottom - 1; 00111 dy2 = DestRect->top; 00112 sy1 = SourcePoint->y + dy1 - dy2; 00113 yinc = -1; 00114 ySrcDelta = -SourceSurf->lDelta; 00115 yDstDelta = -DestSurf->lDelta; 00116 } 00117 if ( DestRect->left <= SourcePoint->x ) 00118 { 00119 // Moving left (scan left->right) 00120 dwx = dl&~7; 00121 swx = (sl-(dl&7))&~7; 00122 dwx2 = dr&~7; 00123 xinc = 1; 00124 } 00125 else 00126 { 00127 // Moving right (scan right->left) 00128 dwx = dr & ~7; 00129 swx = (sr - (dr & 7)) & ~7; // (sr - 7) & ~7; // We need the left edge of this block. Thus the -7 00130 dwx2 = dl & ~7; 00131 xinc = -1; 00132 } 00133 d = &(((PBYTE)DestSurf->pvScan0)[dy1*DestSurf->lDelta + (dwx>>3)]); 00134 s = &(((PBYTE)SourceSurf->pvScan0)[sy1*SourceSurf->lDelta + (swx>>3)]); 00135 for ( ;; ) 00136 { 00137 dy = dy1; 00138 pd = d; 00139 ps = s; 00140 srcmask = 0xff; 00141 if ( dwx < dl ) 00142 { 00143 int diff = dl-dwx; 00144 srcmask &= (1<<(8-diff))-1; 00145 } 00146 if ( dwx+7 > dr ) 00147 { 00148 int diff = dr-dwx+1; 00149 srcmask &= ~((1<<(8-diff))-1); 00150 } 00151 dstmask = ~srcmask; 00152 00153 // We unfortunately *must* have 5 different versions of the inner 00154 // loop to be certain we don't try to read from memory that is not 00155 // needed and may in fact be invalid. 00156 if ( !shift ) 00157 { 00158 for ( ;; ) 00159 { 00160 *pd = (BYTE)((*pd & dstmask) | ((ps[0]^xormask) & srcmask)); 00161 00162 // This *must* be here, because we could be going up *or* down... 00163 if ( dy == dy2 ) 00164 break; 00165 dy += yinc; 00166 pd += yDstDelta; 00167 ps += ySrcDelta; 00168 } 00169 } 00170 else if ( !(0xFF00 & (srcmask<<shift) ) ) // Check if ps[0] not needed... 00171 { 00172 for ( ;; ) 00173 { 00174 *pd = (BYTE)((*pd & dstmask) 00175 | ( ( (ps[1]^xormask) >> shift ) & srcmask )); 00176 00177 // This *must* be here, because we could be going up *or* down... 00178 if ( dy == dy2 ) 00179 break; 00180 dy += yinc; 00181 pd += yDstDelta; 00182 ps += ySrcDelta; 00183 } 00184 } 00185 else if ( !(0xFF & (srcmask<<shift) ) ) // Check if ps[1] not needed... 00186 { 00187 for ( ;; ) 00188 { 00189 *pd = (*pd & dstmask) 00190 | ( ( (ps[0]^xormask) << ( 8 - shift ) ) & srcmask ); 00191 00192 // This *must* be here, because we could be going up *or* down... 00193 if ( dy == dy2 ) 00194 break; 00195 dy += yinc; 00196 pd += yDstDelta; 00197 ps += ySrcDelta; 00198 } 00199 } 00200 else // Both ps[0] and ps[1] are needed 00201 { 00202 for ( ;; ) 00203 { 00204 *pd = (*pd & dstmask) 00205 | ( ( ( ((ps[1]^xormask))|((ps[0]^xormask)<<8) ) >> shift ) & srcmask ); 00206 00207 // This *must* be here, because we could be going up *or* down... 00208 if ( dy == dy2 ) 00209 break; 00210 dy += yinc; 00211 pd += yDstDelta; 00212 ps += ySrcDelta; 00213 } 00214 } 00215 00216 // This *must* be here, because we could be going right *or* left... 00217 if ( dwx == dwx2 ) 00218 break; 00219 d += xinc; 00220 s += xinc; 00221 dwx += xinc<<3; 00222 swx += xinc<<3; 00223 } 00224 } 00225 00226 BOOLEAN 00227 DIB_1BPP_BitBltSrcCopy(PBLTINFO BltInfo) 00228 { 00229 ULONG Color; 00230 LONG i, j, sx, sy = BltInfo->SourcePoint.y; 00231 00232 switch ( BltInfo->SourceSurface->iBitmapFormat ) 00233 { 00234 case BMF_1BPP: 00235 DIB_1BPP_BitBltSrcCopy_From1BPP ( BltInfo->DestSurface, BltInfo->SourceSurface, BltInfo->XlateSourceToDest, &BltInfo->DestRect, &BltInfo->SourcePoint ); 00236 break; 00237 00238 case BMF_4BPP: 00239 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++) 00240 { 00241 sx = BltInfo->SourcePoint.x; 00242 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00243 { 00244 Color = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, DIB_4BPP_GetPixel(BltInfo->SourceSurface, sx, sy)); 00245 DIB_1BPP_PutPixel(BltInfo->DestSurface, i, j, Color); 00246 sx++; 00247 } 00248 sy++; 00249 } 00250 break; 00251 00252 case BMF_8BPP: 00253 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++) 00254 { 00255 sx = BltInfo->SourcePoint.x; 00256 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00257 { 00258 Color = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, DIB_8BPP_GetPixel(BltInfo->SourceSurface, sx, sy)); 00259 DIB_1BPP_PutPixel(BltInfo->DestSurface, i, j, Color); 00260 sx++; 00261 } 00262 sy++; 00263 } 00264 break; 00265 00266 case BMF_16BPP: 00267 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++) 00268 { 00269 sx = BltInfo->SourcePoint.x; 00270 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00271 { 00272 Color = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, DIB_16BPP_GetPixel(BltInfo->SourceSurface, sx, sy)); 00273 DIB_1BPP_PutPixel(BltInfo->DestSurface, i, j, Color); 00274 sx++; 00275 } 00276 sy++; 00277 } 00278 break; 00279 00280 case BMF_24BPP: 00281 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++) 00282 { 00283 sx = BltInfo->SourcePoint.x; 00284 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00285 { 00286 Color = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, DIB_24BPP_GetPixel(BltInfo->SourceSurface, sx, sy)); 00287 DIB_1BPP_PutPixel(BltInfo->DestSurface, i, j, Color); 00288 sx++; 00289 } 00290 sy++; 00291 } 00292 break; 00293 00294 case BMF_32BPP: 00295 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++) 00296 { 00297 sx = BltInfo->SourcePoint.x; 00298 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00299 { 00300 Color = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, DIB_32BPP_GetPixel(BltInfo->SourceSurface, sx, sy)); 00301 DIB_1BPP_PutPixel(BltInfo->DestSurface, i, j, Color); 00302 sx++; 00303 } 00304 sy++; 00305 } 00306 break; 00307 00308 default: 00309 DbgPrint("DIB_1BPP_BitBlt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat)); 00310 return FALSE; 00311 } 00312 00313 return TRUE; 00314 } 00315 00316 #ifndef _USE_DIBLIB_ 00317 BOOLEAN 00318 DIB_1BPP_BitBlt(PBLTINFO BltInfo) 00319 { 00320 LONG DestX, DestY; 00321 LONG SourceX, SourceY; 00322 LONG PatternY = 0; 00323 ULONG Dest, Source = 0, Pattern = 0; 00324 ULONG Index; 00325 BOOLEAN UsesSource; 00326 BOOLEAN UsesPattern; 00327 PULONG DestBits; 00328 LONG RoundedRight; 00329 00330 UsesSource = ROP4_USES_SOURCE(BltInfo->Rop4); 00331 UsesPattern = ROP4_USES_PATTERN(BltInfo->Rop4); 00332 00333 RoundedRight = BltInfo->DestRect.right - 00334 ((BltInfo->DestRect.right - BltInfo->DestRect.left) & 31); 00335 SourceY = BltInfo->SourcePoint.y; 00336 00337 if (UsesPattern) 00338 { 00339 if (BltInfo->PatternSurface) 00340 { 00341 PatternY = (BltInfo->DestRect.top + BltInfo->BrushOrigin.y) % 00342 BltInfo->PatternSurface->sizlBitmap.cy; 00343 } 00344 else 00345 { 00346 /* FIXME: Shouldn't it be expanded? */ 00347 if (BltInfo->Brush) 00348 Pattern = BltInfo->Brush->iSolidColor; 00349 } 00350 } 00351 00352 for (DestY = BltInfo->DestRect.top; DestY < BltInfo->DestRect.bottom; DestY++) 00353 { 00354 DestX = BltInfo->DestRect.left; 00355 SourceX = BltInfo->SourcePoint.x; 00356 DestBits = (PULONG)( 00357 (PBYTE)BltInfo->DestSurface->pvScan0 + 00358 (BltInfo->DestRect.left >> 3) + 00359 DestY * BltInfo->DestSurface->lDelta); 00360 00361 if (DestX & 31) 00362 { 00363 #if 0 00364 /* FIXME: This case is completely untested!!! */ 00365 00366 Dest = *((PBYTE)DestBits); 00367 NoBits = 31 - (DestX & 31); 00368 00369 if (UsesSource) 00370 { 00371 Source = 0; 00372 /* FIXME: This is incorrect! */ 00373 for (Index = 31 - NoBits; Index >= 0; Index++) 00374 Source |= (DIB_GetSource(SourceSurf, SourceX + Index, SourceY, ColorTranslation) << (31 - Index)); 00375 } 00376 00377 if (BltInfo->PatternSurface) 00378 { 00379 Pattern = 0; 00380 for (k = 31 - NoBits; k >= 0; k++) 00381 Pattern |= (DIB_GetSourceIndex(PatternObj, (X + BrushOrigin.x + k) % PatternWidth, PatternY) << (31 - k)); 00382 } 00383 00384 Dest = DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern); 00385 Dest &= ~((1 << (31 - NoBits)) - 1); 00386 Dest |= *((PBYTE)DestBits) & ((1 << (31 - NoBits)) - 1); 00387 00388 *DestBits = Dest; 00389 00390 DestX += NoBits; 00391 SourceX += NoBits; 00392 #endif 00393 } 00394 00395 for (; DestX < RoundedRight; DestX += 32, DestBits++, SourceX += 32) 00396 { 00397 Dest = *DestBits; 00398 00399 if (UsesSource) 00400 { 00401 Source = 0; 00402 for (Index = 0; Index < 8; Index++) 00403 { 00404 Source |= DIB_GetSource(BltInfo->SourceSurface, SourceX + Index, SourceY, BltInfo->XlateSourceToDest) << (7 - Index); 00405 Source |= DIB_GetSource(BltInfo->SourceSurface, SourceX + Index + 8, SourceY, BltInfo->XlateSourceToDest) << (8 + (7 - Index)); 00406 Source |= DIB_GetSource(BltInfo->SourceSurface, SourceX + Index + 16, SourceY, BltInfo->XlateSourceToDest) << (16 + (7 - Index)); 00407 Source |= DIB_GetSource(BltInfo->SourceSurface, SourceX + Index + 24, SourceY, BltInfo->XlateSourceToDest) << (24 + (7 - Index)); 00408 } 00409 } 00410 00411 if (BltInfo->PatternSurface) 00412 { 00413 Pattern = 0; 00414 for (Index = 0; Index < 8; Index++) 00415 { 00416 Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + Index) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << (7 - Index); 00417 Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + Index + 8) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << (8 + (7 - Index)); 00418 Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + Index + 16) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << (16 + (7 - Index)); 00419 Pattern |= DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + Index + 24) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY) << (24 + (7 - Index)); 00420 } 00421 } 00422 00423 *DestBits = DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern); 00424 } 00425 00426 if (DestX < BltInfo->DestRect.right) 00427 { 00428 for (; DestX < BltInfo->DestRect.right; DestX++, SourceX++) 00429 { 00430 Dest = DIB_1BPP_GetPixel(BltInfo->DestSurface, DestX, DestY); 00431 00432 if (UsesSource) 00433 { 00434 Source = DIB_GetSource(BltInfo->SourceSurface, SourceX, SourceY, BltInfo->XlateSourceToDest); 00435 } 00436 00437 if (BltInfo->PatternSurface) 00438 { 00439 Pattern = DIB_GetSourceIndex(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY); 00440 } 00441 00442 DIB_1BPP_PutPixel(BltInfo->DestSurface, DestX, DestY, DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern) & 0xF); 00443 } 00444 } 00445 00446 SourceY++; 00447 if (BltInfo->PatternSurface) 00448 { 00449 PatternY++; 00450 PatternY %= BltInfo->PatternSurface->sizlBitmap.cy; 00451 } 00452 } 00453 00454 return TRUE; 00455 } 00456 00457 /* BitBlt Optimize */ 00458 BOOLEAN 00459 DIB_1BPP_ColorFill(SURFOBJ* DestSurface, RECTL* DestRect, ULONG color) 00460 { 00461 LONG DestY; 00462 00463 for (DestY = DestRect->top; DestY< DestRect->bottom; DestY++) 00464 { 00465 DIB_1BPP_HLine(DestSurface, DestRect->left, DestRect->right, DestY, color); 00466 } 00467 return TRUE; 00468 } 00469 #endif // !_USE_DIBLIB_ 00470 00471 BOOLEAN 00472 DIB_1BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf, 00473 RECTL* DestRect, RECTL *SourceRect, 00474 XLATEOBJ *ColorTranslation, ULONG iTransColor) 00475 { 00476 return FALSE; 00477 } 00478 00479 /* EOF */ Generated on Sat May 26 2012 04:36:59 for ReactOS by
1.7.6.1
|