|
Jomy John wrote:
ie how an image will be stored on the hdd..it seems there is an algo for that ..that applies to all types of images
Sorry, but you MUST still be confused. How an image is stored depends on the format, and is common to all image types only in that, at the end of the day, it's all a bunch of 1s and 0s. There's a variety of compression algorithms used in image formats, but no common one. BMP is one that is not compressed at all.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
No..im just quoting the stuff my project guide has said ...
Like he gave me an example was : When u open a paint application ...draw sumthing in it ..and the "Save As" option gives options to save as a number of file options ..
So , there has to be a general algo that applies to all ..
Sadly, he had read it in a book ,6-7 yrs back...hehee..whose name he cant recall
|
|
|
|
|
Jomy John wrote:
When u open a paint application ...draw sumthing in it ..and the "Save As" option gives options to save as a number of file options ..
Yes, there are options. And for each one, the image is encoded differently, that's what makes them options
Jomy John wrote:
So , there has to be a general algo that applies to all ..
Bollocks. The only thing that is general is that you need to use a disk API to write the files, and you need in every case to access the bits of the image, which would generally mean you used a DIBSection, which in turn means you have a pointer to the bitmap. The only algorithm I can thing of is how you traverse those bits.
Jomy John wrote:
Sadly, he had read it in a book ,6-7 yrs back...hehee..whose name he cant recall
How in the HELL can he test you on something he 'read in a book 7 years ago' ? If he does not know the answer, if he does not have, or cannot produce a solution, how will he mark yours ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I really dont know what to do or say
|
|
|
|
|
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 ??
|
|
|
|