Changeset 9565 for trunk/src


Ignore:
Timestamp:
Dec 30, 2002, 3:05:21 PM (23 years ago)
Author:
sandervl
Message:

Support reversed bitmap data in SetDIBits

File:
1 edited

Legend:

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

    r9429 r9565  
    1 /* $Id: dibitmap.cpp,v 1.35 2002-11-26 10:53:07 sandervl Exp $ */
     1/* $Id: dibitmap.cpp,v 1.36 2002-12-30 14:05:21 sandervl Exp $ */
    22
    33/*
     
    5353        ((BITMAPINFOHEADER *)lpbmih)->biHeight = -lpbmih->biHeight;
    5454
    55         if(lpbInit && fdwInit == CBM_INIT) {
     55        if(lpbInit && fdwInit == CBM_INIT)
     56        {
    5657            // upside down
    5758            HBITMAP rc = 0;
     
    6970                }
    7071                rc = CreateDIBitmap(hdc, lpbmih, fdwInit, newbits, lpbmi, fuUsage);
    71                         free( newbits );
     72                free( newbits );
    7273            }
    7374
     
    544545    }
    545546
    546     if(pBitmapInfo->bmiHeader.biHeight < 0) {
    547         dprintf(("!WARNING! Negative height!!"));
    548     }
    549     ret = O32_SetDIBits(hdc, hBitmap, startscan, numlines, pBits, pBitmapInfo, usage);
     547    //If upside down, reverse scanlines and call SetDIBits again
     548    if(pBitmapInfo->bmiHeader.biHeight < 0 && (pBitmapInfo->bmiHeader.biCompression == BI_RGB ||
     549       pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS))
     550    {
     551        // upside down
     552        INT rc = -1;
     553        long lLineByte;
     554
     555        //TODO: doesn't work if memory is readonly!!
     556        ((BITMAPINFO *)pBitmapInfo)->bmiHeader.biHeight = -pBitmapInfo->bmiHeader.biHeight;
     557
     558        lLineByte = DIB_GetDIBWidthBytes(pBitmapInfo->bmiHeader.biWidth, pBitmapInfo->bmiHeader.biBitCount);
     559
     560        dprintf(("Reverse bitmap (negative height)"));
     561        char *pNewBits = (char *)malloc( lLineByte * numlines );
     562        if(pNewBits) {
     563            unsigned char *pbSrc = (unsigned char *)pBits + lLineByte * (numlines - 1);
     564            unsigned char *pbDst = (unsigned char *)pNewBits;
     565            for(int y = 0; y < numlines; y++) {
     566                memcpy( pbDst, pbSrc, lLineByte );
     567                pbDst += lLineByte;
     568                pbSrc -= lLineByte;
     569            }
     570            ret = O32_SetDIBits(hdc, hBitmap, startscan, numlines, pNewBits, pBitmapInfo, usage);
     571            free(pNewBits);
     572        }
     573        else DebugInt3();
     574
     575        //TODO: doesn't work if memory is readonly!!
     576        ((BITMAPINFO *)pBitmapInfo)->bmiHeader.biHeight = -pBitmapInfo->bmiHeader.biHeight;
     577    }
     578    else {
     579        ret = O32_SetDIBits(hdc, hBitmap, startscan, numlines, pBits, pBitmapInfo, usage);
     580    }
    550581    if(newbits) free(newbits);
    551582
Note: See TracChangeset for help on using the changeset viewer.