游戏开发论坛

 找回密码
 立即注册
搜索
楼主: juexing

[求助]alphablend算法问题.

[复制链接]

15

主题

231

帖子

243

积分

中级会员

Rank: 3Rank: 3

积分
243
 楼主| 发表于 2007-12-24 11:59:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

我有两张图相同大小的图,一张24位色,一张8位色,现在就想通过这个公式合成.
楼上的朋友如果需要它们,我发你.

16

主题

154

帖子

309

积分

中级会员

Rank: 3Rank: 3

积分
309
发表于 2007-12-25 00:56:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

procedure TForm1.AlphaBlend24(BitmapDest, BitmapSrc: TBitmap; Alpha:Byte);
var
  pDest, pSrc : PByteArray;
  X,Y :Integer;
  Beta:Integer;
begin
  GetMem(pDest, SizeOf(Byte)*256);
  GetMem(pSrc, SizeOf(Byte)*256);
  Beta := 255 - Alpha;
  for Y := 0 to BitmapDest.Height - 1 do
  begin
    pDest := BitmapDest.ScanLine[Y];
    pSrc  := BitmapSrc.ScanLine[Y];
    for X := 0 to BitmapDest.Width - 1 do
    begin
      pDest[0]:= (pSrc[0] * Alpha + pDest[0] * Beta) div 255;
      pDest[1]:= (pSrc[1] * Alpha + pDest[1] * Beta) div 255;
      pDest[2]:= (pSrc[2] * Alpha + pDest[2] * Beta) div 255;
      Inc(Longword(pDest) ,3); // 指向下一个像素
      Inc(Longword(pSrc ) ,3);
    end;
  end;
  FreeMem(pDest, SizeOf(Byte)*256);//此次释放
  FreeMem(pSrc, SizeOf(Byte)*256);
end;



//这样也行.
procedure TForm1.AlphaBlend24(BitmapDest, BitmapSrc: TBitmap; Alpha:Byte);
var
  pDest, pSrc : PByte;
  X,Y :Integer;
  Beta:Integer;
begin
  Beta := 255 - Alpha;
  for Y := 0 to BitmapDest.Height - 1 do
  begin
    pDest := BitmapDest.ScanLine[Y];
    pSrc  := BitmapSrc.ScanLine[Y];
    for X := 0 to BitmapDest.Width - 1 do
    begin
      pDest^ := (pSrc^ * Alpha + pDest^ * Beta) div 255;
      Inc(pDest); Inc(pSrc);
      pDest^ := (pSrc^ * Alpha + pDest^ * Beta) div 255;
      Inc(pDest); Inc(pSrc);
      pDest^ := (pSrc^ * Alpha + pDest^ * Beta) div 255;
      Inc(pDest); Inc(pSrc);
    end;
  end;
end;

15

主题

231

帖子

243

积分

中级会员

Rank: 3Rank: 3

积分
243
 楼主| 发表于 2007-12-25 09:50:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

楼上的兄弟,报错啊~

27

主题

418

帖子

455

积分

中级会员

Rank: 3Rank: 3

积分
455
QQ
发表于 2007-12-26 00:43:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

看了一下,应该就是指针越界的问题。
不过怎么解决,我不知道,没有搞过这种算法。

建议你去下载Delphi用Graphics32,很简单就能实现你的功能。
而且他是开源的,你也可以学习算法是如何实现的。

15

主题

231

帖子

243

积分

中级会员

Rank: 3Rank: 3

积分
243
 楼主| 发表于 2007-12-26 10:05:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

我这还有PNG和TGA的图呢,Graphics32能对他们进行alphablend吗?

32

主题

232

帖子

234

积分

中级会员

Rank: 3Rank: 3

积分
234
发表于 2007-12-28 13:28:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

//**************************************************************//
//  Effect File exported by RenderMonkey 1.6
//
//  - Although many improvements were made to RenderMonkey FX  
//    file export, there are still situations that may cause   
//    compilation problems once the file is exported, such as  
//    occasional naming conflicts for methods, since FX format
//    does not support any notions of name spaces. You need to
//    try to create workspaces in such a way as to minimize   
//    potential naming conflicts on export.                    
//   
//  - Note that to minimize resulting name collisions in the FX
//    file, RenderMonkey will mangle names for passes, shaders  
//    and function names as necessary to reduce name conflicts.
//**************************************************************//

//--------------------------------------------------------------//
// Screen-AlignedQuad
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Single Pass
//--------------------------------------------------------------//
string Screen_AlignedQuad_Single_Pass_ScreenAlignedQuad : ModelData = "..\\..\\..\\Program Files\\AMD\\RenderMonkey 1.71\\Examples\\Advanced\\HeatHaze\\ScreenAlignedQuad.3ds";

struct VS_OUTPUT
{
   float4 pos       : POSITION0;
   float2 texCoord  : TEXCOORD0;
};

VS_OUTPUT Screen_AlignedQuad_Single_Pass_Vertex_Shader_vs_main( float4 inPos: POSITION )
{
   VS_OUTPUT o = (VS_OUTPUT) 0;

   inPos.xy = sign( inPos.xy);
   o.pos = float4( inPos.xy, 0.0f, 1.0f);

   // get into range [0,1]
   o.texCoord = (float2(o.pos.x, -o.pos.y) + 1.0f)/2.0f;
   return o;
}

texture base_Tex
<
   string ResourceName = "..\\..\\..\\Program Files\\AMD\\RenderMonkey 1.71\\Examples\\Media\\Textures\\base.tga";
>;
sampler2D Texture0 = sampler_state
{
   Texture = (base_Tex);
   ADDRESSU = WRAP;
   ADDRESSV = WRAP;
   ADDRESSW = WRAP;
   MINFILTER = LINEAR;
   MIPFILTER = LINEAR;
   MAGFILTER = LINEAR;
};
texture tex_Tex
<
   string ResourceName = "..\\..\\..\\Program Files\\AMD\\RenderMonkey 1.71\\Examples\\Media\\Textures\\Spotlight.jpg";
>;
sampler2D Texture1 = sampler_state
{
   Texture = (tex_Tex);
};
float blend
<
   string UIName = "blend";
   string UIWidget = "Numeric";
   bool UIVisible =  false;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = float( 0.50 );

float4 Screen_AlignedQuad_Single_Pass_Pixel_Shader_ps_main( float2 texCoord  : TEXCOORD0 ) : COLOR
{
   float4 color1,color2,color;
   color1=tex2D( Texture0, texCoord );
   color2 = tex2D( Texture1,texCoord );
   color = lerp(color1,color2,blend);
   return color;
}


//--------------------------------------------------------------//
// Technique Section for Screen-AlignedQuad
//--------------------------------------------------------------//
technique Screen_AlignedQuad
{
   pass Single_Pass
   {
      CULLMODE = NONE;

      VertexShader = compile vs_2_0 Screen_AlignedQuad_Single_Pass_Vertex_Shader_vs_main();
      PixelShader = compile ps_2_0 Screen_AlignedQuad_Single_Pass_Pixel_Shader_ps_main();
   }

}

32

主题

232

帖子

234

积分

中级会员

Rank: 3Rank: 3

积分
234
发表于 2007-12-28 13:31:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

实际算法:
float4 color1,color2,color;
   color1=tex2D( Texture0, texCoord );
   color2 = tex2D( Texture1,texCoord );
   color = lerp(color1,color2,blend);
   return color;

27

主题

418

帖子

455

积分

中级会员

Rank: 3Rank: 3

积分
455
QQ
发表于 2007-12-30 14:10:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

你给人家SL代码干什么?

32

主题

232

帖子

234

积分

中级会员

Rank: 3Rank: 3

积分
234
发表于 2008-1-3 14:26:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

哦,呵呵,那就用API吧,什么Draw之类的,那个MASK运算

15

主题

231

帖子

243

积分

中级会员

Rank: 3Rank: 3

积分
243
 楼主| 发表于 2008-1-3 16:16:00 | 显示全部楼层

Re:[求助]alphablend算法问题.

API已有,主要是公式合成,如果我换了算法,不用alphablend,那么我用其它的公式也能合成,Delphi的算法我一直没有找到好的方法去做,不行的话就只有用C++了.我不想.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-19 21:49

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表