|
I dunno how on earth you check if it's HP.
iostream and fstream are the headers you need. Something like ifstream f("c:\whatevr\syslinux.cfg"); then you can read it any way you like ( i.e. use google to find a tutorial on the file streams )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
deeps_cute wrote: i have to check for the machine if its HP machine
.. need an optical scanner to "view" the "HP" logo on the CPU box?
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
yes i need to check it is HP machine or not. is there any function to get this
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
Hello! I get an unhandles exception message when debugging..here is the code. I can't figure out what the problem is.
U8* Yarray =0;
U8* Uarray =0;
U8* Varray =0;
Yarray = (U8*) malloc( W*H );
Uarray = (U8*) malloc( W*H );
Varray = (U8*) malloc( W*H );
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
...
*Yarray++ = Yval;
*Uarray++ = Uval;
*Varray++ = Vval;
}
}
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
U8* Dst = static_cast< U8* >( m_imgImgMap.GetBits() );
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = static_cast< U8 >( *Yarray + (1.4075 * (*Varray - 128)) );
U8 g = static_cast< U8 >( *Yarray - (0.3455 * (*Uarray - 128)) - (0.7169 * (*Varray - 128)) );
U8 b = static_cast< U8 >( *Yarray + (1.7790 * (*Uarray - 128)) );
SET_RGB( Dst, x, y, r, g, b );
*Yarray++;
*Uarray++;
*Varray++;
}
}
pStatus->SetPaneText( 0, _T( "" ) );
fclose (pFile);
free(Yarray); <<unhandled exception="">>
free(Uarray);
free(Varray);
|
|
|
|
|
Try changing this:
Yarray = (U8*) malloc( W*H );
Uarray = (U8*) malloc( W*H );
Varray = (U8*) malloc( W*H );
to this:
Yarray = (U8*)malloc(W*H*sizof(U8));
Uarray = (U8*)malloc(W*H*sizof(U8));
Varray = (U8*)malloc(W*H*sizof(U8));
If you're using C++ you it would be better to use new and delete however. i.e.
Yarray = new U8[W*H];
Uarray = new U8[W*H];
Varray = new U8[W*H];
delete [] Yarray;
delete [] Uarray;
delete [] Varray;
Even better would be to use a std::vector .
Steve
|
|
|
|
|
Thanks for your reply, Steve.
It still gives the exception error..what could be the cause?
Is there any other way besides using vector?
I'd like to code it in c style.
|
|
|
|
|
My earlier suggestion is one problem, however there is another. You must free using the same pointer value returned by malloc .
This code ensures that this doesn't happen (underlined):
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = static_cast< U8 >( *Yarray + (1.4075 * (*Varray - 128)) );
U8 g = static_cast< U8 >( *Yarray - (0.3455 * (*Uarray - 128)) - (0.7169 * (*Varray - 128)) );
U8 b = static_cast< U8 >( *Yarray + (1.7790 * (*Uarray - 128)) );
SET_RGB( Dst, x, y, r, g, b );
*Yarray++;
*Uarray++;
*Varray++;
}
}
Alter your freeing code so it looks like this:
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
free(Yarray);
free(Uarray);
free(Varray);
PS: C sucks. If you used C++ and std::vector s such problems would be far less likely to occur. 'static_cast' is not usable in C.
Steve
|
|
|
|
|
So, did you get it to work?
Steve
|
|
|
|
|
It didn't work, here's the rest of the code.. tried not freeing the arrays and it worked but then eventually, of course, the exception occured after I closed the application.
if ( m_imgImgMap.IsNull() ) {
m_imgImgMap.Create( W, H, 24 );
pDoc->m_img.BitBlt( m_imgImgMap.GetDC(), 0, 0 );
m_imgImgMap.ReleaseDC();
const int iPitch = m_imgImgMap.GetPitch();
U8* pDst = static_cast< U8* >( m_imgImgMap.GetBits() );
U8* Yarray = 0;
U8* Uarray = 0;
U8* Varray = 0;
Yarray = (U8*) malloc(W*H*sizeof(U8));
Uarray = (U8*) malloc(W*H*sizeof(U8));
Varray = (U8*) malloc(W*H*sizeof(U8));
// Yarray = new U8[W*H];
// Uarray = new U8[W*H];
// Varray = new U8[W*H];
FILE * pFile;
int y = 0;
int x = 0;
//convert rgb to YUV
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = GET_R( pDst, x, y );
U8 g = GET_G( pDst, x, y );
U8 b = GET_B( pDst, x, y );
U8 Yval = static_cast< U8 >( r * .299 + g * .587 + b * .114 );
U8 Uval = static_cast< U8 >( r * -.169 + g * -.332 + b * .500 + 128 );
U8 Vval = static_cast< U8 >( r * .500 + g * -.419 + b * -.0813 + 128 );
*Yarray++ = Yval;
*Uarray++ = Uval;
*Varray++ = Vval;
}
}
for ( y = 0; y < H/8; y++ ) {
for ( x = 0; x < W; x+=8 ) {
const short v = g_psSlope[(y)*g_iBW + (x)];
int mag = 0;
if ( 0 < v && v < g_iBokehWidthTh ) {
mag = 1;
} else if ( g_iBokehWidthTh <= v && v < UNKNOWN_MARK ) {
mag = 1;
} else if ( v == UNKNOWN_MARK ) {
mag = 3;
} else {
mag = 3;
}
fprintf (pFile, "%d ", v);
//get block
short buff[64] = {0};
int i,j;
int k = 0;
for ( i=(8*W*y+x) ; i<( 8*(y+1)*W+x ) ; i+=W ){
for ( j=0 ; j<8 ; j++ ){
buff[k] = Yarray[i+j];
k++;
}
}
int i6;
for (i6 = 0; i6 < 63; i6++) {
buff[i6] = (buff[i6]>>mag);
}
//return block
k = 0;
for ( i=(8*W*y+x) ; i<( 8*(y+1)*W+x ) ; i+=W ){
for ( j=0 ; j<8 ; j++ ){
Yarray[i+j] = buff[k];
k++;
}
}
}
csMsg.Format( _T( "Rendering… %d%%" ), static_cast< int >( 100.0 * y / H ) );
pStatus->SetPaneText( 0, csMsg );
}
// convert YUV to RGB
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
U8* Dst = static_cast< U8* >( m_imgImgMap.GetBits() );
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = static_cast< U8 >( *Yarray + (1.4075 * (*Varray - 128)) );
U8 g = static_cast< U8 >( *Yarray - (0.3455 * (*Uarray - 128)) - (0.7169 * (*Varray - 128)) );
U8 b = static_cast< U8 >( *Yarray + (1.7790 * (*Uarray - 128)) );
SET_RGB( Dst, x, y, r, g, b );
*Yarray++;
*Uarray++;
*Varray++;
}
}
pStatus->SetPaneText( 0, _T( "" ) );
fclose (pFile);
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
free(Yarray);
free(Uarray);
free(Varray);
}
|
|
|
|
|
Side step all these issues by caching the initial values and not changing them. i.e.
U8 * const Yarray_org = (U8*)malloc(W*H*sizeof(U8));
U8 * const Uarray_org = (U8*)malloc(W*H*sizeof(U8));
U8 * const Varray_org = (U8*)malloc(W*H*sizeof(U8));
Yarray = Yarray_org;
Uarray = Uarray_org;
Varray = Varray_org;
NOTE: The underlined const s mean that the pointers can't be changed so that any code that attempts to change them from the original values will produce a compiler error.
Any time you have code like this:
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
use this instead:
Yarray = Yarray_org;
Uarray = Uarray_org;
Varray = Varray_org;
Finally free the memory like this:
free(Yarray_org);
free(Uarray_org);
free(Varray_org);
You can drop the following code before the free s:
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
PS: Use std::vector s!!!!!
Steve
|
|
|
|
|
Still doesn't work..not a VC++ bug?
I don't know how to use vectors..
|
|
|
|
|
Can you post the latest code?
Steve
|
|
|
|
|
|
Sorry and thanks for the reminder.
|
|
|
|
|
apoc83 wrote: I'd like to code it in c style
Then why do you use static_cast? =(bla*) should be your way
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
VuNic wrote: hen why do you use static_cast? =(bla*) should be your way
he he he... static_cast<> is not cpp specific !
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
VuNic wrote: Most programmers learn C before C++, and get used to C style casting. When writing C++, sometimes we may be confused about when to use static_cast<> and when to use reinterpret_cast<>. In this article, I will illustrate what static_cast<> actually does, and will show some cases that will lead to errors.
I think i worked very hard last night.. it's time to sleep now
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
LOLL!!! , yeah Obiviously !.. I can see the dark rings around your eyes!
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
Here it is, but shorter:
if ( m_imgImgMap.IsNull() ) {
m_imgImgMap.Create( W, H, 24 );
pDoc->m_img.BitBlt( m_imgImgMap.GetDC(), 0, 0 );
m_imgImgMap.ReleaseDC();
const int iPitch = m_imgImgMap.GetPitch();
U8* pDst = static_cast< U8* >( m_imgImgMap.GetBits() );
U8* Rarray = (U8*)malloc( W*H*sizeof(U8));
U8* Garray = (U8*)malloc( W*H*sizeof(U8));
U8* Barray = (U8*)malloc( W*H*sizeof(U8));
U8 * const Rarray_org = (U8*)malloc(W*H*sizeof(U8));
U8 * const Garray_org = (U8*)malloc(W*H*sizeof(U8));
U8 * const Barray_org = (U8*)malloc(W*H*sizeof(U8));
Rarray = Rarray_org;
Garray = Garray_org;
Barray = Barray_org;
FILE * pFile;
#ifndef NO_FLOAT
pFile = fopen ("slopefloat.txt","w");
#else
pFile = fopen ("slopefixed.txt","w");
#endif
int y = 0;
int x = 0;
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
*Rarray++ = GET_R( pDst, x, y );
*Garray++ = GET_G( pDst, x, y );
*Barray++ = GET_B( pDst, x, y );
}
}
Rarray = Rarray_org;
Garray = Garray_org;
Barray = Barray_org;
int a = 0;
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
const int v = g_psSlope[(y/8)*g_iBW + (x/8)];
double mag = 0;
if ( 0 < v && v < g_iBokehWidthTh ) {
mag = 1;
} else if ( g_iBokehWidthTh <= v && v < UNKNOWN_MARK ) {
mag = .5;
} else if ( v == UNKNOWN_MARK ) {
mag = .10; // 不明
} else { // 平坦
mag = .10;
}
U8 r = static_cast< U8 >( (*Rarray++) * mag );
U8 g = static_cast< U8 >( (*Garray++) * mag );
U8 b = static_cast< U8 >( (*Barray++) * mag );
SET_RGB( pDst, x, y, r, g, b );
}
csMsg.Format( _T( "Rendering… %d%%" ), static_cast< int >( 100.0 * y / H ) );
pStatus->SetPaneText( 0, csMsg );
}
pStatus->SetPaneText( 0, _T( "" ) );
// free(pFile);
// free(Rarray);
// free(Garray);
// free(Barray); ray[i+j] = Ubuff[k];
Varray[i+j] = Vbuff[k];
k++;
}
}
}
csMsg.Format( _T( "Rendering… %d%%" ), static_cast< int >( 100.0 * y / H ) );
pStatus->SetPaneText( 0, csMsg );
}
ray[i+j] = Ubuff[k];
Varray[i+j] = Vbuff[k];
k++;
}
}
}
csMsg.Format( _T( "Rendering… %d%%" ), static_cast< int >( 100.0 * y / H ) );
pStatus->SetPaneText( 0, csMsg );
}
-- modified at 5:02 Wednesday 28th February, 2007
|
|
|
|
|
It worked!
Using this:
U8 * const Yarray_org = (U8*)malloc(W*H*sizeof(U8));
U8 * const Uarray_org const = (U8*)malloc(W*H*sizeof(U8));
U8 * const Varray_org const = (U8*)malloc(W*H*sizeof(U8));
Yarray = Yarray_org;
Uarray = Yarray_org;
Varray = Yarray_org;
everytime I did this:
*Yarray++
This is like Yarray[0], Yarray[1]...
so after incrementing to pointer, I have to
Yarray = Yarray_org; to go back to its base
(pointer) address..is this correct?
|
|
|
|
|
I am trying to retrieve the RGB code of GetPixel() and I have a slight bit of understanding of C++, I'm pretty fluent in Java and VB.net, but the first parameter for the GetPixel function has to be some sort of HDC thing, how would I return it as RGB or hexadecimal, like using it as this: GetPixel(0,50,50); returns a number that is too large for an integer 42929... Can anyone help me?
Please don't write a bunch of classes and constructors and stuff, just simple non-OOP code, best if its just one word, it's less confusing.
Thanks alot.
|
|
|
|
|
It returns a COLORREF (a DWORD in nature!), You must use GetRValue , GetGValue , and GetBValue to extract individual RGB values.
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
Thanks, I sorta understand what you mean, but can you tell me what additional code I need to use it/how to set it up?
|
|
|
|
|
For eg:
BYTE redValue;
BYTE greenValue;
BYTE blueValue;
redValue = GetRValue(GetPixel(hdc,50,50));
greenalue = GetGValue(GetPixel(hdc,50,50));
blueValue = GetBValue(GetPixel(hdc,50,50));
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|