Mail Archives: djgpp/1998/06/24/01:46:10
I have few suggestions & a question
>In the following code, when I attemp to load a 24bit, 320*200 file and place
>on the screen it returns after puting only about 750 pixles. Also I know
>this because if I skip the eof() test it will make 90% of the screen white.
>(could be lightest gray). The file that I am loading is one saved by PSP 4
>in the RAW format ( 24bit, ordered, not flipped RRGBRGBR...)
>
>Any help would be greatly preciated :-)
>
>#include <fstream.h>
>
>void Raw::Load(char * Name, int dx = 320, int dy = 200, int tx=0, int ty=0)
>{
> char r,g,b,rgb;
use a buffer to get your data & convert when put in the buffer
do this instead(may be faster)
you know that a 320x200 image is the input so all you need is
a counter & a buffer
You should also get the file size to check it against what you
read in( but you have to include <io.h>
unsigned int counter, filesize;
char *buff = new (sizeof(char) * (320 * 200));
>
> ifstream temp(Name);
>
> if(!temp) exit(3);
I think this should be
if(temp.fail()) // temp.fail() returns true if the last stream
// failed
{
cout << "Could not open file\n";
exit(3);
}
filesize = filelength(temp.filedesc());
>
> for(int ly = 0; ly < dy; ly++)
> {
> for(int lx = 0; lx < dx; lx++)
> {
> if(temp.eof()) return;
>
> r=temp.get();
> g=temp.get();
> b=temp.get();
>
>
> r=(r>>5);
> g=(g>>5);
> b=(b>>6);
>
>
> rgb= (r<<5)+(g<<2)+b;
>
You could this in a while or a for loops instead of nested
loops
counter = 0;
while( (counter < 0xFA00) && !(temp.eof()) )
{
// I dont know why you do all the shifting
// as I dont see it giving you a pallete
// index which you need set a pixel
buff[counter] = ((temp.get() >> 5) << 5) +
((temp.get() >> 5) << 2) +
(temp.get() >> 6);
// here you check against the file's size
filesize -= 3;
PutPixel(buff[counter], counter % 320, counter / 320)
}
// here you check to see if you read the entire file
if(filesize > 0)
{
cout << "File not entirely read\n";
exit(3);
}
temp.close
}
***BTW***
Are you either the Daniel Urquhart that works at CDC or the one goes
to Washington High?
> PutPixel(rgb,lx+tx,ly+ty);
>}
> }
>
> temp.close();
>}
>
>
> webmaster donations delorie software
> Copyright © 1998 by DJ Delorie Updated Jun 10 1998
>
> Powered by Apache!
>
> You can help support this site by visiting the advertisers that
> sponsor it!
- Raw text -