|
You should specify the directX libs in the project settings.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Hi everyone,
i'm trying to write a real-time image processing program.I've made the following class, how can i improve it further?
array[] contains all the image bits from a CBitmap
using GetBitmapBits. First 8 bits=Blue, next 8 Green,
next 8 Red and next 8 unused.
BitDepth=4;
How can i improve the Threshold, Grayscale & Rotate functions? It must be timecritical.
Usage,
uImage image;
image.Create(bmp_x_width,bmp_y_width,32);
image.GetImage(&memDCLoad);
image.Grayscale();
image.Rotate(45);
image.SetImage(&memDCLoad);
pDC->StretchBlt(243,30,stretch_x,stretch_y,&memDCLoad,0,0,bmp_x_width,bmp_y_width,SRCCOPY);
class uImage
{
private:
int height_y;
int width_x;
int bitDepth;
int imgDepth;
public:
BYTE *array;
BYTE *array_copy;
CBitmap *pBitmap;
void Create(int x,int y,int depth);
void GetImage(CDC *MemDC);
void SetImage(CDC *MemDC);
void Delete();
BYTE GetR(int x,int y);
BYTE GetG(int x,int y);
BYTE GetB(int x,int y);
void SetR(int x,int y, BYTE value);
void SetG(int x,int y, BYTE value);
void SetB(int x,int y, BYTE value);
void Threshold(int value);
void Grayscale();
void Rotate(double degree);
};
void uImage::GetImage(CDC *MemDC)
{
pBitmap =MemDC->GetCurrentBitmap();
pBitmap->GetBitmapBits(bitDepth*width_x*height_y,array);
}
void uImage::SetImage(CDC *MemDC)
{
pBitmap =MemDC->GetCurrentBitmap();
pBitmap->SetBitmapBits(bitDepth*width_x*height_y,array);
}
void uImage::Create(int x,int y, int depth)
{
bitDepth=depth/8;
imgDepth=depth;
array=new BYTE[x*y*bitDepth];
array_copy=new BYTE[x*y*bitDepth];
height_y=y;
width_x=x;
}
void uImage::Delete()
{
delete[] array;
delete[] array_copy;
}
BYTE uImage::GetR(int x, int y)
{
return array[(x+y*width_x)*bitDepth+2];
}
BYTE uImage::GetG(int x, int y)
{
return array[(x+y*width_x)*bitDepth+1];
}
BYTE uImage::GetB(int x, int y)
{
return array[(x+y*width_x)*bitDepth+0];
}
void uImage::SetR(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+2]=value;
}
void uImage::SetG(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+1]=value;
}
void uImage::SetB(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+0]=value;
}
void uImage::Threshold(int value)
{
BYTE gray;
int temp;
for(int i=0;i<width_x*height_y;i++)
{
="" temp="i*4;
" gray="array[temp];
" if(gray<="value)
" array[temp++]="0;//blue
" }
="" else
="" }
}
void="" uimage::grayscale()
{
=""
="" byte="" gray;
="" int="" temp;
for(int="" i="0;i<width_x*height_y;i++)
" +array[temp+2]*0.299);
="" array[temp]="gray;
" array[temp+1]="gray;
" array[temp+2]="gray;
" }
}
void="" uimage::rotate(double="" degree)
{
double="" pi="3.1415926535897932384626433832795;
double" angle_rad="PI/180*degree;
double" cos="cos(angle_rad);
double" sin="sin(angle_rad);
int" center_x="width_x/2;
int" center_y="height_y/2;
int" xs;
int="" ys;
for(int="" xd="0;xd<width_x;xd++)
" for(int="" yd="0;yd<height_y;yd++)
" xs="(int)" (xd*cos-yd*sin+center_x*(1-cos)+center_y*sin);
="" ys="(int)" (xd*sin+yd*cos-center_x*sin+center_y*(1-cos));
="" if(!((xs<0)||(ys<0)||(xs="">(width_x-1))||(ys>(height_y-1))))
{
array_copy[(xd+yd*width_x)*bitDepth]=array[(xs+ys*width_x)*bitDepth];
array_copy[(xd+yd*width_x)*bitDepth+1]=array[(xs+ys*width_x)*bitDepth+1];
array_copy[(xd+yd*width_x)*bitDepth+2]=array[(xs+ys*width_x)*bitDepth+2];
}
else
{
array_copy[(xd+yd*width_x)*bitDepth]=255;
array_copy[(xd+yd*width_x)*bitDepth+1]=255;
array_copy[(xd+yd*width_x)*bitDepth+2]=255;
}
}
array=array_copy;
}
|
|
|
|
|
in what way ?
do you really need to create the array_copy when you create your object ? maybe delay it when you actually need it.
maybe put array and array_copy in private part of the class ?
when you rotate an image, me think the size of the array needs to be changed ? no ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I want to improve the code, to speed it up. I mean, perhaps using some MMX, more pointers etc to really speed the code...
The .create will only be executed once, so creating an array_copy is ok there, other functions like Threshold, Grayscale, Rotate will be called over and over again, and if i declare array_copy there will cause overhead.
Yeah, you are right, i'll put array & array_copy in private.
The size of the image need not be changed, coz anything that goes beyond the current size of the image, i will ommit.
So, how can i speed the code to be faster? Can you see any bottlenecks anywhere?
Thx
|
|
|
|
|
Nothing really stands out to me from a quick look. However, one thing you could improve - in the Rotate function the array indexes are this :
array_copy[(xd+yd*width_x)*bitDepth]=array[(xs+ys*width_x)*bitDepth];
the values (xd+yd*width_x)*bitDepth and (xs+ys*width_x)*bitDepth are computed three times per loop. You could save those into temporary variables and speed things up a bit.
Also, the code appears garbled for the loop terms. You could possibly save any factors from the outer loop so that they are not recalculated for each term of the inner loop.
These may seem minor but when they are done hundreds or thousands of times per pass they can add up.
a two cent stamp short of going postal.
|
|
|
|
|
You are right, i can cut some time there, thanks. Anything else?
|
|
|
|
|
I have one CSplitterWnd inside my CFrameWnd with 3 rows and one column. In the first two rows are two different CFormViews and in the last row is a new CSplitterWnd with 1 row and 2 columns, which contain a CFormView each. The creation works with the following code in CFrameWnd::OnCreateClient:
<br />
m_wndSplitterMain.CreateStatic( this, 3, 1 ) )<br />
m_wndSplitterMain.CreateView( 0, 0, RUNTIME_CLASS(CFunctionsDlg), size, pContext );<br />
<br />
m_wndSplitterMain.CreateView( 1, 0, RUNTIME_CLASS(CPlaylistDlg), size, pContext );<br />
<br />
m_wndSplitterBrowser.CreateStatic(&m_wndSplitterMain, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitterMain.IdFromRowCol(2, 0));<br />
<br />
m_wndSplitterBrowser.CreateView(0, 0, RUNTIME_CLASS(CDirectoryDlg), size, pContext);<br />
m_wndSplitterBrowser.CreateView(0, 1, RUNTIME_CLASS(CFilelistDlg), size, pContext);
The problem is, that I use the WM_SIZE messages within the 4 CFormViews to resize the controls, but I don't get a WM_SIZE message for the first two CFormViews (within the first CSplitterWnd), with a safe (GetSafeHwnd() != NULL) handle of the dialog controls of that CFormView. Only the last 2 CFormViews (within the second CSplitterWnd) get correct WM_SIZE messages.
Even if I call RecalcLayout( true ); from within CFrameWnd only the last two CFormViews get the WM_SIZE messages. Is that bug already confirmed by Microsoft? What is a workaround for that?
Thanks for any help!
Konrad
|
|
|
|
|
In the WM_SIZE handler for your CFrameWnd, you will need to call m_wndSplitterMain.RecalcLayout() and m_wndSplitterBrowser.RecalcLayout().
Software Zen: delete this;
|
|
|
|
|
So there is no bug in the MFC???
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Mr.Prakash wrote:
So there is no bug in the MFC???
I don't think so. I'll grant you, however, that the CSplitterWnd class is difficult to work with. I spent two days this week working on splitter-related problems in an application.
Software Zen: delete this;
|
|
|
|
|
Thanx for a good answer. but my question was sarcastic.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
I am using EnumProcesses functon in my program and also GetModuleBaseName.But its gives linker error.
error is unresolved external symbol for both this function.
|
|
|
|
|
add this in the stdafx.h
#pragma comment(lib, psapi.lib)
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
#pragma comment(lib, "psapi.lib")
(Mr. Prakash forgot the quotes)
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote:
(Mr. Prakash forgot the quotes)
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Hi
I am try to find one solution but failed ... i had treid hard but not seems to success...
Generally I had download one example from
http://www.codeguru.com/Cpp/W-P/dll/article.php/c3637
In this example One MDI application is in .dll with resouce and Resouce is displaying from Main application.
<cpp>
in .dll describe like this
#define CLSID_APP 0x10
// interface IDs
#define IID_MyIUnknown 0x1000
#define IID_IDocument 0x1001
// document constants
#define C_DOC_1 0x100
#define C_DOC_2 0x101
// instantiate an interface class object
BOOL __declspec(dllexport) App_GetClassObject(int nClsid,
int nId,
void** ppvObj);
struct MyIUnknown
{
MyIUnknown() { TRACE("Entering IUnknown ctor %p\n", this); }
virtual BOOL QueryInterface(int nIid, void** ppvObj) = 0;
virtual DWORD Release() = 0;
virtual DWORD AddRef() = 0;
};
struct AFX_EXT_CLASS IDocument : public MyIUnknown
{
IDocument() { TRACE("Entering IDocument ctor %p\n", this); }
virtual CDocTemplate* CreateDocTempl( CWinApp*, int ) = 0;
virtual void CreateFrame() = 0;
};
//end of .dll
<cpp>
in .exe calling like this
<cpp>
void CExeApp::InitDll()
{
VERIFY( App_GetClassObject(CLSID_APP,
IID_IDocument,
(void**)&pIDoc) );
}
///and
BOOL CExeApp::InitInstance()
{
InitDll();
pIDoc->CreateDocTempl(this, C_DOC_1);
pIDoc->CreateFrame();
}
also
int CExeApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call
// the base class
ReleaseDll();
return CWinApp::ExitInstance();
}
void CExeApp::ReleaseDll()
{
pIDoc->Release();
}
//end of .exe
<cpp>
So this code for loading resouce from .dll. ALl going great it's loading resouce from .dll and taking function also
But Now problem is there in .dll i have one dialog that i am displaying from .exe . SO in this dialog i want to call one function from Button1
so i have to copy my function into .dll but it's useless..
Basically i want to creat this function in .exe and calling from .dll like this
This will be in .dll
<cpp>
CDialog::OnButton1
{
CallFunctionFromexe()
}
<cpp>
This will be in .exe
CFormView::Void CallFunctionFromexe()
{
//my function
}
So i one who can understand all this say me how i do all this ?
This is some ascii work also
Dll has
Contain Resource------>One Dialog with Button1
| |
| |
| |
| Dialog::OnButton1()
| {
| callfunctionfromexe()
| }
|
|
|
exe has
Importing resouce-------->Function ::Void Callfunctionfromexe()
from .dll
SO when button1 will clicked so function will call from .exe using resouce .dll
Suggestion required !!!!!!!!
thanx
naresh
|
|
|
|
|
Hi
I am try to find one solution but failed ... i had treid hard but not seems to success...
Generally I had download one example from
http://www.codeguru.com/Cpp/W-P/dll/article.php/c3637
In this example One MDI application is in .dll with resouce and Resouce is displaying from Main application.
<cpp>
in .dll describe like this
#define CLSID_APP 0x10
// interface IDs
#define IID_MyIUnknown 0x1000
#define IID_IDocument 0x1001
// document constants
#define C_DOC_1 0x100
#define C_DOC_2 0x101
// instantiate an interface class object
BOOL __declspec(dllexport) App_GetClassObject(int nClsid,
int nId,
void** ppvObj);
struct MyIUnknown
{
MyIUnknown() { TRACE("Entering IUnknown ctor %p\n", this); }
virtual BOOL QueryInterface(int nIid, void** ppvObj) = 0;
virtual DWORD Release() = 0;
virtual DWORD AddRef() = 0;
};
struct AFX_EXT_CLASS IDocument : public MyIUnknown
{
IDocument() { TRACE("Entering IDocument ctor %p\n", this); }
virtual CDocTemplate* CreateDocTempl( CWinApp*, int ) = 0;
virtual void CreateFrame() = 0;
};
//end of .dll
<cpp>
in .exe calling like this
<cpp>
void CExeApp::InitDll()
{
VERIFY( App_GetClassObject(CLSID_APP,
IID_IDocument,
(void**)&pIDoc) );
}
///and
BOOL CExeApp::InitInstance()
{
InitDll();
pIDoc->CreateDocTempl(this, C_DOC_1);
pIDoc->CreateFrame();
}
also
int CExeApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call
// the base class
ReleaseDll();
return CWinApp::ExitInstance();
}
void CExeApp::ReleaseDll()
{
pIDoc->Release();
}
//end of .exe
<cpp>
So this code for loading resouce from .dll. ALl going great it's loading resouce from .dll and taking function also
But Now problem is there in .dll i have one dialog that i am displaying from .exe . SO in this dialog i want to call one function from Button1
so i have to copy my function into .dll but it's useless..
Basically i want to creat this function in .exe and calling from .dll like this
This will be in .dll
<cpp>
CDialog::OnButton1
{
CallFunctionFromexe()
}
<cpp>
This will be in .exe
CFormView::Void CallFunctionFromexe()
{
//my function
}
So i one who can understand all this say me how i do all this ?
This is some ascii work also
Dll has
Contain Resource------>One Dialog with Button1
| |
| |
| |
| Dialog::OnButton1()
| {
| callfunctionfromexe()
| }
|
|
|
exe has
Importing resouce-------->Function ::Void Callfunctionfromexe()
from .dll
SO when button1 will clicked so function will call from .exe using resouce .dll
Suggestion required !!!!!!!!
thanx
naresh
|
|
|
|
|
Hi everybody,
Does anybody know, how I can derive from an ATL object?
I have an ATL 3.0 project and I want to have a base class (suppose CMyBase) with some members, and an interface (suppose IMyBase) with some exposed methods and properties. how do I create a new ATL object that is derived from that class? I mean that the new ATL object inherits members from CMyBase and methods and properties from IMyBase.
Regards,
Roozbeh.
|
|
|
|
|
First create the IBaseClass with pure virtual functions of your methods that you want to be derived.
Create another class CBaseClass and inherite it from IBaseClass and implement the methods and functions.
Now create a new simple ATL object, and in the list of inheritances, also include this CBaseClass.
Now you need to add and implement the interface methods that is exposed to the world.
If you are thinking of inheriting one COM object from another, then its not possible.
Hope i got your question right.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Hi;)
I'm still a beginner in vc++,me and my friends are devolopeing a network app.(instance messanger),and I need your help at the following topics:
1-making an edit box transparent.
2-creating a menu at a dialoge based app.
3-creating apopup menu.
4-adding a bitmap to a button with it's states.
note:
the project I'm working in is educational one.
finally thank you for your time.
Hatem M Nassar
|
|
|
|
|
I dont know about the first one but you will get the solutions for the others if you try search using the search option here in CP. Or navigate according to the requiremets from the mainpage.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
I have a couple global variables that I would like to use in more than one file. What I want to do is delcare the variables in one file and then be able to access them from other files/classes. So for example if I set the value of the variables in file1 I want to be able to retreive those values from the variables in file2. I thought I could do this with "extern", but I can't figure out how. Any help would be appreciated. I tried this
extern TCHAR* var1;
extern TCHAR* var2;
extern TCHAR* cvar1;
extern TCHAR* cvar2; When I compile that though I get an error that the variable has an illegal storage class.
- Aaron
|
|
|
|
|
file1.cpp
TCHAR* cvar1;
...
void somefunc()
{
cvar1 = new char[60];
....
}
-----------------------------------
in common.h
extern TCHAR* cvar1;
....
-----------------------------------
file2.cpp
#include "common.h"
....
void someanotherfunction()
{
printf("%s",cvar1);
}
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Hi,
I have a question about the thread issue on the string class. If you do the following, would you need to put a lock around the string code?
Void ThreadFunc()
{
// Only created in each thread, not global.
String strStuff;
While (1)
{
// Do I need to put a lock around this call?
strStuff = “Hello”;
}
}
Void main (void)
{
Thread hThreadStuff[3];
For ( int I = 0; I < 3; ++i)
hThreadStuff [i] = CreathThread(…, ThreadFunc, …);
hThreadStuff.WaitonExit();
}
Thanks in advance,
Ken
|
|
|
|
|
Since strStuff is declared inside the thread routine, each thread would have their own copy. Thus, no locking is required. However, if strStuff was declared outside the routine, then you would need to place a lock around the assignment or any time you where fetching the value of the string.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|