Ignore:
Timestamp:
Aug 9, 2001, 5:02:11 PM (24 years ago)
Author:
sandervl
Message:

add 40x40 icon when converting windows icons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/icon.cpp

    r6490 r6503  
    1 /* $Id: icon.cpp,v 1.12 2001-08-08 12:06:29 sandervl Exp $ */
     1/* $Id: icon.cpp,v 1.13 2001-08-09 15:02:11 sandervl Exp $ */
    22
    33/*
     
    4040//******************************************************************************
    4141//******************************************************************************
    42 ULONG QueryConvertedIconSize(WINBITMAPINFOHEADER *bmpHdr, int size)
     42ULONG QueryConvertedIconSize(WINBITMAPINFOHEADER *bmpHdr, int size, BOOL fResizeTo40x40 = FALSE)
    4343{
    4444 int bwsize, colorsize, rgbsize, iconsize;
    4545
    46   bwsize    = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), 1);
    47   colorsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), bmpHdr->biBitCount);
     46  if(fResizeTo40x40) {
     47      bwsize    = DIB_GetDIBImageBytes(40, 40, 1);
     48      colorsize = DIB_GetDIBImageBytes(40, 40, bmpHdr->biBitCount);
     49  }
     50  else {
     51      bwsize    = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), 1);
     52      colorsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), bmpHdr->biBitCount);
     53  }
    4854
    4955  if(bmpHdr->biBitCount <= 8)
     
    7177//      (handy for converting icon groups)
    7278//******************************************************************************
    73 void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int *os2size, int offsetBits)
     79void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int *os2size, int offsetBits,
     80                  BOOL fResizeTo40x40 = FALSE)
    7481{
    7582 RGBQUAD *rgb;
    7683 RGB2    *os2rgb;
    77  int bwsize, i, colorsize, rgbsize, iconsize;
     84 int bwsize, i, colorsize, rgbsize, iconsize, orgbwsize, orgcolorsize;
    7885 BITMAPFILEHEADER2 *iconhdr;
    7986 BITMAPFILEHEADER2 *iconhdr2;
    8087 char *pAnd, *pXor;
    8188
    82   bwsize    = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), 1);
    83   colorsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), bmpHdr->biBitCount);
     89  if(fResizeTo40x40) {
     90      orgbwsize    = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), 1);
     91      orgcolorsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), bmpHdr->biBitCount);
     92      bwsize       = DIB_GetDIBImageBytes(40, 40, 1);
     93      colorsize    = DIB_GetDIBImageBytes(40, 40, bmpHdr->biBitCount);
     94  }
     95  else {
     96      bwsize    = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), 1);
     97      colorsize = DIB_GetDIBImageBytes(bmpHdr->biWidth, (bmpHdr->biHeight/2), bmpHdr->biBitCount);
     98  }
    8499  //SvL: 28-09-'98: only for <= 8
    85100  if(bmpHdr->biBitCount <= 8)
     
    116131                           2*sizeof(RGB2) + rgbsize + offsetBits;
    117132  iconhdr->bmp2.cbFix    = sizeof(BITMAPINFOHEADER2);
    118   iconhdr->bmp2.cx       = (USHORT)bmpHdr->biWidth;
    119   iconhdr->bmp2.cy       = (USHORT)bmpHdr->biHeight;
     133  if(fResizeTo40x40) {
     134      iconhdr->bmp2.cx   = (USHORT)40;
     135      iconhdr->bmp2.cy   = (USHORT)80;
     136  }
     137  else {
     138      iconhdr->bmp2.cx   = (USHORT)bmpHdr->biWidth;
     139      iconhdr->bmp2.cy   = (USHORT)bmpHdr->biHeight;
     140  }
    120141  iconhdr->bmp2.cPlanes  = 1;
    121142  iconhdr->bmp2.cBitCount= 1;
     
    136157                           2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
    137158  iconhdr2->bmp2.cbFix   = sizeof(BITMAPINFOHEADER2);
    138   iconhdr2->bmp2.cx      = (USHORT)bmpHdr->biWidth;
    139   iconhdr2->bmp2.cy      = (USHORT)(bmpHdr->biHeight/2);
     159  if(fResizeTo40x40) {
     160      iconhdr2->bmp2.cx  = (USHORT)40;
     161      iconhdr2->bmp2.cy  = (USHORT)40;
     162  }
     163  else {
     164      iconhdr2->bmp2.cx  = (USHORT)bmpHdr->biWidth;
     165      iconhdr2->bmp2.cy  = (USHORT)(bmpHdr->biHeight/2);
     166  }
    140167  iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
    141168  iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
     
    157184  }
    158185
    159   pXor = (char *)os2rgb;
    160   pAnd = (char *)os2rgb + bwsize;
    161 
    162   if ((size - (bmpHdr->biSize + rgbsize + colorsize + bwsize)) == bwsize)
    163   {//this means an AND and XOR mask is present (interleaved; and/xor)
    164     char *q;
    165     int i, linesize;
    166 
    167     linesize = bmpHdr->biWidth / 8;
    168     q = (char *)rgb + colorsize;
    169     for (i = 0; i < (bmpHdr->biHeight/2); i++) {
    170       memcpy (pAnd, q, linesize);
    171       pAnd += linesize;
    172       q += linesize;
    173 
    174       memcpy (pXor, q, linesize);
    175       pXor += linesize;
    176       q += linesize;
    177     }
    178   } else {
    179     memcpy (pAnd, (char *)rgb + colorsize, bwsize);
    180     memset (pXor, 0, bwsize);
    181   }
    182   memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
    183 
     186  if(fResizeTo40x40)
     187  {
     188      BYTE *src, *dest;
     189      int linesizesrc, linesizedest;
     190
     191      pXor = (char *)os2rgb;
     192      pAnd = (char *)os2rgb + bwsize;
     193
     194      if ((size - (bmpHdr->biSize + rgbsize + orgcolorsize + orgbwsize)) == orgbwsize)
     195      {//this means an AND and XOR mask is present (interleaved; and/xor)
     196        char *q;
     197        int i, linesize;
     198
     199        linesize = DIB_GetDIBWidthBytes(bmpHdr->biWidth, 1);
     200        q = (char *)rgb + orgcolorsize;
     201        for (i = 0; i < bmpHdr->biHeight/2; i++) {
     202          memcpy (pAnd, q, linesize);
     203          pAnd += linesize;
     204          q += linesize;
     205
     206          memcpy (pXor, q, linesize);
     207          pXor += linesize;
     208          q += linesize;
     209        }
     210      }
     211      else {
     212        linesizesrc  = DIB_GetDIBWidthBytes(bmpHdr->biWidth, 1);
     213        linesizedest = DIB_GetDIBWidthBytes(40, 1);
     214
     215        src  = (BYTE *)rgb + orgcolorsize;
     216        dest = (BYTE *)pAnd + 4*linesizedest; //skip 4 lines
     217        memset((char *)pAnd, 0xFF, bwsize);
     218        for (i = 0; i < bmpHdr->biHeight/2; i++) {
     219            for(int j=0;j<linesizesrc;j++) {
     220                //must skip 4 pixels (4 bits)
     221                dest[j]   = (dest[j] & 0xF0) | ((src[j] >> 4));
     222                dest[j+1] = (dest[j+1] & 0x0F) | ((src[j] & 0xF) << 4);
     223            }
     224            dest += linesizedest;
     225            src  += linesizesrc;
     226        }
     227        memset (pXor, 0, bwsize);
     228      }
     229      linesizesrc  = DIB_GetDIBWidthBytes(32, bmpHdr->biBitCount);
     230      linesizedest = DIB_GetDIBWidthBytes(40, bmpHdr->biBitCount);
     231      int skipsize = (4*bmpHdr->biBitCount)/8; //must skip 4 pixels
     232      src  = (BYTE *)rgb;
     233      dest = (BYTE *)os2rgb+2*bwsize + 4*linesizedest; //skip 4 rows
     234
     235      for (i = 0; i < 32; i++) {
     236          memcpy(dest+skipsize, src, linesizesrc);
     237          dest += linesizedest;
     238          src  += linesizesrc;
     239      }
     240  }
     241  else {
     242      pXor = (char *)os2rgb;
     243      pAnd = (char *)os2rgb + bwsize;
     244
     245      if ((size - (bmpHdr->biSize + rgbsize + colorsize + bwsize)) == bwsize)
     246      {//this means an AND and XOR mask is present (interleaved; and/xor)
     247        char *q;
     248        int i, linesize;
     249
     250        linesize = DIB_GetDIBWidthBytes(bmpHdr->biWidth, 1);
     251        q = (char *)rgb + orgcolorsize;
     252        for (i = 0; i < bmpHdr->biHeight/2; i++) {
     253          memcpy (pAnd, q, linesize);
     254          pAnd += linesize;
     255          q += linesize;
     256
     257          memcpy (pXor, q, linesize);
     258          pXor += linesize;
     259          q += linesize;
     260        }
     261      }
     262      else {
     263        memcpy (pAnd, (char *)rgb + colorsize, bwsize);
     264        memset (pXor, 0, bwsize);
     265      }
     266      memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
     267  }
    184268  *os2size = iconsize;
    185269  return (void *)iconhdr;
     
    196280 void                   *os2icon;
    197281 HRSRC                   hRes;
     282 int                     nricons = 0;
    198283
    199284  dprintf(("Icon Group type :%d", ihdr->wType));
     
    211296        groupsize += QueryConvertedIconSize((WINBITMAPINFOHEADER *)LockResource(LoadResource(hInstance, hRes)),
    212297                                            SizeofResource(hInstance, hRes));
     298        if(rdir->bWidth == 32 && rdir->bHeight == 32 && rdir->wBitCount >= 4) {
     299            groupsize += QueryConvertedIconSize((WINBITMAPINFOHEADER *)LockResource(LoadResource(hInstance, hRes)),
     300                                                SizeofResource(hInstance, hRes), TRUE);
     301            nricons++;
     302        }
     303        nricons++;
    213304        rdir++;
    214305  }
    215   groupsize = groupsize+ihdr->wCount*(sizeof(BITMAPARRAYFILEHEADER2) - sizeof(BITMAPFILEHEADER2));
     306  groupsize = groupsize+nricons*(sizeof(BITMAPARRAYFILEHEADER2) - sizeof(BITMAPFILEHEADER2));
    216307  bafh    = (BITMAPARRAYFILEHEADER2 *)malloc(groupsize);
    217308  memset(bafh, 0, groupsize);
     
    239330        }
    240331
     332        if(rdir->bWidth == 32 && rdir->bHeight == 32 && rdir->wBitCount >= 4)
     333        {
     334                //add 40x40 icon by centering 32x32 icon in 40x40 grid
     335                //(resize is really ugly)
     336                bafh->offNext = (ULONG)&bafh->bfh2 - (ULONG)orgbafh + os2iconsize;
     337                memcpy((char *)&bafh->bfh2, os2icon, os2iconsize);
     338                free(os2icon);
     339
     340                bafh = (BITMAPARRAYFILEHEADER2 *)((ULONG)&bafh->bfh2 + os2iconsize);
     341
     342                os2icon = ConvertIcon(iconhdr, SizeofResource(hInstance, hRes), &os2iconsize, (ULONG)bafh - (ULONG)orgbafh + sizeof(BITMAPARRAYFILEHEADER2)-sizeof(BITMAPFILEHEADER2), TRUE);
     343                if(os2icon == NULL) {
     344                        dprintf(("Can't convert icon!"));
     345                        rdir++;
     346                        continue;
     347                }
     348        }
     349
    241350        if(i != ihdr->wCount -1) {
    242351                bafh->offNext = (ULONG)&bafh->bfh2 - (ULONG)orgbafh + os2iconsize;
Note: See TracChangeset for help on using the changeset viewer.