Changeset 4447 for trunk/src


Ignore:
Timestamp:
Oct 7, 2000, 11:03:50 AM (25 years ago)
Author:
hugh
Message:

Fixed bitblt, it used the size of the source DC
when no destwindow was found. this doesn't work
for bitblt between dibsections if the dest is larger.
so now it checks if the dest DC belongs to a dibsection
and uses sets hdcHeight/Width to the size of the dibsection.
Added GetWidth() member function for this.

Fixes Civilisation Test of Times.

Location:
trunk/src/gdi32
Files:
2 edited

Legend:

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

    r4354 r4447  
    1 /* $Id: dibsect.cpp,v 1.39 2000-10-01 21:16:17 phaller Exp $ */
     1/* $Id: dibsect.cpp,v 1.40 2000-10-07 09:03:49 hugh Exp $ */
    22
    33/*
     
    3131#include "rgbcvt.h"
    3232
    33 #define DBG_LOCALLOG    DBG_dibsect
     33#define DBG_LOCALLOG  DBG_dibsect
    3434#include "dbglocal.h"
    3535
     
    5252  {
    5353        case 1:
    54                 bmpsize = ((bmpsize + 31) & ~31) / 8;
    55                 palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
    56                 os2bmphdrsize += palsize;
     54          bmpsize = ((bmpsize + 31) & ~31) / 8;
     55          palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
     56          os2bmphdrsize += palsize;
    5757                break;
    5858        case 4:
    5959                bmpsize = ((bmpsize + 7) & ~7) / 2;
    60                 palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
     60          palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
    6161                os2bmphdrsize += palsize;
    6262                break;
    6363        case 8:
    64                 palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
    65                 os2bmphdrsize += palsize;
    66                 bmpsize = (bmpsize + 3) & ~3;
     64          palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
     65          os2bmphdrsize += palsize;
     66          bmpsize = (bmpsize + 3) & ~3;
    6767                break;
    6868        case 16:
    6969                bmpsize *= 2;
    70                 bmpsize = (bmpsize + 3) & ~3;
     70          bmpsize = (bmpsize + 3) & ~3;
    7171                break;
    7272        case 24:
    7373                bmpsize *= 3;
    74                 bmpsize = (bmpsize + 3) & ~3;
     74          bmpsize = (bmpsize + 3) & ~3;
    7575                break;
    7676        case 32:
    7777                bmpsize *= 4;
    7878                break;
    79         default:
    80                 dprintf(("Unsupported nr of bits %d", pbmi->biBitCount));
    81                 DebugInt3();
    82                 break;
     79  default:
     80    dprintf(("Unsupported nr of bits %d", pbmi->biBitCount));
     81    DebugInt3();
     82    break;
    8383   }
    8484
     
    8686   this->dwOffset = dwOffset;
    8787   if(hSection) {
    88         bmpBits = (char *)MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS_W, 0, dwOffset, bmpsize*pbmi->biHeight);
    89         if(!bmpBits) {
    90                 dprintf(("Dibsection: mapViewOfFile %x failed!", hSection));
    91                 DebugInt3();
    92         }
     88  bmpBits = (char *)MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS_W, 0, dwOffset, bmpsize*pbmi->biHeight);
     89  if(!bmpBits) {
     90    dprintf(("Dibsection: mapViewOfFile %x failed!", hSection));
     91    DebugInt3();
     92  }
    9393   }
    9494   if(!bmpBits) {
    95         DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
     95  DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
    9696   }
    9797   memset(bmpBits, 0, bmpsize*pbmi->biHeight);
     
    111111   //SvL: Ignore BI_BITFIELDS_W type (GpiDrawBits fails otherwise)
    112112   if(pOS2bmp->ulCompression == BI_BITFIELDS_W) {
    113         pOS2bmp->ulCompression = 0;
     113  pOS2bmp->ulCompression = 0;
    114114   }
    115115   pOS2bmp->cbImage       = pbmi->biSizeImage;
     
    142142   {
    143143        dibinfo.dsBitfields[0] = dibinfo.dsBitfields[1] = dibinfo.dsBitfields[2] = 0;
    144         if(palsize) {
    145                 SetDIBColorTable(0, (1 << pbmi->biBitCount), (RGBQUAD *)(pbmi+1));
    146         }
     144    if(palsize) {
     145    SetDIBColorTable(0, (1 << pbmi->biBitCount), (RGBQUAD *)(pbmi+1));
     146    }
    147147   }
    148148   else {
    149         switch(pbmi->biBitCount)
    150         {
     149  switch(pbmi->biBitCount)
     150    {
    151151           case 16:
    152                 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0x7c00;
    153                 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
    154                 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0x001f;
    155                 break;
     152                dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0x7c00;
     153                dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
     154                dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0x001f;
     155                break;
    156156
    157157           case 24:
    158                 dibinfo.dsBitfields[0] = 0xff;
    159                 dibinfo.dsBitfields[1] = 0xff00;
    160                 dibinfo.dsBitfields[2] = 0xff0000;
    161                 break;
     158                dibinfo.dsBitfields[0] = 0xff;
     159                dibinfo.dsBitfields[1] = 0xff00;
     160                dibinfo.dsBitfields[2] = 0xff0000;
     161                break;
    162162
    163163           case 32:
    164                 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0xff;
    165                 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
    166                 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0xff0000;
    167                 if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
    168                         dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
    169                 }
    170                 break;
    171         }
    172         dprintf(("BI_BITFIELDS_W %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
     164                dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0xff;
     165                dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
     166                dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0xff0000;
     167    if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
     168      dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
     169    }
     170                break;
     171        }
     172  dprintf(("BI_BITFIELDS_W %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
    173173   }
    174174   //double buffer for rgb 555 dib sections (for conversion) or flipped sections
    175175   if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
    176         DosAllocMem((PPVOID)&bmpBitsDblBuffer, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
     176  DosAllocMem((PPVOID)&bmpBitsDblBuffer, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
    177177   }
    178178
     
    209209
    210210   if(hSection) {
    211         UnmapViewOfFile(bmpBits);
     211  UnmapViewOfFile(bmpBits);
    212212   }
    213213   else
     
    216216
    217217   if(bmpBitsDblBuffer)
    218         DosFreeMem(bmpBitsDblBuffer);
     218  DosFreeMem(bmpBitsDblBuffer);
    219219
    220220   if(pOS2bmp)
     
    282282   //SvL: TODO: Correct??
    283283   if(!hSection && pOS2bmp->cx != pbmi->biWidth && pOS2bmp->cy != pbmi->biHeight &&
    284       pOS2bmp->cBitCount != pbmi->biBitCount) 
     284      pOS2bmp->cBitCount != pbmi->biBitCount)
    285285   {
    286         char *oldbits = bmpBits;
    287         int oldsize = dibinfo.dsBm.bmWidthBytes * dibinfo.dsBm.bmHeight;
    288 
    289         DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
    290         memcpy(bmpBits, oldbits, min(oldsize, bmpsize*pbmi->biHeight));
    291         DosFreeMem(oldbits);
     286  char *oldbits = bmpBits;
     287  int oldsize = dibinfo.dsBm.bmWidthBytes * dibinfo.dsBm.bmHeight;
     288
     289  DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
     290  memcpy(bmpBits, oldbits, min(oldsize, bmpsize*pbmi->biHeight));
     291  DosFreeMem(oldbits);
    292292   }
    293293   pOS2bmp    = (BITMAPINFO2 *)realloc(pOS2bmp, os2bmphdrsize);
     
    321321   }
    322322   else {
    323         char *pColors = (char *)pbmi + 1;
    324 
    325         switch(pbmi->biBitCount)
    326         {
     323  char *pColors = (char *)pbmi + 1;
     324
     325  switch(pbmi->biBitCount)
     326    {
    327327           case 16:
    328                 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0x7c00;
    329                 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
    330                 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0x001f;
    331                 break;
     328                dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0x7c00;
     329                dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
     330                dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0x001f;
     331                break;
    332332
    333333           case 24:
    334                 dibinfo.dsBitfields[0] = 0xff;
    335                 dibinfo.dsBitfields[1] = 0xff00;
    336                 dibinfo.dsBitfields[2] = 0xff0000;
    337                 break;
     334                dibinfo.dsBitfields[0] = 0xff;
     335                dibinfo.dsBitfields[1] = 0xff00;
     336                dibinfo.dsBitfields[2] = 0xff0000;
     337                break;
    338338
    339339           case 32:
    340                 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0xff;
    341                 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
    342                 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0xff0000;
    343                 if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
    344                         dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
    345                 }
    346                 break;
    347         }
    348         dprintf(("BI_BITFIELDS_W %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
     340                dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0xff;
     341                dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
     342                dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0xff0000;
     343    if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
     344      dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
     345    }
     346                break;
     347        }
     348  dprintf(("BI_BITFIELDS_W %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
    349349   }
    350350
    351351   //double buffer for rgb 555 dib sections (for conversion) or flipped sections
    352352   if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
    353         if(bmpBitsDblBuffer) {
    354                 DosFreeMem(bmpBitsDblBuffer);
    355         }
    356         DosAllocMem((PPVOID)&bmpBitsDblBuffer, dibinfo.dsBm.bmWidthBytes*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
     353  if(bmpBitsDblBuffer) {
     354    DosFreeMem(bmpBitsDblBuffer);
     355  }
     356  DosAllocMem((PPVOID)&bmpBitsDblBuffer, dibinfo.dsBm.bmWidthBytes*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
    357357   }
    358358
    359359   dprintf(("DIBSection::SetDIBits (%d,%d), %d %d", pbmi->biWidth, pbmi->biHeight, pbmi->biBitCount, pbmi->biCompression));
    360360   if(palsize) {
    361         SetDIBColorTable(0, 1 << pbmi->biBitCount, (RGBQUAD *)(pbmi+1));
     361  SetDIBColorTable(0, 1 << pbmi->biBitCount, (RGBQUAD *)(pbmi+1));
    362362   }
    363363
    364364   if(bits)
    365365   {
    366         int size = bmpsize*lines;
    367         memcpy(bmpBits+bmpsize*startscan, bits, size);
     366      int size = bmpsize*lines;
     367      memcpy(bmpBits+bmpsize*startscan, bits, size);
    368368   }
    369369   return(lines);
     
    417417  hwndDest = WindowFromDC(hdcDest); //could return desktop window, so check that
    418418  if(hwndDest && pHps->hwnd && !pHps->isClient) {
    419         fFrameWindowDC = TRUE;
     419  fFrameWindowDC = TRUE;
    420420  }
    421421
     
    425425
    426426  if(hwndDest) {
    427         RECT rect;
    428 
    429         if(fFrameWindowDC) {
    430                 GetWindowRect(hwndDest, &rect);
    431         }
    432         else    GetClientRect(hwndDest, &rect);
    433         hdcHeight = rect.bottom - rect.top;
    434         hdcWidth  = rect.right - rect.left;
     427  RECT rect;
     428
     429  if(fFrameWindowDC) {
     430    GetWindowRect(hwndDest, &rect);
     431  }
     432  else  GetClientRect(hwndDest, &rect);
     433  hdcHeight = rect.bottom - rect.top;
     434  hdcWidth  = rect.right - rect.left;
    435435  }
    436436  else {
    437         hdcHeight = pOS2bmp->cy;
    438         hdcWidth  = pOS2bmp->cx;
     437    DIBSection *dsect = DIBSection::findHDC(hdcDest);
     438    if(dsect)
     439    {
     440      hdcHeight = dsect->GetHeight();
     441      hdcWidth  = dsect->GetWidth();
     442    }
     443    else
     444    {
     445      hdcHeight = pOS2bmp->cy;
     446      hdcWidth  = pOS2bmp->cx;
     447    }
    439448  }
    440449
     
    442451  //source rectangle is non-inclusive (top, right not included)
    443452  //destination rectangle is incl.-inclusive (everything included)
     453
    444454  if(nXdest + nDestWidth > hdcWidth) {
    445         nDestWidth  = hdcWidth - nXdest;
    446   }
     455    nDestWidth  = hdcWidth - nXdest;
     456    }
     457
    447458  if(nYdest + nDestHeight > hdcHeight) {
    448         nDestHeight = hdcHeight - nYdest;
    449   }
     459    nDestHeight = hdcHeight - nYdest;
     460    }
     461
    450462  point[0].x = nXdest;
    451463  point[0].y = hdcHeight - nYdest - nDestHeight;
     
    455467  //target rectangle is inclusive-inclusive
    456468  if(nXsrc + nSrcWidth > pOS2bmp->cx) {
    457         nSrcWidth  = pOS2bmp->cx - nXsrc;
     469  nSrcWidth  = pOS2bmp->cx - nXsrc;
    458470  }
    459471  if(nYsrc + nSrcHeight > pOS2bmp->cy) {
    460         nSrcHeight = pOS2bmp->cy - nYsrc;
     472  nSrcHeight = pOS2bmp->cy - nYsrc;
    461473  }
    462474  point[2].x = nXsrc;
     
    473485  if(hwndDest != 0)
    474486  {
    475         hps = WinGetPS(hwndDest);
     487      hps = WinGetPS(hwndDest);
    476488  }
    477489*/
    478490  oldyinversion = GpiQueryYInversion(hps);
    479491  if(oldyinversion != 0) {
    480         GpiEnableYInversion(hps, 0);
    481         fRestoryYInversion = TRUE;
     492  GpiEnableYInversion(hps, 0);
     493  fRestoryYInversion = TRUE;
    482494  }
    483495
    484496  if(fFlip & FLIP_HOR)
    485497  {
    486         ULONG x;
    487         x = point[0].x;
    488         point[0].x = point[1].x;
    489         point[1].x = x;
     498      ULONG x;
     499      x = point[0].x;
     500      point[0].x = point[1].x;
     501      point[1].x = x;
    490502  }
    491503
     
    496508  switch(winmode) {
    497509  case BLACKONWHITE_W:
    498         os2mode = BBO_AND;
    499         break;
     510  os2mode = BBO_AND;
     511  break;
    500512  case WHITEONBLACK_W:
    501513  case HALFTONE_W: //TODO:
    502         os2mode = BBO_OR;
    503         break;
     514  os2mode = BBO_OR;
     515  break;
    504516  case COLORONCOLOR_W:
    505         os2mode = BBO_IGNORE;
    506         break;
     517  os2mode = BBO_IGNORE;
     518  break;
    507519  }
    508520  if(fFlip & FLIP_VERT) {
    509         //manually reverse bitmap data
    510         char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
    511         char *dst = bmpBitsDblBuffer;
    512         for(int i=0;i<pOS2bmp->cy;i++) {
    513                 memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
    514                 dst += dibinfo.dsBm.bmWidthBytes;
    515                 src -= dibinfo.dsBm.bmWidthBytes;
    516         }
    517         bitmapBits = bmpBitsDblBuffer;
     521  //manually reverse bitmap data
     522  char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
     523  char *dst = bmpBitsDblBuffer;
     524  for(int i=0;i<pOS2bmp->cy;i++) {
     525    memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
     526    dst += dibinfo.dsBm.bmWidthBytes;
     527    src -= dibinfo.dsBm.bmWidthBytes;
     528  }
     529  bitmapBits = bmpBitsDblBuffer;
    518530  }
    519531  else  bitmapBits = bmpBits;
     
    521533  //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
    522534  if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
    523         dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
    524 
    525         if(bmpBitsDblBuffer == NULL)
    526                 DebugInt3();
    527    
     535        dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
     536
     537  if(bmpBitsDblBuffer == NULL)
     538    DebugInt3();
     539
    528540    // PH 2000/10/01 - Fix for Beyond Compare 1.9d
    529541    // Note: according to documentation, cmImage can be zero for
     
    532544    if (iLength == 0)
    533545      iLength = pOS2bmp->cx * pOS2bmp->cy * (pOS2bmp->cBitCount >> 3);
    534      
     546
    535547    if (iLength > 0)
    536548    {
    537       if(CPUFeatures & CPUID_MMX) 
     549      if(CPUFeatures & CPUID_MMX)
    538550        RGB555to565MMX((WORD *)bmpBitsDblBuffer, (WORD *)bitmapBits, iLength/sizeof(WORD));
    539       else     
     551      else
    540552        RGB555to565((WORD *)bmpBitsDblBuffer, (WORD *)bitmapBits, iLength/sizeof(WORD));
    541553    }
     
    549561    rc = GpiDrawBits(hps, bmpBitsDblBuffer, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
    550562  }
    551   else  rc = GpiDrawBits(hps, bitmapBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
     563  else  rc = GpiDrawBits(hps, bitmapBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
    552564
    553565/*
     
    558570*/
    559571  if(rc == GPI_OK) {
    560         DIBSection *destdib = DIBSection::findHDC(hdcDest);
     572    DIBSection *destdib = DIBSection::findHDC(hdcDest);
    561573        if(destdib) {
    562                 destdib->sync(hps, nYdest, nDestHeight);
     574    destdib->sync(hps, nYdest, nDestHeight);
    563575        }
    564         //restore old y inversion height
    565         if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
    566         SetLastError(ERROR_SUCCESS_W);
    567 
    568         return(TRUE);
     576  //restore old y inversion height
     577  if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
     578      SetLastError(ERROR_SUCCESS_W);
     579
     580      return(TRUE);
    569581  }
    570582  if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
     
    575587}
    576588//******************************************************************************
    577 int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines, 
     589int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines,
    578590                       void *lpvBits, BITMAPINFO_W * lpbi, UINT uUsage);
    579591
    580592//******************************************************************************
    581 void DIBSection::sync(HDC hdc, DWORD nYdest, DWORD nDestHeight) 
     593void DIBSection::sync(HDC hdc, DWORD nYdest, DWORD nDestHeight)
    582594{
    583595 APIRET rc;
     
    594606#ifdef DEBUG_PALETTE
    595607  if(rc && tmphdr->bmiHeader.biBitCount <= 8) {
    596         for(int i=0;i<(1<<tmphdr->bmiHeader.biBitCount);i++)
    597         {
    598                 dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&tmphdr->bmiColors[i])) ));
    599         }
     608    for(int i=0;i<(1<<tmphdr->bmiHeader.biBitCount);i++)
     609    {
     610        dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&tmphdr->bmiColors[i])) ));
     611    }
    600612  }
    601613#endif
     
    606618
    607619  if(fFlip & FLIP_VERT) {
    608         destBuf = bmpBitsDblBuffer + nYdest*dibinfo.dsBm.bmWidthBytes;
     620    destBuf = bmpBitsDblBuffer + nYdest*dibinfo.dsBm.bmWidthBytes;
    609621
    610622        rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
    611623                                tmphdr);
    612         //manually reverse bitmap data
    613         char *src = destBuf;
    614         char *dst = GetDIBObject() + (nYdest+nDestHeight-1)*dibinfo.dsBm.bmWidthBytes;
    615         for(int i=0;i<nDestHeight;i++) {
    616                 memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
    617                 dst -= dibinfo.dsBm.bmWidthBytes;
    618                 src += dibinfo.dsBm.bmWidthBytes;
    619         }
     624  //manually reverse bitmap data
     625  char *src = destBuf;
     626  char *dst = GetDIBObject() + (nYdest+nDestHeight-1)*dibinfo.dsBm.bmWidthBytes;
     627  for(int i=0;i<nDestHeight;i++) {
     628    memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
     629    dst -= dibinfo.dsBm.bmWidthBytes;
     630    src += dibinfo.dsBm.bmWidthBytes;
     631  }
    620632  }
    621633  else {
    622         destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
     634    destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
    623635        rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
    624636                          tmphdr);
    625637#ifdef DEBUG_PALETTE
    626         if(rc != GPI_ALTERROR && tmphdr->cBitCount <= 8) {
    627                 for(int i=0;i<(1<<tmphdr->cBitCount);i++)
    628                 {
    629                         dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&tmphdr->argbColor[i])) ));
    630                 }
    631         }
     638  if(rc != GPI_ALTERROR && tmphdr->cBitCount <= 8) {
     639      for(int i=0;i<(1<<tmphdr->cBitCount);i++)
     640      {
     641          dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&tmphdr->argbColor[i])) ));
     642      }
     643  }
    632644#endif
    633645  }
     
    635647#if 0
    636648  if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
    637         dprintf(("DIBSection::sync: convert RGB 565 to RGB 555"));
    638 
    639         destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
    640 
    641         if(CPUFeatures & CPUID_MMX) {
    642                 RGB565to555MMX((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
    643         }
    644         else    RGB565to555((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
     649  dprintf(("DIBSection::sync: convert RGB 565 to RGB 555"));
     650
     651    destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
     652
     653  if(CPUFeatures & CPUID_MMX) {
     654    RGB565to555MMX((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
     655  }
     656  else    RGB565to555((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
    645657  }
    646658#endif
    647659  free(tmphdr);
    648660  if(rc != nDestHeight) {
    649         DebugInt3();
     661  DebugInt3();
    650662  }
    651663}
    652664//******************************************************************************
    653665//manual sync if no stretching and bpp is the same
    654 //WARNING: this also assumes the colortables are the same 
     666//WARNING: this also assumes the colortables are the same
    655667//******************************************************************************
    656668void DIBSection::sync(DWORD xDst, DWORD yDst, DWORD widthDst, DWORD heightDst, PVOID bits)
     
    659671 int  linesize;
    660672
    661    srcbuf  = (char *)bits + dibinfo.dsBm.bmWidthBytes*yDst + 
     673   srcbuf  = (char *)bits + dibinfo.dsBm.bmWidthBytes*yDst +
    662674                    (xDst*dibinfo.dsBm.bmWidthBytes)/pOS2bmp->cx;
    663    destbuf = (char *)GetDIBObject() + dibinfo.dsBm.bmWidthBytes*yDst + 
     675   destbuf = (char *)GetDIBObject() + dibinfo.dsBm.bmWidthBytes*yDst +
    664676                    (xDst*dibinfo.dsBm.bmWidthBytes)/pOS2bmp->cx;
    665677   linesize = (widthDst*dibinfo.dsBm.bmWidthBytes)/pOS2bmp->cx;
    666678   for(int i=0;i<heightDst;i++) {
    667         memcpy(destbuf, srcbuf, linesize);
    668         destbuf += dibinfo.dsBm.bmWidthBytes;
    669         srcbuf  += linesize;
     679  memcpy(destbuf, srcbuf, linesize);
     680  destbuf += dibinfo.dsBm.bmWidthBytes;
     681  srcbuf  += linesize;
    670682   }
    671683}
     
    689701    if(dsect->handle == handle)
    690702    {
    691         dibMutex.leave();
    692         return(dsect);
     703    dibMutex.leave();
     704        return(dsect);
    693705    }
    694706    dsect = dsect->next;
     
    734746  if(iSize == sizeof(DIBSECTION))
    735747  {
    736         memcpy(pDIBSection, &dibinfo, sizeof(dibinfo));
     748  memcpy(pDIBSection, &dibinfo, sizeof(dibinfo));
    737749        return sizeof(DIBSECTION);
    738750  }
     
    740752  if(iSize == sizeof(BITMAP_W))
    741753  {
    742         memcpy(dsBm, &dibinfo.dsBm, sizeof(dibinfo.dsBm));
    743         return sizeof(BITMAP_W);
     754  memcpy(dsBm, &dibinfo.dsBm, sizeof(dibinfo.dsBm));
     755  return sizeof(BITMAP_W);
    744756  }
    745757  return 0;
     
    766778//******************************************************************************
    767779//******************************************************************************
     780int DIBSection::GetWidth()
     781{
     782   if(pOS2bmp == NULL)
     783     return 0;
     784   else
     785     return pOS2bmp->cx;
     786}
     787//******************************************************************************
     788//******************************************************************************
    768789DIBSection *DIBSection::section = NULL;
  • trunk/src/gdi32/dibsect.h

    r4127 r4447  
    1 /* $Id: dibsect.h,v 1.20 2000-08-30 18:05:24 sandervl Exp $ */
     1/* $Id: dibsect.h,v 1.21 2000-10-07 09:03:50 hugh Exp $ */
    22
    33/*
     
    5050
    5151typedef struct {
    52         BITMAPINFOHEADER_W bmiHeader;
    53         RGBQUAD bmiColors[1];
     52  BITMAPINFOHEADER_W bmiHeader;
     53  RGBQUAD bmiColors[1];
    5454} BITMAPINFO_W;
    5555typedef BITMAPINFO *LPBITMAPINFO;
     
    7979              int   GetBitCount();
    8080              int   GetHeight();
     81              int   GetWidth();
    8182              void  UnSelectDIBObject()      { this->hdc = 0;   };
    8283
    83               DWORD GetBitmapHandle()        { return handle; };
     84        DWORD GetBitmapHandle()      { return handle; };
    8485              void  SetBitmapHandle(DWORD bmphandle) { handle = bmphandle; };
    85               DWORD GetRGBUsage()            { return iUsage; };
     86        DWORD GetRGBUsage()            { return iUsage; };
    8687
    8788              BOOL  BitBlt(HDC hdcDest, int nXdest, int nYDest,
Note: See TracChangeset for help on using the changeset viewer.