Re: Writing several images into a single binary file
- From: "[Jongware]" <sorry@xxxxxxxxxxx>
- Date: Thu, 30 Aug 2007 15:45:25 +0200
"Giff" <giffnews@xxxxxxxxxxxxxxxxx> wrote in message
news:46d69af2$1@xxxxxxxxxxxxxxxxxxxxxx
Logan Shaw wrote:
There is no way this can ever possibly work reliably. The pixel data
is arbitrary data and can include any arbitrary sequence of bytes.
OK, I was slowly getting convinced of this too.
I would use a library that already knows how to read and write a standard
image format.
Is there a library that allows you to write several images in the same
file? images with pixels of 32 bits?
But if for some reason you have a compelling reason to invent your own
format, you are already storing the width in pixels of the first image,
so based on that data, you should be able to compute the offset to
the next image without relying on an inherently unreliable method like
looking for newlines.
Well I tried and it didn't work, but I'll give it another try. Would you
suggest to read one image at the time from the file or, instead, read
everything in a single buffer and then extract the images from there? The
total size of the file usually ends up between one and two megabytes.
That total size should not be a problem on any relatively modern system :-)
Have you thought about adding a catalog? That allows you to seek and read
any particular image at will, with only the catalog in main memory.
If you know up front how many images you add, and how many bytes each image
is, it's as easy as:
- write out the number of images first
- for the first image, write out sizeof(int) PLUS num_image * sizeof(int) --
this skips the catalog and gets you the position of the first image.
- for every next image, add the total size of the previous ones.
This creates a catalog which you can use to fseek immediately to the right
position for any image.
If you don't know the number and/or size at first, write at first a random
number. Then add your images (keeping track of each one's position). Note
the end position of the last image, go to the start of your file and
overwrite the number there with the end pos. Add your catalog to the end of
the file.
Using this, you can read the first offset (which points to your catalog),
then seek that catalog and read it.
You can insert any amount of other data between the images, as long as you
remember to write the correct file offset for the images themselves. If you
want to be able to index these random comments as well, use a structure such
as
image {
image_offset
comment_offset
}
per image entry in the catalog.
[Jw]
.
- References:
- Writing several images into a single binary file
- From: Giff
- Re: Writing several images into a single binary file
- From: Logan Shaw
- Re: Writing several images into a single binary file
- From: Giff
- Writing several images into a single binary file
- Prev by Date: Re: Writing several images into a single binary file
- Next by Date: How to make the playlist in embedded wmp plays from given time, not begging?
- Previous by thread: Re: Writing several images into a single binary file
- Next by thread: Re: How to make sure my in-memory db does not flush corrupt page to disk?
- Index(es):