Ignore:
Timestamp:
Oct 27, 1999, 12:35:42 PM (26 years ago)
Author:
sandervl
Message:

Color cursor changes + dll loading fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/cvtcursor.cpp

    r1427 r1475  
    1 /* $Id: cvtcursor.cpp,v 1.7 1999-10-24 09:43:02 sandervl Exp $ */
     1/* $Id: cvtcursor.cpp,v 1.8 1999-10-27 10:35:41 sandervl Exp $ */
    22
    33/*
     
    3232ULONG QueryConvertedCursorSize(CursorComponent *curHdr, int size)
    3333{
    34  WINBITMAPINFOHEADER *bhdr = (WINBITMAPINFOHEADER *)(curHdr+1);
    35  int                  bmpsize, cursorsize;
    36 
    37   bmpsize = size - sizeof(CursorComponent) - (1<<bhdr->biBitCount)*sizeof(RGBQUAD);
    38   cursorsize = sizeof(BITMAPFILEHEADER2) + bmpsize + (1<<bhdr->biBitCount)*sizeof(RGB2);
     34 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)(curHdr+1);
     35 int bwsize, colorsize, rgbsize, cursorsize;
     36
     37  bwsize   = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
     38  colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
     39
     40  if(bmpHdr->biBitCount <= 8)
     41        rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
     42  else  rgbsize = 0;
     43
     44  switch(bmpHdr->biBitCount) {
     45        case 1:
     46                colorsize /= 8;
     47                break;
     48        case 4:
     49                colorsize /= 2;
     50                break;
     51        case 8:
     52                break;
     53        case 16:
     54                colorsize *= 2;
     55                break;
     56        case 24:
     57                colorsize *= 3;
     58                break;
     59        case 32:
     60                colorsize *= 4;
     61                break;
     62  }
     63  if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
     64        bmpHdr->biSizeImage = bwsize + colorsize;
     65  }
     66
     67  //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
     68  if(bmpHdr->biSizeImage < colorsize) {
     69        bmpHdr->biSizeImage = colorsize;
     70  }
     71  if(bmpHdr->biBitCount > 1) {
     72        //And mask, xor mask (0) + color image
     73        cursorsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
     74                     rgbsize + 2*bwsize + bmpHdr->biSizeImage;
     75  }
     76  else {
     77        //And + xor mask
     78        cursorsize = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 2*bwsize;
     79  }
    3980
    4081  return cursorsize;
     
    4889 RGBQUAD   *rgb;
    4990 RGB2      *os2rgb;
    50  WINBITMAPINFOHEADER *bhdr = (WINBITMAPINFOHEADER *)(curHdr+1);
    51  BITMAPFILEHEADER2   *cursorhdr;
    52  int        i, bwsize, bmpsize, cursorsize;
     91 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)(curHdr+1);
     92 BITMAPFILEHEADER2   *cursorhdr, *cursorhdr2;
     93 int        i, bwsize, bmpsize, cursorsize, rgbsize, colorsize;
    5394
    5495  dprintf(("ConvertCursor: Cursor size %d", size));
    55   bmpsize = size - sizeof(CursorComponent) - (1<<bhdr->biBitCount)*sizeof(RGBQUAD);
    56   cursorsize = sizeof(BITMAPFILEHEADER2) + bmpsize + (1<<bhdr->biBitCount)*sizeof(RGB2);
     96  bwsize   = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
     97  colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
     98
     99  if(bmpHdr->biBitCount <= 8)
     100        rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
     101  else  rgbsize = 0;
     102
     103  switch(bmpHdr->biBitCount) {
     104        case 1:
     105                colorsize /= 8;
     106                break;
     107        case 4:
     108                colorsize /= 2;
     109                break;
     110        case 8:
     111                break;
     112        case 16:
     113                colorsize *= 2;
     114                break;
     115        case 24:
     116                colorsize *= 3;
     117                break;
     118        case 32:
     119                colorsize *= 4;
     120                break;
     121  }
     122  if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
     123        bmpHdr->biSizeImage = bwsize + colorsize;
     124  }
     125
     126  //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
     127  if(bmpHdr->biSizeImage < colorsize) {
     128        bmpHdr->biSizeImage = colorsize;
     129  }
     130  if(bmpHdr->biBitCount == 1) {
     131        //And + xor mask
     132        cursorsize = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 2*bwsize;
     133  }
     134  else {
     135        //And mask, xor mask (0) + color image
     136        cursorsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
     137                     rgbsize + 2*bwsize + bmpHdr->biSizeImage;
     138  }
    57139
    58140  cursorhdr  = (BITMAPFILEHEADER2 *)malloc(cursorsize);
     
    63145
    64146  /* @@@PH y-hotspot is upside down ! */
    65   cursorhdr->yHotspot      = (bhdr->biHeight >> 1)       /* height div 2 */
     147  cursorhdr->yHotspot      = (bmpHdr->biHeight >> 1)       /* height div 2 */
    66148                             - curHdr->yHotspot;         /* subtract hot.y */
    67149
     
    69151  dprintf(("Cursor Hot.y   : %d", curHdr->yHotspot));
    70152
    71   cursorhdr->offBits       = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + offsetBits;
     153  if(bmpHdr->biBitCount == 1) {
     154        cursorhdr->offBits = sizeof(BITMAPFILEHEADER2) +
     155                             2*sizeof(RGB2) + offsetBits;
     156  }
     157  else {
     158        cursorhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) +
     159                             2*sizeof(RGB2) + rgbsize + offsetBits;
     160  }
     161
    72162  cursorhdr->bmp2.cbFix     = sizeof(BITMAPINFOHEADER2);
    73   cursorhdr->bmp2.cx        = (USHORT)bhdr->biWidth;
    74   cursorhdr->bmp2.cy        = (USHORT)(bhdr->biHeight);
    75   cursorhdr->bmp2.cPlanes   = bhdr->biPlanes;
    76   cursorhdr->bmp2.cBitCount = bhdr->biBitCount;
     163  cursorhdr->bmp2.cx        = (USHORT)bmpHdr->biWidth;
     164  cursorhdr->bmp2.cy        = (USHORT)(bmpHdr->biHeight);
     165  cursorhdr->bmp2.cPlanes   = bmpHdr->biPlanes;
     166  cursorhdr->bmp2.cBitCount = 1;
    77167  cursorhdr->bmp2.ulCompression   = BCA_UNCOMP;
    78168  cursorhdr->bmp2.ulColorEncoding = BCE_RGB;
    79   dprintf(("Cursor size    : %d", bhdr->biSizeImage));
    80   dprintf(("Cursor Width   : %d", bhdr->biWidth));
     169  dprintf(("Cursor size    : %d", bmpHdr->biSizeImage));
     170  dprintf(("Cursor Width   : %d", bmpHdr->biWidth));
    81171  //height for both the XOR and AND bitmap (color & BW)
    82   dprintf(("Height         : %d", bhdr->biHeight));
    83   dprintf(("Cursor Bitcount: %d", bhdr->biBitCount));
    84   dprintf(("Cursor Compress: %d", bhdr->biCompression));
     172  dprintf(("Height         : %d", bmpHdr->biHeight));
     173  dprintf(("Cursor Bitcount: %d", bmpHdr->biBitCount));
     174  dprintf(("Cursor Compress: %d", bmpHdr->biCompression));
    85175
    86176  os2rgb                   = (RGB2 *)(cursorhdr+1);
    87   rgb                      = (RGBQUAD *)(bhdr+1);
    88   for(i=0;i<(1<<bhdr->biBitCount);i++) {
    89         os2rgb->bRed   = rgb->red;
    90         os2rgb->bBlue  = rgb->blue;
    91         os2rgb->bGreen = rgb->green;
    92         os2rgb++;
    93         rgb++;
    94   }
    95 
    96   bhdr->biSizeImage *= 2;       // we have 2 bitmaps !
    97 
    98   if(bhdr->biSizeImage > bmpsize || bhdr->biSizeImage == 0) {
    99         bwsize = bhdr->biWidth*(bhdr->biHeight);
    100 
    101         switch(bhdr->biBitCount) {
    102                 case 1:
    103                         bwsize /= 8;
    104                         break;
    105                 case 4:
    106                         bwsize /= 2;
    107                         break;
    108                 case 8:
    109                         break;
    110                 case 16:
    111                         bwsize *= 2;
    112                         break;
    113                 case 24:
    114                         bwsize *= 3;
    115                         break;
    116                 case 32:
    117                         bwsize *= 4;
    118                         break;
    119           }
    120   }
    121   else    bwsize = bhdr->biSizeImage;
    122 
    123   //write XOR and AND mask
    124   memcpy((char *)os2rgb, (char *)rgb, bwsize);
     177  rgb                      = (RGBQUAD *)(bmpHdr+1);
     178  if(bmpHdr->biBitCount == 1) {
     179        for(i=0;i<2;i++) {
     180                os2rgb->bRed   = rgb->red;
     181                os2rgb->bBlue  = rgb->blue;
     182                os2rgb->bGreen = rgb->green;
     183                os2rgb++;
     184                rgb++;
     185        }
     186        //write XOR and AND mask
     187        memcpy((char *)os2rgb, (char *)rgb, bwsize*2);
     188  }
     189  else {
     190        memset(os2rgb, 0, sizeof(RGB2));
     191        memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte!
     192        cursorhdr2               = (BITMAPFILEHEADER2 *)(os2rgb+2);
     193        cursorhdr2->usType       = BFT_COLORICON;
     194        cursorhdr2->cbSize       = sizeof(BITMAPFILEHEADER2);
     195        cursorhdr2->xHotspot     = curHdr->xHotspot;
     196        cursorhdr2->yHotspot     = (bmpHdr->biHeight >> 1)       /* height div 2 */
     197                                   - curHdr->yHotspot;         /* subtract hot.y */
     198        cursorhdr2->offBits      = 2*sizeof(BITMAPFILEHEADER2) +
     199                                   2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
     200        cursorhdr2->bmp2.cbFix   = sizeof(BITMAPINFOHEADER2);
     201        cursorhdr2->bmp2.cx      = (USHORT)bmpHdr->biWidth;
     202        cursorhdr2->bmp2.cy      = (USHORT)(bmpHdr->biHeight/2);
     203        cursorhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
     204        cursorhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
     205        cursorhdr2->bmp2.ulCompression   = BCA_UNCOMP;
     206        cursorhdr2->bmp2.ulColorEncoding = BCE_RGB;
     207        os2rgb                 = (RGB2 *)(cursorhdr2+1);
     208        rgb                    = (RGBQUAD *)(bmpHdr+1);
     209        if(bmpHdr->biBitCount <= 8) {
     210                for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
     211                        os2rgb->bRed   = rgb->red;
     212                        os2rgb->bBlue  = rgb->blue;
     213                        os2rgb->bGreen = rgb->green;
     214                        os2rgb++;
     215                        rgb++;
     216                }
     217        }
     218        //write XOR and AND mask
     219        char *pXor = (char *)os2rgb;
     220        char *pAnd = (char *)os2rgb + bwsize;
     221
     222        memcpy (pAnd, (char *)rgb + colorsize, bwsize);
     223        memset (pXor, 0, bwsize);
     224        memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
     225  }
    125226
    126227  *os2size = cursorsize;
Note: See TracChangeset for help on using the changeset viewer.