|
Doesn't surprise me. I did the same thing with a similar algorithm several years ago and saw less of a gain. My biggest gain was by using GDI+ instead.
|
|
|
|
|
It is a question that can't be answered. The problem is that you can get a 15-20% speed increase with assembler on either a good or bad algorithm.
Post the algorithm.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Joe gave me the kind of answer I was looking for. I wasn't looking for help to optimize my code...just feedback from people who have done similar things. Thanks for your reply.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
I would assume that this is a memory-intensive process in that you need to have the 'source' and 'destination' bitmaps present at the same time. My guess is you need to work the algorithm such that you're not thrashing the CPU cache each time you access the bitmaps.
In our application (ink jet printers), where we generate massive bitmaps, we've found proper cache usage to be critical. The performance difference between a cache hit per pixel and a cache hit per scan line can be an order of magnitude or better.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote:
I would assume that this is a memory-intensive process in that you need to have the 'source' and 'destination' bitmaps present at the same time.
yes...it does this pixel by pixel. it finds 4 source pixels for every destination pixel (based on the scale transformation) so it can interpolate four colors (RGBA) to come up with the destination pixel. it interpolates in each direction x, y. this requires that I find adjacent pixels on two rows and two columns that bound the calculated source pixel location.
I suspose that if I did linear interpolation, instead of bi-linear, and just dealt with a row at a time it would be faster...just don't know how it would look.
I don't know if this makes sense...it's not that complicated, just hard to explain. If you have a better approach I would like to see it.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
It's not so much the fact that you've got the entire bitmaps in memory at one time, it's how you access it. If you can access it in a fashion that avoids cache misses, which force expensive cache flushes and refills, that improves performance. Typically, you want to access memory through consecutive addresses, 'skipping about' as little as possible.
For your example, let's assume that each pixel in a row occupies consecutive memory addresses. In that case, you want to work within a row as much as possible, and change rows only when you have to. If you went column by column instead, you would have cache misses on almost every pixel reference, which would hamper performance.
(brief pause while I Google bilinear interpolation)
Assuming I understand what bilinear interpolation does, if you keep pointers to a preceding row, current row, and a next row, and increment them down the row, this avoids the cache misses that would occur if you went column by column.
I'm not sure if this helps. Good luck.
Software Zen: delete this;
|
|
|
|
|
I need to traverse the tree with the output function and send its data or the tree over to the List class to be inserted into a List. I am having problems implementing the arguments to be passed in the functions treeNode::Output and List::insertNode. Can somebody give me some ideas. Thanks.
Here is my code:
#include <iostream>
#include <string>
#include "List.h"
using namespace std;
class treeNode
{
string name;
treeNode *smaller, *bigger;
public:
treeNode(string newName="", treeNode *newSmaller=NULL, treeNode *newBigger=NULL)
{
name=newName;
smaller=newSmaller;
bigger=newBigger;
}
void add(string newName)
{
if(newName<name)
{
if(smaller==NULL)
smaller=new treeNode(newName);
else
smaller->add(newName);
}
if(newName>name)
{
if(bigger==NULL)
bigger=new treeNode(newName);
else
bigger->add(newName);
}
}
void output(List &l)
{
if(smaller!=NULL)
smaller->output(l);
l.insertNode();
if(bigger!=NULL)
bigger->output(l);
}
};
void main()
{
List l;
treeNode t;
string newName;
int howMany;
cin >> howMany;
for(int i=0; i<howMany; ++i)
{
cin >> newName;
t.add(newName);
//l.insertNode(treeNode *t);
}
t.output(l);
//l.outputList(cout);
}
#include <iostream>
#include <string>
#ifndef LIST_H
#define LIST_H
using namespace std;
struct node
{
string data;
node *next;
};
//Linked List class
class List
{
node *first;
public:
List()
{
first=NULL;
}
void insertNode()
{
node *p;
cout << newName << endl;
p=new node;
p->data=newName;
p->next=first;
first=p;
}
void outputList(ostream &out)
{
node *p;
p=first;
if(!empty())
{
while(p!=NULL)
{
cout << p->data << endl;
p=p->next;
}
}
else
cout << "The list is empty!" << endl;
}
bool empty()
{
if(first==NULL)
return true;
else
return false;
}
};
#endif
|
|
|
|
|
|
i think i fixed it. Sorry, I never come here and didn't know about those <pre> tags and stuff.
|
|
|
|
|
I need to traverse the tree with the output function and send its data or the tree over to the List class to be inserted into a List. I am having problems implementing the arguments to be passed in the functions treeNode::Output and List::insertNode. Can somebody give me some ideas. Thanks.
Here is my code:
<pre>#include <iostream>
#include <string>
#include "List.h"
using namespace std;
class treeNode
{
string name;
treeNode *smaller, *bigger;
public:
treeNode(string newName="", treeNode *newSmaller=NULL, treeNode *newBigger=NULL)
{
name=newName;
smaller=newSmaller;
bigger=newBigger;
}
void add(string newName)
{
if(newName<name)
{
if(smaller==NULL)
smaller=new treeNode(newName);
else
smaller->add(newName);
}
if(newName>name)
{
if(bigger==NULL)
bigger=new treeNode(newName);
else
bigger->add(newName);
}
}
void output(List &l)
{
if(smaller!=NULL)
smaller->output(l);
l.insertNode();
if(bigger!=NULL)
bigger->output(l);
}
};
void main()
{
List l;
treeNode t;
string newName;
int howMany;
cin >> howMany;
for(int i=0; i<howMany; ++i)
{
cin >> newName;
t.add(newName);
//l.insertNode(treeNode *t);
}
t.output(l);
//l.outputList(cout);
}
#include <iostream>
#include <string>
#ifndef LIST_H
#define LIST_H
using namespace std;
struct node
{
string data;
node *next;
};
//Linked List class
class List
{
node *first;
public:
List()
{
first=NULL;
}
void insertNode()
{
node *p;
cout << newName << endl;
p=new node;
p->data=newName;
p->next=first;
first=p;
}
void outputList(ostream &out)
{
node *p;
p=first;
if(!empty())
{
while(p!=NULL)
{
cout << p->data << endl;
p=p->next;
}
}
else
cout << "The list is empty!" << endl;
}
bool empty()
{
if(first==NULL)
return true;
else
return false;
}
};
#endif</pre>
|
|
|
|
|
Hello
I have a RichEdit and a multiline edit in my app. What is the simplest and easiest way to change word-wrap of the edit controls during run-time of app?
Thanks in advance.
|
|
|
|
|
I don't know whether you're still out there, but if you are: look up EditWordBreakProc in MSDN. You can define a callback which sets up a different word wrap routine for an edit. I might be posting an article on this since I think there's a bug with the word wrap in XP-themed edits.
|
|
|
|
|
I am just learning how to use C++. I'm trying to create a simple program to do the following: A) allow the user to enter 2 integer values, B) determine the sum of all values between x & y, C) to show the product of x and y.
My code for steps A & C is working. My code for step B is not, I think I'm making it much more complicated then is required. Here is the sample code:
/* Write a program to find the sum of the integers between x & y. You
are then
to find the product*/
#include <iostream>
using namespace std;
int main ()
{
int x, y, z, s, p, h, sum;
s = 0;
sum = 0;
cout << "Please enter two integers" << endl;
cin >> x >> y;
p = x; //p is a place holder for the value x
z = x*y; // calculate the product
while (s <= y)
{
s = ++ x; // increment x by 1
h = p+s; // calucate the value of p + h
sum +=h; // compile the sum
cout <<"p = " << p << ". s = " << s << ". h = "<< h << endl;
}
cout <<"The product of " << p << " * " << y << " is "<< z << endl;
return 0;
}
Pam
|
|
|
|
|
There's a story that Gauss was asked along with his class to sum the numbers from 1 to 100. He blurted out 5050, explaining that there were 50 pairs of numbers that added to 101 (1 + 100, 99 + 2, etc).
Not so easy if the number of integers is not even, but should help.
If I've just given away the answer I'm sorry - but hey, you can still get fancy with the details!
|
|
|
|
|
The rule works for even and odd values of x.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
For values greater than 0, the sum of all integers between 1 and n can be computed as n(n+1)/2.
Now for your specific problem, we want to compute the sum of all integers between x and y. This can also be expressed as the sum of all integers between 1 and y minus the sum of all integers between 1 and (x-1). So the final answer would be...
result = y(y+1)/2 - (x-1)x/2
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Finding the sum of the numbers between two integers can be done as follows:
int i = x + 1; // we start counting 1 higher then x
// or make this i = x if you want to include x
int sum = 0;
while (i < y) { // repeat while we haven't reached y
// or make this i<=y if you want to include y
sum = sum + i;
i++;
}
voila.
or shorter:
int sum = 0;
for (int i=x+1;i
|
|
|
|
|
I have the following class:
class BaseClass {<br />
static char* wp;<br />
<br />
void Dynamic(char* s) {<br />
this->wp = s;<br />
}<br />
}
and a derivative:
class Derived : public BaseClass {<br />
}
Basically, what I want to accomplish is this: I want to reference the static member wp of the derived class in the inhereted function and reference the BaseClass member in the Baseclass function
so..
BaseClass *bc = new BaseClass();<br />
Derived *d = new Derived();<br />
<br />
bc->Dynamic("something");<br />
d->Dynamic("something else");
After this code, I want bc::wp != d::wp, but alas, bc::wp == d::wp == "something else". I would LIKE to have bc::wp == "something" and d::wp == "something else".
Anybody have any clues as to how I might realise this? And yes I do realise I could make them non-static, but I am interested in a way of doing this... if at all possible.
|
|
|
|
|
If you want the derived class to have its own, separate copy of the static member,
you have to declare it in the derived class. Then, you also have to implement Dynamic() in the derived class so it refers to the derived class' static member and not the base class' static member.
|
|
|
|
|
Can I create a CWnd* class from an DLL that is loaded at runtime and the use it.
Like this.
I have a tabview in my program that takes CWnd* objects.
And say that the user select something and then a DLL is lunched ( a plugin )
And all Plugin DLLs have a function call CreateObject(). It calls it and returns a CWnd* object.
The main program don’t know anything about the object except that it’s a CWnd* object
Now.
Can I just take this object and threat it as any other object ?
What restriction are they?
Do I need to do some special stuff to make it work?
What I understand is that I need to let the DLL also take care of
the deleting of the object, since it create it. Is that correct ?
/Mathias
|
|
|
|
|
I have a object that I created that is derived from CWnd. In my SDI
application with a CFormView, I have created the object. (Draws a box on the
form) Now I would like the object to handle the left mouse down event. I
added the left mouse button down event to my object. But how do I ??? so
that my object receives the left mouse down event when a user clicks on the
object? (box)
Thanks
|
|
|
|
|
MFC sure can be confusing.........
When would you use OnPaint() instead of OnDraw() for drawing in an MFC application?
Should on be used in a dialog and the other used in a doc/view app?
|
|
|
|
|
Well, OnPaint() calls OnDraw() . I think OnDraw() is specific to views, whereas OnPaint() is for repainting in general.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I want to change the background color of the Combo box with drop down style.
I tried doing it using WM_CTLCOLOR message code. however it works for all edit boxes and combo boxes of style list box and not for the drop down.
kindly advise on this.
|
|
|
|
|
How i can convert a CString to LPCTSTR?
I can't found an easy solution for this. Please give a help.
Thank's bros.
|
|
|
|