|
Assuming that the JPEG is decoded and that you have a raw RGB888 (24 bpp) DWORD-aligned stream:
- Get a pointer to the first
DWORD , pPixel . - Assign the color componenent values of that pixel to a
COLORREEF , color = *pPixel . - Multiply the RGB components to get the intensity (assuming that is the intensity definition...),
intensity = GetRValue(color) * GetGValue(color) * GetBValue(color) . - Store the pixel id and its intensity somehow (defined by you),
StorePixelIntensity(id, intensity) . - Continue to the next pixel,
++pPixel . - Goto 1 if there are more pixels.
--
The Blog: Bits and Pieces
-- modified at 2:05 Wednesday 21st September, 2005
|
|
|
|
|
i have to code purely in C++ ...!!!
newes ..using Sir Johann 's method is gud..assuming thats the right defn of intensity ....
Anuther thing one of my friends suggested ..was to convert to gray scale ..and check for similar intensity ...
Will that be rite ?
And all i have with me in C++ , for RGB color extraction is getpixel() ...how do i process my Jpeg file using getpixel as its just returning me single integer values ....
That is ...
int c = getpixel(0,0)
cout << c ;
gives me not the typical 32 bit value ...but a single 0
and a series of sets of 0's and 7's when tried for the entire file !
How should i continue ?
Thanks
Jomy
|
|
|
|
|
My question is about pointers to pointers. A book I’m using to teach myself C++ uses a function whose first argument is a pointer to a pointer and receives the address of the root pointer into that binary tree class insertion function. It says that it uses the pointer to a pointer in order to modify the pointer's value. In general, why would one ever have to use a pointer to a pointer, instead of just passing the pointer itself? It just seems like a needless extra step to me.
The code is posted below:
template< class NODETYPE>
void Tree<nodetype>::insertNode(const NODETYPE &value)
{
insertNodeHelper( &rootPtr, value);
}
template< class NODETYPE>
void Tree<nodetype>::insertNodeHelper( TreeNode< NODETYPE> **ptr, const NODETYPE &value)
{
if(*ptr == 0)
*ptr = new TreeNode< NODETYPE> (value);
else
if (value < (*ptr)->data)
insertNodeHelper(&((*ptr)->leftPtr), value);
else
if (value >(*ptr)->data)
insertNodeHelper(&((*ptr)->rightPtr), value);
else cout << value << " dup" << endl;
}
Any help or insight would be greatly appreciated.
|
|
|
|
|
passing pointer to any function passes copy of that pointer. It will give problem when you change the variable it is addressing.
Good article is present on CP,which has explained with example the problem.
http://www.codeproject.com/cpp/PtrToPtr.asp#1[^]
|
|
|
|
|
There are also a lot of techniques in which you may pass processing to one of a set of functions by means of a switch statement. If you have an array of function pointers you could simply pass to that offset in your array of pointers.
There's also ease of adding a new function to that list where all you need to do is add an extra switch statement and the pointer into the array.
|
|
|
|
|
Normaly you try to write your code so that passing a pointer to a pointer is not needed, but some times it is needed.
int alloc_type(NODE** ptr)
{ return( (*ptr=(NODE*)malloc(sizeof(NODE)) != (NODE*)0) ); }
somefunc()
{
NODE* ptr = (NODE*)0;
if( alloc_type(&ptr) )
}
What the provided code is doing:
1) The first time insertNodeHelper is called, rootPtr is null, so it just allocates a new node. That is, rootPtr now points to a node.
2) The second time insertNodeHelper is called it recursively calls itself to allocate/add a new leaf node. The recursive call has no effect on the rootPtr.
3) See (2).
The code you provided is a good example of when you might use a pointer to a pointer as an argument. It is very creative and provides a simple solution for what could be a difficult problem.
I do not know if a latter example shows you how to remove the recursive call, but there should be one. If not, consider it your next assignment.
INTP
Every thing is relative...
|
|
|
|
|
Can someone please tell me how the following is possible?
How is it possible to cast a LeafTrieNode pointer to a "NonLeafTrieNode" pointer, like this?
<br />
p->ptrs[pos] = (NonLeafTrieNode*) new LeafTrieNode(suffix);<br />
The program works like this, but I don't know how it works, because "LeafTrieNode" isn't derived from "NonLeafTrieNode"
<br />
"lieaftrienode.h"<br />
<br />
#ifndef LEAF_TRIE_NODE_H<br />
#define LEAF_TRIE_NODE_H<br />
<br />
class LeafTrieNode<br />
{<br />
public:<br />
LeafTrieNode(){};<br />
LeafTrieNode(char*);<br />
<br />
private:<br />
bool leaf;<br />
char *word;<br />
friend class Trie;<br />
};<br />
<br />
#endif<br />
<br />
"nonlieaftrienode.h"<br />
<br />
#ifndef NON_LEAF_TRIE_NODE_H<br />
<br />
#define NON_LEAF_TRIE_NODE_H<br />
<br />
class NonLeafTrieNode<br />
{<br />
public:<br />
NonLeafTrieNode(){};<br />
NonLeafTrieNode(char);<br />
<br />
private:<br />
friend class Trie;<br />
<br />
NonLeafTrieNode **ptrs;<br />
char *letters;<br />
bool isLeaf;<br />
bool endOfWord;<br />
};<br />
<br />
#endif<br />
-- modified at 9:54 Monday 19th September, 2005
|
|
|
|
|
Hi,
Simple answer is the same way you can cast anything else with a pointer. A pointer just points to memory, hence it can be made to "think" that it is pointing to a different object type.
The new creates a pointer of type LeafTrieNode , and the cast works because you are allowed to change a pointers type.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Hi Rich,
I'm just pondering how his compiler is allowing the cross reference from one object pointer to the other unless p-> is of void that, yes just points to raw memory space by which he will need to not only delete the pointer but reclaim the memory space as well or get a memory leak.
|
|
|
|
|
Hi VaporTrace,
It is just a cast. Any pointer can be cast into any other pointer. The fact that they are unrelated is the programmers fault. Yes you would get a memory leak if you deleted the pointer as is, but the programmer caused the problem not the compiler. Take the situation:
class A {};
class B {};
A *castme = (A *) new B();
The compiler just makes castme point to the memory irrespective of the pointers original type. Remember C/C++ is not type safe so you are allowed to do things like this. Ask yourself how void pointers are created. They need to be a pointer of some type before they become a void pointer; you would have had to cast it to a void pointer first.
Hope this explains it better.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Duh yup,
When you simplify, it's painfully clear as A* = A* to new object as:
NonLeafTrieNode **ptrs = (NonLeafTrieNode*) new object; I think you know what I'm trying to say rather that ptrs[x].
That this pointer -> just kept saying "I'm in a mystery object" which doesn't matter.
Err. Hate it when that happens.
-- modified at 1:50 Tuesday 20th September, 2005
Ya know this dumb thing kept buggin me so I went to my compiler and guess what? It worked! But it still kept bugging me since this is not a normal thing I would try so I thought outside of the obvious why havn't I tried this just for the stupidity of it.
Then I thought.
class A{};
class B{
public:
int j;
};
int main (int argc, char* argv[]){
A* newptr = (A*) new B;
newptr->j=5;
return 0;
}
Ya, I was a bit suprised when it let me do the initial
A* newptr = (A*) new B;
because it just doesn't feel right.
Guess I'm too methodical.
|
|
|
|
|
But you will probably find that you corrupted memory by doing the newptr->j=5; I agree this is not normal programming practice and no-one really does it unless there is a very good reason.
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
I can't see that it would with what you have displayed because there's alot missing to a completed and running example.
What exactly is p-> ?
If p is a member of a child class of both or a trianglular reference to a void parent member not listed, I could see where your compiler may confused.
Either way, it looks like you are opening up to a memory leak.
|
|
|
|
|
A general observation: Don't use C-style casts for non-PODs in C++. They make it far too easy to cast a mountain to hollandaise sauce.
--
The Blog: Bits and Pieces
-- modified at 1:55 Wednesday 21st September, 2005
|
|
|
|
|
By the by, Johann, what is a POD??
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Oh, sorry. POD = Plain Ol' Data, int s, double s and such goodies.
--
The Blog: Bits and Pieces
-- modified at 17:18 Saturday 24th September, 2005
|
|
|
|
|
hi,
im trying to download a file with :
InternetReadFile [B]or[/B] URLDownloadToFile.
i did succeed to work with those functions - [B]BUT![/B] i want to download from the server and not use the cache files.
i did tried to add some flags of no cache use but with no success.
anyone got any inlights?
Avi.
visit me at www.laviadlab.com
|
|
|
|
|
Hi,
Have you tried DeleteUrlCacheEntry to get rid of the actual url, so it has to download the url again?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Hello All,
Say, is there anything akin to a family tree app for classes and their inheirited children, typedef class template wanta be's, etc.? Flippping back and forth between declarations and definitions, tracking back 4-12 levels of header files leaves me wondering what it was I trying to figure out to begin with.
There's got to be a better way.
So is there any open source that will show visual relationships? Even a plain text outline would be better than my strained brain cells.
Or do I have to take yet another deviation from my destination and write one myself?
Thnks
|
|
|
|
|
I've got a problem. I'll get input to my program and I have to determine which type of data that is. Input will occur in a text file and will look similar to this:
<br />
Add: 41.4 51.8 48.4 22.1<br />
Delete: 84.1 57.4 15.1<br />
etc....<br />
The problem is I have to determine the type of the data that needs to be added to the tree.
The tree is a template class.
I want to know code that could do the same as the following is supposed to do:
<br />
typedef T;<br />
T = int of T = double;<br />
AbstractTree<T> *tree = new BTree<T>;<br />
I then want to use type T in the rest of my program. etc.
AbstractClass<t> *tree = new BTree<t>;
I need this for a project that needs to be in on Monday 20:00(GMT)
Your help will be greatly appreciated.
Thanks alot
|
|
|
|
|
You need something to parse your input with like a char str and extract your numerical into a double. int doesn't do decimal so how do you know if a decimal is in your input?
It's a text file input so it's automatically a char going in. atof() and isalnum() would be my first thought or get out your ASCII table if you want to build your own smarter atof() to parse your entire input line at a time.
I don't know of anyone that wants to just hand you an answer to copy.
Remember the basic purpose of a template it to reduce redundant code differing only in parameter type, allowing the same call with different types.
But then again maybe I'm not understanding what you are doing, like are you pulling the entire input file into a buffer or are you grabing input by keyword, space, line ??
|
|
|
|
|
I'm grabbing input word by word.
instead of coding:
<br />
if (input is numeric)<br />
if (input contains '.'){<br />
AbrstrackTree<double> *p = new BTree<double>();<br />
AbrstrackTree<double> *p = new BStarTree<double>();<br />
AbrstrackTree<double> *p = new BPlusTree<double>();<br />
AbrstrackTree<double> *p = new Trie<double>();<br />
}<br />
else {<br />
AbrstrackTree<int> *p = new BTree<int>();<br />
AbrstrackTree<int> *p = new BStarTree<int>();<br />
AbrstrackTree<int> *p = new BPlusTree<int>();<br />
AbrstrackTree<int> *p = new Trie<int>();<br />
}<br />
<br />
if (input is char*){<br />
AbrstrackTree<char> *p = new BTree<char>();<br />
AbrstrackTree<char> *p = new BStarTree<char>();<br />
AbrstrackTree<char> *p = new BPlusTree<char>();<br />
AbrstrackTree<char> *p = new Trie<char>();<br />
}<br />
I want to do something similar to:
<br />
typename int T;<br />
AbrstrackTree<T> *p = new BTree<T>();<br />
AbrstrackTree<T> *p = new BStarTree<T>();<br />
AbrstrackTree<T> *p = new BPlusTree<T>();<br />
AbrstrackTree<T> *p = new Trie<T>();<br />
I'm trying to find out if there's a way of changing the type of T at run-time
|
|
|
|
|
So you're trying to ring my bell because now you are creating ambigious function pointers.
|
|
|
|
|
As far as I can remember once a type is defined that's it. The compiler does the conversion from T to int/double/long/etc. So at run-time there is no T, it as become a known integral type so you can't change it.
Also your code above is really strange and does not make much sense. But I really don't get what the real problem is. If you define T as double (as per VaporTrace) then you can set it as an integer or decimal from your input.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
The problem is that the input I an getting can be of any basic data type....int, double,char..etc
My data-structure is using templates that is been made at compile-time, but I need the type to change in real time. I think there is a way to do it using a derived class of the template class, but I can't seem to figure it out.
I'm sure many people had the same problem before with something like using a STL vector or list, and not knowing what type of data will be stored in the vector, at compile time.
Please help!!
I hope I explained my problem clearly.....?
|
|
|
|