Ignore:
Timestamp:
Mar 9, 2004, 3:24:34 PM (21 years ago)
Author:
sandervl
Message:

SetDIBitsToDevice: fixes for xSrc offset

File:
1 edited

Legend:

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

    r10495 r10497  
    1 /* $Id: blit.cpp,v 1.48 2004-03-09 10:03:21 sandervl Exp $ */
     1/* $Id: blit.cpp,v 1.49 2004-03-09 14:24:34 sandervl Exp $ */
    22
    33/*
     
    276276    if (!cx || !cy) goto invalid_parameter;
    277277
    278 //testestset
    279     if(xSrc != 0 || ySrc != 0)
    280     {
    281         dprintf(("xSrc %d ySrc %d bpp %d", xSrc, ySrc, info->bmiHeader.biBitCount));
    282 //        return lines;
    283     }
    284 //testestest
    285 
    286278    // check if new bitmap must be created
    287279    if (xSrc == 0 && ySrc == 0 && startscan == 0 && lines == height &&
     
    296288            info->bmiHeader.biCompression == BI_BITFIELDS)
    297289        {
     290            // not zero if bpp < 8 and starting on an uneven pixel
     291            UINT xOffset = (xSrc * info->bmiHeader.biBitCount) % 8;
     292
    298293            // compute size of memory buffer
    299294            UINT lBytesPerLineOrig = DIB_GetDIBWidthBytes (info->bmiHeader.biWidth, info->bmiHeader.biBitCount);
    300             UINT lBytesToCopyInLine = DIB_GetDIBWidthBytes (cx, info->bmiHeader.biBitCount);
     295            UINT lBytesToCopyInLine = DIB_GetDIBWidthBytes (cx + xOffset, info->bmiHeader.biBitCount);
    301296           
    302297            newBits = (char *)malloc (lBytesToCopyInLine * cy);
     
    306301                // copy bits to new buffer
    307302                int i;
    308                 // starting pointer
    309                 char *pBits = (char *)bits +                           // origin
    310                               (ySrc - startscan) * lBytesPerLineOrig + // y offset
    311                               (xSrc * info->bmiHeader.biBitCount) / 8; // x offset
    312                                
     303
     304                char *pNewBits = (char *)newBits;
     305                             
    313306                if (info->bmiHeader.biHeight > 0)
    314307                {
    315                     char *pNewBits = (char *)newBits;
    316                
     308                    // starting pointer
     309                    char *pBits = (char *)bits +                           // origin
     310                                  (ySrc - startscan) * lBytesPerLineOrig + // y offset
     311                                  (xSrc * info->bmiHeader.biBitCount) / 8; // x offset
     312               
    317313                    for (i = 0; i < cy; i++)
    318314                    {
     
    324320                else
    325321                {
    326                     char *pNewBits = (char *)newBits + (cy - 1) * lBytesToCopyInLine;
    327                
     322                    // starting pointer
     323                    char *pBits = (char *)bits +                           // origin
     324                                  (lines - 1 - (ySrc - startscan)) * lBytesPerLineOrig + // y offset
     325                                  (xSrc * info->bmiHeader.biBitCount) / 8; // x offset
     326
    328327                    for (i = 0; i < cy; i++)
    329328                    {
    330329                        memcpy (pNewBits, pBits, lBytesToCopyInLine);
    331                         pBits += lBytesPerLineOrig;
    332                         pNewBits -= lBytesToCopyInLine;
     330                        pBits    -= lBytesPerLineOrig;
     331                        pNewBits += lBytesToCopyInLine;
    333332                    }
    334333                }
     
    336335                // newBits contain partial bitmap, correct the header
    337336                // todo bitcount < 8
    338                 ((BITMAPINFO *)info)->bmiHeader.biWidth = cx;
     337                ((BITMAPINFO *)info)->bmiHeader.biWidth  = cx + xOffset;
    339338                ((BITMAPINFO *)info)->bmiHeader.biHeight = cy;
    340339                ((BITMAPINFO *)info)->bmiHeader.biSizeImage = lBytesToCopyInLine * cy;
    341340               
    342                 xSrc = (xSrc * info->bmiHeader.biBitCount) % 8;
    343341                ySrc = startscan = 0;
     342                xSrc = xOffset;
    344343                lines = cy;
    345                 dprintf(("Converted BITMAP: (%d,%d) %d bytes",
    346                          info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biSizeImage));
     344                dprintf(("Converted BITMAP: (%d,%d) %d bytes xSrc %d ySrc %d",
     345                         info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biSizeImage, xSrc, ySrc));
    347346            }
    348347        }
Note: See TracChangeset for help on using the changeset viewer.