Ignore:
Timestamp:
Nov 13, 2001, 2:18:22 PM (24 years ago)
Author:
sandervl
Message:

workaround added for 32 bpp blitting with matrox display driver

File:
1 edited

Legend:

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

    r6692 r7327  
    1 /* $Id: blit.cpp,v 1.34 2001-09-10 11:02:40 sandervl Exp $ */
     1/* $Id: blit.cpp,v 1.35 2001-11-13 13:18:22 sandervl Exp $ */
    22
    33/*
     
    147147        bitfields[2] = (info->bmiHeader.biCompression == BI_BITFIELDS) ?  *((DWORD *)info->bmiColors + 2) : 0x001f;
    148148        break;
     149
     150    case 24:
    149151    case 32:
    150152        bitfields[0] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)info->bmiColors : 0xff0000;
     
    226228                               const BITMAPINFO *info, UINT coloruse)
    227229{
     230    static BOOL fMatrox32BppBug = FALSE;
     231    INT rc = 0;
     232    char *newBits = NULL;
     233
     234    //If upside down, reverse scanlines and call SetDIBitsToDevice again
    228235    if(info->bmiHeader.biHeight < 0 && info->bmiHeader.biBitCount != 8 && info->bmiHeader.biCompression == 0) {
    229236        // upside down
    230         INT rc = 0;
     237        INT rc = -1;
    231238        BITMAPINFO newInfo;
    232239        newInfo.bmiHeader = info->bmiHeader;
     
    244251                pbSrc -= lLineByte;
    245252            }
    246             rc = SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (void *)newBits, &newInfo, DIB_RGB_COLORS );
     253            rc = SetDIBitsToDevice( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (void *)newBits, &newInfo, coloruse );
    247254            free( newBits );
    248255        }
     256        else DebugInt3();
     257
    249258        return rc;
    250259    }
     260
     261    //We must convert 32 bpp bitmap data to 24 bpp on systems with the Matrox
     262    //display driver. (GpiDrawBits for 32 bpp fails with insufficient memory error)
     263    if(info->bmiHeader.biBitCount == 32 && fMatrox32BppBug)
     264    {
     265        BITMAPINFO newInfo;
     266        newInfo.bmiHeader = info->bmiHeader;
     267
     268        long lLineWidth;
     269        long lHeight    = (newInfo.bmiHeader.biHeight > 0) ? newInfo.bmiHeader.biHeight : -newInfo.bmiHeader.biHeight;
     270        long lWidth     = newInfo.bmiHeader.biWidth;
     271
     272        newInfo.bmiHeader.biBitCount  = 24;
     273        newInfo.bmiHeader.biSizeImage = CalcBitmapSize(24, newInfo.bmiHeader.biWidth,
     274                                                       newInfo.bmiHeader.biHeight);
     275
     276        lLineWidth = newInfo.bmiHeader.biSizeImage / lHeight;
     277
     278        //convert 32 bits bitmap data to 24 bits
     279        newBits = (char *)malloc(newInfo.bmiHeader.biSizeImage+16); //extra room needed for copying (too much)
     280        if(!newBits) {
     281            DebugInt3();
     282            return -1;
     283        }
     284        unsigned char *pbSrc = (unsigned char *)bits;
     285        unsigned char *pbDst = (unsigned char *)newBits;
     286        //not very efficient
     287        for(int i = 0; i < lHeight; i++) {
     288            for(int j=0;j<lWidth;j++) {
     289                *(DWORD *)pbDst = *(DWORD *)pbSrc;
     290                pbSrc += 4;
     291                pbDst += 3;
     292            }
     293            //24 bpp scanline must be aligned at 4 byte boundary
     294            pbDst += (lLineWidth - 3*lWidth);
     295        }
     296        rc = SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, newBits, &newInfo, coloruse );
     297        free(newBits);
     298        return rc;
     299    }
     300    rc = SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse );
     301
     302    if(rc == -1 && info->bmiHeader.biBitCount == 32 && !fMatrox32BppBug)
     303    {
     304        //The Matrox driver seems to have some difficulty blitting 32bpp
     305        //data. (out of memory error) The same operation works fine with SDD.
     306        fMatrox32BppBug = TRUE;
     307        return SetDIBitsToDevice(hdc, xDest, yDest, cx,
     308                                 cy, xSrc, ySrc,
     309                                 startscan, lines, bits,
     310                                 info, coloruse);
     311    }
     312    return rc;
     313
    251314//SvL: Breaks startup bitmap of Acrobat Reader 4.05
    252315#if 0
     
    319382    }
    320383#endif
    321     else {
    322         return SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse );
    323     }
    324384}
    325385//******************************************************************************
     
    441501        bitfields[2] = (info->bmiHeader.biCompression == BI_BITFIELDS) ?  *((DWORD *)info->bmiColors + 2) : 0x001f;
    442502        break;
     503    case 24:
    443504    case 32:
    444505        bitfields[0] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)info->bmiColors : 0xff0000;
     
    470531        ((BITMAPINFO *)info)->bmiHeader.biCompression = 0;
    471532        compression = BI_BITFIELDS;
    472 
    473533    }
    474534
     
    629689
    630690                case 32:
    631                         return cx*cy;
     691                        return cx*cy*4;
    632692
    633693                default:
Note: See TracChangeset for help on using the changeset viewer.