BlockRead 
Author Message
 BlockRead

Hello,

I have a little problem with using the commando Blockread:

I write multiple images in one file using Blockwrite, first I adress the
size off the
first image by writing x size(2 bytes),y size(2 bytes) and then write the
image's x*y coords. to the file. After that, I calculate the size off the
second image by doing that all over again + the size off the previous
calculated image, and use Blockwrite again to save it to the file. When it
is finished the written file is the correct size (the sum off the all
image's size's). But when I want to read the images from that file I only
manage to read the first image from it (I first read the first 4 bytes wich
tell the x,y dim. and then read that size from the file and put that data in
a pointer).
Could anyone tell me if there's a better aproach to this or what I do wrong?

Thanks.



Wed, 18 Jun 1902 08:00:00 GMT  
 BlockRead

Quote:

> Hello,

> I have a little problem with using the commando Blockread:

> I write multiple images in one file using Blockwrite, first I adress the
> size off the
> first image by writing x size(2 bytes),y size(2 bytes) and then write the
> image's x*y coords. to the file. After that, I calculate the size off the
> second image by doing that all over again + the size off the previous
> calculated image, and use Blockwrite again to save it to the file. When it
> is finished the written file is the correct size (the sum off the all
> image's size's). But when I want to read the images from that file I only
> manage to read the first image from it (I first read the first 4 bytes wich
> tell the x,y dim. and then read that size from the file and put that data in
> a pointer).
> Could anyone tell me if there's a better aproach to this or what I do wrong?

> Thanks.

If you'd append your code it be easier to see what is wrong.

Something like this should work:

assign(f,'pics.dat');
rewrite(f,1);
for tt=1 to num_pics do
begin
  blockwrite(pic_xsize[tt],sizeof(integer));
  blockwrite(pic_ysize[tt],sizeof(integer));
  blockwrite(pic_data^[tt],pic_xsize[tt]*pic_ysize[tt]);
end;
close(f);

assuming you are writing one byte per pixel and pic_data[tt] is an array
(in which case here all the images will have the same size but it's just to get
an idea).

Ajeto!

Remco
http://www.xs4all.nl/~remcodek/program.html



Wed, 18 Jun 1902 08:00:00 GMT  
 BlockRead


Quote:
>Hello,

>I have a little problem with using the commando Blockread:

>I write multiple images in one file using Blockwrite, first I adress the
>size off the
>first image by writing x size(2 bytes),y size(2 bytes) and then write the
>image's x*y coords. to the file. After that, I calculate the size off the
>second image by doing that all over again + the size off the previous
>calculated image, and use Blockwrite again to save it to the file. When it
>is finished the written file is the correct size (the sum off the all
>image's size's). But when I want to read the images from that file I only
>manage to read the first image from it (I first read the first 4 bytes wich
>tell the x,y dim. and then read that size from the file and put that data in
>a pointer).

Now why is it that you manage only read the first image????? Code?

Quote:
>Could anyone tell me if there's a better aproach to this or what I do wrong?

A smarter way would be to keep a separate directory. The directory could
hold for example the the dimensions and the starting position
in the file for each image. Then you would just read the directory and
use that to seek and access the file. You can put the directory at the
beginning of the file.

Block read is a raw disk read. Basically every time you do blockread
the disk head moves (though caching can prevent that) so you should avoid
doing blockread with small arguments. It is better to do large reads to
a temporary buffer and move the data from there. Or construct your data
structures so that you do not need to do small reads and writes.

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 BlockRead

Quote:

>   blockwrite(pic_xsize[tt],sizeof(integer));

  Should that be

  blockwrite(f, pic_xsize[tt],sizeof(integer));  ?
             ^

        - Bob



Wed, 18 Jun 1902 08:00:00 GMT  
 BlockRead

Quote:


> >   blockwrite(pic_xsize[tt],sizeof(integer));

>   Should that be

>   blockwrite(f, pic_xsize[tt],sizeof(integer));  ?
>              ^

>         - Bob

YEP!
I knew it would go wrong if I typed it just like that in a message.

Remco
http://www.xs4all.nl/~remcodek/



Wed, 18 Jun 1902 08:00:00 GMT  
 BlockRead

Quote:
>I knew it would go wrong if I typed it just like that in a message.

So why did you? (c;

/GreenGhost



Wed, 18 Jun 1902 08:00:00 GMT  
 BlockRead

Quote:

> >I knew it would go wrong if I typed it just like that in a message.

> So why did you? (c;

> /GreenGhost

I'll try to never do it again, you funny you.


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. error 200 on blockread (w/ patched tpl files)

2. Blockread/Blockwrite question.

3. Blockread/Blockwrite question

4. BLOCKREAD&BLOCKWRITE?

5. Q : Help with fpk and blockread

6. help need with BlockRead

7. Urgent help needed with GFx mode and BlockRead/BlockWrite

8. Correct use of BlockRead or alternative loading approach

9. blockread and JAVA

10. Blockread/write, how fast?

11. blockread/blockwrite

12. Help with BlockRead

 

 
Powered by phpBB® Forum Software