Ignore:
Timestamp:
Feb 21, 2000, 11:34:46 AM (26 years ago)
Author:
sandervl
Message:

SetDIBits bugfix (for dib sections)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gdi32/dibsect.cpp

    r2802 r2845  
    1 /* $Id: dibsect.cpp,v 1.18 2000-02-16 14:18:09 sandervl Exp $ */
     1/* $Id: dibsect.cpp,v 1.19 2000-02-21 10:34:46 sandervl Exp $ */
    22
    33/*
     
    6363        case 8:
    6464                os2bmpsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
     65                bmpsize = (bmpsize + 3) & ~3;
    6566                break;
    6667        case 16:
    6768                bmpsize *= 2;
     69                bmpsize = (bmpsize + 3) & ~3;
    6870                break;
    6971        case 24:
    7072                bmpsize *= 3;
     73                bmpsize = (bmpsize + 3) & ~3;
    7174                break;
    7275        case 32:
    7376                bmpsize *= 4;
    7477                break;
    75    }
    76    if(bmpsize & 3) {
    77         bmpsize = (bmpsize + 3) & ~3;
    7878   }
    7979
     
    226226      palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
    227227      os2bmpsize += palsize;
     228      bmpsize = (bmpsize + 3) & ~3;
    228229      break;
    229230    case 16:
    230231      bmpsize *= 2;
     232      bmpsize = (bmpsize + 3) & ~3;
    231233      break;
    232234    case 24:
    233235      bmpsize *= 3;
     236      bmpsize = (bmpsize + 3) & ~3;
    234237      break;
    235238    case 32:
     
    238241   }
    239242
    240    if(bmpsize & 3)
    241    {
    242         bmpsize = (bmpsize + 3) & ~3;
    243    }
    244 
    245    bmpBits    = (char *)realloc(bmpBits, bmpsize*pbmi->biHeight);
     243   //SvL: TODO: Correct??
     244   if(!hSection && pOS2bmp->cx != pbmi->biWidth && pOS2bmp->cy != pbmi->biHeight &&
     245      pOS2bmp->cBitCount != pbmi->biBitCount)
     246   {
     247        char *oldbits = bmpBits;
     248
     249        DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
     250        memcpy(bmpBits, oldbits, bmpsize*pbmi->biHeight);
     251        DosFreeMem(oldbits);
     252   }
    246253   pOS2bmp    = (BITMAPINFO2 *)realloc(pOS2bmp, os2bmpsize);
    247 
    248254   pOS2bmp->cbFix         = sizeof(BITMAPINFO2) - sizeof(RGB2);
    249255   pOS2bmp->cx            = pbmi->biWidth;
     
    254260   pOS2bmp->cbImage       = pbmi->biSizeImage;
    255261
     262   // clear DIBSECTION structure
     263   memset(&dibinfo, 0, sizeof(dibinfo));
     264
     265   // copy BITMAPINFOHEADER data into DIBSECTION structure
     266   memcpy(&dibinfo.dsBmih, pbmi, sizeof(*pbmi));
     267   dibinfo.dsBm.bmType      = 0;
     268   dibinfo.dsBm.bmWidth     = pbmi->biWidth;
     269   dibinfo.dsBm.bmHeight    = pbmi->biHeight;
     270   dibinfo.dsBm.bmWidthBytes= bmpsize;
     271   dibinfo.dsBm.bmPlanes    = pbmi->biPlanes;
     272   dibinfo.dsBm.bmBitsPixel = pbmi->biBitCount;
     273   dibinfo.dsBm.bmBits      = bmpBits;
     274
     275   dibinfo.dshSection       = hSection;
     276   dibinfo.dsOffset         = 0; // TODO: put the correct value here (if createdibsection with file handle)
     277
     278   if(pbmi->biCompression == BI_BITFIELDS)
     279   {
     280        char *pColors = (char *)pbmi + 1;
     281
     282        dibinfo.dsBitfields[0] = *((DWORD *)pColors);
     283        dibinfo.dsBitfields[1] = *((DWORD *)pColors+1);
     284        dibinfo.dsBitfields[2] = *((DWORD *)pColors+2);
     285        dprintf(("BI_BITFIELDS %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
     286   }
     287
    256288   dprintf(("DIBSection::SetDIBits (%d,%d), %d %d", pbmi->biWidth, pbmi->biHeight, pbmi->biBitCount, pbmi->biCompression));
    257 
    258289   if(palsize)
    259      memcpy(pOS2bmp->argbColor, (char *)pbmi + 1 , palsize);
     290        memcpy(pOS2bmp->argbColor, (char *)pbmi + 1 , palsize);
    260291
    261292   if(bits)
    262293   {
    263      int size = bmpsize*lines;
    264      memcpy(bmpBits+bmpsize*startscan, bits, size);
     294        int size = bmpsize*lines;
     295        memcpy(bmpBits+bmpsize*startscan, bits, size);
    265296   }
    266297   return(lines);
Note: See TracChangeset for help on using the changeset viewer.