|
Can you explain what you're trying to do more clearly? I'm not sure what you're asking.
Steve
|
|
|
|
|
Hi,
I am reading some image data out of a camera pixels and have extracted the raw pixel intensity. Each "pixel" on the Camera sensor has either a R,G, or B filter that gives the intensity of the 'R', 'G', or 'B' 'pixel'. I read this data and then extract and store the individual R, G, or B pixel intensities into 3 separate 2d unsigned char arrays called m_ptrRed2DPostDecimationArray. m_ptrGreen2DPostDecimationArray, and m_ptrBlue2DPostDecimationArray. Now I can use SetPixel to display the extracted R, G, and B in 3 separate 'R', 'G', or 'B' window areas. I can display them either in color or grayscale through:
For grayscale: dc.SetPixel(j, i, RGB(theApp.m_ptrRed2DPostDecimationArray[i][j], theApp.m_ptrRed2DPostDecimationArray[i][j], theApp.m_ptrRed2DPostDecimationArray[i][j]));
For color: dc.SetPixel(j, i, RGB(theApp.m_ptrRed2DPostDecimationArray[i][j], 0, 0));
However, I realize SetPixel is very ineffecient so looking at other ways to display. I only need the 8 bit grayscale image so was hoping that I could achieve it using CreateBitmap. m_ptrRed2DPostDecimationArray is a BYTE array (actually unsigned char) that holds the 8 bit raw pixel intensities from the camera pixels that have a red filter on them. Here is my current code (that does not work):
void CVC_ExampleDlg::OnPaint()
{
CDC *pDC = GetDC();
BOOL retval = m_redBitmap.CreateBitmap(600, 200, 1, 8, theApp.m_ptrRed2DPostDecimationArray);
CDC memDC;
memDC.CreateCompatibleDC(pDC);
memDC.SelectObject(&m_redBitmap);
retVal = pDC->BitBlt(0, 0, 600, 200, &memDC, 0, 0, SRCCOPY);
memDC.DeleteDC();
ReleaseDC(pDC);
CDialog::OnPaint();
}
Now I know I can create a grayscale palette and use the raw data as an index to that palette but it seems to me that CreateBitmap has that built in functionality. I mean it seems like that when I give it 1 color plane and 8bpp, it should automatically create a grayscale 8bit bitmap, no?
Can anyone see what I'm doing wrong. I mean all I want is that I already have the pixel intensity from 0-255 (8 bit) in a byte array. Since I just only want a grayscale bitmap, creating a grayscale palette and indexing it seems overkill especially when CreateBitmap seems to (theoretically) encapsulate that functionality.
I guess, if my question is clear enough, what is the easiet and/or most efficiect way to create a 8bit grayscale image from the raw pixel intensity value from 0-255?
Thank you,
-Vivek Kinra
|
|
|
|
|
You should be looking at creating a DIB using CreatDIBSection() and SetDIBits() .
This may help CDibData[^]
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
Thanks Jon..but really, why is it that CreateBitmap doesn't work? I mean based on its documentation it should right?
I'm trying to do this the simple way and I suspect that there is built in functionality to take raw pixel intensity data and create a 8bit grayscale bitmap without explicitly creating a grayscale palette and using the raw pixel data as indices to that palette right?
I mean it seems fairly basic to simply take intensity data that is from 0-255 and drawing that as a grayscale bitmap.
-V
|
|
|
|
|
It has been a long time, but the problem could be as simple as word alignment. The length of each scan line must be divisible by 4. That is, each line must be padded with zeros if it is not already word aligned.
Example: (assuming single-byte per pixel)
wrong_data[2][1] = {
{0x00},
{0xFF}
};
correct_data[2][4] = {
{0x00, 0x00, 0x00, 0x00},
{0xFF, 0x00, 0x00, 0x00}
};
I have not tested the above, but it looks right.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
I always thought I had a good grip on short circuit evaluation for Logical AND and Logical OR but I'm mixing the two and the results are not intuitive. The specification does not suggest the behavior I'm seeing with VC++ 2003 so I thought I'd post the test and results and see if anyone can tell me why "Eval3" never gets evaluated.
void Test()
{
if (Eval1() || Eval2() && Eval3()) {
TRACE("Result = TRUE\n");
} else {
TRACE("Result = FALSE\n");
}
}
BOOL Eval1(void)
{
TRACE("Eval1\n");
return TRUE;
}
BOOL Eval2(void)
{
TRACE("Eval2\n");
return TRUE;
}
BOOL Eval3(void)
{
TRACE("Eval3\n");
return FALSE;
}
Output:
Eval1
Result = TRUE
|
|
|
|
|
rather than worrying about short circuiting, you should pay attention first to precedence.
a || b && c
isn't
(a || b) && c
it is equivalent to
a || (b && c)
When a is true, no need to evaluate b nor c.
The and/or precedence rule is simple, it is very similar to the one for 1 + 2 * 3
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
For some reason I had thought && and || were at the same precedence level and evaluated left to right but what your saying makes sense now that you helped me focus.
thanks for your guidance.
|
|
|
|
|
you're welcome.
PS: when in doubt, add parentheses.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Forget doubt, always use parentheses. Just make it bonehead simple and you never get what you don't expect. And you don't confuse people who are precedence challenged.
The wonderful thing about the Darwin Awards is that everyone wins, especially the members of the audience.
|
|
|
|
|
Luc Pattyn wrote: PS: when in doubt, add parentheses.
Words of wisdom.
Steve
|
|
|
|
|
How can I find how much memory my application is using up programatically? i.e Task Manager
|
|
|
|
|
|
It does not really matter, read this[^].
Watched code never compiles.
|
|
|
|
|
You can use GetProcessMemoryInfo[^] function.
This[^] is MSDN example for the usage of the function.
If you want to find the memory usage of your application only then you can pass GetCurrentProcess[^] as the process handle in order to get the information.
|
|
|
|
|
What I am trying to get at is find (private working set) like it shows on Task Manger per process. GetProcessmemoryInfo gets me workingsetsize which isn't the private. Do you know how I can calculate the private number?
Thanks
modified on Thursday, June 3, 2010 1:21 PM
|
|
|
|
|
Have you seen this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
|
The article was exactly what I am looking for.
Thanks
|
|
|
|
|
Glad to hear that. You're welcome.
|
|
|
|
|
Just reviewing some code...
In it, there is a line like this :
CString s;
//... do something with s.
if ( s.GetLength() > 0 )
{
}
my first reaction was to note that and propose change the GetLength with IsEmpty()
if ( !s.IsEmpty() )
{
}
Looking at the code CString code (VS2008 and VS2010) for IsEmpty() , it calls GetLength() . The generated code will probably be optimized to the same assembly.
Was there a time (I don't have VS2003 or VC6 installed to check) when GetLength and IsEmpty were "really" different ? or they are there for code readbility issue ?
Thanks.
Max.
Watched code never compiles.
|
|
|
|
|
Back when I used MFC in the early 90s IsEmpty was defined in terms ot GetLength .
if( str.IsEmpty() )
{
....
}
can almost be read as english text: "If str is empty..." Compare that with:
if( str.GetLength() == 0 )
{
}
which has to be read as "if str's length is zero" and then translated. There's less of a semantic gap between what's written and it's meaning.
Anyway, sorry about the verbose answer, overly complicated logical expressions are one of my hobby horses - change the code in your review, future generations will thank you for it.
Cheers,
Ash
|
|
|
|
|
Since they both reference the nDataLength member variable, it likely does not matter.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Saying if a text is empty and say how long a text is are two different concepts: the first is simpler (requires an immediate check) than the second (requires to count somehow the data).
So they have two distinct functions.
The fact that the actual implementation keeps track of the length as long as it changes, so that both methods take advantage by a same computation is an "implementation detail" that may vary in future releases.
!GetLength() is semantically the same as IsEmpty() but don't expect they will always do the same computation and result in the same performance.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote: Saying if a text is empty and say how long a text is are two different concepts...
True, but saying if a text is empty and if the text's length is 0 are identical.
emilio_grv wrote: The fact that the actual implementation keeps track of the length as long as it changes, so that both methods take advantage by a same computation is an "implementation detail" that may vary in future releases.
It hasn't since day one and likely won't for the foreseeable future.
emilio_grv wrote: !GetLength() is semantically...
...wrong since GetLength() is not a boolean function and thus should not be treated as such.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|