|
void ImageEncDec::ByteSwap(PWORD imptr, UINT length)
{
PWORD item;
PBYTE hi;
BYTE temp;
for( UINT i = 0; i < length; i++ ) {
item = &imptr[ i ];
hi = (PBYTE)item;
temp = hi[0];
hi[0] = hi[1];
hi[1] = temp;
}
}
John
|
|
|
|
|
template <class T> T ReverseBYTES (T &t)
{
int bytes = sizeof(T);
T rev;
BYTE *ptr1 = (BYTE *)&t;
BYTE *ptr2 = (BYTE *)&rev;
for (int x = 0; x < bytes; x++)
ptr2[x] = ptr1[bytes - x - 1];
return rev;
}
Works with data of any size.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
sweet! thanx.
I also found a fun little function tucked away in winsock2.h...
u_long ntohl (
u_long netlong
);
The ntohl function takes a 32-bit number in TCP/IP network byte order and returns a 32-bit number in host byte order.
in other words: byte swap. Who'd a thought.
Anyway, I like your approach better, it's more generic. Thanks again!
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Should be noted that the ntohl (and corresponding htonl) wont actually swap any bytes if your machine architecture is already in network order - but it will on x86 processors!
|
|
|
|
|
hmmm... So it will swap all the time on x86?
I'm not going cross-platform here, it's hardcore MFC7.1...
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
It sure would byte swap. But do you need to load winsock in order to use it? Also, I'd have to dock you 5 style points for misusing that function to perform byte swapping....
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks
|
|
|
|
|
i try to use a c library which require me to pass a function pointer
as callback. hence, i build a static function inside a class .
however, i face a very strange problem while trying to access a member
function through that static function with the following trick.
i have the following classes:
CXFaceRecognitionDlg - main dialog class and with a static CPicture
control
CPicture - static control derived from CStatic
CFaceDetectionManager - generic class
in CXFaceRecognitionDlg.h
-------------------------
class CXFaceRecognitionDlg : public CDialog
{
public:
bool GetIsCaptureDetectedFace(){ return m_bIsCaptureDetectedFace; }
// Dialog Data
//{{AFX_DATA(CXFaceRecognitionDlg)
enum { IDD = IDD_XFACERECOGNITION_DIALOG };
CPicture m_Picture;
protected:
bool m_bIsCaptureDetectedFace;
-------------------------
in CXFaceRecognitionDlg.cpp
---------------------------
BOOL CXFaceRecognitionDlg::OnInitDialog()
{
//this callback will process every frame
cvcamSetProperty(0, CVCAM_PROP_CALLBACK, CPicture::callback);
m_bIsCaptureDetectedFace = true;
}
void CXFaceRecognitionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXFaceRecognitionDlg)
DDX_Control(pDX, IDC_PICTURE, m_Picture);
//}}AFX_DATA_MAP
}
---------------------------
in CPicture.h
-------------
class CPicture : public CStatic
{
// Construction
public:
static void callback(IplImage* image);
protected:
CFaceDetectionManager* m_pFaceDetectionManager;
static CFaceDetectionManager* m_spFaceDetectionManager;
-------------
in CPicture.cpp
---------------
CFaceDetectionManager* CPicture::m_spFaceDetectionManager = NULL;
CPicture::CPicture()
{
try
{
m_pFaceDetectionManager = new CFaceDetectionManager(this);
}
catch(const char* c)
{
MessageBox(c);
m_pFaceDetectionManager = NULL;
}
// I NEED THIS TO ENABLE ME TO ACCESS MEMBER FUNCTION THROUGH STATIC
FUNCTION
m_spFaceDetectionManager = m_pFaceDetectionManager;
}
void CPicture::callback(IplImage* image)
{
// THIS IS THE WAY I ACCESS MEMBER FUNCTION THROUGH STATIC FUNCTION
if(m_spFaceDetectionManager != NULL)
m_spFaceDetectionManager->DetectAndDrawFaces(video_image);
}
---------------
in CFaceDetectionManager.h
--------------------------
class CFaceDetectionManager
{
// Construction
public:
CFaceDetectionManager(CPicture* pParent, const char
*classifier_cascade_path = "<default_face_cascade>"); // standard
constructor
void DetectAndDrawFaces( IplImage* img );
protected:
CPicture* m_pParent;
--------------------------
in CFaceDetectionManager.cpp
----------------------------
CFaceDetectionManager::CFaceDetectionManager( CPicture* pParent, const
char *classifier_cascade_path)
{
m_pParent = pParent;
}
void CFaceDetectionManager::DetectAndDrawFaces( IplImage* img )
{ if(((CXFaceRecognitionDlg*)(m_pParent->GetParent()))->GetIsCaptureDetectedFace())
{
}
}
----------------------------
The strange problem occurs here. i realize that the line of code
if(((CXFaceRecognitionDlg*)(m_pParent->GetParent()))->GetIsCaptureDetectedFace())
isn't getting result "true", but it is getting result "false".
although, i oledi explicitly set m_bIsCaptureDetectedFace into "true"
during the initialize of dialog box.
can anyone tell me why this strange situation happen? this really
getting me crazy
thank you.
regards
yccheok
|
|
|
|
|
I would make sure the pointer returned from GetParent() is actually the type you think it is. Do something like:
ASSERT_KINDOF(CXFaceRecognitionDlg, m_pParent->GetParent())
|
|
|
|
|
i had ur advice and now roughly can get the root of evil but still have no idea how to solve it. here is the root of evil. (i simplify my previous problem)
----------------------------------------------------------
i try to use a c library which require me to pass a function poinger as callback. hence, i build
a static function inside a class .
however, i face a very strange problem while trying to access a member function through that
static function with the following trick.
i have the following classes:
CXFaceRecognitionDlg - main dialog class and with a CPicture control
CPicture - control derived from CStatic
in CXFaceRecognitionDlg.h
-------------------------
class CXFaceRecognitionDlg : public CDialog
{
public:
int GetDummy(){ return dummy; }
void ShowDummy();
// Dialog Data
//{{AFX_DATA(CXFaceRecognitionDlg)
enum { IDD = IDD_XFACERECOGNITION_DIALOG };
CPicture m_Picture;
protected:
int dummy;
-------------------------
in CXFaceRecognitionDlg.cpp
---------------------------
BOOL CXFaceRecognitionDlg::OnInitDialog()
{
// this is the c library
// this callback will process every seconds
cvcamSetProperty(0, CVCAM_PROP_CALLBACK, CPicture::callback);
// explicitly set to 108
dummy = 108;
}
void CXFaceRecognitionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXFaceRecognitionDlg)
DDX_Control(pDX, IDC_PICTURE, m_Picture);
//}}AFX_DATA_MAP
}
void CXFaceRecognitionDlg::ShowDummy()
{
CString s;
s.Format("%i", dummy);
MessageBox(s, s, MB_OK);
}
---------------------------
in CPicture.h
-------------
class CPicture : public CStatic
{
// Construction
public:
static void callback(IplImage* image);
protected:
static CPicture* m_pThis;
-------------
in CPicture.cpp
---------------
CFaceDetectionManager* CPicture::m_spFaceDetectionManager = NULL;
CPicture::CPicture()
{
// I NEED THIS TO ENABLE ME TO ACCESS MEMBER FUNCTION THROUGH STATIC FUNCTION
m_pThis = this;
}
void CPicture::OnLButtonDown(UINT nFlags, CPoint point)
{
// YAHOO! I GET 108 DISPLAY
((CXFaceRecognitionDlg*)GetParent())->ShowDummy();
}
// PLEASE NOTE THAT CALLBACK IS STATIC FUNCTION
void CPicture::callback(IplImage* image)
{
// WILL GET COMPILATION ERROR FOR THE FOLLOWING CODE
// 'CWnd::GetParent' : illegal call of non-static member function
//
// ((CXFaceRecognitionDlg*)GetParent())->ShowDummy();
//
// BUT VALUE 0 IS DISPLAYED
((CXFaceRecognitionDlg*)(m_pThis->GetParent()))->ShowDummy();
}
---------------
I try to debug the application by inserting
ASSERT_KINDOF(CXFaceRecognitionDlg, GetParent()); in CPicture::OnLButtonDown
ASSERT_KINDOF(CXFaceRecognitionDlg, m_pThis->GetParent() ); in CPicture::callback
note that ASSERT_KINDOF(CXFaceRecognitionDlg, m_pThis->GetParent() ); in CPicture::callback will
fail!!!
(1) why m_pThis->GetParent() is not class type of CXFaceRecognitionDlg but can have a access to
function ShowDummy?
(2) how can i avoid that failure at the same time mantaining callback as static and able to
access instance member variable?
thank you.
regards
yccheok
|
|
|
|
|
Hello !!!
I have a CListView with a CListCtrl inside.
Now I want that the horizontal Scroll-Bar is not
dissepearing when it is no more needed.
What can I Do??
with SetScrollInfo() with the Flag SIF_DISABLENOSCROLL
it does not work. But I can all other things set, but not SIF_DISABLENOSCROLL
Why??
Thanx for helping me
schoni
|
|
|
|
|
Hi all,
I have a simple dialog box with two list view controls on it.
the controls both have a vertical scroll bar and are created via Visual Studio (not manually using CreateWindowEx).
I need to syncronize the scrollbars so when a user selects one scrollbar, the other list view's scroll bar also moves (obviously moving the information within as well).
From what I read in MSDN, I thought the scroll messages from a control within were propagated to the parent window (in this case a dialog box).
With this information, I understood it as I could just handle the WM_VSCROLL message in the parent's windproc and figure out where the message came from and do what I got to do (using SetScrollPos and such).
Only thing is, my parent window is not receving ANY messages from the two list view controls.
I don't remember what I need to do so the parent windproc receives these messages so I can handle my scrolling.
Any suggestions on how to get the messages? Other than adding a windproc for each control? I don't really want to do it that way and I'm looking for a better way.
Any suggestions are greatly appreciated.
Thank you!
|
|
|
|
|
i opened a the wave in device and record through the line in. the audio samples are collected in a buffer. i convolve this buffer with a filter and send this buffer back to the wave out device for playback. however it does not play the filtered audio. at the output i get the data from line in. however if the filtered audio is saved to a wave file it gets saved properly and properly played back. can anyone tell me why the filtered data from the buffer is not played then. why can i hear the same as the wave in input. does it have to do something with opening the wave in device.
|
|
|
|
|
Gaurs wrote:
can anyone tell me why the filtered data from the buffer is not played then
This seems like an impossibility. However, if you are trying to do this in "almost" real-time, I think you should to have a look at the IAudioStream (or whatever they were called) interface(s) of DirectX.
|
|
|
|
|
Hi there,
I try to connect to Oracle using C++ and ADO with the following conection string...Upon trying to open, I get an access violation error.
This is the connection string:
"Driver={Microsoft ODBC for Oracle};Server=LST3.WORLD;Uid=MyUserName;Pwd=MyPassword;"
The same set of stuff seem to connect me to the database through VB. Any ideas?
HRESULT hRes;
CLSID clsid;
BOOL bRet = FALSE;
LONG nOption = 1;
CoInitialize(NULL);
hRes = CLSIDFromProgID(L"ADODB.Connection", &clsid);
if (SUCCEEDED(hRes))
{
hRes = CoCreateInstance(
clsid, 0, CLSCTX_INPROC_SERVER, __uuidof(_Connection), (void **)&m_pConnection );
}
else
{
bRet = FALSE;
}
if(SUCCEEDED(hRes))
{
SetDSN(nDatabase);
try
{
hRes = m_pConnection->Open(m_varDSN.bstrVal,L"",L"", adConnectUnspecified);
}
catch (_com_error e)
{
bRet = FALSE;
}
......
|
|
|
|
|
I want to read rtf file format and analyse every char format in rtf file and
draw it by myself! How Can I do it!
ZHANGYIFEI
|
|
|
|
|
|
|
Have a look at the (GPL) source code for AbiWord. Since it imports RTF I think you can find the data you want without too much problems.
|
|
|
|
|
where can i find (GPL) source code for AbiWord ?
ZHANGYIFEI
|
|
|
|
|
Hi guys
Related to my last query is this one.
How would you do to make your code be as fast as possible?
compiler options, tricks in code, etc...
Best Regards
|
|
|
|
|
Intelligence and Experience.
Kuphryn
|
|
|
|
|
|
but that's true, experience is one of the major factor in optimization.
One other thing, is good source level analysis, how can you restructure your source code to remove as much as possible useless computation, for example, loop unfolding, pre-computation of values.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Hi Maximilien
I've got an old program that makes 20.000.000.000 calculations in few minutes due to a precalculated tables, etc... I'm relaly happy with speed and clients too. But I was thinking about compiler switches about p4 optimizations.
The program was done before p4 and in my old msdn I haven't found switches about p4 optimization.
I was thinking in MMX optimization for comparisons. Maybe in the future 'cos now it's a lot of work.
Best Regards
|
|
|
|
|
Geesh, you give somebody 20 billion CPM and they want more! What's the world coming to?
|
|
|
|