| Re: Unknown data type [message #42119 is a reply to message #42107] |
Tue, 28 December 2004 20:11   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
ed@schmahl.org writes:
> The first line of most image formats (at least the few that I've poked
> into) contains a code that tells you the format of the image. For
> example, a gif file may start off with GIF89, and a jpg file will have
> JFIF in the bytes 5-8. If you can figure out these codes in advance
> for each type of image you are likely to read, you can write a program
> to read the first dozen or so bytes and search for the code, then use
> that information to run the appropriate IDL routine (read_gif,
> read_jpeg, or whatever).
>
> You might even be able to learn how it's done for the 3 web-based
> formats
> (gif, jpg & png) by looking at the freely-available source code for
> Firefox or Mozilla, since these browsers (and any other competent one)
> identify the file type by reading the first several bytes.
Quite a few defined file formats have a "magic number"
that can be read to identify the file type. But, generally,
you know if you have one of these kind of files by the
file extension and you can read them directly with the
appropriate file reading program (READ_JPEG, READ_TIFF, etc.).
Most people who inquire about "how do I read this file
if I don't know what's in it" have been presented with
some kind of one-off file format written by a colleague
who divorced his wife of 25 years and ran off with the
department secretary and didn't leave very good notes
in his office drawer. For that kind of file you either
have to be incredibly clairvoyant or you have to use
some detective skills. But there no "easy way". :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|