Ignore:
Timestamp:
May 12, 2000, 9:14:56 PM (25 years ago)
Author:
sandervl
Message:

manual flipping of dibsection images

File:
1 edited

Legend:

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

    r3437 r3527  
    1 /* $Id: dibsect.cpp,v 1.29 2000-04-23 15:34:10 sandervl Exp $ */
     1/* $Id: dibsect.cpp,v 1.30 2000-05-12 19:14:55 sandervl Exp $ */
    22
    33/*
     
    3838//******************************************************************************
    3939DIBSection::DIBSection(BITMAPINFOHEADER_W *pbmi, char *pColors, DWORD iUsage, DWORD hSection, DWORD dwOffset, DWORD handle, int fFlip)
    40                 : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsRGB565(NULL)
     40                : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsBuffer(NULL)
    4141{
    4242  bmpsize = pbmi->biWidth;
     
    143143                dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
    144144                dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0x001f;
    145 
    146                 //double buffer for rgb 555 dib sections (for conversion)
    147                 if(dibinfo.dsBitfields[1] == 0x03e0) {
    148                         DosAllocMem((PPVOID)&bmpBitsRGB565, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
    149                 }
    150145                break;
    151146
     
    167162        dprintf(("BI_BITFIELDS %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
    168163   }
     164   //double buffer for rgb 555 dib sections (for conversion) or flipped sections
     165   if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
     166        DosAllocMem((PPVOID)&bmpBitsBuffer, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
     167   }
    169168
    170169   this->handle = handle;
     
    206205        DosFreeMem(bmpBits);
    207206
    208    if(bmpBitsRGB565)
    209         DosFreeMem(bmpBitsRGB565);
     207   if(bmpBitsBuffer)
     208        DosFreeMem(bmpBitsBuffer);
    210209
    211210   if(pOS2bmp)
     
    320319                dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
    321320                dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0x001f;
    322                 if(dibinfo.dsBitfields[1] == 0x03e0) {
    323                         if(bmpBitsRGB565)
    324                                 DosFreeMem(bmpBitsRGB565);
    325                         DosAllocMem((PPVOID)&bmpBitsRGB565, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
    326                 }
    327321                break;
    328322
     
    345339   }
    346340
     341   //double buffer for rgb 555 dib sections (for conversion) or flipped sections
     342   if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
     343        if(bmpBitsBuffer) {
     344                DosFreeMem(bmpBitsBuffer);
     345        }
     346        DosAllocMem((PPVOID)&bmpBitsBuffer, dibinfo.dsBm.bmWidthBytes*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
     347   }
     348
    347349   dprintf(("DIBSection::SetDIBits (%d,%d), %d %d", pbmi->biWidth, pbmi->biHeight, pbmi->biBitCount, pbmi->biCompression));
    348350   if(palsize)
     
    417419  }
    418420
     421#if 0
     422  nXdest = 0;
     423  nYdest = 0;
     424  nXsrc  = 0;
     425  nXsrc  = 0;
     426  nDestWidth = pOS2bmp->cx;
     427  nDestHeight = pOS2bmp->cy;
     428  nSrcWidth = pOS2bmp->cx;
     429  nSrcHeight = pOS2bmp->cy;
     430#endif
     431
    419432  //win32 coordinates are of the left top, OS/2 expects left bottom
    420433  //source rectangle is non-inclusive (top, right not included)
     
    443456
    444457  oldyinversion = GpiQueryYInversion(hps);
    445   if(fFlip & FLIP_VERT)
    446   {
    447         if(oldyinversion != hdcHeight-1) {
    448                 GpiEnableYInversion(hps, hdcHeight-1);
    449                 fRestoryYInversion = TRUE;
    450         }
    451   }
    452   else 
    453458  if(oldyinversion != 0) {
    454459        GpiEnableYInversion(hps, 0);
     
    464469  }
    465470
     471  ULONG os2mode, winmode;
     472
     473  os2mode = BBO_OR;
     474  winmode = GetStretchBltMode(hdcDest);
     475  switch(winmode) {
     476  case BLACKONWHITE_W:
     477        os2mode = BBO_AND;
     478        break;
     479  case WHITEONBLACK_W:
     480  case HALFTONE_W: //TODO:
     481        os2mode = BBO_OR;
     482        break;
     483  case COLORONCOLOR_W:
     484        os2mode = BBO_IGNORE;
     485        break;
     486  }
     487  if(fFlip & FLIP_VERT) {
     488        //manually reverse bitmap data
     489        char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
     490        char *dst = bmpBitsBuffer;
     491        for(int i=0;i<pOS2bmp->cy;i++) {
     492                memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
     493                dst += dibinfo.dsBm.bmWidthBytes;
     494                src -= dibinfo.dsBm.bmWidthBytes;
     495        }
     496        bmpBits = bmpBitsBuffer;
     497  }
     498
    466499  //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
    467500  if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
    468501        dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
    469502
    470         if(bmpBitsRGB565 == NULL)
     503        if(bmpBitsBuffer == NULL)
    471504                DebugInt3();
    472505
    473506        if(CPUFeatures & CPUID_MMX) {
    474                 RGB555to565MMX((WORD *)bmpBitsRGB565, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
     507                RGB555to565MMX((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
    475508        }
    476         else    RGB555to565((WORD *)bmpBitsRGB565, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
    477         rc = GpiDrawBits(hps, bmpBitsRGB565, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
    478   }
    479   else  rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
     509        else    RGB555to565((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
     510        rc = GpiDrawBits(hps, bmpBitsBuffer, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
     511  }
     512  else  rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
    480513
    481514  if(rc == GPI_OK) {
Note: See TracChangeset for help on using the changeset viewer.