Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.08.08;
Скачать: CL | DM;

Вниз

Поключение функции из C++ DLL в Delphi (DirectDraw Alpha Blendin)   Найти похожие ветки 

 
ПсихЪ_клон   (2004-05-22 16:02) [0]

Пишу графический движок на Delphi. Так как аппаратного AlphaBlending"а для DirectDraw нету, то пишу софтверную версию этой функции. но в Delphi это работало очень медленно, поэтому решил написать на C++ (MSVC++6.0) DLL"ьку с реализацией этой функции. Затем пытаюсь подключить всё это в Delphi, при при запуске приложения выскакивает ошибка:
"The procedure entry point TransAlphaFast could not be located in the dynamic link library AlphaDLL.dll."

Вот исходники:

////// AlphaDLL.cpp
#include "stdafx.h"
#include "AlphaDLL.h"
#include <windows.h>
#include <ddraw.h>

BOOL APIENTRY DllMain( HANDLE hModule,
                      DWORD  ul_reason_for_call,
                      LPVOID lpReserved
     )
{
   return TRUE;
}

ALPHADLL_API HRESULT nTransAlphaFast;

ALPHADLL_API HRESULT TransAlphaFast(LPDIRECTDRAWSURFACE src, LPDIRECTDRAWSURFACE dest,
       LONG lDestX, LONG lDestY, RECT srcRect, DWORD ColorKey, WORD BPP)
{
 ////// см. Приложение 1
}

////// StdAfx.cpp
#include "stdafx.h"

////// AlphaDLL.h
#ifdef ALPHADLL_EXPORTS
#define ALPHADLL_API __declspec(dllexport)
#else
#define ALPHADLL_API __declspec(dllimport)
#endif

#include <ddraw.h>

extern ALPHADLL_API HRESULT nTransAlphaFast;

extern ALPHADLL_API HRESULT TransAlphaFast(LPDIRECTDRAWSURFACE src, LPDIRECTDRAWSURFACE dest,
       LONG lDestX, LONG lDestY, RECT srcRect, DWORD ColorKey, WORD BPP);

////// StdAfx.h
#if !defined(AFX_STDAFX_H__4E21DA8A_9595_43D2_8B2D_AC11D1814171__INCLUDED_)
#define AFX_STDAFX_H__4E21DA8A_9595_43D2_8B2D_AC11D1814171__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// Insert your headers here
#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers

#include <windows.h>

// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__4E21DA8A_9595_43D2_8B2D_AC11D1814171__INCLUDED_)

В Delphi функцию линкую так:
function TransAlphaFast( src, dest : PDirectDrawSurface; lDestX, lDestY : integer; srcRect : TRect; ColorKey : DWORD; BPP : DWORD ) : HRESULT; stdcall; external "AlphaDLL.dll"

В чём ошибка? По мимо того, что в генах... (:


 
ПсихЪ_клон   (2004-05-22 16:11) [1]

/////// Приложение 1

 int i,j; //register
int height,width;
 BYTE* lpSprite;
 BYTE* lpDest;
 LONG dPitch, SpritePitch;
 DWORD sColorKey;
 DWORD sTemp,dTemp;
 WORD sbuf,dbuf;
 DWORD Result;
BOOL oddWidth = FALSE;
DDSURFACEDESC srcDDSD, destDDSD;

 // Set height and width of SPRITE
 height = srcRect.bottom - srcRect.top;
 width  = srcRect.right - srcRect.left;

   // Lock down both surfaces for read and write
ZeroMemory(&srcDDSD, sizeof(srcDDSD));
srcDDSD.dwSize = sizeof(srcDDSD);
src->Lock(NULL, &srcDDSD, DDLOCK_WAIT, NULL);
   
ZeroMemory(&destDDSD, sizeof(destDDSD));
destDDSD.dwSize = sizeof(destDDSD);
dest->Lock(NULL, &destDDSD, DDLOCK_WAIT, NULL);

 // Set the pitch for both surfaces
 SpritePitch = srcDDSD.lPitch;
 dPitch      = destDDSD.lPitch;

 // Initialize the pointers to the upper left hand corner of the surface
 lpSprite = (BYTE*)srcDDSD.lpSurface;
 lpDest   = (BYTE*)destDDSD.lpSurface;

// Get the color key for sprite surface
sColorKey = ColorKey;

// Start RGB Format switch statement
switch(BPP)
{
case 8:
 // IMHO paletized modes are a thing of the past please feel free to
 // implement this if you so desire.
 break;

case 15:  ////////////////////////////////////////////////////////////////////////
       //
       //  WARNING!!!: I do not have a video card that uses the 5-5-5 format
       //              this barnch of code has not be tested.
       //
       ////////////////////////////////////////////////////////////////////////

 // Initialize the pointers to the first pixel in the rectangle
 lpSprite += (srcRect.top * SpritePitch) + (srcRect.left * 2);
 lpDest   += (lDestY * dPitch) + (lDestX * 2);

 // Set the horizontal padding
 sbuf = (WORD)(SpritePitch - (2 * width));
 dbuf = (WORD)(dPitch - (2 * width));

 // Is the Sprite width odd or even?
 if (width % 2 == 1)
 {
  oddWidth = TRUE;
  width = (width - 1) / 2; //div by 2, processing 2 pixels at a time.
 }
 else
  width = width / 2;  //div by 2, processing 2 pixels at a time.

 i = height;
 do
 {
  if (oddWidth)
  {
   sTemp = *((WORD*)lpSprite);

   if (sTemp != sColorKey)
   {
    dTemp = *((WORD*)lpDest);
    *((WORD*)lpDest) = (WORD)(((sTemp & 0x7BDE) >> 1) + ((dTemp & 0x7BDE) >> 1));
   }

   lpDest   += 2;
   lpSprite += 2;
  }

  j = width;
  do
  {
   sTemp  = *((DWORD*)lpSprite);
   dTemp  = *((DWORD*)lpDest);
   Result = dTemp;

   if ((sTemp & 0xFFFF) != sColorKey)
   {
    Result &= 0xFFFF0000;
    Result |= ((sTemp & 0x7BDE) >> 1) + ((dTemp & 0x7BDE) >> 1);
   }
   if ((sTemp >> 16) != sColorKey)
   {
    Result &= 0xFFFF;
    Result |= ((sTemp & 0x7BDE0000) >> 1) + ((dTemp & 0x7BDE0000) >> 1);
   }

   *((DWORD*)lpDest) = Result;
   lpDest   += 4;
   lpSprite += 4;
  }while (--j > 0);
  lpDest   += dbuf;
  lpSprite += sbuf;

 }while (--i > 0);

 break;

case 16:

 // Initialize the pointers to the first pixel in the rectangle
 lpSprite += (srcRect.top * SpritePitch) + (srcRect.left * 2);
 lpDest   += (lDestY * dPitch) + (lDestX * 2);

 // Set the horizontal padding
 sbuf = (WORD)(SpritePitch - (2 * width));
 dbuf = (WORD)(dPitch - (2 * width));

 // Is the Sprite width odd or even?
 if (width % 2 == 1)
 {
  oddWidth = TRUE;
  width = (width - 1) / 2; //div by 2, processing 2 pixels at a time.
 }
 else
  width = width / 2;  //div by 2, processing 2 pixels at a time.

 i = height;
 do
 {
  if (oddWidth)
  {
   sTemp = *((WORD*)lpSprite);

   if (sTemp != sColorKey)
   {
    dTemp = *((WORD*)lpDest);
    *((WORD*)lpDest) = (WORD)(((sTemp & 0xF7DE) >> 1) + ((dTemp & 0xF7DE) >> 1));
   }

   lpDest   += 2;
   lpSprite += 2;
  }

  j = width;
  do
  {
   sTemp  = *((DWORD*)lpSprite);
   dTemp  = *((DWORD*)lpDest);
   Result = dTemp;

   if ((sTemp & 0xFFFF) != sColorKey)
   {
    Result &= 0xFFFF0000;
    Result |= ((sTemp & 0xF7DE) >> 1) + ((dTemp & 0xF7DE) >> 1);
   }
   if ((sTemp >> 16) != sColorKey)
   {
    Result &= 0xFFFF;
    Result |= ((sTemp & 0xF7DE0000) >> 1) + ((dTemp & 0xF7DE0000) >> 1);
   }

   *((DWORD*)lpDest) = Result;
   lpDest   += 4;
   lpSprite += 4;

  }while (--j > 0);
  lpDest += dbuf;
  lpSprite += sbuf;

 }while (--i > 0);
 break;

case 24:  ////////////////////////////////////////////////////////////////////////
       //
       //  WARNING!!!: I do not have a video card capable of 24bit rendering
       //              this barnch of code has not be tested.
       //
       ////////////////////////////////////////////////////////////////////////

 // Initialize the pointers to the first pixel in the rectangle
 lpSprite += (srcRect.top * SpritePitch) + (srcRect.left * 3);
 lpDest   += (lDestY * dPitch) + (lDestX * 3);

 // Set the horizontal padding
 sbuf = (WORD)(SpritePitch - (3 * width));
 dbuf = (WORD)(dPitch - (3 * width));

 i = height;
 do
 {
  j = width;
  do
  {
   sTemp = *((DWORD*)lpSprite);

   if ((sTemp &= 0xFFFFFF) != sColorKey)
   {
    dTemp  = *((DWORD*)lpDest);
    Result = ((sTemp & 0xFEFEFE) >> 1) + ((dTemp & 0xFEFEFE) >> 1);

    *((WORD*)lpDest) = (WORD)(Result & 0xFFFF);
    lpDest += 2;
    *lpDest = (BYTE)(Result >> 16);
    lpDest++;
   }
   else
   {
    lpDest += 3;
   }

   lpSprite += 3;

  }while (--j > 0);
  lpDest += dbuf;
  lpSprite += sbuf;

 }while (--i > 0);
 break;

case 32:
 // Initialize the pointers to the first pixel in the rectangle
 lpSprite += (srcRect.top * SpritePitch) + (srcRect.left * 4);
 lpDest   += (lDestY * dPitch) + (lDestX * 4);

 // Set the horizontal padding
 sbuf = (WORD)(SpritePitch - (4 * width));
 dbuf = (WORD)(dPitch - (4 * width));

 i = height;
 do
 {
  j = width;
  do
  {
   sTemp = *((DWORD*)lpSprite);

   if ((sTemp &= 0xFFFFFF) != sColorKey)
   {
    dTemp  = *((DWORD*)lpDest);
    Result = ((sTemp & 0xFEFEFE) >> 1) + ((dTemp & 0xFEFEFE) >> 1);

    *((WORD*)lpDest) = (WORD)(Result & 0xFFFF);
    lpDest += 2;
    *lpDest = (BYTE)(Result >> 16);
    lpDest += 2;
   }
   else
   {
    lpDest += 4;
   }

   lpSprite += 4;

  }while (--j > 0);
  lpDest += dbuf;
  lpSprite += sbuf;

 }while (--i > 0);
 break;
} // End RGB Format switch statement

   src->Unlock(NULL);
   dest->Unlock(NULL);

 nTransAlphaFast = DD_OK;
return DD_OK;


 
cyborg   (2004-05-22 19:20) [2]

Дааааа....... вот это вот быстро? :) Нашёл себе проблему на голову.
Для быстро ММХ используй прямо в своём проекте.


 
ПсихЪ_клон   (2004-05-23 00:05) [3]

MMX я использую. Но вдруг он не подерживается? К тому же MMX только для глубины цвета 16. В либе будет 4 функции реализации прозрачности. Выбирай какую хочешь.

С ddl"кой я разобрался. Всё написал. Качать отсюда: http://stalker2010.front.ru/down/AlphaDLLSetup.exe



Страницы: 1 вся ветка

Текущий архив: 2004.08.08;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.024 c
1-1090895290
Phoenix
2004-07-27 06:28
2004.08.08
Выпадающее меню в DBGridEh


4-1088437839
MetalFan
2004-06-28 19:50
2004.08.08
как программно "залочить" комп?


1-1090598058
AlexDee
2004-07-23 19:54
2004.08.08
Возведение в "сложную" степень и число "E"


3-1089900139
Delpher
2004-07-15 18:02
2004.08.08
Таблица в таблице.


4-1088413866
Buster
2004-06-28 13:11
2004.08.08
Как определить время создания файла и директории?