Changeset 5677 for trunk/src/gdi32/blit.cpp
- Timestamp:
- May 10, 2001, 7:03:18 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gdi32/blit.cpp
r5252 r5677 1 /* $Id: blit.cpp,v 1.2 4 2001-02-23 10:37:42sandervl Exp $ */1 /* $Id: blit.cpp,v 1.25 2001-05-10 17:03:17 sandervl Exp $ */ 2 2 3 3 /* … … 91 91 //****************************************************************************** 92 92 //****************************************************************************** 93 INT WIN32API SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD cx,93 static INT SetDIBitsToDevice_(HDC hdc, INT xDest, INT yDest, DWORD cx, 94 94 DWORD cy, INT xSrc, INT ySrc, 95 95 UINT startscan, UINT lines, LPCVOID bits, … … 198 198 SetLastError(ERROR_INVALID_PARAMETER); 199 199 return 0; 200 } 201 //****************************************************************************** 202 //****************************************************************************** 203 INT WIN32API SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD cx, 204 DWORD cy, INT xSrc, INT ySrc, 205 UINT startscan, UINT lines, LPCVOID bits, 206 const BITMAPINFO *info, UINT coloruse) 207 { 208 if(info->bmiHeader.biHeight < 0 && info->bmiHeader.biBitCount != 8 && info->bmiHeader.biCompression == 0) { 209 // upside down 210 INT rc = 0; 211 BITMAPINFO newInfo; 212 newInfo.bmiHeader = info->bmiHeader; 213 long lLineByte = ((newInfo.bmiHeader.biWidth * (info->bmiHeader.biBitCount == 15 ? 16 : info->bmiHeader.biBitCount) + 31) / 32) * 4; 214 long lHeight = -newInfo.bmiHeader.biHeight; 215 newInfo.bmiHeader.biHeight = -info->bmiHeader.biHeight; 216 217 char *newBits = (char *)malloc( lLineByte * lHeight ); 218 if(newBits) { 219 unsigned char *pbSrc = (unsigned char *)bits + lLineByte * (lHeight - 1); 220 unsigned char *pbDst = (unsigned char *)newBits; 221 for(int y = 0; y < lHeight; y++) { 222 memcpy( pbDst, pbSrc, lLineByte ); 223 pbDst += lLineByte; 224 pbSrc -= lLineByte; 225 } 226 rc = SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (void *)newBits, &newInfo, DIB_RGB_COLORS ); 227 free( newBits ); 228 } 229 return rc; 230 } 231 else 232 if(info->bmiHeader.biBitCount == 8 && info->bmiHeader.biCompression == 0 && !(GetDeviceCaps( hdc, RASTERCAPS ) & RC_PALETTE)) { 233 INT rc = 0; 234 // convert 8bit to 24bit 235 236 BITMAPINFO newInfo; 237 newInfo.bmiHeader = info->bmiHeader; 238 newInfo.bmiHeader.biBitCount = 24; 239 long lLineByte24 = ((newInfo.bmiHeader.biWidth * 24 + 31) / 32) * 4; 240 long lLineByte8 = ((newInfo.bmiHeader.biWidth * 8 + 31) / 32) * 4; 241 long lHeight = newInfo.bmiHeader.biHeight; 242 if(lHeight < 0) lHeight = -lHeight; 243 244 char *newBits = (char *)malloc( lLineByte24 * lHeight ); 245 if(newBits) { 246 // 247 // Get Palette Entries 248 // 249 PALETTEENTRY aEntries[256]; 250 LOGPALETTE *pLog = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * 256 ); 251 pLog->palVersion = 0x300; 252 pLog->palNumEntries = 256; 253 254 HPALETTE hPaletteDummy = CreatePalette( pLog ); 255 free( pLog ); 256 HPALETTE hPalette = SelectPalette( hdc, hPaletteDummy, FALSE ); 257 GetPaletteEntries( hPalette, 0, 255, aEntries ); 258 SelectPalette( hdc, hPalette, FALSE ); 259 DeleteObject( hPaletteDummy ); 260 261 // 262 // convert 8bit to 24bit 263 // 264 if(newInfo.bmiHeader.biHeight > 0) { 265 unsigned char *pbSrc = (unsigned char *)bits; 266 unsigned char *pbDst = (unsigned char *)newBits; 267 for(int y = 0; y < lHeight; y++) { 268 for(int x = 0; x < newInfo.bmiHeader.biWidth; x++) { 269 PALETTEENTRY src = aEntries[pbSrc[x]]; 270 pbDst[x * 3 + 0] = src.peBlue; 271 pbDst[x * 3 + 1] = src.peGreen; 272 pbDst[x * 3 + 2] = src.peRed; 273 } 274 pbDst += lLineByte24; 275 pbSrc += lLineByte8; 276 } 277 } else { 278 // upside down 279 newInfo.bmiHeader.biHeight = -info->bmiHeader.biHeight; 280 unsigned char *pbSrc = (unsigned char *)bits + lLineByte8 * (lHeight - 1); 281 unsigned char *pbDst = (unsigned char *)newBits; 282 for(int y = 0; y < lHeight; y++) { 283 for(int x = 0; x < newInfo.bmiHeader.biWidth; x++) { 284 PALETTEENTRY src = aEntries[pbSrc[x]]; 285 pbDst[x * 3 + 0] = src.peBlue; 286 pbDst[x * 3 + 1] = src.peGreen; 287 pbDst[x * 3 + 2] = src.peRed; 288 } 289 pbDst += lLineByte24; 290 pbSrc -= lLineByte8; 291 } 292 } 293 rc = SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (void *)newBits, &newInfo, DIB_RGB_COLORS ); 294 free( newBits ); 295 } 296 return rc; 297 } else { 298 return SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse ); 299 } 200 300 } 201 301 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.