dib16bpp.c

来自「一个类似windows」· C语言 代码 · 共 971 行 · 第 1/3 页

C
971
字号
       {	 
            sy = ((DesY  * SrcSizeY) / DesSizeY) + SourceRect->top;
                                 
            for (DesX=0; DesX<DesSizeX; DesX++)
            {	
									
                  sx = ((DesX * SrcSizeX) / DesSizeX) + SourceRect->left;  		
                   		
                  if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
				  {					
					*DestBits = XLATEOBJ_iXlate(ColorTranslation, 0);				  				  
				     DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
                  } 
				  else 
				  {                    
                    *DestBits = XLATEOBJ_iXlate(ColorTranslation, 1);				  				  
				     DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
                  }
            }
            DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
       }
       break;

      case BMF_4BPP:		
      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
      /* This is a reference implementation, it hasn't been optimized for speed */

      DestBits = (PULONG)((PBYTE)DestSurf->pvScan0 + (DestRect->left << 1) +
                   DestRect->top * DestSurf->lDelta);
      
	  DifflDelta = DestSurf->lDelta -  (DesSizeX << 1); 
	                  
       for (DesY=0; DesY<DesSizeY; DesY++)
       {	 
            sy = ((DesY  * SrcSizeY) / DesSizeY) + SourceRect->top;
                                 
            for (DesX=0; DesX<DesSizeX; DesX++)
            {	
									
                  sx = ((DesX * SrcSizeX) / DesSizeX) + SourceRect->left;  		
                  color = DIB_4BPP_GetPixel(SourceSurf, sx, sy);
                  color = XLATEOBJ_iXlate(ColorTranslation, color);
                              
				  *DestBits = color;				  				  
				   DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
            }
            DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
       }
       break;
       
      case BMF_8BPP:		
      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
      /* This is a reference implementation, it hasn't been optimized for speed */
            
      DestBits = (PULONG)((PBYTE)DestSurf->pvScan0 + (DestRect->left << 1) +
                   DestRect->top * DestSurf->lDelta);
                   
      DifflDelta = DestSurf->lDelta -  (DesSizeX << 1); 
                      
       for (DesY=0; DesY<DesSizeY; DesY++)
       {	 
            sy = ((DesY  * SrcSizeY) / DesSizeY) + SourceRect->top;
                                 
            for (DesX=0; DesX<DesSizeX; DesX++)
            {	
									
                  sx = ((DesX * SrcSizeX) / DesSizeX) + SourceRect->left;  		
                  color = DIB_8BPP_GetPixel(SourceSurf, sx, sy);
                  color = XLATEOBJ_iXlate(ColorTranslation, color);            
				  *DestBits = color;				  				  
				   DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
            }
            DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
       }
       break;
       

      case BMF_24BPP:		
      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
      /* This is a reference implementation, it hasn't been optimized for speed */
                      
      DestBits = (PULONG)((PBYTE)DestSurf->pvScan0 + (DestRect->left << 1) +
                   DestRect->top * DestSurf->lDelta);
      
	  DifflDelta = DestSurf->lDelta -  (DesSizeX << 1); 
	                  
       for (DesY=0; DesY<DesSizeY; DesY++)
       {	 
            sy = ((DesY  * SrcSizeY) / DesSizeY) + SourceRect->top;
                                 
            for (DesX=0; DesX<DesSizeX; DesX++)
            {	
									
                  sx = ((DesX * SrcSizeX) / DesSizeX) + SourceRect->left;  		
                  color = DIB_24BPP_GetPixel(SourceSurf, sx, sy);
                  color = XLATEOBJ_iXlate(ColorTranslation, color);
                              
				  *DestBits = color;				  				  
				   DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
            }
            DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
       }       
	   break;

      case BMF_32BPP:		
      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
      /* This is a reference implementation, it hasn't been optimized for speed */
                      
      DestBits = (PULONG)((PBYTE)DestSurf->pvScan0 + (DestRect->left << 1) +
                   DestRect->top * DestSurf->lDelta);
      
	  DifflDelta = DestSurf->lDelta -  (DesSizeX << 1); 
	                  
       for (DesY=0; DesY<DesSizeY; DesY++)
       {	 
            sy = ((DesY  * SrcSizeY) / DesSizeY) + SourceRect->top;
                                 
            for (DesX=0; DesX<DesSizeX; DesX++)
            {	
									
                  sx = ((DesX * SrcSizeX) / DesSizeX) + SourceRect->left;  		
                  color = DIB_32BPP_GetPixel(SourceSurf, sx, sy);
                  color = XLATEOBJ_iXlate(ColorTranslation, color);
                              
				  *DestBits = color;				  				  
				   DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
            }
            DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
       }
       break;

      case BMF_16BPP:
        return ScaleRectAvg16(DestSurf, SourceSurf, DestRect, SourceRect, MaskOrigin, BrushOrigin,
                              ClipRegion, ColorTranslation, Mode);
      break;

      default:
         DPRINT1("DIB_16BPP_StretchBlt: Unhandled Source BPP: %u\n", BitsPerFormat(SourceSurf->iBitmapFormat));
      return FALSE;
    }



  return TRUE;
}

BOOLEAN
DIB_16BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
                         RECTL*  DestRect,  POINTL  *SourcePoint,
                         XLATEOBJ *ColorTranslation, ULONG iTransColor)
{
  ULONG RoundedRight, X, Y, SourceX, SourceY, Source, wd, Dest;
  ULONG *DestBits;

  RoundedRight = DestRect->right - ((DestRect->right - DestRect->left) & 0x1);
  SourceY = SourcePoint->y;
  DestBits = (ULONG*)((PBYTE)DestSurf->pvScan0 +
                      (DestRect->left << 1) +
                      DestRect->top * DestSurf->lDelta);
  wd = DestSurf->lDelta - ((DestRect->right - DestRect->left) << 1);

  for(Y = DestRect->top; Y < DestRect->bottom; Y++)
  {
    SourceX = SourcePoint->x;
    for(X = DestRect->left; X < RoundedRight; X += 2, DestBits++, SourceX += 2)
    {
      Dest = *DestBits;

      Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY);
      if(Source != iTransColor)
      {
        Dest &= 0xFFFF0000;
        Dest |= (XLATEOBJ_iXlate(ColorTranslation, Source) & 0xFFFF);
      }

      Source = DIB_GetSourceIndex(SourceSurf, SourceX + 1, SourceY);
      if(Source != iTransColor)
      {
        Dest &= 0xFFFF;
        Dest |= (XLATEOBJ_iXlate(ColorTranslation, Source) << 16);
      }

      *DestBits = Dest;
    }

    if(X < DestRect->right)
    {
      Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY);
      if(Source != iTransColor)
      {
        *((USHORT*)DestBits) = (USHORT)XLATEOBJ_iXlate(ColorTranslation, Source);
      }

      DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
    }
    SourceY++;
    DestBits = (ULONG*)((ULONG_PTR)DestBits + wd);
  }

  return TRUE;
}

typedef union {
   ULONG ul;
   struct {
      UCHAR red;
      UCHAR green;
      UCHAR blue;
      UCHAR alpha;
   } col;
} NICEPIXEL32;

typedef union {
   USHORT us;
   struct {
      USHORT red:5,
             green:6,
             blue:5;
   } col;
} NICEPIXEL16;

static __inline UCHAR
Clamp5(ULONG val)
{
   return (val > 31) ? 31 : val;
}

static __inline UCHAR
Clamp6(ULONG val)
{
   return (val > 63) ? 63 : val;
}

BOOLEAN
DIB_16BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
                     RECTL* SourceRect, CLIPOBJ* ClipRegion,
                     XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
{
   INT Rows, Cols, SrcX, SrcY;
   register PUSHORT Dst;
   ULONG DstDelta;
   BLENDFUNCTION BlendFunc;
   register NICEPIXEL16 DstPixel;
   register NICEPIXEL32 SrcPixel;
   UCHAR Alpha, SrcBpp;

   DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
          SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
          DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);

   ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
          DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);

   BlendFunc = BlendObj->BlendFunction;
   if (BlendFunc.BlendOp != AC_SRC_OVER)
   {
      DPRINT1("BlendOp != AC_SRC_OVER\n");
      return FALSE;
   }
   if (BlendFunc.BlendFlags != 0)
   {
      DPRINT1("BlendFlags != 0\n");
      return FALSE;
   }
   if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
   {
      DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
      return FALSE;
   }
   if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
       BitsPerFormat(Source->iBitmapFormat) != 32)
   {
      DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
      return FALSE;
   }

   Dst = (PUSHORT)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
                              (DestRect->left << 1));
   DstDelta = Dest->lDelta - ((DestRect->right - DestRect->left) << 1);
   SrcBpp = BitsPerFormat(Source->iBitmapFormat);

   Rows = DestRect->bottom - DestRect->top;
   SrcY = SourceRect->top;
   while (--Rows >= 0)
   {
      Cols = DestRect->right - DestRect->left;
      SrcX = SourceRect->left;
      while (--Cols >= 0)
      {
         if (SrcBpp <= 16)
         {
            DstPixel.us = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
            SrcPixel.col.red = (DstPixel.col.red << 3) | (DstPixel.col.red >> 2);
            SrcPixel.col.green = (DstPixel.col.green << 2) | (DstPixel.col.green >> 4);
            SrcPixel.col.blue = (DstPixel.col.blue << 3) | (DstPixel.col.blue >> 2);
         }
         else
         {
            SrcPixel.ul = DIB_GetSourceIndex(Source, SrcX++, SrcY);
         }
         SrcPixel.col.red = SrcPixel.col.red * BlendFunc.SourceConstantAlpha / 255;
         SrcPixel.col.green = SrcPixel.col.green * BlendFunc.SourceConstantAlpha / 255;
         SrcPixel.col.blue = SrcPixel.col.blue * BlendFunc.SourceConstantAlpha / 255;
         SrcPixel.col.alpha = (SrcBpp == 32) ? (SrcPixel.col.alpha * BlendFunc.SourceConstantAlpha / 255) : BlendFunc.SourceConstantAlpha;

         Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
                 SrcPixel.col.alpha : BlendFunc.SourceConstantAlpha;

         DstPixel.us = *Dst;
         DstPixel.col.red = Clamp5(DstPixel.col.red * (255 - Alpha) / 255 + (SrcPixel.col.red >> 3));
         DstPixel.col.green = Clamp6(DstPixel.col.green * (255 - Alpha) / 255 + (SrcPixel.col.green >> 2));
         DstPixel.col.blue = Clamp5(DstPixel.col.blue * (255 - Alpha) / 255 + (SrcPixel.col.blue >> 3));
         *Dst++ = DstPixel.us;
      }
      Dst = (PUSHORT)((ULONG_PTR)Dst + DstDelta);
      SrcY++;
   }

   return TRUE;
}

/* EOF */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?