Click here to Skip to main content
15,892,674 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to make an MDI child wnd like Model dlg? Pin
jhwurmbach7-Apr-06 4:00
jhwurmbach7-Apr-06 4:00 
QuestionRename Variables Add-in Pin
fxam7-Apr-06 3:38
fxam7-Apr-06 3:38 
AnswerRe: Rename Variables Add-in Pin
toxcct7-Apr-06 3:43
toxcct7-Apr-06 3:43 
AnswerYes, at least one I know of Pin
jhwurmbach7-Apr-06 3:57
jhwurmbach7-Apr-06 3:57 
QuestionFinding my way in NYC Pin
alex__b7-Apr-06 3:19
professionalalex__b7-Apr-06 3:19 
AnswerRe: Finding my way in NYC Pin
Ravi Bhavnani7-Apr-06 7:05
professionalRavi Bhavnani7-Apr-06 7:05 
GeneralRe: Finding my way in NYC Pin
alex__b7-Apr-06 21:20
professionalalex__b7-Apr-06 21:20 
QuestionPGM image format - buffer vs file Pin
georgie.moss7-Apr-06 2:38
georgie.moss7-Apr-06 2:38 
Hi - I don't usually like to post questions which are "here's some code - why doesn't it work?" but I am well and truly stumped on this one...it's been more than a whole day's effort so far and it is 1025 on friday night and i'm still working on it....so i'd really appreciate some help...

I have two functions, one takes a buffer, turns it into PGM format (P6) and saves it to file....the other takes the buffer, turns it into PGM format in place and the calling function then returns the buffer and it is displayed

the saving to file one works a treat
<code>
/*
* writes a colour PGM file from a buffer
*/</code>

<code>
int write_P6(char *name, int W, int H, unsigned char *buf)
{
FILE *f;
int i, j;

if( (f = fopen(name, "w")) == NULL)
{
printf("Could not open >%s<\n", name);
return FALSE;
}

fprintf(f,"P6\n %d %d\n 255\n",W, H);
fflush(f);

for(i=0;i<H;i++)
{
for(j=0;j<W;j++)
{
fwrite(buf + (i * W + j)*3+2, 1, 1, f);
fwrite(buf + (i * W + j)*3+1, 1, 1, f);
fwrite(buf + (i * W + j)*3 , 1, 1, f);
}
}
fclose(f);

return TRUE;
}
</code>


and I am able to display the images just fine, but obviously this is sub-optimal and the disk accesses makes it real slow

so i want to use this function instead
<code>
/*********************************************************************/
/*
* changes a rgb buffer in place into PGM format without saving to disk
*/



int make_P6(int W, int H, unsigned char *buf)
{
int i, j;
unsigned char* temp;
temp = (unsigned char*)malloc(x * y *3+15);

sprintf(temp, "P6\n %d %d\n 255\n",W, H);
for(i=0;i<H;i++)
{
for(j=0;j<W;j++)
{
sprintf(temp, buf + (i * W + j)*3+2);
sprintf(temp, buf + (i * W + j)*3+1);
sprintf(temp, buf + (i * W + j)*3);
}
}
buf = (unsigned char*)realloc(buf, x * y *3+15);
buf = temp;
free(temp);
return TRUE;
}
</code>
the calling getframe function looks kinda like this:
<code>
unsigned char * getframe(int save_file)
{
int ret ;

ret = read(fd1, s, x * y);
if( ret != (x * y ) )
{
printf("We will have fragmented picture\n" );
}
nb_frame ++ ;
bayer2rgb24(d, s, x, y);

// at this point we should have a raw, RGB image
if( save_file )
{
write_P6("P6.pgm", x, y, d);
}
else
{
d = make_P6(x,y,d);
}

return d;
}
</code>
and the function which calls getframe knows whether to disregard the return value and open the file, or look at the return value for the pic....


now the problem comes in make_P6 --> the code just hangs at

<code> sprintf(temp, buf + (i * W + j)*3+2);
sprintf(temp, buf + (i * W + j)*3+1);
sprintf(temp, buf + (i * W + j)*3);</code>

- if i comment out these lines, there is no freeze (but clearly, nothing sensible happens to the image)....but if i leave them there, it just kinda waits....doing nothing....not crashing.....not taking up heaps of resources

it doesn't make any sense to me because the line
<code>sprintf(temp, "P6\n %d %d\n 255\n",W, H);</code>
works just fine....

i'll be eternally grateful if somebody can give me a hand
XX georgia Blush | :O


-- modified at 8:40 Friday 7th April, 2006
QuestionRe: PGM image format - buffer vs file Pin
David Crow7-Apr-06 2:51
David Crow7-Apr-06 2:51 
AnswerRe: PGM image format - buffer vs file Pin
James R. Twine7-Apr-06 3:18
James R. Twine7-Apr-06 3:18 
GeneralRe: PGM image format - buffer vs file Pin
georgie.moss10-Apr-06 14:45
georgie.moss10-Apr-06 14:45 
QuestionStatus Bar Problem Pin
si_697-Apr-06 1:56
si_697-Apr-06 1:56 
AnswerRe: Status Bar Problem Pin
James R. Twine7-Apr-06 2:02
James R. Twine7-Apr-06 2:02 
QuestionA CString question Pin
<color>Aljechin 7-Apr-06 1:29
<color>Aljechin 7-Apr-06 1:29 
AnswerRe: A CString question Pin
si_697-Apr-06 1:31
si_697-Apr-06 1:31 
GeneralRe: A CString question Pin
Ștefan-Mihai MOGA7-Apr-06 1:35
professionalȘtefan-Mihai MOGA7-Apr-06 1:35 
GeneralRe: A CString question Pin
toxcct7-Apr-06 2:22
toxcct7-Apr-06 2:22 
JokeRe: A CString question Pin
jhwurmbach7-Apr-06 2:29
jhwurmbach7-Apr-06 2:29 
GeneralRe: A CString question Pin
toxcct7-Apr-06 2:55
toxcct7-Apr-06 2:55 
AnswerRe: A CString question Pin
Cedric Moonen7-Apr-06 1:38
Cedric Moonen7-Apr-06 1:38 
GeneralRe: A CString question Pin
<color>Aljechin 7-Apr-06 1:48
<color>Aljechin 7-Apr-06 1:48 
AnswerRe: A CString question Pin
James R. Twine7-Apr-06 1:57
James R. Twine7-Apr-06 1:57 
GeneralRe: A CString question Pin
<color>Aljechin 7-Apr-06 2:00
<color>Aljechin 7-Apr-06 2:00 
GeneralRe: A CString question Pin
Cedric Moonen7-Apr-06 1:58
Cedric Moonen7-Apr-06 1:58 
GeneralRe: A CString question Pin
Roger Stoltz7-Apr-06 1:59
Roger Stoltz7-Apr-06 1:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.