Dec 132017
 
Multimedia GRASP source to extract GIF comments into a variable.
File GIFCOM.ZIP from The Programmer’s Corner in
Category Graphic Animations
Multimedia GRASP source to extract GIF comments into a variable.
File Name File Size Zip Size Zip Type
GIFCOM.TXT 2983 980 deflated
TPCREAD.ME 199 165 deflated

Download File GIFCOM.ZIP Here

Contents of the GIFCOM.TXT file


; Demo program written in MMGrasp 1.0 to read comments from a GIF file
; and put in a variable

set wrap on
local my_image f1.gif
global gifcmt ""; the variable which will contain the comment

read_comment @my_image

if @0
text "
ERROR "[email protected]

waitkey
else
text "
SUCCESS

"
endif

text @gifcmt

waitkey
exit


;===================================================================
; read_comment:
;
; reads single GIF Comment and puts it in a global variable "GIFCMT"
; traps most errors which might be encountered. No guarantees.
; Has received limited testing. Any comments, suggestions, to
;Marc Reinig CIS 72410,77
; ERRORS: 1-GIF data error; 2-Read error; 3-Not a GIF file; 4-Open error

read_comment:

local IOBUFSIZE 257 ;
local gifin 0
local COMMA 0x2C ; image id
local BANG 0x21 ; extension
local SEMICOLON 0x3B; terminator
local ERROR 0
local bufptr 0

local gifname @1
alloc iobuf @IOBUFSIZE

set gifin open(@gifname)
if @gifin==0
return 4
endif
read_header @gifname
if @error end1

show_comments
if @error end1
end1:
free iobuf
set junk close(@gifin)
return @ERROR


read_header:
local colors 0

set bufptr read(@gifin,@iobuf,3)
if @bufptr<>3
set ERROR 2
return
else
if @@iobuf<>"GIF"
set ERROR 3
return
endif
endif
set bufptr read(@gifin,@iobuf,10)
if @bufptr<>10
set ERROR 2
return
else
set tmp peek(@iobuf+7)
if @tmp&0x80
set colors 1<<(((peek(@iobuf+7))&(0x07))+1)
realloc iobuf 3*@colors
set bufptr read(@gifin,@iobuf,3*@colors)
if @bufptr<>3*@colors
set ERROR 2
return
endif
else
set colors 2
endif
endif
return



do_comment:
local count 0
skip1:
set bufptr read(@gifin,@iobuf,1)
if @bufptr<>1
set ERROR 2
return
endif
set count peek(@iobuf)
if @count==0
return
endif
realloc iobuf @count
set bufptr read(@gifin,@iobuf,@count)
if @bufptr<>@count
set ERROR 2
return
endif
set gifcmt @[email protected]@iobuf
goto skip1
return


skip_blocks:
realloc iobuf 257
local count 0
skip:
set bufptr read(@gifin,@iobuf,1)
set count peek(@iobuf)
if @count==0
return
endif
set bufptr read(@gifin,@iobuf,@count)
if @bufptr<>@count
set ERROR 2
return
endif
goto skip
return


show_comments:
local c ""
while:
set bufptr read(@gifin,@iobuf,1)
if @bufptr<>1; EOF
return
endif

set c peek(@iobuf)
if @c<>@SEMICOLON
if @[email protected]; image
set bufptr read(@gifin,@iobuf,10)
if @bufptr<>10
Set ERROR 2
return
endif
skip_blocks
else if @[email protected]
set bufptr read(@gifin,@iobuf,1)
if @bufptr<>1
Set ERROR 2
return
endif
set c peek(@iobuf)
if @c==0xFE
do_comment
else
skip_blocks
endif
else
set ERROR 1
return
endif
if @ERROR
Return
endif
endif
goto while
return



 December 13, 2017  Add comments

Leave a Reply