Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendib8bpp.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/dib8bpp.c 00005 * PURPOSE: Device Independant Bitmap functions, 8bpp 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_8BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c) 00018 { 00019 PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + x; 00020 00021 *byteaddr = (BYTE)c; 00022 } 00023 00024 ULONG 00025 DIB_8BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y) 00026 { 00027 PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + x; 00028 00029 return (ULONG)(*byteaddr); 00030 } 00031 00032 VOID 00033 DIB_8BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c) 00034 { 00035 memset((PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + x1, (BYTE) c, x2 - x1); 00036 } 00037 00038 VOID 00039 DIB_8BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c) 00040 { 00041 PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y1 * SurfObj->lDelta; 00042 PBYTE addr = byteaddr + x; 00043 LONG lDelta = SurfObj->lDelta; 00044 00045 byteaddr = addr; 00046 while(y1++ < y2) 00047 { 00048 *addr = (BYTE)c; 00049 00050 addr += lDelta; 00051 } 00052 } 00053 00054 BOOLEAN 00055 DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo) 00056 { 00057 LONG i, j, sx, sy, xColor, f1; 00058 PBYTE SourceBits, DestBits, SourceLine, DestLine; 00059 PBYTE SourceBits_4BPP, SourceLine_4BPP; 00060 00061 DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left; 00062 00063 switch(BltInfo->SourceSurface->iBitmapFormat) 00064 { 00065 case BMF_1BPP: 00066 sx = BltInfo->SourcePoint.x; 00067 sy = BltInfo->SourcePoint.y; 00068 00069 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++) 00070 { 00071 sx = BltInfo->SourcePoint.x; 00072 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00073 { 00074 if(DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0) 00075 { 00076 DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0)); 00077 } 00078 else 00079 { 00080 DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1)); 00081 } 00082 sx++; 00083 } 00084 sy++; 00085 } 00086 break; 00087 00088 case BMF_4BPP: 00089 SourceBits_4BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + (BltInfo->SourcePoint.x >> 1); 00090 00091 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++) 00092 { 00093 SourceLine_4BPP = SourceBits_4BPP; 00094 sx = BltInfo->SourcePoint.x; 00095 f1 = sx & 1; 00096 00097 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00098 { 00099 xColor = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 00100 (*SourceLine_4BPP & altnotmask[f1]) >> (4 * (1 - f1))); 00101 DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, xColor); 00102 if(f1 == 1) { SourceLine_4BPP++; f1 = 0; } else { f1 = 1; } 00103 sx++; 00104 } 00105 00106 SourceBits_4BPP += BltInfo->SourceSurface->lDelta; 00107 } 00108 break; 00109 00110 case BMF_8BPP: 00111 if (NULL == BltInfo->XlateSourceToDest || 0 != (BltInfo->XlateSourceToDest->flXlate & XO_TRIVIAL)) 00112 { 00113 if (BltInfo->DestRect.top < BltInfo->SourcePoint.y) 00114 { 00115 SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x; 00116 for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++) 00117 { 00118 RtlMoveMemory(DestBits, SourceBits, BltInfo->DestRect.right - BltInfo->DestRect.left); 00119 SourceBits += BltInfo->SourceSurface->lDelta; 00120 DestBits += BltInfo->DestSurface->lDelta; 00121 } 00122 } 00123 else 00124 { 00125 SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x; 00126 DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left; 00127 for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--) 00128 { 00129 RtlMoveMemory(DestBits, SourceBits, BltInfo->DestRect.right - BltInfo->DestRect.left); 00130 SourceBits -= BltInfo->SourceSurface->lDelta; 00131 DestBits -= BltInfo->DestSurface->lDelta; 00132 } 00133 } 00134 } 00135 else 00136 { 00137 if (BltInfo->DestRect.top < BltInfo->SourcePoint.y) 00138 { 00139 SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x; 00140 DestLine = DestBits; 00141 for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++) 00142 { 00143 SourceBits = SourceLine; 00144 DestBits = DestLine; 00145 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00146 { 00147 *DestBits++ = (BYTE)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *SourceBits++); 00148 } 00149 SourceLine += BltInfo->SourceSurface->lDelta; 00150 DestLine += BltInfo->DestSurface->lDelta; 00151 } 00152 } 00153 else 00154 { 00155 SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x; 00156 DestLine = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left; 00157 for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--) 00158 { 00159 SourceBits = SourceLine; 00160 DestBits = DestLine; 00161 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++) 00162 { 00163 *DestBits++ = (BYTE)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *SourceBits++); 00164 } 00165 SourceLine -= BltInfo->SourceSurface->lDelta; 00166 DestLine -= BltInfo->DestSurface->lDelta; 00167 } 00168 } 00169 } 00170 break; 00171 00172 case BMF_16BPP: 00173 SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x; 00174 DestLine = DestBits; 00175 00176 for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++) 00177 { 00178 SourceBits = SourceLine; 00179 DestBits = DestLine; 00180 00181 for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++) 00182 { 00183 xColor = *((PWORD) SourceBits); 00184 *DestBits = (BYTE)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor); 00185 SourceBits += 2; 00186 DestBits += 1; 00187 } 00188 00189 SourceLine += BltInfo->SourceSurface->lDelta; 00190 DestLine += BltInfo->DestSurface->lDelta; 00191 } 00192 break; 00193 00194 case BMF_24BPP: 00195 SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 3 * BltInfo->SourcePoint.x; 00196 DestLine = DestBits; 00197 00198 for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++) 00199 { 00200 SourceBits = SourceLine; 00201 DestBits = DestLine; 00202 00203 for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++) 00204 { 00205 xColor = (*(SourceBits + 2) << 0x10) + 00206 (*(SourceBits + 1) << 0x08) + 00207 (*(SourceBits)); 00208 *DestBits = (BYTE)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor); 00209 SourceBits += 3; 00210 DestBits += 1; 00211 } 00212 00213 SourceLine += BltInfo->SourceSurface->lDelta; 00214 DestLine += BltInfo->DestSurface->lDelta; 00215 } 00216 break; 00217 00218 case BMF_32BPP: 00219 SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x; 00220 DestLine = DestBits; 00221 00222 for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++) 00223 { 00224 SourceBits = SourceLine; 00225 DestBits = DestLine; 00226 00227 for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++) 00228 { 00229 xColor = *((PDWORD) SourceBits); 00230 *DestBits = (BYTE)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor); 00231 SourceBits += 4; 00232 DestBits += 1; 00233 } 00234 00235 SourceLine += BltInfo->SourceSurface->lDelta; 00236 DestLine += BltInfo->DestSurface->lDelta; 00237 } 00238 break; 00239 00240 default: 00241 DPRINT1("DIB_8BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat)); 00242 return FALSE; 00243 } 00244 00245 return TRUE; 00246 } 00247 00248 /* BitBlt Optimize */ 00249 BOOLEAN 00250 DIB_8BPP_ColorFill(SURFOBJ* DestSurface, RECTL* DestRect, ULONG color) 00251 { 00252 LONG DestY; 00253 for (DestY = DestRect->top; DestY< DestRect->bottom; DestY++) 00254 { 00255 DIB_8BPP_HLine(DestSurface, DestRect->left, DestRect->right, DestY, color); 00256 } 00257 return TRUE; 00258 } 00259 00260 00261 BOOLEAN 00262 DIB_8BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf, 00263 RECTL* DestRect, RECTL *SourceRect, 00264 XLATEOBJ *ColorTranslation, ULONG iTransColor) 00265 { 00266 LONG RoundedRight, X, Y, SourceX = 0, SourceY = 0; 00267 ULONG *DestBits, Source, Dest; 00268 00269 LONG DstHeight; 00270 LONG DstWidth; 00271 LONG SrcHeight; 00272 LONG SrcWidth; 00273 00274 DstHeight = DestRect->bottom - DestRect->top; 00275 DstWidth = DestRect->right - DestRect->left; 00276 SrcHeight = SourceRect->bottom - SourceRect->top; 00277 SrcWidth = SourceRect->right - SourceRect->left; 00278 00279 RoundedRight = DestRect->right - ((DestRect->right - DestRect->left) & 0x3); 00280 DestBits = (ULONG*)((PBYTE)DestSurf->pvScan0 + DestRect->left + 00281 (DestRect->top * DestSurf->lDelta)); 00282 00283 for(Y = DestRect->top; Y < DestRect->bottom; Y++) 00284 { 00285 DestBits = (ULONG*)((PBYTE)DestSurf->pvScan0 + DestRect->left + 00286 (Y * DestSurf->lDelta)); 00287 SourceY = SourceRect->top+(Y - DestRect->top) * SrcHeight / DstHeight; 00288 for (X = DestRect->left; X < RoundedRight; X += 4, DestBits++) 00289 { 00290 Dest = *DestBits; 00291 00292 SourceX = SourceRect->left+(X - DestRect->left) * SrcWidth / DstWidth; 00293 if (SourceX >= 0 && SourceY >= 0 && 00294 SourceSurf->sizlBitmap.cx > SourceX && SourceSurf->sizlBitmap.cy > SourceY) 00295 { 00296 Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY); 00297 if(Source != iTransColor) 00298 { 00299 Dest &= 0xFFFFFF00; 00300 Dest |= (XLATEOBJ_iXlate(ColorTranslation, Source) & 0xFF); 00301 } 00302 } 00303 00304 SourceX = SourceRect->left+(X+1 - DestRect->left) * SrcWidth / DstWidth; 00305 if (SourceX >= 0 && SourceY >= 0 && 00306 SourceSurf->sizlBitmap.cx > SourceX && SourceSurf->sizlBitmap.cy > SourceY) 00307 { 00308 Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY); 00309 if(Source != iTransColor) 00310 { 00311 Dest &= 0xFFFF00FF; 00312 Dest |= ((XLATEOBJ_iXlate(ColorTranslation, Source) << 8) & 0xFF00); 00313 } 00314 } 00315 00316 SourceX = SourceRect->left+(X+2 - DestRect->left) * SrcWidth / DstWidth; 00317 if (SourceX >= 0 && SourceY >= 0 && 00318 SourceSurf->sizlBitmap.cx > SourceX && SourceSurf->sizlBitmap.cy > SourceY) 00319 { 00320 Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY); 00321 if(Source != iTransColor) 00322 { 00323 Dest &= 0xFF00FFFF; 00324 Dest |= ((XLATEOBJ_iXlate(ColorTranslation, Source) << 16) & 0xFF0000); 00325 } 00326 } 00327 00328 SourceX = SourceRect->left+(X+3 - DestRect->left) * SrcWidth / DstWidth; 00329 if (SourceX >= 0 && SourceY >= 0 && 00330 SourceSurf->sizlBitmap.cx > SourceX && SourceSurf->sizlBitmap.cy > SourceY) 00331 { 00332 Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY); 00333 if(Source != iTransColor) 00334 { 00335 Dest &= 0x00FFFFFF; 00336 Dest |= ((XLATEOBJ_iXlate(ColorTranslation, Source) << 24) & 0xFF000000); 00337 } 00338 } 00339 00340 *DestBits = Dest; 00341 } 00342 00343 if(X < DestRect->right) 00344 { 00345 for (; X < DestRect->right; X++) 00346 { 00347 SourceX = SourceRect->left+(X - DestRect->left) * SrcWidth / DstWidth; 00348 if (SourceX >= 0 && SourceY >= 0 && 00349 SourceSurf->sizlBitmap.cx > SourceX && SourceSurf->sizlBitmap.cy > SourceY) 00350 { 00351 Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY); 00352 if(Source != iTransColor) 00353 { 00354 *((BYTE*)DestBits) = (BYTE)(XLATEOBJ_iXlate(ColorTranslation, Source) & 0xFF); 00355 } 00356 } 00357 DestBits = (PULONG)((ULONG_PTR)DestBits + 1); 00358 } 00359 } 00360 } 00361 00362 return TRUE; 00363 } 00364 00365 /* EOF */ Generated on Sat May 26 2012 04:36:59 for ReactOS by
1.7.6.1
|