Changeset 6487 for trunk/src/user32/icon.cpp
- Timestamp:
- Aug 8, 2001, 12:07:19 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/icon.cpp
r2804 r6487 1 /* $Id: icon.cpp,v 1.1 0 2000-02-16 14:34:19sandervl Exp $ */1 /* $Id: icon.cpp,v 1.11 2001-08-08 10:07:18 sandervl Exp $ */ 2 2 3 3 /* … … 24 24 #include <string.h> 25 25 26 #include <win32api.h> 26 27 #include <win32type.h> 27 28 #include "dib.h" 28 29 #include <winicon.h> 29 30 #include <misc.h> … … 32 33 #include "dbglocal.h" 33 34 35 #define DIB_RGB_COLORS_W 0 36 #define DIB_PAL_COLORS_W 1 37 #define CBM_INIT_W 4 38 39 #if 0 34 40 //****************************************************************************** 35 41 //****************************************************************************** … … 150 156 //****************************************************************************** 151 157 //****************************************************************************** 158 #endif 159 160 //****************************************************************************** 161 //****************************************************************************** 162 ULONG QueryConvertedIconSize(WINBITMAPINFOHEADER *bmpHdr, int size) 163 { 164 int bwsize, colorsize, rgbsize, iconsize; 165 166 bwsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), 1); 167 colorsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), bmpHdr->biBitCount); 168 169 //SvL: 28-09-'98: only for <= 8 170 if(bmpHdr->biBitCount <= 8) 171 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2); 172 else rgbsize = 0; 173 174 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) { 175 bmpHdr->biSizeImage = bwsize + colorsize; 176 } 177 178 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header 179 if(bmpHdr->biSizeImage < colorsize) { 180 bmpHdr->biSizeImage = colorsize; 181 } 182 //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader 183 //for color bitmap + RGB structs for all the colors 184 //SvL, 3-3-98: 2*bwsize 185 iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 186 rgbsize + 2*bwsize + bmpHdr->biSizeImage; 187 188 return iconsize; 189 } 190 //****************************************************************************** 191 //NOTE: offsetBits is the value added to the offBits bitmap structure members 192 // (handy for converting icon groups) 193 //****************************************************************************** 194 void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int *os2size, int offsetBits) 195 { 196 RGBQUAD *rgb; 197 RGB2 *os2rgb; 198 int bwsize, i, colorsize, rgbsize, iconsize; 199 BITMAPFILEHEADER2 *iconhdr; 200 BITMAPFILEHEADER2 *iconhdr2; 201 char *pAnd, *pXor; 202 203 bwsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), 1); 204 colorsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), bmpHdr->biBitCount); 205 //SvL: 28-09-'98: only for <= 8 206 if(bmpHdr->biBitCount <= 8) 207 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2); 208 else rgbsize = 0; 209 210 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) { 211 bmpHdr->biSizeImage = bwsize + colorsize; 212 } 213 dprintf(("Icon size : %d", bmpHdr->biSizeImage)); 214 dprintf(("Icon Width : %d", bmpHdr->biWidth)); 215 //height for both the XOR and AND bitmap (color & BW) 216 dprintf(("Height : %d", bmpHdr->biHeight)); 217 dprintf(("Icon Bitcount: %d", bmpHdr->biBitCount)); 218 dprintf(("Icon Compress: %d", bmpHdr->biCompression)); 219 220 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header 221 if(bmpHdr->biSizeImage < colorsize) { 222 bmpHdr->biSizeImage = colorsize; 223 } 224 //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader 225 //for color bitmap + RGB structs for all the colors 226 //SvL, 3-3-98: 2*bwsize 227 iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 228 rgbsize + 2*bwsize + bmpHdr->biSizeImage; 229 230 iconhdr = (BITMAPFILEHEADER2 *)malloc(iconsize); 231 memset(iconhdr, 0, iconsize); 232 iconhdr->usType = BFT_COLORICON; 233 iconhdr->cbSize = sizeof(BITMAPFILEHEADER2); 234 iconhdr->xHotspot = 0; 235 iconhdr->yHotspot = 0; 236 iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) + 237 2*sizeof(RGB2) + rgbsize + offsetBits; 238 iconhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2); 239 iconhdr->bmp2.cx = (USHORT)bmpHdr->biWidth; 240 iconhdr->bmp2.cy = (USHORT)bmpHdr->biHeight; 241 iconhdr->bmp2.cPlanes = 1; 242 iconhdr->bmp2.cBitCount= 1; 243 iconhdr->bmp2.ulCompression = BCA_UNCOMP; 244 iconhdr->bmp2.ulColorEncoding = BCE_RGB; 245 os2rgb = (RGB2 *)(iconhdr+1); 246 memset(os2rgb, 0, sizeof(RGB2)); 247 memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte! 248 iconhdr2 = (BITMAPFILEHEADER2 *)(os2rgb+2); 249 iconhdr2->usType = BFT_COLORICON; 250 iconhdr2->cbSize = sizeof(BITMAPFILEHEADER2); 251 iconhdr2->xHotspot = 0; 252 iconhdr2->yHotspot = 0; 253 iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER2) + 254 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits; 255 iconhdr2->bmp2.cbFix = sizeof(BITMAPINFOHEADER2); 256 iconhdr2->bmp2.cx = (USHORT)bmpHdr->biWidth; 257 iconhdr2->bmp2.cy = (USHORT)(bmpHdr->biHeight/2); 258 iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes; 259 iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount; 260 iconhdr2->bmp2.ulCompression = BCA_UNCOMP; 261 iconhdr2->bmp2.ulColorEncoding = BCE_RGB; 262 os2rgb = (RGB2 *)(iconhdr2+1); 263 rgb = (RGBQUAD *)(bmpHdr+1); 264 if(bmpHdr->biBitCount <= 8) { 265 for(i=0;i<(1<<bmpHdr->biBitCount);i++) { 266 os2rgb->bRed = rgb->red; 267 os2rgb->bBlue = rgb->blue; 268 os2rgb->bGreen = rgb->green; 269 os2rgb++; 270 rgb++; 271 } 272 } 273 274 pXor = (char *)os2rgb; 275 pAnd = (char *)os2rgb + bwsize; 276 277 if ((size - (bmpHdr->biSize + rgbsize + colorsize + bwsize)) == bwsize) 278 {//this means an AND and XOR mask is present (interleaved; and/xor) 279 char *q; 280 int i, linesize; 281 282 linesize = bmpHdr->biWidth / 8; 283 q = (char *)rgb + colorsize; 284 for (i = 0; i < (bmpHdr->biHeight/2); i++) { 285 memcpy (pAnd, q, linesize); 286 pAnd += linesize; 287 q += linesize; 288 289 memcpy (pXor, q, linesize); 290 pXor += linesize; 291 q += linesize; 292 } 293 } else { 294 memcpy (pAnd, (char *)rgb + colorsize, bwsize); 295 memset (pXor, 0, bwsize); 296 } 297 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize); 298 299 *os2size = iconsize; 300 return (void *)iconhdr; 301 } 302 //****************************************************************************** 303 //****************************************************************************** 304 void * WIN32API ConvertIconGroup(void *hdr, HINSTANCE hInstance, DWORD *ressize) 305 { 306 IconHeader *ihdr = (IconHeader *)hdr; 307 ResourceDirectory *rdir = (ResourceDirectory *)(ihdr + 1); 308 int i, groupsize = 0, os2iconsize; 309 BITMAPARRAYFILEHEADER2 *bafh, *orgbafh; 310 WINBITMAPINFOHEADER *iconhdr; 311 void *os2icon; 312 HRSRC hRes; 313 314 dprintf(("Icon Group type :%d", ihdr->wType)); 315 dprintf(("Icon Group count:%d", ihdr->wCount)); 316 for(i=0;i<ihdr->wCount;i++) { 317 dprintf2(("Icon : %d", rdir->wNameOrdinal)); 318 dprintf2(("Width : %d", (int)rdir->bWidth)); 319 dprintf2(("Height : %d", (int)rdir->bHeight)); 320 dprintf2(("Colors : %d", (int)rdir->bColorCount)); 321 dprintf2(("Bits : %d", rdir->wBitCount)); 322 dprintf2(("ResBytes: %d", rdir->lBytesInRes)); 323 hRes = FindResourceA(hInstance, 324 (LPCSTR)rdir->wNameOrdinal, (LPSTR)NTRT_ICON); 325 326 groupsize += QueryConvertedIconSize((WINBITMAPINFOHEADER *)LockResource(LoadResource(hInstance, hRes)), 327 SizeofResource(hInstance, hRes)); 328 rdir++; 329 } 330 groupsize = groupsize+ihdr->wCount*sizeof(BITMAPARRAYFILEHEADER2); 331 bafh = (BITMAPARRAYFILEHEADER2 *)malloc(groupsize); 332 memset(bafh, 0, groupsize); 333 orgbafh = bafh; 334 335 rdir = (ResourceDirectory *)(ihdr + 1); 336 for(i=0;i<ihdr->wCount;i++) { 337 bafh->usType = BFT_BITMAPARRAY; 338 bafh->cbSize = sizeof(BITMAPARRAYFILEHEADER2); 339 bafh->cxDisplay = 0; 340 bafh->cyDisplay = 0; 341 hRes = FindResourceA(hInstance, 342 (LPCSTR)rdir->wNameOrdinal, (LPSTR)NTRT_ICON); 343 if(hRes == NULL) { 344 dprintf(("Can't find icon!")); 345 rdir++; 346 continue; 347 } 348 iconhdr = (WINBITMAPINFOHEADER *)LockResource(LoadResource(hInstance, hRes)); 349 os2icon = ConvertIcon(iconhdr, SizeofResource(hInstance, hRes), &os2iconsize, (ULONG)bafh - (ULONG)orgbafh + sizeof(BITMAPARRAYFILEHEADER2)-sizeof(BITMAPFILEHEADER2)); 350 if(os2icon == NULL) { 351 dprintf(("Can't convert icon!")); 352 rdir++; 353 continue; 354 } 355 356 if(i != ihdr->wCount -1) { 357 bafh->offNext = (ULONG)&bafh->bfh2 - (ULONG)orgbafh + os2iconsize; 358 } 359 else bafh->offNext = 0; 360 361 memcpy((char *)&bafh->bfh2, os2icon, os2iconsize); 362 free(os2icon); 363 364 bafh = (BITMAPARRAYFILEHEADER2 *)((ULONG)&bafh->bfh2 + os2iconsize); 365 366 rdir++; 367 } 368 *ressize = groupsize; 369 return (void *)orgbafh; 370 } 371 //****************************************************************************** 372 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.