|
The width of the bitmap is in pixels (DWORDs)
and your buffer is in BYTEs ...
PS: You can use all GDI functions in the memory-DC as well.
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
modified 14-Aug-12 3:29am.
|
|
|
|
|
Thanks so much for the quick reply. You are a lifesaver! (Or... at least a sleep saver.)
|
|
|
|
|
A good advice for the future: The size in bytes occupied by one row of pixels in memory is called stride. Its important that in bitmaps stride is always a multiple of 4 bytes. In your cases this condition is true in all cases regardless of the bitmap width because 1 pixel occupies 4 bytes. But for example in a 8 bit bitmap (256 colors) with width==3 the stride would be 4 bytes regardless of the actual size being 3 bytes, there would go 1 byte extra padding.
stride = ((width * bits_per_pixel + 31) >> 3) & ~3;
|
|
|
|
|
|
|
Hi Guys
I have designed a digital controller in matlab. The continuos s domain controller is as follows:
1.16e006 s^2 + 6.287e006 s + 2.436e006
--------------------------------------
s^2 + 10 s
The discretised z domain version (with a sampling rate of 100Hz) is as follows:
1.16e006 z^2 - 2.26e006 z + 1.1e006
-----------------------------------
z^2 - 1.905 z + 0.9048
Now i have managed to program this in C++ and it "sort of" works. However the code is by no means optimal and therefore does not execute as quickly as it should. The code basically looks like this:
float SpeedDemand;
float SpeedError;
float MeasuredGeneratorSpeed;
float y;
float numcoeff[3];
float dencoeff [3];
numcoeff[0] = 1160000;
numcoeff[1] = -2260000;
numcoeff[2] = 1100000;
dencoeff[0] = 1;
dencoeff[1] = -1.905;
dencoeff[2] = 0.9048;
static float xprevious[3];
static float yprevious[3];
SpeedError = MeasuredGeneratorSpeed - SpeedDemand;
xprevious[0] = SpeedError; y = xprevious[0]*numcoeff[0];
y += ((xprevious[1]*numcoeff[1])+(xprevious[2]*numcoeff[2])-(yprevious[1]*dencoeff[1])-(yprevious[2]*dencoeff[2]));
xprevious[2] = xprevious[1]; xprevious[1] = xprevious[0];
yprevious[2] = yprevious[1];
yprevious[1] = y;
Where xprevious[],yprevious[] are arrays that i define earlier in the program. They are used to store the previous input and output values. X is the input and Y is the output. The numbers stored in the numcoeff[] and dencoeff[] arrays correspond to the coefficients in the z domain transfer function shown at the top. Is there a faster way to do this calculation in c++, perhaps by using a circular queue!!??. Unfortunately my programming knowledge is not great(I'm a Matlab guy). If there is a better way to do it that would speed up the calculation perhaps someone could give me an eample of how to do it. By the way all the variables and arrays are floating point. Any help or advice would be much appreciated.
Many Thanks
Ben
modified 14-Aug-12 5:16am.
|
|
|
|
|
that looks pretty straightforward. i doubt a circular buffer is going to give you much improvement - you're just copying some floats around, after all. no matter where they reside or how you abstract your data structure (array, circ buffer, etc), you're still copying floats.
you could probably speed it up a bit using vector processing - execute those four multiplications in one call. you could do the addition/subtraction in one call, too. search here for "SIMD" or "SSE". though that stuff might look a little scary, if you're coming from MatLab...
modified 13-Aug-12 15:35pm.
|
|
|
|
|
Chris Losinger wrote: might look a little scary, if you're coming from MatLab...
just very-little bit scary
|
|
|
|
|
Introduction to SSE Programming [here].
Fast SIMD Prototyping [here].
Matrix/Vector Multiplication Optimization [here].
|
|
|
|
|
Hi,
would anyone know if there is any kind of plug-in to the Visual studio debugger which tracks heap storage
Thanks
|
|
|
|
|
Are you looking for memory profiling tools?
If affirmative, you can have a look at Purify Plus etc.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
I have been using CMemoryState
|
|
|
|
|
I would like to know a way to change the view of a particular pane in a splitter window.
It should be something like an explorer window. Where on click of any tree branch on left side of window right hand side view updates.
Similarily i would like to update my view. On click of any tree node a new pane should be displayed at the same position overriding the previous pane.
sample code would be highly appreciated.
|
|
|
|
|
There are lots of samples of code such as you describe; take a look in the articles section[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
these examples describe how to use a tree control.. what i want is to update the SPLITTER pane with a new view on click of any tree item..
|
|
|
|
|
Rishav Prabhakar wrote: what i want is to update the SPLITTER pane with a new view on click of any tree item.. Then you need to handle the notifications from the TreeView [^] side and take some action, like redrawing the window in the other pane, when the selection changes.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
HI,
Is there any API available to Pan a window, as we can in autocad/pdf file/Pro-e.
If not, how pan a window using C++ code.
Regards,
Maha
modified 17-Aug-12 2:22am.
|
|
|
|
|
What do you mean on panning? Moving? Or scrolling the contents of the displayed stuff?
modified 13-Aug-12 10:36am.
|
|
|
|
|
Yes, just need to move content and not the window.
|
|
|
|
|
There is an article about that right [here].
|
|
|
|
|
I want to pan the client area using left button of mouse. As one that works with PDF file.
And i want to implement this using MFC/WIN32
-Thanks in advance.
|
|
|
|
|
I guess I know what you mean: You press down the pan mouse button while the cursor is over the view and then you pan by moving the mouse cursor until you release the pan mouse button. This panning basically scrolls the visible portion of the stuff you can see in your view. There is no API to do that, you have to implement it by yourself by handling primitive mouse events like mouse button down, mouse move, and mouse button up events. Custom implementation makes sense because its totally dependent on the program which parameters should be modified by the panning operation.
In a 2D pdf viewer the program stores some position data about which part of the pdf should be drawn to the view. This position is changed when you are panning. In a 3D CAD program there is a 3d world in which you can find an active camera as well with a position and rotation parameter (and also with horizontal and vertical fov). This camera is used by the rednerer to decide which part of the world should be rendered, the camera is like an eye and you see in the view what this eye looks at in the 3d world. This camera has an up and right direction that defines a plane. When you pan with your mouse you basically calculate a 2D offset from the mouse movement and you add this 2D offset to the camera position on the plane that is defined by the up and right vectors of the camera rotation (maybe not right but left if you are using left handed coordinate system...). Even if you are not good at 3D, the answer to your question is: Those pan functions are implemented by those programs, its custom code in them and not some operating system provided api function calls.
How to implement panning: When panning starts (mouse button down) you store the actual pan-start position of the mouse cursor, and also the position value (the 3d cam pos, or the 2d pos in the pdf file) in your program to some variables that wont change during panning. When a mouse move event comes you always calculate the delta between the pan-start mouse pos and the current moved mouse cursor pos, and you use this 2D offset to calculate the pan offset in your world (you can leave it as it is, or any simple transform can do the job, for example multiplying it with something to set panning speed...). When you have your pan offset you add the resulting pan-offset to the stored pan-start position and set the result as the current position.
The panning operation is a kind of dragging operation so you should consider implementing it with correct mouse capturing: Using SetCapture() and ReleaseCapture() correctly (usually during a drag n' drop operation).[^]
Omitting mouse capture is not the end of the world, but try to be always perfect when possible!
|
|
|
|
|
Hello!!
Thank you very much for all your reply.
Mr pasztorpisti - Thank you much for detailed explanation. I will try to implement this and let you know about the same.
-Maha
|
|
|
|
|
|
HI Pasztorpisti,
What the code you have give is to move the window, but what i need to move the client area.
I know if there is a api to capture the client area and move it.
Regards,
Maha
|
|
|
|