home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Graphics
/
Graphics.zip
/
gif_info.zip
/
gif_info.doc
< prev
Wrap
Text File
|
1998-02-03
|
12KB
|
311 lines
3 Feb 1998:
Author: Daniel Hellerstein danielh@econ.ag.gov
GIF_INFO: A REXX procedure for extracting information from GIF files.
GIF_INFO is an OS/2 REXX procedure that will extract information from a GIF file.
This information includes the height, width and color table information for
the "global" image as well as for each (of possibly several) images in
an animated GIF file. GIF_INFO can also be used to extract comments, "application
blocks", and "plain text" blocks from GIF files.
GIF_INFO is freeware; with the usual "use at your own risk" disclaimer (see
below for the details).
---------------------------
Usage:
stuff=GIF_INFO(gif_file,infotype,imgnum,idmess)
Parameters:
gif_file: A fully qualified file name.
OR
A string containing the contents of a gif_file
infotype: Type of information to extract
imgnum: Selects nth image
idmess: If specified, then GIF_FILE contains the contents of a gif_File
with a name of idmess. If not specified, GIF_FILE is a file name.
In the former case, idmess should have no embedded spaces.
Returns:
Depends on the value of infotype.
---------------------------
Description of INFOTYPE:
INFOTYPE='' or INFOTYPE='S', IMGNUM is ignored
Write a report to stdout. Returns a value of 1.
INFOTYPE='BASIC', IMGNUM=0 or IMGNUM=''
Return basic image info in a space delimited list.
i)If no such file, return ''
ii)If not a GIF file, return: fully_qualified_filename -1
iii) Otherwise,return:
fqn #_imgs #_cmts #_apps #_ptext img_wd img_ht img_ct
where;
fqn : the fully qualified name of the gif file
#_imgs : the number of images
#cmts : the number of comment blocks
#_apps : the number of application control blocks
#_ptext : the number of plain text blocks
img_wd and img_ht : "global" width and height
img_ct : # of colors in the global color table;
or 0, if (rarely)no global color table specified
INFOTYPE='BASIC', IMGNUM=nn (nn>0)
Return basic info on image # nn
i) If no such file, return ''
ii) If not a GIF file, return: fqn -1
iii) If fewer then nn images, return: fqn -2
iv) Otherwise, return:
fqn wd ht tc_index delay int_flag ct
where;
fqn : same as above
tc_index : transparent color index (-1 if not specified)
wd, ht : width and height of this image
ct : # of colors for this image's own color table.
This is typically equal to 0; which means "use
global color table"
delay: Delay in 1/100ths seconds (-1 means not specified)
int_flag : 1 if interlaced image
INFOTYPE='IMAGE', IMGNUM=nn
Return the nn'th image.
i) If no such file, return: ''
ii) If not a GIF file, return: fully_qualified_filename -1
iii) If no such image (i.e.; nn># of images), return:
fully_qualified_filename -2
iv) Otherwise, return:
fqn wd ht tc_index delay int_flag ct jbytes,image_data
where the values are as specified above, with;
jbytes: byte size of compressed data
image_data: "jbytes" of image data; compressed.
Note the use of a comma after the jbyte value.
Immediately following this comma will be the jbytes of the image data.
This is not the raw image, you'll have to lzw decompress it.
INFOTYPE='TABLE', IMGNUM=0 or IMGNUM=''
Return the 3 * img_ct elements of the global color table.
i) If no such file, return: ''
ii) If not a GIF file, return: fully_qualified_filename -1
iii) Otherwise, return:
fqn img_ct,color_table_data
where;
fqn and img_ct: defined above
ct_data: The color table data; arranged Red0,Green0,Blue0,Red1,
...,Blue255 (1 byte per value). Note that it immediately
follows a comma.
INFOTYPE='TABLE', IMGNUM=nn; nn>0
Return the 3 * img_ct elements of the local color table for image nn
i) If no such file, return: ''
ii) If not a GIF file, return: fully_qualified_filename -1
iii) If no such image (i.e.; nn># of images), return:
fully_qualified_filename -2
iv) Otherwise, return:
fqn ct,color_table_data
where;
fqn and img_ct:defined above (ct is the "number of colors in the
local color table"
ct_data: The color table data; arranged Red0,Green0,Blue0,Red1,
...,Blue255 (1 byte per value). Note that it
immediately follows a comma.
Typically, ct_data will be 0.
INFOTYPE='COMMENT, IMGNUM=nn; nn>0
Return the nn'th comment.
i) If no such gif_file, return: ''
ii) If not a GIF file, return: fully_qualified_filename -1
iii) If no such image (i.e.; nn># of images), return:
fully_qualified_filename -2
iv) Otherwise, return:
fqn jbytes,comment
where;
fqn and jbytes: defined above
comment: The comment. Note that it immediately follows a comma.
Comments are usually straight (7 bit) ascii text.
INFOTYPE='PLAINTEXT', IMGNUM=nn; nn>0
Return the nn'th Plaintext block
i) If no such gif_file, return: ''
ii) If not a GIF file, return: fully_qualified_filename -1
iii) If no such image (i.e.; nn># of images), return:
fully_qualified_filename -2
iv) Otherwise, return:
fqn pt_left pt_top pt_width pt_height jbytes,ptext
where;
fqn and jbytes: defined above
pt_left: left corner
pt_top: top corner
pt_width: width of text block (in pixels)
pt_height: height of text block (in pixels)
ptext: The Plaintext message. Note that it immediately follows
a comma.
Plaintext are usually straight (7 bit) ascii text. They are rarely
used.
INFOTYPE='APP', IMGNUM=nn; nn>0
Return the nn'th Application block
i) If no such gif_file, return: ''
ii) If not a GIF file, return: fully_qualified_filename -1
iii) If no such image (i.e.; nn># of images), return:
fully_qualified_filename -2
iv) Otherwise, return:
fqn,app_id app_auth,jbytes,appdata
where;
fqn and jbytes: defined above
app_id: 8 bytes naming the application
app_auth: 3 byte application authorization code
appdata: Data meant for the application. Note that appdata follows a comma.
Note that app_id is always 8 bytes, and app_auth is always 3 bytes. Also
note that a comma appears just BEFORE app_id, and just AFTER app_auth.
---------------------------
Errors:
Error codes are returned when a bad .GIF file is encountered.
The return has the form:
ERROR n
where n can be:
0 : Unrecognized "INFOTYPE" parameter
-1 : Bad Extension label
-2 : Bad Descriptor label
-3 : Error in application block
-33 : Overrun reading Application block data
-4 : Error in plain text block
-44 : Overrun reading Plain Text block data
-6 : Overrun reading Image Descriptor data
-7 : Overrun reading Comment data
-8 : Bad terminator in Graphics control block
Note that errors need not occur in a "relevant" block. For example, if plaintext
block #1 precedes image #2, and this plaintext block is corrupted, then
an error will occur (even though you may not care about the contents of
this plaintext block). This stringency is motivated by the sequential structure
of .GIF files; where corruption of one part may degrade the entire
remaining portions.
---------------------------
Notes:
* For gif89a specs, please see http://member.aol.com/royalef/gif89a.txt
* Remember that data values are typically preceded by a comma -- the
actual data begins immediately after this comma (that is, there are no
intervening spaces).
* If you use the "string" mode of GIF_INFO, gif_text must be a verbatim
.GIF file; say, as read with:
gif_file=charin(afile,1,chars(afile))
* As noted, the IMAGE data returned is compressed. If someone would like to
provide some LZW decompression code (and GIF has a few variants of that),
I'll be happy to include it (remember, this is freeware, so the copyright
stuff should not be problem).
---------------------------
Sample Program:
You can use this to extract information from one (or several) .GIF files. Just
be sure that GIF_INFO.CMD is in the same directory.
/***************************************************/
/* Sample program that uses GIF_INFO.CMD to retrieve information from a gif file */
parse arg gfile
if gfile='' then do
call charout," Enter gif file name: "; parse pull gfile
END
if pos('.',gfile)=0 then gfile=gfile'.gif'
/* just show Basic info on lots of .gif files */
if pos('*',gfile)>0 then do
aa=sysfiletree(gfile,oys,'FO')
do mm=1 to oys.0
agfile=oys.mm
aa=gif_info(agfile)
if aa<0 then say " Error; code= " a
call charout,' (hit enter to get next file )';parse pull .
end /* do */
exit
end /* do */
/* single image retrieval -- multiple rounds of info*/
a=stream(gfile,'c','query exists')
if a='' then do
say " no such file "gfile
exit
end /* do */
gg=charin(gfile,1,chars(gfile))
oo=stream(gfile,'c','close')
do forever
call charout," Enter info type (S,B,I,T,C,P,A,X to exit): " ; pull atype
if atype='X' then exit
call charout," Enter image # (or 0 for image info): " ; parse pull aval
oo=gif_info(gg,atype,aval,gfile)
say "Result= " oo
say
end
---------------------------
Basic copyright and it's never our fault disclaimer:
Copyright 1998 by Daniel Hellerstein. Permission to use this program
for any purpose is hereby granted without fee, provided that
the author's name not be used in advertising or publicity
pertaining to distribution of the software without specific written
prior permision.
This includes the right to subset and reuse the code, with proper attribution,
and subject to the proviso:
We, the authors of GIF_INFO and any potentially affiliated institutions,
disclaim any and all liability for damages due to the use, misuse, or
failure of the product or subsets of the product.
THIS SOFTWARE PACKAGE IS PROVIDED "AS IS" WITHOUT EXPRESS
OR IMPLIED WARRANTY.
THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE PACKAGE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL THE AUTHOR (Daniel Hellerstein) OR ANY PERSON OR
INSTITUTION ASSOCIATED WITH THIS PRODUCT BE LIABLE FOR ANY
SPECIAL,INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT,NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE PACKAGE.
GIF_INFO was developed on the personal time of Daniel Hellerstein,
and is not supported, approved, or in any way an official product
of my employer (USDA/ERS).